Skip to content

Commit df7f8a8

Browse files
apply simple linting changes
1 parent 85c55c3 commit df7f8a8

File tree

11 files changed

+101
-132
lines changed

11 files changed

+101
-132
lines changed

models/group/group.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type Group struct {
3232
Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"`
3333
Avatar string `xorm:"VARCHAR(64)"`
3434

35-
ParentGroupID int64 `xorm:"DEFAULT NULL"`
36-
ParentGroup *Group `xorm:"-"`
37-
Subgroups GroupList `xorm:"-"`
35+
ParentGroupID int64 `xorm:"DEFAULT NULL"`
36+
ParentGroup *Group `xorm:"-"`
37+
Subgroups RepoGroupList `xorm:"-"`
3838

3939
SortOrder int `xorm:"INDEX"`
4040
}
@@ -52,8 +52,8 @@ func (Group) TableName() string { return "repo_group" }
5252

5353
func init() {
5454
db.RegisterModel(new(Group))
55-
db.RegisterModel(new(GroupTeam))
56-
db.RegisterModel(new(GroupUnit))
55+
db.RegisterModel(new(RepoGroupTeam))
56+
db.RegisterModel(new(RepoGroupUnit))
5757
}
5858

5959
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
141141
func (g *Group) IsOwnedBy(ctx context.Context, userID int64) (bool, error) {
142142
return db.GetEngine(ctx).
143143
Where("team_user.uid = ?", userID).
144-
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
145-
And("group_team.access_mode = ?", perm.AccessModeOwner).
146-
And("group_team.group_id = ?", g.ID).
147-
Table("group_team").
144+
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
145+
And("repo_group_team.access_mode = ?", perm.AccessModeOwner).
146+
And("repo_group_team.group_id = ?", g.ID).
147+
Table("repo_group_team").
148148
Exist()
149149
}
150150

151151
func (g *Group) CanCreateIn(ctx context.Context, userID int64) (bool, error) {
152152
return db.GetEngine(ctx).
153153
Where("team_user.uid = ?", userID).
154-
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
155-
And("group_team.group_id = ?", g.ID).
156-
And("group_team.can_create_in = ?", true).
157-
Table("group_team").
154+
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
155+
And("repo_group_team.group_id = ?", g.ID).
156+
And("repo_group_team.can_create_in = ?", true).
157+
Table("repo_group_team").
158158
Exist()
159159
}
160160

161161
func (g *Group) IsAdminOf(ctx context.Context, userID int64) (bool, error) {
162162
return db.GetEngine(ctx).
163163
Where("team_user.uid = ?", userID).
164-
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
165-
And("group_team.group_id = ?", g.ID).
166-
And("group_team.access_mode >= ?", perm.AccessModeAdmin).
167-
Table("group_team").
164+
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
165+
And("repo_group_team.group_id = ?", g.ID).
166+
And("repo_group_team.access_mode >= ?", perm.AccessModeAdmin).
167+
Table("repo_group_team").
168168
Exist()
169169
}
170170

@@ -224,19 +224,19 @@ func (opts FindGroupsOptions) ToConds() builder.Cond {
224224
}
225225
if opts.CanCreateIn.Has() && opts.ActorID > 0 {
226226
cond = cond.And(builder.In("id",
227-
builder.Select("group_team.group_id").
228-
From("group_team").
227+
builder.Select("repo_group_team.group_id").
228+
From("repo_group_team").
229229
Where(builder.Eq{"team_user.uid": opts.ActorID}).
230-
Join("INNER", "team_user", "team_user.team_id = group_team.team_id").
231-
And(builder.Eq{"group_team.can_create_in": true})))
230+
Join("INNER", "team_user", "team_user.team_id = repo_group_team.team_id").
231+
And(builder.Eq{"repo_group_team.can_create_in": true})))
232232
}
233233
if opts.Name != "" {
234234
cond = cond.And(builder.Eq{"lower_name": opts.Name})
235235
}
236236
return cond
237237
}
238238

