0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-04-05 01:21:17 +02:00

update group_unit.go

- export `GetUnitsByGroupID`
- add `GetGroupUnit` function to retrieve a specific unit in a group
- add `GetMaxGroupUnit` function that returns a specific type of group unit with the highest permissions granted
This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-01-09 17:01:44 -05:00
parent 4fc767c815
commit ae4c13529c
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C

View File

@ -10,7 +10,7 @@ import (
// GroupUnit describes all units of a repository group
type GroupUnit struct {
ID int64 `xorm:"pk autoincr"`
GroupID int64 `xorm:"INDEX"`
GroupID int64 `xorm:"UNIQUE(s)"`
TeamID int64 `xorm:"UNIQUE(s)"`
Type unit.Type `xorm:"UNIQUE(s)"`
AccessMode perm.AccessMode
@ -20,6 +20,33 @@ func (g *GroupUnit) Unit() unit.Unit {
return unit.Units[g.Type]
}
func getUnitsByGroupID(ctx context.Context, groupID int64) (units []*GroupUnit, err error) {
func GetUnitsByGroupID(ctx context.Context, groupID int64) (units []*GroupUnit, err error) {
return units, db.GetEngine(ctx).Where("group_id = ?", groupID).Find(&units)
}
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *GroupUnit, err error) {
unit = new(GroupUnit)
_, err = db.GetEngine(ctx).
Where("group_id = ?", groupID).
And("team_id = ?", teamID).
And("type = ?", unitType).
Get(unit)
return
}
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *GroupUnit, err error) {
units := make([]*GroupUnit, 0)
err = db.GetEngine(ctx).
Where("group_id = ?", groupID).
And("type = ?", unitType).
Find(&units)
if err != nil {
return
}
for _, u := range units {
if unit == nil || u.AccessMode > unit.AccessMode {
unit = u
}
}
return
}