Skip to content

Commit 26a0cd7

Browse files
authored
Allow repo admins too to delete the repo (#23940)
Fixes #23934 We need to check `AccessModeAdmin` in `CanUserDelete` instead of `AccessModeOwner`
1 parent 36c0840 commit 26a0cd7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

models/organization/org.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (org *Organization) IsOwnedBy(uid int64) (bool, error) {
100100
return IsOrganizationOwner(db.DefaultContext, org.ID, uid)
101101
}
102102

103+
// IsOrgAdmin returns true if given user is in the owner team or an admin team.
104+
func (org *Organization) IsOrgAdmin(uid int64) (bool, error) {
105+
return IsOrganizationAdmin(db.DefaultContext, org.ID, uid)
106+
}
107+
103108
// IsOrgMember returns true if given user is member of organization.
104109
func (org *Organization) IsOrgMember(uid int64) (bool, error) {
105110
return IsOrganizationMember(db.DefaultContext, org.ID, uid)

models/organization/org_user.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99

1010
"code.gitea.io/gitea/models/db"
11+
"code.gitea.io/gitea/models/perm"
1112
user_model "code.gitea.io/gitea/models/user"
1213
"code.gitea.io/gitea/modules/log"
1314

@@ -53,6 +54,20 @@ func IsOrganizationOwner(ctx context.Context, orgID, uid int64) (bool, error) {
5354
return IsTeamMember(ctx, orgID, ownerTeam.ID, uid)
5455
}
5556

57+
// IsOrganizationAdmin returns true if given user is in the owner team or an admin team.
58+
func IsOrganizationAdmin(ctx context.Context, orgID, uid int64) (bool, error) {
59+
teams, err := GetUserOrgTeams(ctx, orgID, uid)
60+
if err != nil {
61+
return false, err
62+
}
63+
for _, t := range teams {
64+
if t.AccessMode >= perm.AccessModeAdmin {
65+
return true, nil
66+
}
67+
}
68+
return false, nil
69+
}
70+
5671
// IsOrganizationMember returns true if given user is member of organization.
5772
func IsOrganizationMember(ctx context.Context, orgID, uid int64) (bool, error) {
5873
return db.GetEngine(ctx).

modules/repository/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func CanUserDelete(repo *repo_model.Repository, user *user_model.User) (bool, er
2121
}
2222

2323
if repo.Owner.IsOrganization() {
24-
isOwner, err := organization.OrgFromUser(repo.Owner).IsOwnedBy(user.ID)
24+
isAdmin, err := organization.OrgFromUser(repo.Owner).IsOrgAdmin(user.ID)
2525
if err != nil {
2626
return false, err
2727
}
28-
return isOwner, nil
28+
return isAdmin, nil
2929
}
3030

3131
return false, nil

0 commit comments

Comments
 (0)