mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-21 11:51:54 +02:00
apply simple linting changes
This commit is contained in:
+27
-26
@@ -32,9 +32,9 @@ type Group struct {
|
||||
Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"`
|
||||
Avatar string `xorm:"VARCHAR(64)"`
|
||||
|
||||
ParentGroupID int64 `xorm:"DEFAULT NULL"`
|
||||
ParentGroup *Group `xorm:"-"`
|
||||
Subgroups GroupList `xorm:"-"`
|
||||
ParentGroupID int64 `xorm:"DEFAULT NULL"`
|
||||
ParentGroup *Group `xorm:"-"`
|
||||
Subgroups RepoGroupList `xorm:"-"`
|
||||
|
||||
SortOrder int `xorm:"INDEX"`
|
||||
}
|
||||
@@ -52,8 +52,8 @@ func (Group) TableName() string { return "repo_group" }
|
||||
|
||||
func init() {
|
||||
db.RegisterModel(new(Group))
|
||||
db.RegisterModel(new(GroupTeam))
|
||||
db.RegisterModel(new(GroupUnit))
|
||||
db.RegisterModel(new(RepoGroupTeam))
|
||||
db.RegisterModel(new(RepoGroupUnit))
|
||||
}
|
||||
|
||||
func (g *Group) doLoadSubgroups(ctx context.Context, recursive bool, cond builder.Cond, currentLevel int) error {
|
||||
@@ -141,30 +141,30 @@ func (g *Group) CanAccessAtLevel(ctx context.Context, userID int64, level perm.A
|
||||
func (g *Group) IsOwnedBy(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.access_mode = ?", perm.AccessModeOwner).
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.access_mode = ?", perm.AccessModeOwner).
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
func (g *Group) CanCreateIn(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
And("group_team.can_create_in = ?", true).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
And("repo_group_team.can_create_in = ?", true).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
func (g *Group) IsAdminOf(ctx context.Context, userID int64) (bool, error) {
|
||||
return db.GetEngine(ctx).
|
||||
Where("team_user.uid = ?", userID).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And("group_team.group_id = ?", g.ID).
|
||||
And("group_team.access_mode >= ?", perm.AccessModeAdmin).
|
||||
Table("group_team").
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And("repo_group_team.group_id = ?", g.ID).
|
||||
And("repo_group_team.access_mode >= ?", perm.AccessModeAdmin).
|
||||
Table("repo_group_team").
|
||||
Exist()
|
||||
}
|
||||
|
||||
@@ -224,11 +224,11 @@ func (opts FindGroupsOptions) ToConds() builder.Cond {
|
||||
}
|
||||
if opts.CanCreateIn.Has() && opts.ActorID > 0 {
|
||||
cond = cond.And(builder.In("id",
|
||||
builder.Select("group_team.group_id").
|
||||
From("group_team").
|
||||
builder.Select("repo_group_team.group_id").
|
||||
From("repo_group_team").
|
||||
Where(builder.Eq{"team_user.uid": opts.ActorID}).
|
||||
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
|
||||
And(builder.Eq{"group_team.can_create_in": true})))
|
||||
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
|
||||
And(builder.Eq{"repo_group_team.can_create_in": true})))
|
||||
}
|
||||
if opts.Name != "" {
|
||||
cond = cond.And(builder.Eq{"lower_name": opts.Name})
|
||||
@@ -236,7 +236,7 @@ func (opts FindGroupsOptions) ToConds() builder.Cond {
|
||||
return cond
|
||||
}
|
||||
|
||||
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (GroupList, error) {
|
||||
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (RepoGroupList, error) {
|
||||
sess := db.GetEngine(ctx).Where(opts.ToConds())
|
||||
if opts.Page > 0 {
|
||||
sess = db.SetSessionPagination(sess, opts)
|
||||
@@ -260,7 +260,7 @@ func findGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder
|
||||
return sess.Asc("sort_order")
|
||||
}
|
||||
|
||||
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (GroupList, error) {
|
||||
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (RepoGroupList, error) {
|
||||
defaultSize := 50
|
||||
if opts.PageSize > 0 {
|
||||
defaultSize = opts.PageSize
|
||||
@@ -285,7 +285,7 @@ func UpdateGroupOwnerName(ctx context.Context, oldUser, newUser string) error {
|
||||
}
|
||||
|
||||
// GetParentGroupChain returns a slice containing a group and its ancestors
|
||||
func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error) {
|
||||
func GetParentGroupChain(ctx context.Context, groupID int64) (RepoGroupList, error) {
|
||||
groupList := make([]*Group, 0, 20)
|
||||
currentGroupID := groupID
|
||||
for {
|
||||
@@ -306,7 +306,8 @@ func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error)
|
||||
return groupList, nil
|
||||
}
|
||||
|
||||
func GetParentGroupIDChain(ctx context.Context, groupID int64) (ids []int64, err error) {
|
||||
func GetParentGroupIDChain(ctx context.Context, groupID int64) ([]int64, error) {
|
||||
var ids []int64
|
||||
groupList, err := GetParentGroupChain(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -314,7 +315,7 @@ func GetParentGroupIDChain(ctx context.Context, groupID int64) (ids []int64, err
|
||||
ids = util.SliceMap(groupList, func(g *Group) int64 {
|
||||
return g.ID
|
||||
})
|
||||
return
|
||||
return ids, err
|
||||
}
|
||||
|
||||
// ParentGroupCond returns a condition matching a group and its ancestors
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type GroupList []*Group
|
||||
type RepoGroupList []*Group
|
||||
|
||||
func (groups GroupList) LoadOwners(ctx context.Context) error {
|
||||
func (groups RepoGroupList) LoadOwners(ctx context.Context) error {
|
||||
for _, g := range groups {
|
||||
if g.Owner == nil {
|
||||
err := g.LoadOwner(ctx)
|
||||
|
||||
+21
-20
@@ -10,23 +10,24 @@ import (
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// GroupTeam represents a relation for a team's access to a group
|
||||
type GroupTeam struct {
|
||||
// RepoGroupTeam represents a relation for a team's access to a group
|
||||
type RepoGroupTeam struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
OrgID int64 `xorm:"INDEX"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
GroupID int64 `xorm:"UNIQUE(s)"`
|
||||
AccessMode perm.AccessMode
|
||||
CanCreateIn bool
|
||||
Units []*GroupUnit `xorm:"-"`
|
||||
Units []*RepoGroupUnit `xorm:"-"`
|
||||
}
|
||||
|
||||
func (g *GroupTeam) LoadGroupUnits(ctx context.Context) (err error) {
|
||||
func (g *RepoGroupTeam) LoadGroupUnits(ctx context.Context) error {
|
||||
var err error
|
||||
g.Units, err = GetUnitsByGroupID(ctx, g.GroupID)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
func (g *GroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
|
||||
func (g *RepoGroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
|
||||
accessMode = perm.AccessModeNone
|
||||
if err := g.LoadGroupUnits(ctx); err != nil {
|
||||
log.Warn("Error loading units of team for group[%d] (ID: %d): %s", g.GroupID, g.TeamID, err.Error())
|
||||
@@ -38,7 +39,7 @@ func (g *GroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessM
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
return accessMode, exist
|
||||
}
|
||||
|
||||
// HasTeamGroup returns true if the given group belongs to a team.
|
||||
@@ -48,7 +49,7 @@ func HasTeamGroup(ctx context.Context, orgID, teamID, groupID int64) bool {
|
||||
And("team_id=?", teamID).
|
||||
And("group_id=?", groupID).
|
||||
And("access_mode >= ?", perm.AccessModeRead).
|
||||
Get(new(GroupTeam))
|
||||
Get(new(RepoGroupTeam))
|
||||
return has
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ func AddTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access perm
|
||||
if access <= perm.AccessModeWrite {
|
||||
canCreateIn = false
|
||||
}
|
||||
_, err := db.GetEngine(ctx).Insert(&GroupTeam{
|
||||
_, err := db.GetEngine(ctx).Insert(&RepoGroupTeam{
|
||||
OrgID: orgID,
|
||||
GroupID: groupID,
|
||||
TeamID: teamID,
|
||||
@@ -75,11 +76,11 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
|
||||
err = AddTeamGroup(ctx, orgID, teamID, groupID, access, canCreateIn)
|
||||
} else {
|
||||
_, err = db.GetEngine(ctx).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Where("org_id=?", orgID).
|
||||
And("team_id=?", teamID).
|
||||
And("group_id =?", groupID).
|
||||
Update(&GroupTeam{
|
||||
Update(&RepoGroupTeam{
|
||||
OrgID: orgID,
|
||||
TeamID: teamID,
|
||||
GroupID: groupID,
|
||||
@@ -93,7 +94,7 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
|
||||
|
||||
// RemoveTeamGroup removes a group from a team
|
||||
func RemoveTeamGroup(ctx context.Context, orgID, teamID, groupID int64) error {
|
||||
_, err := db.DeleteByBean(ctx, &GroupTeam{
|
||||
_, err := db.DeleteByBean(ctx, &RepoGroupTeam{
|
||||
TeamID: teamID,
|
||||
GroupID: groupID,
|
||||
OrgID: orgID,
|
||||
@@ -101,24 +102,24 @@ func RemoveTeamGroup(ctx context.Context, orgID, teamID, groupID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*GroupTeam, err error) {
|
||||
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*RepoGroupTeam, err error) {
|
||||
return gteams, db.GetEngine(ctx).
|
||||
Where("group_id=?", groupID).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Find(>eams)
|
||||
}
|
||||
|
||||
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *GroupTeam, err error) {
|
||||
gteam = new(GroupTeam)
|
||||
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *RepoGroupTeam, err error) {
|
||||
gteam = new(RepoGroupTeam)
|
||||
has, err := db.GetEngine(ctx).
|
||||
Where("group_id=?", groupID).
|
||||
And("team_id = ?", teamID).
|
||||
Table("group_team").
|
||||
Table("repo_group_team").
|
||||
Get(gteam)
|
||||
if !has {
|
||||
gteam = nil
|
||||
}
|
||||
return
|
||||
return gteam, err
|
||||
}
|
||||
|
||||
func GetAncestorPermissions(ctx context.Context, groupID, teamID int64) (perm.AccessMode, error) {
|
||||
@@ -127,12 +128,12 @@ func GetAncestorPermissions(ctx context.Context, groupID, teamID int64) (perm.Ac
|
||||
if err != nil {
|
||||
return perm.AccessModeNone, err
|
||||
}
|
||||
gteams := make([]*GroupTeam, 0)
|
||||
gteams := make([]*RepoGroupTeam, 0)
|
||||
err = sess.In("group_id", groups).And("team_id = ?", teamID).Find(>eams)
|
||||
if err != nil {
|
||||
return perm.AccessModeNone, err
|
||||
}
|
||||
mapped := util.SliceMap(gteams, func(g *GroupTeam) perm.AccessMode {
|
||||
mapped := util.SliceMap(gteams, func(g *RepoGroupTeam) perm.AccessMode {
|
||||
return g.AccessMode
|
||||
})
|
||||
maxMode := max(mapped[0])
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
)
|
||||
|
||||
// GroupUnit describes all units of a repository group
|
||||
type GroupUnit struct {
|
||||
// RepoGroupUnit describes all units of a repository group
|
||||
type RepoGroupUnit struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
GroupID int64 `xorm:"UNIQUE(s)"`
|
||||
TeamID int64 `xorm:"UNIQUE(s)"`
|
||||
@@ -17,16 +17,16 @@ type GroupUnit struct {
|
||||
AccessMode perm.AccessMode
|
||||
}
|
||||
|
||||
func (g *GroupUnit) Unit() unit.Unit {
|
||||
func (g *RepoGroupUnit) 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 []*RepoGroupUnit, 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)
|
||||
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
|
||||
unit = new(RepoGroupUnit)
|
||||
_, err = db.GetEngine(ctx).
|
||||
Where("group_id = ?", groupID).
|
||||
And("team_id = ?", teamID).
|
||||
@@ -35,8 +35,8 @@ func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type
|
||||
return
|
||||
}
|
||||
|
||||
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *GroupUnit, err error) {
|
||||
units := make([]*GroupUnit, 0)
|
||||
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
|
||||
units := make([]*RepoGroupUnit, 0)
|
||||
err = db.GetEngine(ctx).
|
||||
Where("group_id = ?", groupID).
|
||||
And("type = ?", unitType).
|
||||
|
||||
@@ -35,13 +35,13 @@ func FindGroupMembers(ctx context.Context, groupID int64, opts *organization_mod
|
||||
return users, err
|
||||
}
|
||||
|
||||
func GetGroupTeams(ctx context.Context, groupID int64) (teams []*organization_model.Team, err error) {
|
||||
err = db.GetEngine(ctx).
|
||||
func GetGroupTeams(ctx context.Context, groupID int64) ([]*organization_model.Team, error) {
|
||||
var teams []*organization_model.Team
|
||||
return teams, db.GetEngine(ctx).
|
||||
Where("`group_team`.group_id = ?", groupID).
|
||||
Join("INNER", "group_team", "`group_team`.team_id = `team`.id").
|
||||
Asc("`team`.name").
|
||||
Find(&teams)
|
||||
return
|
||||
}
|
||||
|
||||
func IsGroupMember(ctx context.Context, groupID, userID int64) (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user