@@ -291,15 +291,16 @@ func Routes() *web.Router {
291291	return  routes 
292292}
293293
294- var  ignSignInAndCsrf  =  verifyAuthWithOptions (& common.VerifyOptions {DisableCSRF : true })
294+ var  optSignInIgnoreCsrf  =  verifyAuthWithOptions (& common.VerifyOptions {DisableCSRF : true })
295295
296296// registerRoutes register routes 
297297func  registerRoutes (m  * web.Router ) {
298+ 	// required to be signed in or signed out 
298299	reqSignIn  :=  verifyAuthWithOptions (& common.VerifyOptions {SignInRequired : true })
299300	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 })
303304
304305	validation .AddBindingRules ()
305306
@@ -470,7 +471,7 @@ func registerRoutes(m *web.Router) {
470471	// Especially some AJAX requests, we can reduce middleware number to improve performance. 
471472
472473	m .Get ("/" , Home )
473- 	m .Get ("/sitemap.xml" , sitemapEnabled , ignExploreSignIn , HomeSitemap )
474+ 	m .Get ("/sitemap.xml" , sitemapEnabled , optExploreSignIn , HomeSitemap )
474475	m .Group ("/.well-known" , func () {
475476		m .Get ("/openid-configuration" , auth .OIDCWellKnown )
476477		m .Group ("" , func () {
@@ -500,7 +501,7 @@ func registerRoutes(m *web.Router) {
500501			}
501502		}, explore .Code )
502503		m .Get ("/topics/search" , explore .TopicSearch )
503- 	}, ignExploreSignIn )
504+ 	}, optExploreSignIn )
504505
505506	m .Group ("/issues" , func () {
506507		m .Get ("" , user .Issues )
@@ -558,12 +559,12 @@ func registerRoutes(m *web.Router) {
558559			m .Post ("/grant" , web .Bind (forms.GrantApplicationForm {}), auth .GrantApplicationOAuth )
559560			// TODO manage redirection 
560561			m .Post ("/authorize" , web .Bind (forms.AuthorizationForm {}), auth .AuthorizeOAuth )
561- 		}, ignSignInAndCsrf , reqSignIn )
562+ 		}, optSignInIgnoreCsrf , reqSignIn )
562563
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 )
567568	}, oauth2Enabled )
568569
569570	m .Group ("/user/settings" , func () {
@@ -685,7 +686,7 @@ func registerRoutes(m *web.Router) {
685686		m .Post ("/forgot_password" , auth .ForgotPasswdPost )
686687		m .Post ("/logout" , auth .SignOut )
687688		m .Get ("/stopwatches" , reqSignIn , user .GetStopwatches )
688- 		m .Get ("/search_candidates" , ignExploreSignIn , user .SearchCandidates )
689+ 		m .Get ("/search_candidates" , optExploreSignIn , user .SearchCandidates )
689690		m .Group ("/oauth2" , func () {
690691			m .Get ("/{provider}" , auth .SignInOAuth )
691692			m .Get ("/{provider}/callback" , auth .SignInOAuthCallback )
@@ -809,7 +810,7 @@ func registerRoutes(m *web.Router) {
809810	m .Group ("" , func () {
810811		m .Get ("/{username}" , user .UsernameSubRoute )
811812		m .Methods ("GET, OPTIONS" , "/attachments/{uuid}" , optionsCorsHandler (), repo .GetAttachment )
812- 	}, ignSignIn )
813+ 	}, optSignIn )
813814
814815	m .Post ("/{username}" , reqSignIn , context .UserAssignmentWeb (), user .Action )
815816
@@ -860,7 +861,7 @@ func registerRoutes(m *web.Router) {
860861		m .Group ("/{org}" , func () {
861862			m .Get ("/members" , org .Members )
862863		}, context .OrgAssignment ())
863- 	}, ignSignIn )
864+ 	}, optSignIn )
864865	// end "/org": members 
865866
866867	m .Group ("/org" , func () {
@@ -1043,14 +1044,14 @@ func registerRoutes(m *web.Router) {
10431044		m .Group ("" , func () {
10441045			m .Get ("/code" , user .CodeSearch )
10451046		}, reqUnitAccess (unit .TypeCode , perm .AccessModeRead , false ), individualPermsChecker )
1046- 	}, ignSignIn , context .UserAssignmentWeb (), context .OrgAssignment ())
1047+ 	}, optSignIn , context .UserAssignmentWeb (), context .OrgAssignment ())
10471048	// end "/{username}/-": packages, projects, code 
10481049
10491050	m .Group ("/{username}/{reponame}/-" , func () {
10501051		m .Group ("/migrate" , func () {
10511052			m .Get ("/status" , repo .MigrateStatus )
10521053		})
1053- 	}, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1054+ 	}, optSignIn , context .RepoAssignment , reqRepoCodeReader )
10541055	// end "/{username}/{reponame}/-": migrate 
10551056
10561057	m .Group ("/{username}/{reponame}/settings" , func () {
@@ -1145,10 +1146,10 @@ func registerRoutes(m *web.Router) {
11451146	// end "/{username}/{reponame}/settings" 
11461147
11471148	// 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 )
11491150
11501151	// 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 )
11521153
11531154	m .Group ("/{username}/{reponame}" , func () {
11541155		m .Get ("/find/*" , repo .FindFiles )
@@ -1161,7 +1162,7 @@ func registerRoutes(m *web.Router) {
11611162		m .Combo ("/compare/*" , repo .MustBeNotEmpty , repo .SetEditorconfigIfExists ).
11621163			Get (repo .SetDiffViewStyle , repo .SetWhitespaceBehavior , repo .CompareDiff ).
11631164			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 )
11651166	// end "/{username}/{reponame}": find, compare, list (code related) 
11661167
11671168	m .Group ("/{username}/{reponame}" , func () {
@@ -1184,7 +1185,7 @@ func registerRoutes(m *web.Router) {
11841185			})
11851186		}, context .RepoRef ())
11861187		m .Get ("/issues/suggestions" , repo .IssueSuggestions )
1187- 	}, ignSignIn , context .RepoAssignment , reqRepoIssuesOrPullsReader )
1188+ 	}, optSignIn , context .RepoAssignment , reqRepoIssuesOrPullsReader )
11881189	// end "/{username}/{reponame}": view milestone, label, issue, pull, etc 
11891190
11901191	m .Group ("/{username}/{reponame}" , func () {
@@ -1194,7 +1195,7 @@ func registerRoutes(m *web.Router) {
11941195				m .Get ("" , repo .ViewIssue )
11951196			})
11961197		})
1197- 	}, ignSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeIssues , unit .TypePullRequests , unit .TypeExternalTracker ))
1198+ 	}, optSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypeIssues , unit .TypePullRequests , unit .TypeExternalTracker ))
11981199	// end "/{username}/{reponame}": issue/pull list, issue/pull view, external tracker 
11991200
12001201	m .Group ("/{username}/{reponame}" , func () { // edit issues, pulls, labels, milestones, etc 
@@ -1331,7 +1332,7 @@ func registerRoutes(m *web.Router) {
13311332			repo .MustBeNotEmpty , context .RepoRefByType (context .RepoRefTag , context.RepoRefByTypeOptions {IgnoreNotExistErr : true }))
13321333		m .Post ("/tags/delete" , repo .DeleteTag , reqSignIn ,
13331334			repo .MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoCodeWriter , context .RepoRef ())
1334- 	}, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1335+ 	}, optSignIn , context .RepoAssignment , reqRepoCodeReader )
13351336	// end "/{username}/{reponame}": repo tags 
13361337
13371338	m .Group ("/{username}/{reponame}" , func () { // repo releases 
@@ -1356,12 +1357,12 @@ func registerRoutes(m *web.Router) {
13561357			m .Get ("/edit/*" , repo .EditRelease )
13571358			m .Post ("/edit/*" , web .Bind (forms.EditReleaseForm {}), repo .EditReleasePost )
13581359		}, reqSignIn , repo .MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , repo .CommitInfoCache )
1359- 	}, ignSignIn , context .RepoAssignment , reqRepoReleaseReader )
1360+ 	}, optSignIn , context .RepoAssignment , reqRepoReleaseReader )
13601361	// end "/{username}/{reponame}": repo releases 
13611362
13621363	m .Group ("/{username}/{reponame}" , func () { // to maintain compatibility with old attachments 
13631364		m .Get ("/attachments/{uuid}" , repo .GetAttachment )
1364- 	}, ignSignIn , context .RepoAssignment )
1365+ 	}, optSignIn , context .RepoAssignment )
13651366	// end "/{username}/{reponame}": compatibility with old attachments 
13661367
13671368	m .Group ("/{username}/{reponame}" , func () {
@@ -1372,7 +1373,7 @@ func registerRoutes(m *web.Router) {
13721373		if  setting .Packages .Enabled  {
13731374			m .Get ("/packages" , repo .Packages )
13741375		}
1375- 	}, ignSignIn , context .RepoAssignment )
1376+ 	}, optSignIn , context .RepoAssignment )
13761377
13771378	m .Group ("/{username}/{reponame}/projects" , func () {
13781379		m .Get ("" , repo .Projects )
@@ -1397,7 +1398,7 @@ func registerRoutes(m *web.Router) {
13971398				})
13981399			})
13991400		}, reqRepoProjectsWriter , context .RepoMustNotBeArchived ())
1400- 	}, ignSignIn , context .RepoAssignment , reqRepoProjectsReader , repo .MustEnableRepoProjects )
1401+ 	}, optSignIn , context .RepoAssignment , reqRepoProjectsReader , repo .MustEnableRepoProjects )
14011402	// end "/{username}/{reponame}/projects" 
14021403
14031404	m .Group ("/{username}/{reponame}/actions" , func () {
@@ -1427,7 +1428,7 @@ func registerRoutes(m *web.Router) {
14271428		m .Group ("/workflows/{workflow_name}" , func () {
14281429			m .Get ("/badge.svg" , actions .GetWorkflowBadge )
14291430		})
1430- 	}, ignSignIn , context .RepoAssignment , reqRepoActionsReader , actions .MustEnableActions )
1431+ 	}, optSignIn , context .RepoAssignment , reqRepoActionsReader , actions .MustEnableActions )
14311432	// end "/{username}/{reponame}/actions" 
14321433
14331434	m .Group ("/{username}/{reponame}/wiki" , func () {
@@ -1440,7 +1441,7 @@ func registerRoutes(m *web.Router) {
14401441		m .Get ("/commit/{sha:[a-f0-9]{7,64}}" , repo .SetEditorconfigIfExists , repo .SetDiffViewStyle , repo .SetWhitespaceBehavior , repo .Diff )
14411442		m .Get ("/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}" , repo .RawDiff )
14421443		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 ) {
14441445		ctx .Data ["PageIsWiki" ] =  true 
14451446		ctx .Data ["CloneButtonOriginLink" ] =  ctx .Repo .Repository .WikiCloneLink ()
14461447	})
@@ -1462,7 +1463,7 @@ func registerRoutes(m *web.Router) {
14621463			m .Get ("/data" , repo .RecentCommitsData )
14631464		})
14641465	},
1465- 		ignSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypePullRequests , unit .TypeIssues , unit .TypeReleases ),
1466+ 		optSignIn , context .RepoAssignment , context .RequireRepoReaderOr (unit .TypePullRequests , unit .TypeIssues , unit .TypeReleases ),
14661467		context .RepoRef (), repo .MustBeNotEmpty ,
14671468	)
14681469	// end "/{username}/{reponame}/activity" 
@@ -1493,7 +1494,7 @@ func registerRoutes(m *web.Router) {
14931494				}, context .RepoMustNotBeArchived ())
14941495			})
14951496		})
1496- 	}, ignSignIn , context .RepoAssignment , repo .MustAllowPulls , reqRepoPullsReader )
1497+ 	}, optSignIn , context .RepoAssignment , repo .MustAllowPulls , reqRepoPullsReader )
14971498	// end "/{username}/{reponame}/pulls/{index}": repo pull request 
14981499
14991500	m .Group ("/{username}/{reponame}" , func () {
@@ -1593,21 +1594,19 @@ func registerRoutes(m *web.Router) {
15931594		m .Get ("/forks" , context .RepoRef (), repo .Forks )
15941595		m .Get ("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}" , repo .MustBeNotEmpty , repo .RawDiff )
15951596		m .Post ("/lastcommit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .LastCommit )
1596- 	}, ignSignIn , context .RepoAssignment , reqRepoCodeReader )
1597+ 	}, optSignIn , context .RepoAssignment , reqRepoCodeReader )
15971598	// end "/{username}/{reponame}": repo code 
15981599
15991600	m .Group ("/{username}/{reponame}" , func () {
16001601		m .Get ("/stars" , repo .Stars )
16011602		m .Get ("/watchers" , repo .Watchers )
16021603		m .Get ("/search" , reqRepoCodeReader , repo .Search )
16031604		m .Post ("/action/{action}" , reqSignIn , repo .Action )
1604- 	}, ignSignIn , context .RepoAssignment , context .RepoRef ())
1605+ 	}, optSignIn , context .RepoAssignment , context .RepoRef ())
16051606
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 
16111610
16121611	m .Group ("/notifications" , func () {
16131612		m .Get ("" , user .Notifications )
0 commit comments