mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 13:47:52 +01:00
Fix creation of Organization repos by Users with max created personal repos (#11183)
* Fix creation of Org repos Fix go-gitea#9269 * Change variable name to appease linter * Update PR with suggestions Add a note for user.CanCreateRepo() about failure assumptions Change repo.create help message Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
This commit is contained in:
parent
28e5e7fcbc
commit
3dc6af3d70
@ -279,6 +279,7 @@ func (u *User) MaxCreationLimit() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CanCreateRepo returns if user login can create a repository
|
// CanCreateRepo returns if user login can create a repository
|
||||||
|
// NOTE: functions calling this assume a failure due to repository count limit; if new checks are added, those functions should be revised
|
||||||
func (u *User) CanCreateRepo() bool {
|
func (u *User) CanCreateRepo() bool {
|
||||||
if u.IsAdmin {
|
if u.IsAdmin {
|
||||||
return true
|
return true
|
||||||
|
@ -61,7 +61,6 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
|||||||
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
|
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ctx.Data["Orgs"] = orgs
|
|
||||||
|
|
||||||
// Not equal means current user is an organization.
|
// Not equal means current user is an organization.
|
||||||
if uid == ctx.User.ID || uid == 0 {
|
if uid == ctx.User.ID || uid == 0 {
|
||||||
@ -84,6 +83,14 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !ctx.User.IsAdmin {
|
if !ctx.User.IsAdmin {
|
||||||
|
orgsAvailable := []*models.User{}
|
||||||
|
for i := 0; i < len(orgs); i++ {
|
||||||
|
if orgs[i].CanCreateRepo() {
|
||||||
|
orgsAvailable = append(orgsAvailable, orgs[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.Data["Orgs"] = orgsAvailable
|
||||||
|
|
||||||
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
|
canCreate, err := org.CanCreateOrgRepo(ctx.User.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CanCreateOrgRepo", err)
|
ctx.ServerError("CanCreateOrgRepo", err)
|
||||||
@ -92,6 +99,8 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
|
|||||||
ctx.Error(403)
|
ctx.Error(403)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Data["Orgs"] = orgs
|
||||||
}
|
}
|
||||||
return org
|
return org
|
||||||
}
|
}
|
||||||
@ -111,10 +120,6 @@ func getRepoPrivate(ctx *context.Context) bool {
|
|||||||
|
|
||||||
// Create render creating repository page
|
// Create render creating repository page
|
||||||
func Create(ctx *context.Context) {
|
func Create(ctx *context.Context) {
|
||||||
if !ctx.User.CanCreateRepo() {
|
|
||||||
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", ctx.User.MaxCreationLimit()), tplCreate, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Data["Title"] = ctx.Tr("new_repo")
|
ctx.Data["Title"] = ctx.Tr("new_repo")
|
||||||
|
|
||||||
// Give default value for template to render.
|
// Give default value for template to render.
|
||||||
@ -142,7 +147,11 @@ func Create(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !ctx.User.CanCreateRepo() {
|
||||||
|
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", ctx.User.MaxCreationLimit()), tplCreate, nil)
|
||||||
|
} else {
|
||||||
ctx.HTML(200, tplCreate)
|
ctx.HTML(200, tplCreate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
|
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<span class="help">Some organizations may not show up in the dropdown due to a maximum repository count limit</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
|
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
|
||||||
|
Loading…
Reference in New Issue
Block a user