239-
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (GroupList, error) {
239+
func FindGroups(ctx context.Context, opts *FindGroupsOptions) (RepoGroupList, error) {
240240
sess := db.GetEngine(ctx).Where(opts.ToConds())
241241
if opts.Page > 0 {
242242
sess = db.SetSessionPagination(sess, opts)
@@ -260,7 +260,7 @@ func findGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder
260260
return sess.Asc("sort_order")
261261
}
262262

263-
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (GroupList, error) {
263+
func FindGroupsByCond(ctx context.Context, opts *FindGroupsOptions, cond builder.Cond) (RepoGroupList, error) {
264264
defaultSize := 50
265265
if opts.PageSize > 0 {
266266
defaultSize = opts.PageSize
@@ -285,7 +285,7 @@ func UpdateGroupOwnerName(ctx context.Context, oldUser, newUser string) error {
285285
}
286286

287287
// GetParentGroupChain returns a slice containing a group and its ancestors
288-
func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error) {
288+
func GetParentGroupChain(ctx context.Context, groupID int64) (RepoGroupList, error) {
289289
groupList := make([]*Group, 0, 20)
290290
currentGroupID := groupID
291291
for {
@@ -306,15 +306,16 @@ func GetParentGroupChain(ctx context.Context, groupID int64) (GroupList, error)
306306
return groupList, nil
307307
}
308308

309-
func GetParentGroupIDChain(ctx context.Context, groupID int64) (ids []int64, err error) {
309+
func GetParentGroupIDChain(ctx context.Context, groupID int64) ([]int64, error) {
310+
var ids []int64
310311
groupList, err := GetParentGroupChain(ctx, groupID)
311312
if err != nil {
312313
return nil, err
313314
}
314315
ids = util.SliceMap(groupList, func(g *Group) int64 {
315316
return g.ID
316317
})
317-
return
318+
return ids, err
318319
}
319320

320321
// ParentGroupCond returns a condition matching a group and its ancestors

models/group/group_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"xorm.io/builder"
1212
)
1313

14-
type GroupList []*Group
14+
type RepoGroupList []*Group
1515

16-
func (groups GroupList) LoadOwners(ctx context.Context) error {
16+
func (groups RepoGroupList) LoadOwners(ctx context.Context) error {
1717
for _, g := range groups {
1818
if g.Owner == nil {
1919
err := g.LoadOwner(ctx)

models/group/group_team.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@ import (
1010
"code.gitea.io/gitea/modules/util"
1111
)
1212

13-
// GroupTeam represents a relation for a team's access to a group
14-
type GroupTeam struct {
13+
// RepoGroupTeam represents a relation for a team's access to a group
14+
type RepoGroupTeam struct {
1515
ID int64 `xorm:"pk autoincr"`
1616
OrgID int64 `xorm:"INDEX"`
1717
TeamID int64 `xorm:"UNIQUE(s)"`
1818
GroupID int64 `xorm:"UNIQUE(s)"`
1919
AccessMode perm.AccessMode
2020
CanCreateIn bool
21-
Units []*GroupUnit `xorm:"-"`
21+
Units []*RepoGroupUnit `xorm:"-"`
2222
}
2323

24-
func (g *GroupTeam) LoadGroupUnits(ctx context.Context) (err error) {
24+
func (g *RepoGroupTeam) LoadGroupUnits(ctx context.Context) error {
25+
var err error
2526
g.Units, err = GetUnitsByGroupID(ctx, g.GroupID)
26-
return
27+
return err
2728
}
2829

29-
func (g *GroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
30+
func (g *RepoGroupTeam) UnitAccessModeEx(ctx context.Context, tp unit.Type) (accessMode perm.AccessMode, exist bool) {
3031
accessMode = perm.AccessModeNone
3132
if err := g.LoadGroupUnits(ctx); err != nil {
3233
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
3839
break
3940
}
4041
}
41-
return
42+
return accessMode, exist
4243
}
4344

4445
// 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 {
4849
And("team_id=?", teamID).
4950
And("group_id=?", groupID).
5051
And("access_mode >= ?", perm.AccessModeRead).
51-
Get(new(GroupTeam))
52+
Get(new(RepoGroupTeam))
5253
return has
5354
}
5455

@@ -57,7 +58,7 @@ func AddTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access perm
5758
if access <= perm.AccessModeWrite {
5859
canCreateIn = false
5960
}
60-
_, err := db.GetEngine(ctx).Insert(&GroupTeam{
61+
_, err := db.GetEngine(ctx).Insert(&RepoGroupTeam{
6162
OrgID: orgID,
6263
GroupID: groupID,
6364
TeamID: teamID,
@@ -75,11 +76,11 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
7576
err = AddTeamGroup(ctx, orgID, teamID, groupID, access, canCreateIn)
7677
} else {
7778
_, err = db.GetEngine(ctx).
78-
Table("group_team").
79+
Table("repo_group_team").
7980
Where("org_id=?", orgID).
8081
And("team_id=?", teamID).
8182
And("group_id =?", groupID).
82-
Update(&GroupTeam{
83+
Update(&RepoGroupTeam{
8384
OrgID: orgID,
8485
TeamID: teamID,
8586
GroupID: groupID,
@@ -93,32 +94,32 @@ func UpdateTeamGroup(ctx context.Context, orgID, teamID, groupID int64, access p
9394

9495
// RemoveTeamGroup removes a group from a team
9596
func RemoveTeamGroup(ctx context.Context, orgID, teamID, groupID int64) error {
96-
_, err := db.DeleteByBean(ctx, &GroupTeam{
97+
_, err := db.DeleteByBean(ctx, &RepoGroupTeam{
9798
TeamID: teamID,
9899
GroupID: groupID,
99100
OrgID: orgID,
100101
})
101102
return err
102103
}
103104

104-
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*GroupTeam, err error) {
105+
func FindGroupTeams(ctx context.Context, groupID int64) (gteams []*RepoGroupTeam, err error) {
105106
return gteams, db.GetEngine(ctx).
106107
Where("group_id=?", groupID).
107-
Table("group_team").
108+
Table("repo_group_team").
108109
Find(&gteams)
109110
}
110111

111-
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *GroupTeam, err error) {
112-
gteam = new(GroupTeam)
112+
func FindGroupTeamByTeamID(ctx context.Context, groupID, teamID int64) (gteam *RepoGroupTeam, err error) {
113+
gteam = new(RepoGroupTeam)
113114
has, err := db.GetEngine(ctx).
114115
Where("group_id=?", groupID).
115116
And("team_id = ?", teamID).
116-
Table("group_team").
117+
Table("repo_group_team").
117118
Get(gteam)
118119
if !has {
119120
gteam = nil
120121
}
121-
return
122+
return gteam, err
122123
}
123124

124125
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
127128
if err != nil {
128129
return perm.AccessModeNone, err
129130
}
130-
gteams := make([]*GroupTeam, 0)
131+
gteams := make([]*RepoGroupTeam, 0)
131132
err = sess.In("group_id", groups).And("team_id = ?", teamID).Find(&gteams)
132133
if err != nil {
133134
return perm.AccessModeNone, err
134135
}
135-
mapped := util.SliceMap(gteams, func(g *GroupTeam) perm.AccessMode {
136+
mapped := util.SliceMap(gteams, func(g *RepoGroupTeam) perm.AccessMode {
136137
return g.AccessMode
137138
})
138139
maxMode := max(mapped[0])

models/group/group_unit.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ import (
88
"code.gitea.io/gitea/models/unit"
99
)
1010

11-
// GroupUnit describes all units of a repository group
12-
type GroupUnit struct {
11+
// RepoGroupUnit describes all units of a repository group
12+
type RepoGroupUnit struct {
1313
ID int64 `xorm:"pk autoincr"`
1414
GroupID int64 `xorm:"UNIQUE(s)"`
1515
TeamID int64 `xorm:"UNIQUE(s)"`
1616
Type unit.Type `xorm:"UNIQUE(s)"`
1717
AccessMode perm.AccessMode
1818
}
1919

20-
func (g *GroupUnit) Unit() unit.Unit {
20+
func (g *RepoGroupUnit) Unit() unit.Unit {
2121
return unit.Units[g.Type]
2222
}
2323

24-
func GetUnitsByGroupID(ctx context.Context, groupID int64) (units []*GroupUnit, err error) {
24+
func GetUnitsByGroupID(ctx context.Context, groupID int64) (units []*RepoGroupUnit, err error) {
2525
return units, db.GetEngine(ctx).Where("group_id = ?", groupID).Find(&units)
2626
}
2727

28-
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *GroupUnit, err error) {
29-
unit = new(GroupUnit)
28+
func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
29+
unit = new(RepoGroupUnit)
3030
_, err = db.GetEngine(ctx).
3131
Where("group_id = ?", groupID).
3232
And("team_id = ?", teamID).
@@ -35,8 +35,8 @@ func GetGroupUnit(ctx context.Context, groupID, teamID int64, unitType unit.Type
3535
return
3636
}
3737

38-
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *GroupUnit, err error) {
39-
units := make([]*GroupUnit, 0)
38+
func GetMaxGroupUnit(ctx context.Context, groupID int64, unitType unit.Type) (unit *RepoGroupUnit, err error) {
39+
units := make([]*RepoGroupUnit, 0)
4040
err = db.GetEngine(ctx).
4141
Where("group_id = ?", groupID).
4242
And("type = ?", unitType).

models/shared/group/org_group.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func FindGroupMembers(ctx context.Context, groupID int64, opts *organization_mod
3535
return users, err
3636
}
3737

38-
func GetGroupTeams(ctx context.Context, groupID int64) (teams []*organization_model.Team, err error) {
39-
err = db.GetEngine(ctx).
38+
func GetGroupTeams(ctx context.Context, groupID int64) ([]*organization_model.Team, error) {
39+
var teams []*organization_model.Team
40+
return teams, db.GetEngine(ctx).
4041
Where("`group_team`.group_id = ?", groupID).
4142
Join("INNER", "group_team", "`group_team`.team_id = `team`.id").
4243
Asc("`team`.name").
4344
Find(&teams)
44-
return
4545
}
4646

4747
func IsGroupMember(ctx context.Context, groupID, userID int64) (bool, error) {

modules/container/filter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ func DedupeBy[E any, I comparable](s []E, id func(E) I) []E {
2424
filtered := make([]E, 0, len(s)) // slice will be clipped before returning
2525
seen := make(map[I]bool, len(s))
2626
for i := range s {
27-
itemId := id(s[i])
28-
if _, ok := seen[itemId]; !ok {
27+
itemID := id(s[i])
28+
if _, ok := seen[itemID]; !ok {
2929
filtered = append(filtered, s[i])
30-
seen[itemId] = true
30+
seen[itemID] = true
3131
}
3232
}
3333
return slices.Clip(filtered)

services/group/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ func DeleteGroup(ctx context.Context, gid int64) error {
2323
}
2424

2525
// remove team permissions and units for deleted group
26-
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.GroupTeam)); err != nil {
26+
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.RepoGroupTeam)); err != nil {
2727
return err
2828
}
29-
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.GroupUnit)); err != nil {
29+
if _, err = sess.Where("group_id = ?", gid).Delete(new(group_model.RepoGroupUnit)); err != nil {
3030
return err
3131
}
3232

services/group/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewGroup(ctx context.Context, g *group_model.Group) error {
3434
defer committer.Close()
3535

3636
if err = db.Insert(ctx, g); err != nil {
37-
return
37+
return err
3838
}
3939

4040
if err = RecalculateGroupAccess(ctx, g, true); err != nil {

services/group/group_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"code.gitea.io/gitea/models/unittest"
1010

1111
"github.com/stretchr/testify/assert"
12-
"golang.org/x/net/context"
1312
)
1413

1514
// group 12 is private
@@ -39,7 +38,7 @@ func TestMoveGroup(t *testing.T) {
3938
}
4039
origCount := unittest.GetCount(t, new(group_model.Group), cond.ToConds())
4140

42-
assert.NoError(t, MoveGroupItem(context.TODO(), gid, 123, true, -1))
41+
assert.NoError(t, MoveGroupItem(t.Context(), gid, 123, true, -1))
4342
unittest.AssertCountByCond(t, "repo_group", cond.ToConds(), origCount+1)
4443
}
4544
testfn(124)

0 commit comments

Comments
 (0)