Skip to content

Commit 934124c

Browse files
authored
some less naked returns (#25682)
fix upcoming lint issues
1 parent f4c1f43 commit 934124c

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

models/perm/access/repo_permission.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func (p *Permission) LogString() string {
127127
}
128128

129129
// GetUserRepoPermission returns the user permissions to the repository
130-
func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (perm Permission, err error) {
130+
func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (Permission, error) {
131+
var perm Permission
131132
if log.IsTrace() {
132133
defer func() {
133134
if user == nil {
@@ -147,63 +148,64 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
147148
// TODO: anonymous user visit public unit of private repo???
148149
if user == nil && repo.IsPrivate {
149150
perm.AccessMode = perm_model.AccessModeNone
150-
return
151+
return perm, nil
151152
}
152153

153-
var is bool
154+
var isCollaborator bool
155+
var err error
154156
if user != nil {
155-
is, err = repo_model.IsCollaborator(ctx, repo.ID, user.ID)
157+
isCollaborator, err = repo_model.IsCollaborator(ctx, repo.ID, user.ID)
156158
if err != nil {
157159
return perm, err
158160
}
159161
}
160162

161-
if err = repo.LoadOwner(ctx); err != nil {
162-
return
163+
if err := repo.LoadOwner(ctx); err != nil {
164+
return perm, err
163165
}
164166

165167
// Prevent strangers from checking out public repo of private organization/users
166168
// Allow user if they are collaborator of a repo within a private user or a private organization but not a member of the organization itself
167-
if !organization.HasOrgOrUserVisible(ctx, repo.Owner, user) && !is {
169+
if !organization.HasOrgOrUserVisible(ctx, repo.Owner, user) && !isCollaborator {
168170
perm.AccessMode = perm_model.AccessModeNone
169-
return
171+
return perm, nil
170172
}
171173

172-
if err = repo.LoadUnits(ctx); err != nil {
173-
return
174+
if err := repo.LoadUnits(ctx); err != nil {
175+
return perm, err
174176
}
175177

176178
perm.Units = repo.Units
177179

178180
// anonymous visit public repo
179181
if user == nil {
180182
perm.AccessMode = perm_model.AccessModeRead
181-
return
183+
return perm, nil
182184
}
183185

184186
// Admin or the owner has super access to the repository
185187
if user.IsAdmin || user.ID == repo.OwnerID {
186188
perm.AccessMode = perm_model.AccessModeOwner
187-
return
189+
return perm, nil
188190
}
189191

190192
// plain user
191193
perm.AccessMode, err = accessLevel(ctx, user, repo)
192194
if err != nil {
193-
return
195+
return perm, err
194196
}
195197

196-
if err = repo.LoadOwner(ctx); err != nil {
197-
return
198+
if err := repo.LoadOwner(ctx); err != nil {
199+
return perm, err
198200
}
199201
if !repo.Owner.IsOrganization() {
200-
return
202+
return perm, nil
201203
}
202204

203205
perm.UnitsMode = make(map[unit.Type]perm_model.AccessMode)
204206

205207
// Collaborators on organization
206-
if is {
208+
if isCollaborator {
207209
for _, u := range repo.Units {
208210
perm.UnitsMode[u.Type] = perm.AccessMode
209211
}
@@ -212,15 +214,15 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
212214
// get units mode from teams
213215
teams, err := organization.GetUserRepoTeams(ctx, repo.OwnerID, user.ID, repo.ID)
214216
if err != nil {
215-
return
217+
return perm, err
216218
}
217219

218220
// if user in an owner team
219221
for _, team := range teams {
220222
if team.AccessMode >= perm_model.AccessModeAdmin {
221223
perm.AccessMode = perm_model.AccessModeOwner
222224
perm.UnitsMode = nil
223-
return
225+
return perm, nil
224226
}
225227
}
226228

models/repo/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (s releaseMetaSearch) Less(i, j int) bool {
339339
// GetReleaseAttachments retrieves the attachments for releases
340340
func GetReleaseAttachments(ctx context.Context, rels ...*Release) (err error) {
341341
if len(rels) == 0 {
342-
return
342+
return nil
343343
}
344344

345345
// To keep this efficient as possible sort all releases by id,

0 commit comments

Comments
 (0)