diff options
author | 6543 <6543@obermui.de> | 2021-02-25 08:49:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 15:49:27 +0800 |
commit | edef62e69ec2a54a870530a81b20a3cc7ca71dbd (patch) | |
tree | f45731baaafd9bd0e93281dc8539c0275109ccc0 /routers | |
parent | cdff144f76a70d61a6795ffe88d691c6e2b11f47 (diff) | |
download | gitea-edef62e69ec2a54a870530a81b20a3cc7ca71dbd.tar.gz gitea-edef62e69ec2a54a870530a81b20a3cc7ca71dbd.zip |
Backport: Repo Transfer permission checks (#14792) (#14794)
* Backport: Repo Transfer permission checks (#14792)
* update tests
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/transfer.go | 7 | ||||
-rw-r--r-- | routers/repo/setting.go | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index b1271b7721..b52f16f906 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -93,7 +93,12 @@ func Transfer(ctx *context.APIContext, opts api.TransferRepoOption) { } } - if err = repo_service.TransferOwnership(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { + if err = repo_service.StartRepositoryTransfer(ctx.User, newOwner, ctx.Repo.Repository, teams); err != nil { + if models.IsErrCancelled(err) { + ctx.Error(http.StatusForbidden, "transfer", "user has no right to create repo for new owner") + return + } + ctx.InternalServerError(err) return } diff --git a/routers/repo/setting.go b/routers/repo/setting.go index e4f8adc38f..e722cd8c28 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -475,9 +475,12 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Repo.GitRepo.Close() ctx.Repo.GitRepo = nil } - if err = repo_service.TransferOwnership(ctx.User, newOwner, repo, nil); err != nil { + if err = repo_service.StartRepositoryTransfer(ctx.User, newOwner, repo, nil); err != nil { if models.IsErrRepoAlreadyExist(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) + } else if models.IsErrCancelled(err) { + // this err msg is not translated, since it was introduced in a backport + ctx.RenderWithErr("user has no right to create repo for new owner", tplSettingsOptions, nil) } else { ctx.ServerError("TransferOwnership", err) } |