@@ -291,15 +291,16 @@ func Routes() *web.Router {
291
291
return routes
292
292
}
293
293
294
- var ignSignInAndCsrf = verifyAuthWithOptions (& common.VerifyOptions {DisableCSRF : true })
294
+ var optSignInIgnoreCsrf = verifyAuthWithOptions (& common.VerifyOptions {DisableCSRF : true })
295
295
296
296
// registerRoutes register routes
297
297
func registerRoutes (m * web.Router ) {
298
+ // required to be signed in or signed out
298
299
reqSignIn := verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : true })
299
300
reqSignOut := verifyAuthWithOptions (& common.VerifyOptions {SignOutRequired : true })
300
- // TODO: rename them to "optSignIn", which means that the "sign-in" could be optional, depends on the VerifyOptions (RequireSignInView )
301
- ignSignIn := verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : setting .Service .RequireSignInView })
302
- ignExploreSignIn := verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : setting .Service .RequireSignInView || setting .Service .Explore .RequireSigninView })
301
+ // optional sign in (if signed in, use the user as doer, if not, no doer )
302
+ optSignIn := verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : setting .Service .RequireSignInView })
303
+ optExploreSignIn := verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : setting .Service .RequireSignInView || setting .Service .Explore .RequireSigninView })
303
304
304
305
validation .AddBindingRules ()
305
306
@@ -470,7 +471,7 @@ func registerRoutes(m *web.Router) {
470
471
// Especially some AJAX requests, we can reduce middleware number to improve performance.
471
472
472
473
m .Get ("/" , Home )
473
- m .Get ("/sitemap.xml" , sitemapEnabled , ignExploreSignIn , HomeSitemap )
474
+ m .Get ("/sitemap.xml" , sitemapEnabled , optExploreSignIn , HomeSitemap )
474
475
m .Group ("/.well-known" , func () {
475
476
m .Get ("/openid-configuration" , auth .OIDCWellKnown )
476
477
m .Group ("" , func () {
@@ -500,7 +501,7 @@ func registerRoutes(m *web.Router) {
500
501
}
501
502
}, explore .Code )
502
503
m .Get ("/topics/search" , explore .TopicSearch )
503
- }, ignExploreSignIn )
504
+ }, optExploreSignIn )
504
505
505
506
m .Group ("/issues" , func () {
506
507
m .Get ("" , user .Issues )
@@ -558,12 +559,12 @@ func registerRoutes(m *web.Router) {
558
559
m .Post ("/grant" , web .Bind (forms.GrantApplicationForm {}), auth .GrantApplicationOAuth )
559
560
// TODO manage redirection
560
561
m .Post ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
561
- }, ignSignInAndCsrf , reqSignIn )
562
+ }, optSignInIgnoreCsrf , reqSignIn )
562
563
563
- m .Methods ("GET, OPTIONS" , "/userinfo" , optionsCorsHandler (), ignSignInAndCsrf , auth .InfoOAuth )
564
- m .Methods ("POST, OPTIONS" , "/access_token" , optionsCorsHandler (), web .Bind (forms.AccessTokenForm {}), ignSignInAndCsrf , auth .AccessTokenOAuth )
565
- m .Methods ("GET, OPTIONS" , "/keys" , optionsCorsHandler (), ignSignInAndCsrf , auth .OIDCKeys )
566
- m .Methods ("POST, OPTIONS" , "/introspect" , optionsCorsHandler (), web .Bind (forms.IntrospectTokenForm {}), ignSignInAndCsrf , auth .IntrospectOAuth )
564
+ m .Methods ("GET, OPTIONS" , "/userinfo" , optionsCorsHandler (), optSignInIgnoreCsrf , auth .InfoOAuth )
565
+ m .Methods ("POST, OPTIONS" , "/access_token" , optionsCorsHandler (), web .Bind (forms.AccessTokenForm {}), optSignInIgnoreCsrf , auth .AccessTokenOAuth )
566
+ m .Methods ("GET, OPTIONS" , "/keys" , optionsCorsHandler (), optSignInIgnoreCsrf , auth .OIDCKeys )
567
+ m .Methods ("POST, OPTIONS" , "/introspect" , optionsCorsHandler (), web .Bind (forms.IntrospectTokenForm {}), optSignInIgnoreCsrf , auth .IntrospectOAuth )
567
568
}, oauth2Enabled )
568
569
569
570
m .Group ("/user/settings" , func () {
@@ -685,7 +686,7 @@ func registerRoutes(m *web.Router) {
685
686
m .Post ("/forgot_password" , auth .ForgotPasswdPost )
686
687
m .Post ("/logout" , auth .SignOut )
687
688
m .Get ("/stopwatches" , reqSignIn , user .GetStopwatches )
688
- m .Get ("/search_candidates" , ignExploreSignIn , user .SearchCandidates )
689
+ m .Get ("/search_candidates" , optExploreSignIn , user .SearchCandidates )
689
690
m .Group ("/oauth2" , func () {
690
691
m .Get ("/{provider}" , auth .SignInOAuth )
691
692
m .Get ("/{provider}/callback" , auth .SignInOAuthCallback )
@@ -809,7 +810,7 @@ func registerRoutes(m *web.Router) {
809
810
m .Group ("" , func () {
810
811
m .Get ("/{username}" , user .UsernameSubRoute )
811
812
m .Methods ("GET, OPTIONS" , "/attachments/{uuid}" , optionsCorsHandler (), repo .GetAttachment )
812
- }, ignSignIn )
813
+ }, optSignIn )
813
814
814
815
m .Post ("/{username}" , reqSignIn , context .UserAssignmentWeb (), user .Action )
815
816
@@ -860,7 +861,7 @@ func registerRoutes(m *web.Router) {
860
861
m .Group ("/{org}" , func () {
861
862
m .Get ("/members" , org .Members )
862
863
}, context .OrgAssignment ())
863
- }, ignSignIn )
864
+ }, optSignIn )
864
865
// end "/org": members
865
866
866
867
m .Group ("/org" , func () {
@@ -1043,14 +1044,14 @@ func registerRoutes(m *web.Router) {
1043
1044
m .Group ("" , func () {
1044
1045
m .Get ("/code" , user .CodeSearch )
1045
1046
}, reqUnitAccess (unit .TypeCode , perm .AccessModeRead , false ), individualPermsChecker )
1046
- }, ignSignIn , context .UserAssignmentWeb (), context .OrgAssignment ())
1047
+ }, optSignIn , context .UserAssignmentWeb (), context .OrgAssignment ())
1047
1048
// end "/{username}/-": packages, projects, code
1048
1049
1049
1050
m .Group ("/{username}/{reponame}/-" , func () {
1050
1051
m .Group ("/migrate" , func () {
1051
1052
m .Get ("/status" , repo .MigrateStatus )
1052
1053
})
1053
- }, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1054
+ }, optSignIn , context .RepoAssignment , reqRepoCodeReader )
1054
1055
// end "/{username}/{reponame}/-": migrate
1055
1056
1056
1057
m .Group ("/{username}/{reponame}/settings" , func () {
@@ -1145,10 +1146,10 @@ func registerRoutes(m *web.Router) {
1145
1146
// end "/{username}/{reponame}/settings"
1146
1147
1147
1148
// user/org home, including rss feeds
1148
- m .Get ("/{username}/{reponame}" , ignSignIn , context .RepoAssignment , context .RepoRef (), repo .SetEditorconfigIfExists , repo .Home )
1149
+ m .Get ("/{username}/{reponame}" , optSignIn , context .RepoAssignment , context .RepoRef (), repo .SetEditorconfigIfExists , repo .Home )
1149
1150
1150
1151
// TODO: maybe it should relax the permission to allow "any access"
1151
- m .Post ("/{username}/{reponame}/markup" , ignSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeCode , unit .TypeIssues , unit .TypePullRequests , unit .TypeReleases , unit .TypeWiki ), web .Bind (structs.MarkupOption {}), misc .Markup )
1152
+ m .Post ("/{username}/{reponame}/markup" , optSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeCode , unit .TypeIssues , unit .TypePullRequests , unit .TypeReleases , unit .TypeWiki ), web .Bind (structs.MarkupOption {}), misc .Markup )
1152
1153
1153
1154
m .Group ("/{username}/{reponame}" , func () {
1154
1155
m .Get ("/find/*" , repo .FindFiles )
@@ -1161,7 +1162,7 @@ func registerRoutes(m *web.Router) {
1161
1162
m .Combo ("/compare/*" , repo .MustBeNotEmpty , repo .SetEditorconfigIfExists ).
1162
1163
Get (repo .SetDiffViewStyle , repo .SetWhitespaceBehavior , repo .CompareDiff ).
1163
1164
Post (reqSignIn , context .RepoMustNotBeArchived (), reqRepoPullsReader , repo .MustAllowPulls , web .Bind (forms.CreateIssueForm {}), repo .SetWhitespaceBehavior , repo .CompareAndPullRequestPost )
1164
- }, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1165
+ }, optSignIn , context .RepoAssignment , reqRepoCodeReader )
1165
1166
// end "/{username}/{reponame}": find, compare, list (code related)
1166
1167
1167
1168
m .Group ("/{username}/{reponame}" , func () {
@@ -1184,7 +1185,7 @@ func registerRoutes(m *web.Router) {
1184
1185
})
1185
1186
}, context .RepoRef ())
1186
1187
m .Get ("/issues/suggestions" , repo .IssueSuggestions )
1187
- }, ignSignIn , context .RepoAssignment , reqRepoIssuesOrPullsReader )
1188
+ }, optSignIn , context .RepoAssignment , reqRepoIssuesOrPullsReader )
1188
1189
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
1189
1190
1190
1191
m .Group ("/{username}/{reponame}" , func () {
@@ -1194,7 +1195,7 @@ func registerRoutes(m *web.Router) {
1194
1195
m .Get ("" , repo .ViewIssue )
1195
1196
})
1196
1197
})
1197
- }, ignSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeIssues , unit .TypePullRequests , unit .TypeExternalTracker ))
1198
+ }, optSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeIssues , unit .TypePullRequests , unit .TypeExternalTracker ))
1198
1199
// end "/{username}/{reponame}": issue/pull list, issue/pull view, external tracker
1199
1200
1200
1201
m .Group ("/{username}/{reponame}" , func () { // edit issues, pulls, labels, milestones, etc
@@ -1331,7 +1332,7 @@ func registerRoutes(m *web.Router) {
1331
1332
repo .MustBeNotEmpty , context .RepoRefByType (context .RepoRefTag , context.RepoRefByTypeOptions {IgnoreNotExistErr : true }))
1332
1333
m .Post ("/tags/delete" , repo .DeleteTag , reqSignIn ,
1333
1334
repo .MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoCodeWriter , context .RepoRef ())
1334
- }, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1335
+ }, optSignIn , context .RepoAssignment , reqRepoCodeReader )
1335
1336
// end "/{username}/{reponame}": repo tags
1336
1337
1337
1338
m .Group ("/{username}/{reponame}" , func () { // repo releases
@@ -1356,12 +1357,12 @@ func registerRoutes(m *web.Router) {
1356
1357
m .Get ("/edit/*" , repo .EditRelease )
1357
1358
m .Post ("/edit/*" , web .Bind (forms.EditReleaseForm {}), repo .EditReleasePost )
1358
1359
}, reqSignIn , repo .MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , repo .CommitInfoCache )
1359
- }, ignSignIn , context .RepoAssignment , reqRepoReleaseReader )
1360
+ }, optSignIn , context .RepoAssignment , reqRepoReleaseReader )
1360
1361
// end "/{username}/{reponame}": repo releases
1361
1362
1362
1363
m .Group ("/{username}/{reponame}" , func () { // to maintain compatibility with old attachments
1363
1364
m .Get ("/attachments/{uuid}" , repo .GetAttachment )
1364
- }, ignSignIn , context .RepoAssignment )
1365
+ }, optSignIn , context .RepoAssignment )
1365
1366
// end "/{username}/{reponame}": compatibility with old attachments
1366
1367
1367
1368
m .Group ("/{username}/{reponame}" , func () {
@@ -1372,7 +1373,7 @@ func registerRoutes(m *web.Router) {
1372
1373
if setting .Packages .Enabled {
1373
1374
m .Get ("/packages" , repo .Packages )
1374
1375
}
1375
- }, ignSignIn , context .RepoAssignment )
1376
+ }, optSignIn , context .RepoAssignment )
1376
1377
1377
1378
m .Group ("/{username}/{reponame}/projects" , func () {
1378
1379
m .Get ("" , repo .Projects )
@@ -1397,7 +1398,7 @@ func registerRoutes(m *web.Router) {
1397
1398
})
1398
1399
})
1399
1400
}, reqRepoProjectsWriter , context .RepoMustNotBeArchived ())
1400
- }, ignSignIn , context .RepoAssignment , reqRepoProjectsReader , repo .MustEnableRepoProjects )
1401
+ }, optSignIn , context .RepoAssignment , reqRepoProjectsReader , repo .MustEnableRepoProjects )
1401
1402
// end "/{username}/{reponame}/projects"
1402
1403
1403
1404
m .Group ("/{username}/{reponame}/actions" , func () {
@@ -1427,7 +1428,7 @@ func registerRoutes(m *web.Router) {
1427
1428
m .Group ("/workflows/{workflow_name}" , func () {
1428
1429
m .Get ("/badge.svg" , actions .GetWorkflowBadge )
1429
1430
})
1430
- }, ignSignIn , context .RepoAssignment , reqRepoActionsReader , actions .MustEnableActions )
1431
+ }, optSignIn , context .RepoAssignment , reqRepoActionsReader , actions .MustEnableActions )
1431
1432
// end "/{username}/{reponame}/actions"
1432
1433
1433
1434
m .Group ("/{username}/{reponame}/wiki" , func () {
@@ -1440,7 +1441,7 @@ func registerRoutes(m *web.Router) {
1440
1441
m .Get ("/commit/{sha:[a-f0-9]{7,64}}" , repo .SetEditorconfigIfExists , repo .SetDiffViewStyle , repo .SetWhitespaceBehavior , repo .Diff )
1441
1442
m .Get ("/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}" , repo .RawDiff )
1442
1443
m .Get ("/raw/*" , repo .WikiRaw )
1443
- }, ignSignIn , context .RepoAssignment , repo .MustEnableWiki , reqRepoWikiReader , func (ctx * context.Context ) {
1444
+ }, optSignIn , context .RepoAssignment , repo .MustEnableWiki , reqRepoWikiReader , func (ctx * context.Context ) {
1444
1445
ctx .Data ["PageIsWiki" ] = true
1445
1446
ctx .Data ["CloneButtonOriginLink" ] = ctx .Repo .Repository .WikiCloneLink ()
1446
1447
})
@@ -1462,7 +1463,7 @@ func registerRoutes(m *web.Router) {
1462
1463
m .Get ("/data" , repo .RecentCommitsData )
1463
1464
})
1464
1465
},
1465
- ignSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypePullRequests , unit .TypeIssues , unit .TypeReleases ),
1466
+ optSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypePullRequests , unit .TypeIssues , unit .TypeReleases ),
1466
1467
context .RepoRef (), repo .MustBeNotEmpty ,
1467
1468
)
1468
1469
// end "/{username}/{reponame}/activity"
@@ -1493,7 +1494,7 @@ func registerRoutes(m *web.Router) {
1493
1494
}, context .RepoMustNotBeArchived ())
1494
1495
})
1495
1496
})
1496
- }, ignSignIn , context .RepoAssignment , repo .MustAllowPulls , reqRepoPullsReader )
1497
+ }, optSignIn , context .RepoAssignment , repo .MustAllowPulls , reqRepoPullsReader )
1497
1498
// end "/{username}/{reponame}/pulls/{index}": repo pull request
1498
1499
1499
1500
m .Group ("/{username}/{reponame}" , func () {
@@ -1593,21 +1594,19 @@ func registerRoutes(m *web.Router) {
1593
1594
m .Get ("/forks" , context .RepoRef (), repo .Forks )
1594
1595
m .Get ("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}" , repo .MustBeNotEmpty , repo .RawDiff )
1595
1596
m .Post ("/lastcommit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .LastCommit )
1596
- }, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1597
+ }, optSignIn , context .RepoAssignment , reqRepoCodeReader )
1597
1598
// end "/{username}/{reponame}": repo code
1598
1599
1599
1600
m .Group ("/{username}/{reponame}" , func () {
1600
1601
m .Get ("/stars" , repo .Stars )
1601
1602
m .Get ("/watchers" , repo .Watchers )
1602
1603
m .Get ("/search" , reqRepoCodeReader , repo .Search )
1603
1604
m .Post ("/action/{action}" , reqSignIn , repo .Action )
1604
- }, ignSignIn , context .RepoAssignment , context .RepoRef ())
1605
+ }, optSignIn , context .RepoAssignment , context .RepoRef ())
1605
1606
1606
- common .AddOwnerRepoGitLFSRoutes (m , ignSignInAndCsrf , lfsServerEnabled )
1607
- m .Group ("/{username}/{reponame}" , func () {
1608
- gitHTTPRouters (m )
1609
- })
1610
- // end "/{username}/{reponame}.git": git support
1607
+ common .AddOwnerRepoGitLFSRoutes (m , optSignInIgnoreCsrf , lfsServerEnabled ) // "/{username}/{reponame}/{lfs-paths}": git-lfs support
1608
+
1609
+ addOwnerRepoGitHTTPRouters (m ) // "/{username}/{reponame}/{git-paths}": git http support
1611
1610
1612
1611
m .Group ("/notifications" , func () {
1613
1612
m .Get ("" , user .Notifications )
0 commit comments