aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorXinyu Zhou <i@sourcehut.net>2022-12-28 05:21:14 +0800
committerGitHub <noreply@github.com>2022-12-27 15:21:14 -0600
commit7cc7db73b922143a1288d26b39eee9e8e59f7106 (patch)
treeda812b01e5953781a820f05edee52c93efef4bec /routers
parent22a6e9759739af05a862fb5098aec0659aed2e84 (diff)
downloadgitea-7cc7db73b922143a1288d26b39eee9e8e59f7106.tar.gz
gitea-7cc7db73b922143a1288d26b39eee9e8e59f7106.zip
Add option to prohibit fork if user reached maximum limit of repositories (#21848)
If user has reached the maximum limit of repositories: - Before - disallow create - allow fork without limit - This patch: - disallow create - disallow fork - Add option `ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT` (Default **true**) : enable this allow user fork repositories without maximum number limit fixed https://github.com/go-gitea/gitea/issues/21847 Signed-off-by: Xinyu Zhou <i@sourcehut.net>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/web/repo/pull.go13
2 files changed, 14 insertions, 1 deletions
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index f2cd10e711..97c1dc7ba7 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -141,7 +141,7 @@ func CreateFork(ctx *context.APIContext) {
Description: repo.Description,
})
if err != nil {
- if repo_model.IsErrRepoAlreadyExist(err) {
+ if repo_model.IsErrReachLimitOfRepo(err) || repo_model.IsErrRepoAlreadyExist(err) {
ctx.Error(http.StatusConflict, "ForkRepository", err)
} else {
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index bea6bfe433..8929a183ee 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -182,6 +182,15 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository {
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.Data["Flash"] = ctx.Flash
+ ctx.Flash.Error(msg)
+ }
+
getForkRepository(ctx)
if ctx.Written() {
return
@@ -254,6 +263,10 @@ func ForkPost(ctx *context.Context) {
if err != nil {
ctx.Data["Err_RepoName"] = true
switch {
+ case repo_model.IsErrReachLimitOfRepo(err):
+ maxCreationLimit := ctxUser.MaxCreationLimit()
+ msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
+ ctx.RenderWithErr(msg, tplFork, &form)
case repo_model.IsErrRepoAlreadyExist(err):
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
case db.IsErrNameReserved(err):