]> source.dussan.org Git - gitea.git/commitdiff
add permission check for ``GenerateRepository`` (#15946)
authora1012112796 <1012112796@qq.com>
Thu, 27 May 2021 16:08:46 +0000 (00:08 +0800)
committerGitHub <noreply@github.com>
Thu, 27 May 2021 16:08:46 +0000 (12:08 -0400)
Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
services/repository/generate.go

index 067f8f61d0a066a1c10397a70aab162af30eae85..43cbb45a41f01853fa116288971e7dc584736b28 100644 (file)
@@ -13,6 +13,12 @@ import (
 
 // GenerateRepository generates a repository from a template
 func GenerateRepository(doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
+       if !doer.IsAdmin && !owner.CanCreateRepo() {
+               return nil, models.ErrReachLimitOfRepo{
+                       Limit: owner.MaxRepoCreation,
+               }
+       }
+
        var generateRepo *models.Repository
        if err = models.WithTx(func(ctx models.DBContext) error {
                generateRepo, err = repo_module.GenerateRepository(ctx, doer, owner, templateRepo, opts)