Skip to content

Commit 889a41c

Browse files
authored
Do not allow organisation owners add themselves as collaborator (#20043)
We're already checking for repo owners, but we also need to check for organisation owners that try to add themselves as collaborator Closes #17966
1 parent dabc06d commit 889a41c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ settings.confirm_delete = Delete Repository
18981898
settings.add_collaborator = Add Collaborator
18991899
settings.add_collaborator_success = The collaborator has been added.
19001900
settings.add_collaborator_inactive_user = Can not add an inactive user as a collaborator.
1901+
settings.add_collaborator_owner = Can not add an owner as a collaborator.
19011902
settings.add_collaborator_duplicate = The collaborator is already added to this repository.
19021903
settings.delete_collaborator = Remove
19031904
settings.collaborator_deletion = Remove Collaborator

routers/web/repo/setting.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,19 @@ func CollaborationPost(ctx *context.Context) {
917917
return
918918
}
919919

920+
// find the owner team of the organization the repo belongs too and
921+
// check if the user we're trying to add is an owner.
922+
if ctx.Repo.Repository.Owner.IsOrganization() {
923+
if isOwner, err := organization.IsOrganizationOwner(ctx, ctx.Repo.Repository.Owner.ID, u.ID); err != nil {
924+
ctx.ServerError("IsOrganizationOwner", err)
925+
return
926+
} else if isOwner {
927+
ctx.Flash.Error(ctx.Tr("repo.settings.add_collaborator_owner"))
928+
ctx.Redirect(setting.AppSubURL + ctx.Req.URL.EscapedPath())
929+
return
930+
}
931+
}
932+
920933
if err = repo_module.AddCollaborator(ctx.Repo.Repository, u); err != nil {
921934
ctx.ServerError("AddCollaborator", err)
922935
return

0 commit comments

Comments
 (0)