Skip to content

UI preventing org repo creation as well if user org limit is reached #30011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DrMaxNix opened this issue Mar 22, 2024 · 4 comments · Fixed by #34147
Closed

UI preventing org repo creation as well if user org limit is reached #30011

DrMaxNix opened this issue Mar 22, 2024 · 4 comments · Fixed by #34147
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.
Milestone

Comments

@DrMaxNix
Copy link
Contributor

DrMaxNix commented Mar 22, 2024

Scenario

  • On our instance we have MAX_CREATION_LIMIT = 0 to prevent random new users from spamming our instance
  • There is an org which has a few members, which is being used for a collaborative project. These members should only be able to create repos inside this org, but not under their user account.
  • Users have been put into a team Dev which has Create repositories enabled

Problem

  • On the repo create page, the submit button Create Repository is disabled in case CanCreateRepo == false:
    <button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
  • CanCreateRepo checks whether the user already has too many personal repos:

    gitea/models/user/user.go

    Lines 240 to 251 in 5c91d79

    func (u *User) CanCreateRepo() bool {
    if u.IsAdmin {
    return true
    }
    if u.MaxRepoCreation <= -1 {
    if setting.Repository.MaxCreationLimit <= -1 {
    return true
    }
    return u.NumRepos < setting.Repository.MaxCreationLimit
    }
    return u.NumRepos < u.MaxRepoCreation
    }
  • But the submit button will be disabled for all available repo owners; Personal and also Orgs!
  • This means the UI will not allow users to create org repos even though they have the Create repositories permission in their org!
  • EDIT: This problem also affects repos which are created from migrations (this however is a backend issue!)

Solutions

  • This is only a UI bug, the backend validation works as expected (I have tested this by removing the previously mentioned disable check from the template to force the button to be always enabled)
  • The CanCreateRepo value should only influence creation of a personal repo
  • Repo limit of the org is only checked after the form is submitted, this would be a good quick-fix for this issue (removing the disabled button check and the error banner from the template)
  • For a long term solution we could hide the personal user account in the owners list the same way orgs are hidden when their limit is reached. This would make the disabled submit button and the banner completely obsolete, as the user is forced to select an owner that is allowed to have more repos created

Note that I was not able to reproduce the issue on the demo instance, because there is no repo count limit and also it seems like you can't create orgs there..

Screenshots

Trying to create a new repo testrepo45 under testorg organization, note the banner telling me there is a limit:
Screenshot from 2024-03-22 23-19-41

Submit button is disabled:
Screenshot from 2024-03-22 23-19-29

Repo create works anyway when enabling the submit button by hand:
Screenshot from 2024-03-22 23-19-56

Gitea Version

v1.21.9

@a1012112796
Copy link
Member

I has try fix it in #15924, but sadly looks no one think it's a bug :( . maybe need a beter design about how to limit repository number for org. or repo number limit will looks meaningless if all user can create orgs.

@a1012112796 a1012112796 added type/proposal The new feature has not been accepted yet but needs to be discussed first. and removed type/bug labels Apr 1, 2024
@DrMaxNix
Copy link
Contributor Author

DrMaxNix commented Apr 1, 2024

This is definitely a bug! The validation on the frontend does not match the validation in the backend!
If the behaviour of the ui is actually wanted (which would be really weird), the backend validation would be wrong, which would not only still be a bug, but also a security problem!!!

@DrMaxNix DrMaxNix changed the title UI preventing org repo creation as well if user org limit is reached [ ⚠️ BUG, not a feature ⚠️ ] UI preventing org repo creation as well if user org limit is reached Jun 27, 2024
@DrMaxNix DrMaxNix changed the title [ ⚠️ BUG, not a feature ⚠️ ] UI preventing org repo creation as well if user org limit is reached UI preventing org repo creation as well if user org limit is reached Mar 11, 2025
@DrMaxNix
Copy link
Contributor Author

DrMaxNix commented Apr 7, 2025

Partially fixed by #34030, Migrations still affected

@wxiaoguang
Copy link
Contributor

Yes, it is a bug, and thank you very much for finding the fix!

ps; although #15924 was also proposed, but it is incomplete and didn't persuade others to really understand the problem ......

@lunny lunny closed this as completed in fd7c364 Apr 8, 2025
@lunny lunny added this to the 1.24.0 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants