aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorAndrew Bezold <andrew.bezold@gmail.com>2020-04-30 11:11:56 -0400
committerGitHub <noreply@github.com>2020-04-30 16:11:56 +0100
commit3dc6af3d70285b72feb52a41b6ec0bcb9e62aa8b (patch)
tree81d953d12c90da5656a253a4c5fbde192acb1fa7 /routers
parent28e5e7fcbca9cd2030c156ec45f6f3cf67b3682e (diff)
downloadgitea-3dc6af3d70285b72feb52a41b6ec0bcb9e62aa8b.tar.gz
gitea-3dc6af3d70285b72feb52a41b6ec0bcb9e62aa8b.zip
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>
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/repo.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 3f135dd216..994beef7af 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -61,7 +61,6 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
return nil
}
- ctx.Data["Orgs"] = orgs
// Not equal means current user is an organization.
if uid == ctx.User.ID || uid == 0 {
@@ -84,6 +83,14 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
return nil
}
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)
if err != nil {
ctx.ServerError("CanCreateOrgRepo", err)
@@ -92,6 +99,8 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
ctx.Error(403)
return nil
}
+ } else {
+ ctx.Data["Orgs"] = orgs
}
return org
}
@@ -111,10 +120,6 @@ func getRepoPrivate(ctx *context.Context) bool {
// Create render creating repository page
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")
// Give default value for template to render.
@@ -142,7 +147,11 @@ func Create(ctx *context.Context) {
}
}
- ctx.HTML(200, tplCreate)
+ if !ctx.User.CanCreateRepo() {
+ ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", ctx.User.MaxCreationLimit()), tplCreate, nil)
+ } else {
+ ctx.HTML(200, tplCreate)
+ }
}
func handleCreateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {