mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 20:59:29 +02:00
add UserOrgTeamPermCond function
this returns group ids where a user has permissions greater than or equal to `level`
This commit is contained in:
1 parent
608fb4326d
commit
a35d412491
1 file changed
+9
-1
@@ -1,11 +1,12 @@
|
|||||||
package group
|
package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/perm"
|
"code.gitea.io/gitea/models/perm"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"context"
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +32,13 @@ func userOrgTeamGroupBuilder(userID int64) *builder.Builder {
|
|||||||
Where(builder.Eq{"`team_user`.uid": userID})
|
Where(builder.Eq{"`team_user`.uid": userID})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UserOrgTeamPermCond(idStr string, userID int64, level perm.AccessMode) builder.Cond {
|
||||||
|
selCond := userOrgTeamGroupBuilder(userID)
|
||||||
|
selCond = selCond.InnerJoin("team", "`team`.id = `group_team`.team_id").
|
||||||
|
And(builder.Or(builder.Gte{"`team`.authorize": level}, builder.Gte{"`group_team`.access_mode": level}))
|
||||||
|
return builder.In(idStr, selCond)
|
||||||
|
}
|
||||||
|
|
||||||
// UserOrgTeamGroupCond returns a condition to select ids of groups that a user's team can access
|
// UserOrgTeamGroupCond returns a condition to select ids of groups that a user's team can access
|
||||||
func UserOrgTeamGroupCond(idStr string, userID int64) builder.Cond {
|
func UserOrgTeamGroupCond(idStr string, userID int64) builder.Cond {
|
||||||
return builder.In(idStr, userOrgTeamGroupBuilder(userID))
|
return builder.In(idStr, userOrgTeamGroupBuilder(userID))
|
||||||
|
|||||||
Reference in new issue
Block a user