summaryrefslogtreecommitdiffstats
path: root/models/organization
diff options
context:
space:
mode:
authoryp05327 <576951401@qq.com>2023-04-07 17:21:02 +0200
committerGitHub <noreply@github.com>2023-04-07 17:21:02 +0200
commit26a0cd7143cc933cee37ac87696eeda46b1ea437 (patch)
treed56359084e649f7e8f334101800ad83174d513e7 /models/organization
parentMerge template functions "dict/Dict/mergeinto" (#23932) (diff)
downloadforgejo-26a0cd7143cc933cee37ac87696eeda46b1ea437.tar.xz
forgejo-26a0cd7143cc933cee37ac87696eeda46b1ea437.zip
Allow repo admins too to delete the repo (#23940)
Fixes https://github.com/go-gitea/gitea/issues/23934 We need to check `AccessModeAdmin` in `CanUserDelete` instead of `AccessModeOwner`
Diffstat (limited to 'models/organization')
-rw-r--r--models/organization/org.go5
-rw-r--r--models/organization/org_user.go15
2 files changed, 20 insertions, 0 deletions
diff --git a/models/organization/org.go b/models/organization/org.go
index fa2a604721..53b020d704 100644
--- a/models/organization/org.go
+++ b/models/organization/org.go
@@ -100,6 +100,11 @@ func (org *Organization) IsOwnedBy(uid int64) (bool, error) {
return IsOrganizationOwner(db.DefaultContext, org.ID, uid)
}
+// IsOrgAdmin returns true if given user is in the owner team or an admin team.
+func (org *Organization) IsOrgAdmin(uid int64) (bool, error) {
+ return IsOrganizationAdmin(db.DefaultContext, org.ID, uid)
+}
+
// IsOrgMember returns true if given user is member of organization.
func (org *Organization) IsOrgMember(uid int64) (bool, error) {
return IsOrganizationMember(db.DefaultContext, org.ID, uid)
diff --git a/models/organization/org_user.go b/models/organization/org_user.go
index e5cbfe6c0f..d0598ab5d1 100644
--- a/models/organization/org_user.go
+++ b/models/organization/org_user.go
@@ -8,6 +8,7 @@ import (
"fmt"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
@@ -53,6 +54,20 @@ func IsOrganizationOwner(ctx context.Context, orgID, uid int64) (bool, error) {
return IsTeamMember(ctx, orgID, ownerTeam.ID, uid)
}
+// IsOrganizationAdmin returns true if given user is in the owner team or an admin team.
+func IsOrganizationAdmin(ctx context.Context, orgID, uid int64) (bool, error) {
+ teams, err := GetUserOrgTeams(ctx, orgID, uid)
+ if err != nil {
+ return false, err
+ }
+ for _, t := range teams {
+ if t.AccessMode >= perm.AccessModeAdmin {
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
// IsOrganizationMember returns true if given user is member of organization.
func IsOrganizationMember(ctx context.Context, orgID, uid int64) (bool, error) {
return db.GetEngine(ctx).