summaryrefslogtreecommitdiffstats
path: root/models/repo_collaboration.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo_collaboration.go')
-rw-r--r--models/repo_collaboration.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index 8c6ef36230..85bc99f320 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -210,3 +210,23 @@ func (repo *Repository) getRepoTeams(e Engine) (teams []*Team, err error) {
func (repo *Repository) GetRepoTeams() ([]*Team, error) {
return repo.getRepoTeams(x)
}
+
+// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
+func (repo *Repository) IsOwnerMemberCollaborator(userID int64) (bool, error) {
+ if repo.OwnerID == userID {
+ return true, nil
+ }
+ teamMember, err := x.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` = ?", UnitTypeCode).
+ And("team_user.uid = ?", userID).Table("team_user").Exist(&TeamUser{})
+ if err != nil {
+ return false, err
+ }
+ if teamMember {
+ return true, nil
+ }
+
+ return x.Get(&Collaboration{RepoID: repo.ID, UserID: userID})
+}