Skip to content

Commit bc57f66

Browse files
add function to find teams a user is part of within a group
1 parent 1d901cb commit bc57f66

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

models/group/group_team.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func HasTeamGroup(ctx context.Context, orgID, teamID, groupID int64) bool {
5959

6060
// AddTeamGroup adds a group to a team
6161
func AddTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access perm.AccessMode, canCreateIn bool) error {
62-
if access <= perm.AccessModeWrite {
62+
if access < perm.AccessModeWrite {
6363
canCreateIn = false
6464
}
6565
_, err := db.GetEngine(ctx).Insert(&RepoGroupTeam{
@@ -113,6 +113,15 @@ func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*RepoGroupTeam
113113
Find(&gteams)
114114
}
115115

116+
func FindUserGroupTeams(ctx context.Context, groupID int64, userID int64) (gteams []*RepoGroupTeam, err error) {
117+
return gteams, db.GetEngine(ctx).
118+
Where("group_id=?", groupID).
119+
And("team_user.uid = ?", userID).
120+
Table("repo_group_team").
121+
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
122+
Find(&gteams)
123+
}
124+
116125
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *RepoGroupTeam, err error) {
117126
gteam = new(RepoGroupTeam)
118127
has, err := db.GetEngine(ctx).

0 commit comments

Comments
 (0)