aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorRomain <romdum@users.noreply.github.com>2021-10-12 12:47:19 +0200
committerGitHub <noreply@github.com>2021-10-12 12:47:19 +0200
commitd0a681fbc3fb626adcddbbb13f8c96c0bbd72c02 (patch)
treeed807f45d54993e20f63af81d9d964ddc2f258fe /models
parent7b8723158e2a50834617f47b07c29f5436fede6d (diff)
downloadgitea-d0a681fbc3fb626adcddbbb13f8c96c0bbd72c02.tar.gz
gitea-d0a681fbc3fb626adcddbbb13f8c96c0bbd72c02.zip
[API] Add endpount to get user org permissions (#17232)
* Add endpoint * Add swagger response + generate swagger * Stop execution if user / org is not found * Add tests Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'models')
-rw-r--r--models/org.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/models/org.go b/models/org.go
index eadd1e157c..8cba485a89 100644
--- a/models/org.go
+++ b/models/org.go
@@ -392,6 +392,19 @@ func CanCreateOrgRepo(orgID, uid int64) (bool, error) {
Exist(new(Team))
}
+// GetOrgUserMaxAuthorizeLevel returns highest authorize level of user in an organization
+func (org *User) GetOrgUserMaxAuthorizeLevel(uid int64) (AccessMode, error) {
+ var authorize AccessMode
+ _, err := db.GetEngine(db.DefaultContext).
+ Select("max(team.authorize)").
+ Table("team").
+ Join("INNER", "team_user", "team_user.team_id = team.id").
+ Where("team_user.uid = ?", uid).
+ And("team_user.org_id = ?", org.ID).
+ Get(&authorize)
+ return authorize, err
+}
+
// GetUsersWhoCanCreateOrgRepo returns users which are able to create repo in organization
func GetUsersWhoCanCreateOrgRepo(orgID int64) ([]*User, error) {
return getUsersWhoCanCreateOrgRepo(db.GetEngine(db.DefaultContext), orgID)