What is the difference between unit.TypeXXXX.UnitGlobalDisabled() and .Permission.CanRead #10302

Closed
opened 2025-11-02 09:03:40 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @yp05327 on GitHub (Feb 20, 2023).

Feature Description

When I was reviewing the changes in my PR https://github.com/go-gitea/gitea/pull/22705,
I found something strange: why UnitPackagesGlobalDisabled here?
https://github.com/go-gitea/gitea/pull/22705/files#diff-8020089c79cc846f287e738cf57917d21ec16499df1d994e6c31309d06a1a5afL28

Then I searched UnitPackagesGlobalDisabled, it is not existed.
So what about UnitProjectsGlobalDisabled?
I found it in here.
7d3c4c3e8a/modules/context/context.go (L783)

The next question is why we didn't define UnitPackagesGlobalDisabled here. If it is not defined, how do we controll this unit's visibility in repo's header?
Then I checked the codes in repo's header:
b811ab48e5/templates/repo/header.tmpl (L156-L229)
Almost of them use .Permission.CanRead to check the visibility, but some of them also use UnitXXXXXXGlobalDisabled. The definition is:
b811ab48e5/modules/context/context.go (L783)


And at someplaces, I found we also use settings.UnitName.Enabled
e.g.
3596df52c0/modules/context/org.go (L159)
It seems that UnitXXXXXXGlobalDisabled and the permission model is used for repo units,
and we have no permission model for user/org level packages/projects, so settings are used directly here.


Then the next question is what is the difference between them?
Im not familiar with go, and I don't understand how the permission model works now.
Maybe I asked a stupid question, but I want to make sure my PR's codes are correct.


Then I changed the app.ini, to disable Packages, it worked. It seems that .Permission.CanRead is correct.
Then I found DEFAULT_REPO_UNITS and DISABLED_REPO_UNITS in the document. It seems that we can control the repo unit by this setting option. I think maybe UnitXXXXXXGlobalDisabled is related to it?

Then I disabled Package and Projects, restart the server, but it didn't work, I can still access them.
Then I searched DISABLED_REPO_UNITS, and no record in any go files.
So I created this issue https://github.com/go-gitea/gitea/issues/23001

I made a mistake in setting the vaule of DISABLED_REPO_UNITS, but no warning or error info. Maybe we can add it. -> https://github.com/go-gitea/gitea/pull/23024


Screenshots

No response

Originally created by @yp05327 on GitHub (Feb 20, 2023). ### Feature Description When I was reviewing the changes in my PR https://github.com/go-gitea/gitea/pull/22705, I found something strange: why `UnitPackagesGlobalDisabled` here? https://github.com/go-gitea/gitea/pull/22705/files#diff-8020089c79cc846f287e738cf57917d21ec16499df1d994e6c31309d06a1a5afL28 Then I searched `UnitPackagesGlobalDisabled`, it is not existed. So what about `UnitProjectsGlobalDisabled`? I found it in here. https://github.com/go-gitea/gitea/blob/7d3c4c3e8a7b3bf505e3115cbf05b8bb7029a7e8/modules/context/context.go#L783 The next question is why we didn't define `UnitPackagesGlobalDisabled` here. If it is not defined, how do we controll this unit's visibility in repo's header? Then I checked the codes in repo's header: https://github.com/go-gitea/gitea/blob/b811ab48e513a5b98edb935e0c63e76233ee1783/templates/repo/header.tmpl#L156-L229 Almost of them use `.Permission.CanRead` to check the visibility, but some of them also use `UnitXXXXXXGlobalDisabled`. The definition is: https://github.com/go-gitea/gitea/blob/b811ab48e513a5b98edb935e0c63e76233ee1783/modules/context/context.go#L783 ---- And at someplaces, I found we also use `settings.UnitName.Enabled` e.g. https://github.com/go-gitea/gitea/blob/3596df52c09831f7f39f8416264ff267954f35a0/modules/context/org.go#L159 It seems that `UnitXXXXXXGlobalDisabled` and the permission model is used for repo units, and we have no permission model for user/org level packages/projects, so `settings` are used directly here. ---- Then the next question is what is the difference between them? Im not familiar with go, and I don't understand how the permission model works now. Maybe I asked a stupid question, but I want to make sure my PR's codes are correct. ---- Then I changed the app.ini, to disable `Packages`, it worked. It seems that `.Permission.CanRead` is correct. Then I found `DEFAULT_REPO_UNITS` and `DISABLED_REPO_UNITS` in the [document](https://docs.gitea.io/en-us/config-cheat-sheet/#repository-repository). It seems that we can control the repo unit by this setting option. I think maybe `UnitXXXXXXGlobalDisabled` is related to it? ~~Then I disabled `Package` and `Projects`, restart the server, but it didn't work, I can still access them. Then I searched `DISABLED_REPO_UNITS`, and no record in any go files. So I created this issue https://github.com/go-gitea/gitea/issues/23001~~ I made a mistake in setting the vaule of `DISABLED_REPO_UNITS`, but no warning or error info. Maybe we can add it. -> https://github.com/go-gitea/gitea/pull/23024 ---- ### Screenshots _No response_
GiteaMirror added the type/proposaltype/feature labels 2025-11-02 09:03:40 -06:00
Author
Owner

@yp05327 commented on GitHub (Feb 21, 2023):

unit.TypeProjects.UnitGlobalDisabled() checks whether repo.projects is listed in DISABLED_REPO_UNITS
I removed UnitProjectsGlobalDisabled here, and it also worked with only .Permission.CanRead
b811ab48e5/templates/repo/header.tmpl (L201)

It seems that UnitXXXXXXDisabled (unit.TypeXXXXXX.UnitGlobalDisabled()) is not necessary, since we can use .Permission.CanRead.

@yp05327 commented on GitHub (Feb 21, 2023): `unit.TypeProjects.UnitGlobalDisabled()` checks whether `repo.projects` is listed in `DISABLED_REPO_UNITS` I removed `UnitProjectsGlobalDisabled` here, and it also worked with only `.Permission.CanRead` https://github.com/go-gitea/gitea/blob/b811ab48e513a5b98edb935e0c63e76233ee1783/templates/repo/header.tmpl#L201 It seems that `UnitXXXXXXDisabled` (unit.TypeXXXXXX.UnitGlobalDisabled()) is not necessary, since we can use `.Permission.CanRead`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#10302