@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/perm"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/metrics"
"code.gitea.io/gitea/modules/public"
@ -101,7 +102,7 @@ func buildAuthGroup() *auth_service.Group {
group . Add ( & auth_service . Basic { } ) // FIXME: this should be removed and only applied in download and git/lfs routers
if setting . Service . EnableReverseProxyAuth {
group . Add ( & auth_service . ReverseProxy { } ) // reverseproxy should before Session, otherwise the header will be ignored if user has login
group . Add ( & auth_service . ReverseProxy { } ) // reverse- proxy should before Session, otherwise the header will be ignored if user has login
}
group . Add ( & auth_service . Session { } )
@ -816,21 +817,23 @@ func registerRoutes(m *web.Router) {
m . Post ( "/{username}" , reqSignIn , context . UserAssignmentWeb ( ) , user . Action )
reqRepoAdmin := context . RequireRepoAdmin ( )
reqRepoCodeWriter := context . RequireRepoWriter ( unit . TypeCode )
canEnableEditor := context . CanEnableEditor ( )
reqRepoCodeReader := context . RequireRepoReader ( unit . TypeCode )
reqRepoReleaseWriter := context . RequireRepoWriter ( unit . TypeReleases )
reqRepoReleaseReader := context . RequireRepoReader ( unit . TypeReleases )
reqRepoWikiReader := context . RequireRepoReader ( unit . TypeWiki )
reqRepoWikiWriter := context . RequireRepoWriter ( unit . TypeWiki )
reqRepoIssueReader := context . RequireRepoReader ( unit . TypeIssues )
reqRepoPullsReader := context . RequireRepoReader ( unit . TypePullRequests )
reqRepoIssuesOrPullsWriter := context . RequireRepoWriterOr ( unit . TypeIssues , unit . TypePullRequests )
reqRepoIssuesOrPullsReader := context . RequireRepoReaderOr ( unit . TypeIssues , unit . TypePullRequests )
reqRepoProjectsReader := context . RequireRepoReader ( unit . TypeProjects )
reqRepoProjectsWriter := context . RequireRepoWriter ( unit . TypeProjects )
reqRepoActionsReader := context . RequireRepoReader ( unit . TypeActions )
reqRepoActionsWriter := context . RequireRepoWriter ( unit . TypeActions )
reqRepoCodeWriter := context . RequireUnitWriter ( unit . TypeCode )
reqRepoReleaseWriter := context . RequireUnitWriter ( unit . TypeReleases )
reqRepoReleaseReader := context . RequireUnitReader ( unit . TypeReleases )
reqRepoIssuesOrPullsWriter := context . RequireUnitWriter ( unit . TypeIssues , unit . TypePullRequests )
reqRepoIssuesOrPullsReader := context . RequireUnitReader ( unit . TypeIssues , unit . TypePullRequests )
reqRepoProjectsReader := context . RequireUnitReader ( unit . TypeProjects )
reqRepoProjectsWriter := context . RequireUnitWriter ( unit . TypeProjects )
reqRepoActionsReader := context . RequireUnitReader ( unit . TypeActions )
reqRepoActionsWriter := context . RequireUnitWriter ( unit . TypeActions )
// the legacy names "reqRepoXxx" should be renamed to the correct name "reqUnitXxx", these permissions are for units, not repos
reqUnitsWithMarkdown := context . RequireUnitReader ( unit . TypeCode , unit . TypeIssues , unit . TypePullRequests , unit . TypeReleases , unit . TypeWiki )
reqUnitCodeReader := context . RequireUnitReader ( unit . TypeCode )
reqUnitIssuesReader := context . RequireUnitReader ( unit . TypeIssues )
reqUnitPullsReader := context . RequireUnitReader ( unit . TypePullRequests )
reqUnitWikiReader := context . RequireUnitReader ( unit . TypeWiki )
reqUnitWikiWriter := context . RequireUnitWriter ( unit . TypeWiki )
reqPackageAccess := func ( accessMode perm . AccessMode ) func ( ctx * context . Context ) {
return func ( ctx * context . Context ) {
@ -1053,7 +1056,7 @@ func registerRoutes(m *web.Router) {
m . Group ( "/migrate" , func ( ) {
m . Get ( "/status" , repo . MigrateStatus )
} )
} , optSignIn , context . RepoAssignment , reqRepo CodeReader )
} , optSignIn , context . RepoAssignment , reqUnit CodeReader )
// end "/{username}/{reponame}/-": migrate
m . Group ( "/{username}/{reponame}/settings" , func ( ) {
@ -1149,56 +1152,54 @@ func registerRoutes(m *web.Router) {
// end "/{username}/{reponame}/settings"
// user/org home, including rss feeds
m . Get ( "/{username}/{reponame}" , optSignIn , context . RepoAssignment , context . RepoRef ( ) , repo . SetEditorconfigIfExists , repo . Home )
m . Get ( "/{username}/{reponame}" , optSignIn , context . RepoAssignment , context . RepoRefByType ( git . RefTypeBranch ) , repo . SetEditorconfigIfExists , repo . Home )
// TODO: maybe it should relax the permission to allow "any access"
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 )
m . Post ( "/{username}/{reponame}/markup" , optSignIn , context . RepoAssignment , reqUnitsWithMarkdown , web . Bind ( structs . MarkupOption { } ) , misc . Markup )
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Get ( "/find/*" , repo . FindFiles )
m . Group ( "/tree-list" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , repo . TreeList )
m . Get ( "/tag/*" , context . RepoRefByType ( contex t. RepoR ef Tag ) , repo . TreeList )
m . Get ( "/commit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . TreeList )
m . Get ( "/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , repo . TreeList )
m . Get ( "/tag/*" , context . RepoRefByType ( gi t. RefTy peTag ) , repo . TreeList )
m . Get ( "/commit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . TreeList )
} )
m . Get ( "/compare" , repo . MustBeNotEmpty , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . SetWhitespaceBehavior , repo . CompareDiff )
m . Combo ( "/compare/*" , repo . MustBeNotEmpty , repo . SetEditorconfigIfExists ) .
Get ( repo . SetDiffViewStyle , repo . SetWhitespaceBehavior , repo . CompareDiff ) .
Post ( reqSignIn , context . RepoMustNotBeArchived ( ) , reqRepo PullsReader , repo . MustAllowPulls , web . Bind ( forms . CreateIssueForm { } ) , repo . SetWhitespaceBehavior , repo . CompareAndPullRequestPost )
} , optSignIn , context . RepoAssignment , reqRepo CodeReader )
Post ( reqSignIn , context . RepoMustNotBeArchived ( ) , reqUnit PullsReader , repo . MustAllowPulls , web . Bind ( forms . CreateIssueForm { } ) , repo . SetWhitespaceBehavior , repo . CompareAndPullRequestPost )
} , optSignIn , context . RepoAssignment , reqUnit CodeReader )
// end "/{username}/{reponame}": repo code: find, compare, list
addIssuesPullsViewRoutes := func ( ) {
// for /{username}/{reponame}/issues" or "/{username}/{reponame}/pulls"
m . Get ( "/posters" , repo . IssuePullPosters )
m . Group ( "/{index}" , func ( ) {
m . Get ( "/info" , repo . GetIssueInfo )
m . Get ( "/attachments" , repo . GetIssueAttachments )
m . Get ( "/attachments/{uuid}" , repo . GetAttachment )
m . Group ( "/content-history" , func ( ) {
m . Get ( "/overview" , repo . GetContentHistoryOverview )
m . Get ( "/list" , repo . GetContentHistoryList )
m . Get ( "/detail" , repo . GetContentHistoryDetail )
} )
} )
}
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Get ( "/issues/posters" , repo . IssuePosters ) // it can't use {type:issues|pulls} because it would conflict with other routes like "/pulls/{index}"
m . Get ( "/pulls/posters" , repo . PullPosters )
m . Get ( "/comments/{id}/attachments" , repo . GetCommentAttachments )
m . Get ( "/labels" , repo . RetrieveLabelsForList , repo . Labels )
m . Get ( "/milestones" , repo . Milestones )
m . Get ( "/milestone/{id}" , context . RepoRef ( ) , repo . MilestoneIssuesAndPulls )
m . Group ( "/{type:issues|pulls}" , func ( ) {
m . Group ( "/{index}" , func ( ) {
m . Get ( "/info" , repo . GetIssueInfo )
m . Get ( "/attachments" , repo . GetIssueAttachments )
m . Get ( "/attachments/{uuid}" , repo . GetAttachment )
m . Group ( "/content-history" , func ( ) {
m . Get ( "/overview" , repo . GetContentHistoryOverview )
m . Get ( "/list" , repo . GetContentHistoryList )
m . Get ( "/detail" , repo . GetContentHistoryDetail )
} )
} )
} , context . RepoRef ( ) )
m . Get ( "/issues/suggestions" , repo . IssueSuggestions )
} , optSignIn , context . RepoAssignment , reqRepoIssuesOrPullsReader )
} , optSignIn , context . RepoAssignment , reqRepoIssuesOrPullsReader ) // issue/pull attachments, labels, milestones
m . Group ( "/{username}/{reponame}/{type:issues}" , addIssuesPullsViewRoutes , optSignIn , context . RepoAssignment , reqUnitIssuesReader )
m . Group ( "/{username}/{reponame}/{type:pulls}" , addIssuesPullsViewRoutes , optSignIn , context . RepoAssignment , reqUnitPullsReader )
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Group ( "/{type:issues|pulls}" , func ( ) {
m . Get ( "" , repo . Issues )
m . Group ( "/{index}" , func ( ) {
m . Get ( "" , repo . ViewIssue )
} )
} )
} , optSignIn , context . RepoAssignment , context . RequireRepoReaderOr ( unit . TypeIssues , unit . TypePullRequests , unit . TypeExternalTracker ) )
m . Group ( "/{username}/{reponame}/{type:issues}" , func ( ) {
m . Get ( "" , repo . Issues )
m . Get ( "/{index}" , repo . ViewIssue )
} , optSignIn , context . RepoAssignment , context . RequireUnitReader ( unit . TypeIssues , unit . TypeExternalTracker ) )
// end "/{username}/{reponame}": issue/pull list, issue/pull view, external tracker
m . Group ( "/{username}/{reponame}" , func ( ) { // edit issues, pulls, labels, milestones, etc
@ -1209,11 +1210,10 @@ func registerRoutes(m *web.Router) {
m . Get ( "/choose" , context . RepoRef ( ) , repo . NewIssueChooseTemplate )
} )
m . Get ( "/search" , repo . SearchRepoIssuesJSON )
} , context . RepoMustNotBeArchived ( ) , reqRepoIssue Reader)
} , reqUnitIssues Reader)
// FIXME: should use different URLs but mostly same logic for comments of issue and pull request.
// So they can apply their own enable/disable logic on routers.
m . Group ( "/{type:issues|pulls}" , func ( ) {
addIssuesPullsRoutes := func ( ) {
// for "/{username}/{reponame}/issues" or "/{username}/{reponame}/pulls"
m . Group ( "/{index}" , func ( ) {
m . Post ( "/title" , repo . UpdateIssueTitle )
m . Post ( "/content" , repo . UpdateIssueContent )
@ -1240,39 +1240,37 @@ func registerRoutes(m *web.Router) {
m . Post ( "/lock" , reqRepoIssuesOrPullsWriter , web . Bind ( forms . IssueLockForm { } ) , repo . LockIssue )
m . Post ( "/unlock" , reqRepoIssuesOrPullsWriter , repo . UnlockIssue )
m . Post ( "/delete" , reqRepoAdmin , repo . DeleteIssue )
} , context . RepoMustNotBeArchived ( ) )
m . Group ( "/{index}" , func ( ) {
m . Post ( "/content-history/soft-delete" , repo . SoftDeleteContentHistory )
} )
m . Post ( "/labels" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueLabel )
m . Post ( "/milestone" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueMilestone )
m . Post ( "/attachments" , repo . UploadIssueAttachment )
m . Post ( "/attachments/remove" , repo . DeleteAttachment )
m . Post ( "/projects" , reqRepoIssuesOrPullsWriter , reqRepoProjectsReader , repo . UpdateIssueProject )
m . Post ( "/assignee" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueAssignee )
m . Post ( "/request_review" , repo . UpdatePullReviewRequest )
m . Post ( "/dismiss_review" , reqRepoAdmin , web . Bind ( forms . DismissReviewForm { } ) , repo . DismissReview )
m . Post ( "/status" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueStatus )
m . Post ( "/delete" , reqRepoAdmin , repo . BatchDeleteIssues )
m . Post ( "/resolve_conversation" , repo . SetShowOutdatedComments , repo . UpdateResolveConversation )
m . Post ( "/attachments" , repo . UploadIssueAttachment )
m . Post ( "/attachments/remove" , repo . DeleteAttachment )
m . Delete ( "/unpin/{index}" , reqRepoAdmin , repo . IssueUnpin )
m . Post ( "/move_pin" , reqRepoAdmin , repo . IssuePinMove )
} , context . RepoMustNotBeArchived ( ) )
}
m . Group ( "/{type:issues}" , addIssuesPullsRoutes , reqUnitIssuesReader , context . RepoMustNotBeArchived ( ) )
m . Group ( "/{type:pulls}" , addIssuesPullsRoutes , reqUnitPullsReader , context . RepoMustNotBeArchived ( ) )
m . Group ( "/comments/{id}" , func ( ) {
m . Post ( "" , repo . UpdateCommentContent )
m . Post ( "/delete" , repo . DeleteComment )
m . Post ( "/reactions/{action}" , web . Bind ( forms . ReactionForm { } ) , repo . ChangeCommentReaction )
} , context . RepoMustNotBeArchived ( ) )
} , reqRepoIssuesOrPullsReader ) // edit issue/pull comment
m . Post ( "/labels" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueLabel )
m . Group ( "/labels" , func ( ) {
m . Post ( "/new" , web . Bind ( forms . CreateLabelForm { } ) , repo . NewLabel )
m . Post ( "/edit" , web . Bind ( forms . CreateLabelForm { } ) , repo . UpdateLabel )
m . Post ( "/delete" , repo . DeleteLabel )
m . Post ( "/initialize" , web . Bind ( forms . InitializeLabelsForm { } ) , repo . InitializeLabels )
} , context . RepoMustNotBeArchived ( ) , reqRepoIssuesOrPullsWriter , context . RepoRef ( ) )
} , reqRepoIssuesOrPullsWriter , context . RepoRef ( ) )
m . Post ( "/milestone" , reqRepoIssuesOrPullsWriter , repo . UpdateIssueMilestone )
m . Group ( "/milestones" , func ( ) {
m . Combo ( "/new" ) . Get ( repo . NewMilestone ) .
Post ( web . Bind ( forms . CreateMilestoneForm { } ) , repo . NewMilestonePost )
@ -1280,11 +1278,15 @@ func registerRoutes(m *web.Router) {
m . Post ( "/{id}/edit" , web . Bind ( forms . CreateMilestoneForm { } ) , repo . EditMilestonePost )
m . Post ( "/{id}/{action}" , repo . ChangeMilestoneStatus )
m . Post ( "/delete" , repo . DeleteMilestone )
} , context . RepoMustNotBeArchived ( ) , reqRepoIssuesOrPullsWriter , context . RepoRef ( ) )
m . Group ( "/pull" , func ( ) {
m . Post ( "/{index}/target_branch" , repo . UpdatePullRequestTarget )
} , context . RepoMustNotBeArchived ( ) )
} , reqSignIn , context . RepoAssignment , reqRepoIssuesOrPullsReader )
} , reqRepoIssuesOrPullsWriter , context . RepoRef ( ) )
m . Group ( "" , func ( ) {
m . Post ( "/request_review" , repo . UpdatePullReviewRequest )
m . Post ( "/dismiss_review" , reqRepoAdmin , web . Bind ( forms . DismissReviewForm { } ) , repo . DismissReview )
m . Post ( "/resolve_conversation" , repo . SetShowOutdatedComments , repo . UpdateResolveConversation )
m . Post ( "/pull/{index}/target_branch" , repo . UpdatePullRequestTarget )
} , reqUnitPullsReader )
} , reqSignIn , context . RepoAssignment , context . RepoMustNotBeArchived ( ) )
// end "/{username}/{reponame}": create or edit issues, pulls, labels, milestones
m . Group ( "/{username}/{reponame}" , func ( ) { // repo code
@ -1304,18 +1306,18 @@ func registerRoutes(m *web.Router) {
Post ( web . Bind ( forms . EditRepoFileForm { } ) , repo . NewDiffPatchPost )
m . Combo ( "/_cherrypick/{sha:([a-f0-9]{7,64})}/*" ) . Get ( repo . CherryPick ) .
Post ( web . Bind ( forms . CherryPickForm { } ) , repo . CherryPickPost )
} , repo . MustBeEditable )
} , context . RepoRefByType ( git . RefTypeBranch ) , context . CanWriteToBranch ( ) )
m . Group ( "" , func ( ) {
m . Post ( "/upload-file" , repo . UploadFileToServer )
m . Post ( "/upload-remove" , web . Bind ( forms . RemoveUploadFileForm { } ) , repo . RemoveUploadFileFromServer )
} , repo . MustBeEditable , repo . MustBeAbleToUpload )
} , context . RepoRef ( ) , canEnableEditor , context . RepoMustNotBeArchived ( ) )
} , repo . MustBeAbleToUpload , reqRepoCodeWriter )
} , repo . MustBeEditable , context . RepoMustNotBeArchived ( ) )
m . Group ( "/branches" , func ( ) {
m . Group ( "/_new" , func ( ) {
m . Post ( "/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , repo . CreateBranch )
m . Post ( "/tag/*" , context . RepoRefByType ( contex t. RepoR ef Tag ) , repo . CreateBranch )
m . Post ( "/commit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . CreateBranch )
m . Post ( "/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , repo . CreateBranch )
m . Post ( "/tag/*" , context . RepoRefByType ( gi t. RefTy peTag ) , repo . CreateBranch )
m . Post ( "/commit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . CreateBranch )
} , web . Bind ( forms . NewBranchForm { } ) )
m . Post ( "/delete" , repo . DeleteBranchPost )
m . Post ( "/restore" , repo . RestoreBranchPost )
@ -1324,45 +1326,42 @@ func registerRoutes(m *web.Router) {
} , context . RepoMustNotBeArchived ( ) , reqRepoCodeWriter , repo . MustBeNotEmpty )
m . Combo ( "/fork" ) . Get ( repo . Fork ) . Post ( web . Bind ( forms . CreateRepoForm { } ) , repo . ForkPost )
} , reqSignIn , context . RepoAssignment , reqRepo CodeReader )
} , reqSignIn , context . RepoAssignment , reqUnit CodeReader )
// end "/{username}/{reponame}": repo code
m . Group ( "/{username}/{reponame}" , func ( ) { // repo tags
m . Group ( "/tags" , func ( ) {
m . Get ( "" , repo . TagsList )
m . Get ( "/list" , repo . GetTagList )
m . Get ( ".rss" , feedEnabled , repo . TagsListFeedRSS )
m . Get ( ".atom" , feedEnabled , repo . TagsListFeedAtom )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) ,
repo . MustBeNotEmpty , context . RepoRefByType ( context . RepoRefTag , context . RepoRefByTypeOptions { IgnoreNotExistErr : true } ) )
m . Post ( "/tags/delete" , repo . DeleteTag , reqSignIn ,
repo . MustBeNotEmpty , context . RepoMustNotBeArchived ( ) , reqRepoCodeWriter , context . RepoRef ( ) )
} , optSignIn , context . RepoAssignment , reqRepoCodeReader )
m . Get ( "/list" , repo . GetTagList )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) )
m . Post ( "/tags/delete" , reqSignIn , reqRepoCodeWriter , context . RepoMustNotBeArchived ( ) , repo . DeleteTag )
} , optSignIn , context . RepoAssignment , repo . MustBeNotEmpty , reqUnitCodeReader )
// end "/{username}/{reponame}": repo tags
m . Group ( "/{username}/{reponame}" , func ( ) { // repo releases
m . Group ( "/releases" , func ( ) {
m . Get ( "" , repo . Releases )
m . Get ( "/tag/*" , repo . SingleRelease )
m . Get ( "/latest" , repo . LatestRelease )
m . Get ( ".rss" , feedEnabled , repo . ReleasesFeedRSS )
m . Get ( ".atom" , feedEnabled , repo . ReleasesFeedAtom )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) ,
repo . MustBeNotEmpty , context . RepoRefByType ( context . RepoRefTag , context . RepoRefByTypeOptions { IgnoreNotExistErr : true } ) )
m . Get ( "/releases/attachments/{uuid}" , repo . MustBeNotEmpty , repo . GetAttachment )
m . Get ( "/releases/download/{vTag}/{fileName}" , repo . MustBeNotEmpty , repo . RedirectDownload )
m . Get ( "/tag/*" , repo . SingleRelease )
m . Get ( "/latest" , repo . LatestRelease )
} , ctxDataSet ( "EnableFeed" , setting . Other . EnableFeed ) )
m . Get ( "/releases/attachments/{uuid}" , repo . GetAttachment )
m . Get ( "/releases/download/{vTag}/{fileName}" , repo . RedirectDownload )
m . Group ( "/releases" , func ( ) {
m . Get ( "/new" , repo . NewRelease )
m . Post ( "/new" , web . Bind ( forms . NewReleaseForm { } ) , repo . NewReleasePost )
m . Post ( "/delete" , repo . DeleteRelease )
m . Post ( "/attachments" , repo . UploadReleaseAttachment )
m . Post ( "/attachments/remove" , repo . DeleteAttachment )
} , reqSignIn , repo . MustBeNotEmpty , context . RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , context . RepoRef ( ) )
} , reqSignIn , context . RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , context . RepoRef ( ) )
m . Group ( "/releases" , func ( ) {
m . Get ( "/edit/*" , repo . EditRelease )
m . Post ( "/edit/*" , web . Bind ( forms . EditReleaseForm { } ) , repo . EditReleasePost )
} , reqSignIn , repo . MustBeNotEmpty , context . RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , repo . CommitInfoCache )
} , optSignIn , context . RepoAssignment , reqRepoReleaseReader )
} , reqSignIn , context . RepoMustNotBeArchived ( ) , reqRepoReleaseWriter , repo . CommitInfoCache )
} , optSignIn , context . RepoAssignment , repo . MustBeNotEmpty , re qRepoReleaseReader )
// end "/{username}/{reponame}": repo releases
m . Group ( "/{username}/{reponame}" , func ( ) { // to maintain compatibility with old attachments
@ -1440,43 +1439,48 @@ func registerRoutes(m *web.Router) {
m . Group ( "/{username}/{reponame}/wiki" , func ( ) {
m . Combo ( "" ) .
Get ( repo . Wiki ) .
Post ( context . RepoMustNotBeArchived ( ) , reqSignIn , reqRepo WikiWriter , web . Bind ( forms . NewWikiForm { } ) , repo . WikiPost )
Post ( context . RepoMustNotBeArchived ( ) , reqSignIn , reqUnit WikiWriter , web . Bind ( forms . NewWikiForm { } ) , repo . WikiPost )
m . Combo ( "/*" ) .
Get ( repo . Wiki ) .
Post ( context . RepoMustNotBeArchived ( ) , reqSignIn , reqRepo WikiWriter , web . Bind ( forms . NewWikiForm { } ) , repo . WikiPost )
Post ( context . RepoMustNotBeArchived ( ) , reqSignIn , reqUnit WikiWriter , web . Bind ( forms . NewWikiForm { } ) , repo . WikiPost )
m . Get ( "/blob_excerpt/{sha}" , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . ExcerptBlob )
m . Get ( "/commit/{sha:[a-f0-9]{7,64}}" , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . SetWhitespaceBehavior , repo . Diff )
m . Get ( "/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}" , repo . RawDiff )
m . Get ( "/raw/*" , repo . WikiRaw )
} , optSignIn , context . RepoAssignment , repo . MustEnableWiki , reqRepo WikiReader , func ( ctx * context . Context ) {
} , optSignIn , context . RepoAssignment , repo . MustEnableWiki , reqUnit WikiReader , func ( ctx * context . Context ) {
ctx . Data [ "PageIsWiki" ] = true
ctx . Data [ "CloneButtonOriginLink" ] = ctx . Repo . Repository . WikiCloneLink ( ctx , ctx . Doer )
} )
// end "/{username}/{reponame}/wiki"
m . Group ( "/{username}/{reponame}/activity" , func ( ) {
// activity has its own permission checks
m . Get ( "" , repo . Activity )
m . Get ( "/{period}" , repo . Activity )
m . Group ( "/contributors" , func ( ) {
m . Get ( "" , repo . Contributors )
m . Get ( "/data" , repo . ContributorsData )
} )
m . Group ( "/code-frequency" , func ( ) {
m . Get ( "" , repo . CodeFrequency )
m . Get ( "/data" , repo . CodeFrequencyData )
} )
m . Group ( "/recent-commits" , func ( ) {
m . Get ( "" , repo . RecentCommits )
m . Get ( "/data" , repo . RecentCommitsData )
} )
m . Group ( "" , func ( ) {
m . Group ( "/contributors" , func ( ) {
m . Get ( "" , repo . Contributors )
m . Get ( "/data" , repo . ContributorsData )
} )
m . Group ( "/code-frequency" , func ( ) {
m . Get ( "" , repo . CodeFrequency )
m . Get ( "/data" , repo . CodeFrequencyData )
} )
m . Group ( "/recent-commits" , func ( ) {
m . Get ( "" , repo . RecentCommits )
m . Get ( "/data" , repo . RecentCommitsData )
} )
} , reqUnitCodeReader )
} ,
optSignIn , context . RepoAssignment , context . RequireRepoReaderOr ( unit . TypePullRequests , unit . TypeIssues , unit . TypeReleases ) ,
context . RepoRef ( ) , repo . MustBeNotEmpty ,
optSignIn , context . RepoAssignment , repo . MustBeNotEmpty ,
context . RequireUnitReader ( unit . TypeCode , unit . TypeIssues , unit . TypePullRequests , unit . TypeReleases ) ,
)
// end "/{username}/{reponame}/activity"
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Group ( "/pulls/{index}" , func ( ) {
m . Get ( "/{type:pulls}" , repo . Issues )
m . Group ( "/{type:pulls}/{index}" , func ( ) {
m . Get ( "" , repo . SetWhitespaceBehavior , repo . GetPullDiffStats , repo . ViewIssue )
m . Get ( ".diff" , repo . DownloadPullDiff )
m . Get ( ".patch" , repo . DownloadPullPatch )
@ -1501,7 +1505,7 @@ func registerRoutes(m *web.Router) {
} , context . RepoMustNotBeArchived ( ) )
} )
} )
} , optSignIn , context . RepoAssignment , repo . MustAllowPulls , reqRepo PullsReader )
} , optSignIn , context . RepoAssignment , repo . MustAllowPulls , reqUnit PullsReader )
// end "/{username}/{reponame}/pulls/{index}": repo pull request
m . Group ( "/{username}/{reponame}" , func ( ) {
@ -1521,42 +1525,39 @@ func registerRoutes(m *web.Router) {
} , repo . MustBeNotEmpty , context . RepoRef ( ) )
m . Group ( "/media" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . SingleDownloadOrLFS )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . SingleDownloadOrLFS )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . SingleDownloadOrLFS )
m . Get ( "/blob/{sha}" , repo . DownloadByIDOrLFS )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . SingleDownloadOrLFS )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . SingleDownloadOrLFS )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . SingleDownloadOrLFS )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . SingleDownloadOrLFS )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . SingleDownloadOrLFS ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/raw" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . SingleDownload )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . SingleDownload )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . SingleDownload )
m . Get ( "/blob/{sha}" , repo . DownloadByID )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . SingleDownload )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . SingleDownload )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . SingleDownload )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . SingleDownload )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . SingleDownload ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/render" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , repo . RenderFile )
m . Get ( "/tag/*" , context . RepoRefByType ( contex t. RepoR ef Tag ) , repo . RenderFile )
m . Get ( "/commit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . RenderFile )
m . Get ( "/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , repo . RenderFile )
m . Get ( "/tag/*" , context . RepoRefByType ( gi t. RefTy peTag ) , repo . RenderFile )
m . Get ( "/commit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . RenderFile )
m . Get ( "/blob/{sha}" , repo . RenderFile )
} , repo . MustBeNotEmpty )
m . Group ( "/commits" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( context . RepoRefBranch ) , repo . RefCommits )
m . Get ( "/tag/*" , context . RepoRefByType ( context . RepoRefTag ) , repo . RefCommits )
m . Get ( "/commit/*" , context . RepoRefByType ( context . RepoRefCommit ) , repo . RefCommits )
// "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . RefCommits )
m . Get ( "/branch/*" , context . RepoRefByType ( git . RefTypeBranch ) , repo . RefCommits )
m . Get ( "/tag/*" , context . RepoRefByType ( git . RefTypeTag ) , repo . RefCommits )
m . Get ( "/commit/*" , context . RepoRefByType ( git . RefTypeCommit ) , repo . RefCommits )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . RefCommits ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . MustBeNotEmpty )
m . Group ( "/blame" , func ( ) {
m . Get ( "/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , repo . RefBlame )
m . Get ( "/tag/*" , context . RepoRefByType ( contex t. RepoR ef Tag ) , repo . RefBlame )
m . Get ( "/commit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . RefBlame )
m . Get ( "/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , repo . RefBlame )
m . Get ( "/tag/*" , context . RepoRefByType ( gi t. RefTy peTag ) , repo . RefBlame )
m . Get ( "/commit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . RefBlame )
} , repo . MustBeNotEmpty )
m . Get ( "/blob_excerpt/{sha}" , repo . SetEditorconfigIfExists , repo . SetDiffViewStyle , repo . ExcerptBlob )
@ -1568,27 +1569,27 @@ func registerRoutes(m *web.Router) {
m . Get ( "/cherry-pick/{sha:([a-f0-9]{7,64})$}" , repo . SetEditorconfigIfExists , repo . CherryPick )
} , repo . MustBeNotEmpty , context . RepoRef ( ) )
m . Get ( "/rss/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/atom/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/rss/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , feedEnabled , feed . RenderBranchFeed )
m . Get ( "/atom/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , feedEnabled , feed . RenderBranchFeed )
m . Group ( "/src" , func ( ) {
m . Get ( "" , func ( ctx * context . Context ) { ctx . Redirect ( ctx . Repo . RepoLink ) } ) // there is no "{owner}/{repo}/src" page, so redirect to "{owner}/{repo}" to avoid 404
m . Get ( "/branch/*" , context . RepoRefByType ( contex t. RepoR ef Branch ) , repo . Home )
m . Get ( "/tag/*" , context . RepoRefByType ( contex t. RepoR ef Tag ) , repo . Home )
m . Get ( "/commit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . Home )
m . Get ( "/*" , context . RepoRefByType ( context . RepoRefUnknown ) , repo . Home ) // "/*" route is deprecated, and kept for backward compatibility
m . Get ( "/branch/*" , context . RepoRefByType ( gi t. RefTy peBranch ) , repo . Home )
m . Get ( "/tag/*" , context . RepoRefByType ( gi t. RefTy peTag ) , repo . Home )
m . Get ( "/commit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . Home )
m . Get ( "/*" , context . RepoRefByType ( "" ) , repo . Home ) // "/*" route is deprecated, and kept for backward compatibility
} , repo . SetEditorconfigIfExists )
m . Get ( "/forks" , context . RepoRef ( ) , repo . Forks )
m . Get ( "/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}" , repo . MustBeNotEmpty , repo . RawDiff )
m . Post ( "/lastcommit/*" , context . RepoRefByType ( contex t. RepoR ef Commit ) , repo . LastCommit )
} , optSignIn , context . RepoAssignment , reqRepo CodeReader )
m . Post ( "/lastcommit/*" , context . RepoRefByType ( gi t. RefTy peCommit ) , repo . LastCommit )
} , optSignIn , context . RepoAssignment , reqUnit CodeReader )
// end "/{username}/{reponame}": repo code
m . Group ( "/{username}/{reponame}" , func ( ) {
m . Get ( "/stars" , repo . Stars )
m . Get ( "/watchers" , repo . Watchers )
m . Get ( "/search" , reqRepo CodeReader , repo . Search )
m . Get ( "/search" , reqUnit CodeReader , repo . Search )
m . Post ( "/action/{action}" , reqSignIn , repo . Action )
} , optSignIn , context . RepoAssignment , context . RepoRef ( ) )