@@ -14,13 +14,11 @@ import (
14
14
"code.gitea.io/gitea/models"
15
15
"code.gitea.io/gitea/modules/base"
16
16
"code.gitea.io/gitea/modules/context"
17
- "code.gitea.io/gitea/modules/log"
18
17
"code.gitea.io/gitea/modules/setting"
19
18
"code.gitea.io/gitea/modules/util"
20
19
21
20
"github.com/keybase/go-crypto/openpgp"
22
21
"github.com/keybase/go-crypto/openpgp/armor"
23
- "github.com/unknwon/com"
24
22
)
25
23
26
24
const (
@@ -152,6 +150,24 @@ func Dashboard(ctx *context.Context) {
152
150
// Issues render the user issues page
153
151
func Issues (ctx * context.Context ) {
154
152
isPullList := ctx .Params (":type" ) == "pulls"
153
+ repoID := ctx .QueryInt64 ("repo" )
154
+ if repoID > 0 {
155
+ repo , err := models .GetRepositoryByID (repoID )
156
+ if err != nil {
157
+ ctx .ServerError ("GetRepositoryByID" , err )
158
+ return
159
+ }
160
+ perm , err := models .GetUserRepoPermission (repo , ctx .User )
161
+ if err != nil {
162
+ ctx .ServerError ("GetUserRepoPermission" , err )
163
+ return
164
+ }
165
+ if ! perm .CanReadIssuesOrPulls (isPullList ) {
166
+ ctx .NotFound ("Repository does not exist or you have no permission" , nil )
167
+ return
168
+ }
169
+ }
170
+
155
171
if isPullList {
156
172
ctx .Data ["Title" ] = ctx .Tr ("pull_requests" )
157
173
ctx .Data ["PageIsPulls" ] = true
@@ -194,54 +210,32 @@ func Issues(ctx *context.Context) {
194
210
page = 1
195
211
}
196
212
197
- repoID := ctx .QueryInt64 ("repo" )
198
- isShowClosed := ctx .Query ("state" ) == "closed"
213
+ var (
214
+ isShowClosed = ctx .Query ("state" ) == "closed"
215
+ err error
216
+ opts = & models.IssuesOptions {
217
+ IsClosed : util .OptionalBoolOf (isShowClosed ),
218
+ IsPull : util .OptionalBoolOf (isPullList ),
219
+ SortType : sortType ,
220
+ }
221
+ )
199
222
200
223
// Get repositories.
201
- var err error
202
- var userRepoIDs []int64
203
- opts := & models.IssuesOptions {
204
- IsClosed : util .OptionalBoolOf (isShowClosed ),
205
- IsPull : util .OptionalBoolOf (isPullList ),
206
- SortType : sortType ,
207
- }
208
-
209
- if ctxUser .IsOrganization () {
210
- env , err := ctxUser .AccessibleReposEnv (ctx .User .ID )
211
- if err != nil {
212
- ctx .ServerError ("AccessibleReposEnv" , err )
213
- return
214
- }
215
- userRepoIDs , err = env .RepoIDs (1 , ctxUser .NumRepos )
216
- if err != nil {
217
- ctx .ServerError ("env.RepoIDs" , err )
218
- return
219
- }
224
+ if repoID > 0 {
225
+ opts .RepoIDs = []int64 {repoID }
220
226
} else {
221
227
unitType := models .UnitTypeIssues
222
228
if isPullList {
223
229
unitType = models .UnitTypePullRequests
224
230
}
225
- opts .RepoSubQuery = ctxUser .UnitRepositoriesSubQuery (unitType )
226
- }
227
- if len (userRepoIDs ) == 0 {
228
- userRepoIDs = []int64 {- 1 }
229
- }
230
-
231
- if repoID > 0 {
232
- opts .RepoIDs = []int64 {repoID }
231
+ if ctxUser .IsOrganization () {
232
+ opts .RepoSubQuery = ctxUser .OrgUnitRepositoriesSubQuery (ctx .User .ID , unitType )
233
+ } else {
234
+ opts .RepoSubQuery = ctxUser .UnitRepositoriesSubQuery (unitType )
235
+ }
233
236
}
234
237
235
238
switch filterMode {
236
- case models .FilterModeAll :
237
- if repoID > 0 {
238
- if ! com .IsSliceContainsInt64 (userRepoIDs , repoID ) {
239
- // force an empty result
240
- opts .RepoIDs = []int64 {- 1 }
241
- }
242
- } else {
243
- opts .RepoIDs = userRepoIDs
244
- }
245
239
case models .FilterModeAssign :
246
240
opts .AssigneeID = ctxUser .ID
247
241
case models .FilterModeCreate :
@@ -250,14 +244,6 @@ func Issues(ctx *context.Context) {
250
244
opts .MentionedID = ctxUser .ID
251
245
}
252
246
253
- counts , err := models .CountIssuesByRepo (opts )
254
- if err != nil {
255
- ctx .ServerError ("CountIssuesByRepo" , err )
256
- return
257
- }
258
-
259
- opts .Page = page
260
- opts .PageSize = setting .UI .IssuePagingNum
261
247
var labelIDs []int64
262
248
selectLabels := ctx .Query ("labels" )
263
249
if len (selectLabels ) > 0 && selectLabels != "0" {
@@ -269,6 +255,15 @@ func Issues(ctx *context.Context) {
269
255
}
270
256
opts .LabelIDs = labelIDs
271
257
258
+ counts , err := models .CountIssuesByRepo (opts )
259
+ if err != nil {
260
+ ctx .ServerError ("CountIssuesByRepo" , err )
261
+ return
262
+ }
263
+
264
+ opts .Page = page
265
+ opts .PageSize = setting .UI .IssuePagingNum
266
+
272
267
issues , err := models .Issues (opts )
273
268
if err != nil {
274
269
ctx .ServerError ("Issues" , err )
@@ -285,41 +280,6 @@ func Issues(ctx *context.Context) {
285
280
showReposMap [repoID ] = repo
286
281
}
287
282
288
- if repoID > 0 {
289
- if _ , ok := showReposMap [repoID ]; ! ok {
290
- repo , err := models .GetRepositoryByID (repoID )
291
- if models .IsErrRepoNotExist (err ) {
292
- ctx .NotFound ("GetRepositoryByID" , err )
293
- return
294
- } else if err != nil {
295
- ctx .ServerError ("GetRepositoryByID" , fmt .Errorf ("[%d]%v" , repoID , err ))
296
- return
297
- }
298
- showReposMap [repoID ] = repo
299
- }
300
-
301
- repo := showReposMap [repoID ]
302
-
303
- // Check if user has access to given repository.
304
- perm , err := models .GetUserRepoPermission (repo , ctxUser )
305
- if err != nil {
306
- ctx .ServerError ("GetUserRepoPermission" , fmt .Errorf ("[%d]%v" , repoID , err ))
307
- return
308
- }
309
- if ! perm .CanRead (models .UnitTypeIssues ) {
310
- if log .IsTrace () {
311
- log .Trace ("Permission Denied: User %-v cannot read %-v of repo %-v\n " +
312
- "User in repo has Permissions: %-+v" ,
313
- ctxUser ,
314
- models .UnitTypeIssues ,
315
- repo ,
316
- perm )
317
- }
318
- ctx .Status (404 )
319
- return
320
- }
321
- }
322
-
323
283
showRepos := models .RepositoryListOfMap (showReposMap )
324
284
sort .Sort (showRepos )
325
285
if err = showRepos .LoadAttributes (); err != nil {
@@ -337,12 +297,12 @@ func Issues(ctx *context.Context) {
337
297
}
338
298
339
299
issueStats , err := models .GetUserIssueStats (models.UserIssueStatsOptions {
340
- UserID : ctxUser .ID ,
341
- RepoID : repoID ,
342
- UserRepoIDs : userRepoIDs ,
343
- FilterMode : filterMode ,
344
- IsPull : isPullList ,
345
- IsClosed : isShowClosed ,
300
+ UserID : ctxUser .ID ,
301
+ RepoID : repoID ,
302
+ RepoSubQuery : opts . RepoSubQuery ,
303
+ FilterMode : filterMode ,
304
+ IsPull : isPullList ,
305
+ IsClosed : isShowClosed ,
346
306
})
347
307
if err != nil {
348
308
ctx .ServerError ("GetUserIssueStats" , err )
0 commit comments