summaryrefslogtreecommitdiffstats
path: root/models/repo/collaboration.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-06-12 23:51:54 +0800
committerGitHub <noreply@github.com>2022-06-12 23:51:54 +0800
commit110fc57cbcf293c19ed7017d8ea528b4bbbd7396 (patch)
treeb36eb2ee0e3f8417a35ad095e25880b778ded0ba /models/repo/collaboration.go
parenta9dc9b06e4a4106ec8315fe7b2922efa440ca199 (diff)
downloadgitea-110fc57cbcf293c19ed7017d8ea528b4bbbd7396.tar.gz
gitea-110fc57cbcf293c19ed7017d8ea528b4bbbd7396.zip
Move some code into models/git (#19879)
* Move access and repo permission to models/perm/access * fix test * Move some git related files into sub package models/git * Fix build * fix git test * move lfs to sub package * move more git related functions to models/git * Move functions sequence * Some improvements per @KN4CK3R and @delvh
Diffstat (limited to 'models/repo/collaboration.go')
-rw-r--r--models/repo/collaboration.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/models/repo/collaboration.go b/models/repo/collaboration.go
index 09397dd172..be05eba74c 100644
--- a/models/repo/collaboration.go
+++ b/models/repo/collaboration.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
+ "code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
@@ -149,3 +150,23 @@ func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.Access
return committer.Commit()
}
+
+// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
+func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
+ if repo.OwnerID == userID {
+ return true, nil
+ }
+ teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
+ Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
+ Where("team_repo.repo_id = ?", repo.ID).
+ And("team_unit.`type` = ?", unit.TypeCode).
+ And("team_user.uid = ?", userID).Table("team_user").Exist()
+ if err != nil {
+ return false, err
+ }
+ if teamMember {
+ return true, nil
+ }
+
+ return db.GetEngine(db.DefaultContext).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
+}