mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-22 20:53:40 +09:00
fix(repo): require organization owners for team access (#39046)
Require organization ownership before changing repository team associations when team access is restricted. --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -43,6 +43,13 @@ func Collaboration(ctx *context.Context) {
|
||||
ctx.Data["OrgName"] = ctx.Repo.Repository.OwnerName
|
||||
ctx.Data["Org"] = ctx.Repo.Repository.Owner
|
||||
ctx.Data["Units"] = unit_model.Units
|
||||
if ctx.Repo.Owner.IsOrganization() {
|
||||
ctx.Data["CanChangeRepoTeamAccess"], err = organization.OrgFromUser(ctx.Repo.Owner).CanChangeRepoTeamAccess(ctx, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanChangeRepoTeamAccess", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
ctx.HTML(http.StatusOK, tplCollaboration)
|
||||
}
|
||||
@@ -155,9 +162,7 @@ func DeleteCollaboration(ctx *context.Context) {
|
||||
|
||||
// AddTeamPost response for adding a team to a repository
|
||||
func AddTeamPost(ctx *context.Context) {
|
||||
if !ctx.Repo.Owner.RepoAdminChangeTeamAccess && !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.change_team_access_not_allowed"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||
if !canChangeRepoTeamAccess(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -201,9 +206,7 @@ func AddTeamPost(ctx *context.Context) {
|
||||
|
||||
// DeleteTeam response for deleting a team from a repository
|
||||
func DeleteTeam(ctx *context.Context) {
|
||||
if !ctx.Repo.Owner.RepoAdminChangeTeamAccess && !ctx.Repo.Permission.IsOwner() {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.change_team_access_not_allowed"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||
if !canChangeRepoTeamAccess(ctx) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,3 +224,16 @@ func DeleteTeam(ctx *context.Context) {
|
||||
ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success"))
|
||||
ctx.JSONRedirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||
}
|
||||
|
||||
func canChangeRepoTeamAccess(ctx *context.Context) bool {
|
||||
canChange, err := organization.OrgFromUser(ctx.Repo.Owner).CanChangeRepoTeamAccess(ctx, ctx.Doer)
|
||||
if err != nil {
|
||||
ctx.ServerError("CanChangeRepoTeamAccess", err)
|
||||
return false
|
||||
}
|
||||
if !canChange {
|
||||
ctx.Flash.Error(ctx.Tr("repo.settings.change_team_access_not_allowed"))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/settings/collaboration")
|
||||
}
|
||||
return canChange
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user