mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Check user/org repo limit instead of doer (#34147)
This PR tries to finally fix the bug mentioned in #30011 and #15504, where the user repo limit is checked when creating a repo in an organization. Fix #30011 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
@@ -91,12 +91,17 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
|
||||
ctx.Data["CanForkToUser"] = canForkToUser
|
||||
ctx.Data["Orgs"] = orgs
|
||||
|
||||
// TODO: this message should only be shown for the "current doer" when it is selected, just like the "new repo" page.
|
||||
// msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", ctx.Doer.MaxCreationLimit())
|
||||
|
||||
if canForkToUser {
|
||||
ctx.Data["ContextUser"] = ctx.Doer
|
||||
ctx.Data["CanForkRepoInNewOwner"] = true
|
||||
} else if len(orgs) > 0 {
|
||||
ctx.Data["ContextUser"] = orgs[0]
|
||||
ctx.Data["CanForkRepoInNewOwner"] = true
|
||||
} else {
|
||||
ctx.Data["CanForkRepo"] = false
|
||||
ctx.Data["CanForkRepoInNewOwner"] = false
|
||||
ctx.Flash.Error(ctx.Tr("repo.fork_no_valid_owners"), true)
|
||||
return nil
|
||||
}
|
||||
@@ -120,15 +125,6 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
|
||||
// Fork render repository fork page
|
||||
func Fork(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("new_fork")
|
||||
|
||||
if ctx.Doer.CanForkRepo() {
|
||||
ctx.Data["CanForkRepo"] = true
|
||||
} else {
|
||||
maxCreationLimit := ctx.Doer.MaxCreationLimit()
|
||||
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
|
||||
ctx.Flash.Error(msg, true)
|
||||
}
|
||||
|
||||
getForkRepository(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
@@ -141,7 +137,6 @@ func Fork(ctx *context.Context) {
|
||||
func ForkPost(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*forms.CreateRepoForm)
|
||||
ctx.Data["Title"] = ctx.Tr("new_fork")
|
||||
ctx.Data["CanForkRepo"] = true
|
||||
|
||||
ctxUser := checkContextUser(ctx, form.UID)
|
||||
if ctx.Written() {
|
||||
|
@@ -87,17 +87,13 @@ func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !ctx.Doer.IsAdmin {
|
||||
orgsAvailable := []*organization.Organization{}
|
||||
for i := 0; i < len(orgs); i++ {
|
||||
if orgs[i].CanCreateRepo() {
|
||||
orgsAvailable = append(orgsAvailable, orgs[i])
|
||||
}
|
||||
var orgsAvailable []*organization.Organization
|
||||
for i := 0; i < len(orgs); i++ {
|
||||
if ctx.Doer.CanCreateRepoIn(orgs[i].AsUser()) {
|
||||
orgsAvailable = append(orgsAvailable, orgs[i])
|
||||
}
|
||||
ctx.Data["Orgs"] = orgsAvailable
|
||||
} else {
|
||||
ctx.Data["Orgs"] = orgs
|
||||
}
|
||||
ctx.Data["Orgs"] = orgsAvailable
|
||||
|
||||
// Not equal means current user is an organization.
|
||||
if uid == ctx.Doer.ID || uid == 0 {
|
||||
@@ -154,7 +150,7 @@ func createCommon(ctx *context.Context) {
|
||||
ctx.Data["Licenses"] = repo_module.Licenses
|
||||
ctx.Data["Readmes"] = repo_module.Readmes
|
||||
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
|
||||
ctx.Data["CanCreateRepoInDoer"] = ctx.Doer.CanCreateRepo()
|
||||
ctx.Data["CanCreateRepoInDoer"] = ctx.Doer.CanCreateRepoIn(ctx.Doer)
|
||||
ctx.Data["MaxCreationLimitOfDoer"] = ctx.Doer.MaxCreationLimit()
|
||||
ctx.Data["SupportedObjectFormats"] = git.DefaultFeatures().SupportedObjectFormats
|
||||
ctx.Data["DefaultObjectFormat"] = git.Sha1ObjectFormat
|
||||
|
@@ -59,6 +59,7 @@ func SettingsCtxData(ctx *context.Context) {
|
||||
ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush
|
||||
ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval
|
||||
ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval
|
||||
ctx.Data["CanConvertFork"] = ctx.Repo.Repository.IsFork && ctx.Doer.CanCreateRepoIn(ctx.Repo.Repository.Owner)
|
||||
|
||||
signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath())
|
||||
ctx.Data["SigningKeyAvailable"] = len(signing) > 0
|
||||
@@ -786,7 +787,7 @@ func handleSettingsPostConvertFork(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.Repo.Owner.CanCreateRepo() {
|
||||
if !ctx.Doer.CanForkRepoIn(ctx.Repo.Owner) {
|
||||
maxCreationLimit := ctx.Repo.Owner.MaxCreationLimit()
|
||||
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
|
||||
ctx.Flash.Error(msg)
|
||||
|
Reference in New Issue
Block a user