From b27a9d43a5c0b473c30b6137e0309d103793dcad Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 28 May 2021 00:08:46 +0800 Subject: [PATCH] add permission check for ``GenerateRepository`` (#15946) Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: techknowlogick Co-authored-by: Lunny Xiao --- services/repository/generate.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/repository/generate.go b/services/repository/generate.go index 067f8f61d..43cbb45a4 100644 --- a/services/repository/generate.go +++ b/services/repository/generate.go @@ -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)