@@ -11,6 +11,7 @@ import (
11
11
"code.gitea.io/gitea/models/db"
12
12
"code.gitea.io/gitea/models/perm"
13
13
"code.gitea.io/gitea/models/unit"
14
+ "code.gitea.io/gitea/modules/git"
14
15
"code.gitea.io/gitea/modules/log"
15
16
"code.gitea.io/gitea/modules/metrics"
16
17
"code.gitea.io/gitea/modules/public"
@@ -817,7 +818,6 @@ func registerRoutes(m *web.Router) {
817
818
818
819
reqRepoAdmin := context .RequireRepoAdmin ()
819
820
reqRepoCodeWriter := context .RequireUnitWriter (unit .TypeCode )
820
- canEnableEditor := context .CanEnableEditor ()
821
821
reqRepoReleaseWriter := context .RequireUnitWriter (unit .TypeReleases )
822
822
reqRepoReleaseReader := context .RequireUnitReader (unit .TypeReleases )
823
823
reqRepoIssuesOrPullsWriter := context .RequireUnitWriter (unit .TypeIssues , unit .TypePullRequests )
@@ -1152,16 +1152,16 @@ func registerRoutes(m *web.Router) {
1152
1152
// end "/{username}/{reponame}/settings"
1153
1153
1154
1154
// user/org home, including rss feeds
1155
- m .Get ("/{username}/{reponame}" , optSignIn , context .RepoAssignment , context .RepoRef ( ), repo .SetEditorconfigIfExists , repo .Home )
1155
+ m .Get ("/{username}/{reponame}" , optSignIn , context .RepoAssignment , context .RepoRefByType ( git . RefTypeBranch ), repo .SetEditorconfigIfExists , repo .Home )
1156
1156
1157
1157
m .Post ("/{username}/{reponame}/markup" , optSignIn , context .RepoAssignment , reqUnitsWithMarkdown , web .Bind (structs.MarkupOption {}), misc .Markup )
1158
1158
1159
1159
m .Group ("/{username}/{reponame}" , func () {
1160
1160
m .Get ("/find/*" , repo .FindFiles )
1161
1161
m .Group ("/tree-list" , func () {
1162
- m .Get ("/branch/*" , context .RepoRefByType (context . RepoRefBranch ), repo .TreeList )
1163
- m .Get ("/tag/*" , context .RepoRefByType (context . RepoRefTag ), repo .TreeList )
1164
- m .Get ("/commit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .TreeList )
1162
+ m .Get ("/branch/*" , context .RepoRefByType (git . RefTypeBranch ), repo .TreeList )
1163
+ m .Get ("/tag/*" , context .RepoRefByType (git . RefTypeTag ), repo .TreeList )
1164
+ m .Get ("/commit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .TreeList )
1165
1165
})
1166
1166
m .Get ("/compare" , repo .MustBeNotEmpty , repo .SetEditorconfigIfExists , repo .SetDiffViewStyle , repo .SetWhitespaceBehavior , repo .CompareDiff )
1167
1167
m .Combo ("/compare/*" , repo .MustBeNotEmpty , repo .SetEditorconfigIfExists ).
@@ -1306,18 +1306,18 @@ func registerRoutes(m *web.Router) {
1306
1306
Post (web .Bind (forms.EditRepoFileForm {}), repo .NewDiffPatchPost )
1307
1307
m .Combo ("/_cherrypick/{sha:([a-f0-9]{7,64})}/*" ).Get (repo .CherryPick ).
1308
1308
Post (web .Bind (forms.CherryPickForm {}), repo .CherryPickPost )
1309
- }, repo . MustBeEditable )
1309
+ }, context . RepoRefByType ( git . RefTypeBranch ), context . CanWriteToBranch () )
1310
1310
m .Group ("" , func () {
1311
1311
m .Post ("/upload-file" , repo .UploadFileToServer )
1312
1312
m .Post ("/upload-remove" , web .Bind (forms.RemoveUploadFileForm {}), repo .RemoveUploadFileFromServer )
1313
- }, repo .MustBeEditable , repo . MustBeAbleToUpload )
1314
- }, context . RepoRef (), canEnableEditor , context .RepoMustNotBeArchived ())
1313
+ }, repo .MustBeAbleToUpload , reqRepoCodeWriter )
1314
+ }, repo . MustBeEditable , context .RepoMustNotBeArchived ())
1315
1315
1316
1316
m .Group ("/branches" , func () {
1317
1317
m .Group ("/_new" , func () {
1318
- m .Post ("/branch/*" , context .RepoRefByType (context . RepoRefBranch ), repo .CreateBranch )
1319
- m .Post ("/tag/*" , context .RepoRefByType (context . RepoRefTag ), repo .CreateBranch )
1320
- m .Post ("/commit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .CreateBranch )
1318
+ m .Post ("/branch/*" , context .RepoRefByType (git . RefTypeBranch ), repo .CreateBranch )
1319
+ m .Post ("/tag/*" , context .RepoRefByType (git . RefTypeTag ), repo .CreateBranch )
1320
+ m .Post ("/commit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .CreateBranch )
1321
1321
}, web .Bind (forms.NewBranchForm {}))
1322
1322
m .Post ("/delete" , repo .DeleteBranchPost )
1323
1323
m .Post ("/restore" , repo .RestoreBranchPost )
@@ -1332,39 +1332,36 @@ func registerRoutes(m *web.Router) {
1332
1332
m .Group ("/{username}/{reponame}" , func () { // repo tags
1333
1333
m .Group ("/tags" , func () {
1334
1334
m .Get ("" , repo .TagsList )
1335
- m .Get ("/list" , repo .GetTagList )
1336
1335
m .Get (".rss" , feedEnabled , repo .TagsListFeedRSS )
1337
1336
m .Get (".atom" , feedEnabled , repo .TagsListFeedAtom )
1338
- }, ctxDataSet ("EnableFeed" , setting .Other .EnableFeed ),
1339
- repo .MustBeNotEmpty , context .RepoRefByType (context .RepoRefTag , context.RepoRefByTypeOptions {IgnoreNotExistErr : true }))
1340
- m .Post ("/tags/delete" , repo .DeleteTag , reqSignIn ,
1341
- repo .MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoCodeWriter , context .RepoRef ())
1342
- }, optSignIn , context .RepoAssignment , reqUnitCodeReader )
1337
+ m .Get ("/list" , repo .GetTagList )
1338
+ }, ctxDataSet ("EnableFeed" , setting .Other .EnableFeed ))
1339
+ m .Post ("/tags/delete" , reqSignIn , reqRepoCodeWriter , context .RepoMustNotBeArchived (), repo .DeleteTag )
1340
+ }, optSignIn , context .RepoAssignment , repo .MustBeNotEmpty , reqUnitCodeReader )
1343
1341
// end "/{username}/{reponame}": repo tags
1344
1342
1345
1343
m .Group ("/{username}/{reponame}" , func () { // repo releases
1346
1344
m .Group ("/releases" , func () {
1347
1345
m .Get ("" , repo .Releases )
1348
- m .Get ("/tag/*" , repo .SingleRelease )
1349
- m .Get ("/latest" , repo .LatestRelease )
1350
1346
m .Get (".rss" , feedEnabled , repo .ReleasesFeedRSS )
1351
1347
m .Get (".atom" , feedEnabled , repo .ReleasesFeedAtom )
1352
- }, ctxDataSet ("EnableFeed" , setting .Other .EnableFeed ),
1353
- repo .MustBeNotEmpty , context .RepoRefByType (context .RepoRefTag , context.RepoRefByTypeOptions {IgnoreNotExistErr : true }))
1354
- m .Get ("/releases/attachments/{uuid}" , repo .MustBeNotEmpty , repo .GetAttachment )
1355
- m .Get ("/releases/download/{vTag}/{fileName}" , repo .MustBeNotEmpty , repo .RedirectDownload )
1348
+ m .Get ("/tag/*" , repo .SingleRelease )
1349
+ m .Get ("/latest" , repo .LatestRelease )
1350
+ }, ctxDataSet ("EnableFeed" , setting .Other .EnableFeed ))
1351
+ m .Get ("/releases/attachments/{uuid}" , repo .GetAttachment )
1352
+ m .Get ("/releases/download/{vTag}/{fileName}" , repo .RedirectDownload )
1356
1353
m .Group ("/releases" , func () {
1357
1354
m .Get ("/new" , repo .NewRelease )
1358
1355
m .Post ("/new" , web .Bind (forms.NewReleaseForm {}), repo .NewReleasePost )
1359
1356
m .Post ("/delete" , repo .DeleteRelease )
1360
1357
m .Post ("/attachments" , repo .UploadReleaseAttachment )
1361
1358
m .Post ("/attachments/remove" , repo .DeleteAttachment )
1362
- }, reqSignIn , repo . MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , context .RepoRef ())
1359
+ }, reqSignIn , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , context .RepoRef ())
1363
1360
m .Group ("/releases" , func () {
1364
1361
m .Get ("/edit/*" , repo .EditRelease )
1365
1362
m .Post ("/edit/*" , web .Bind (forms.EditReleaseForm {}), repo .EditReleasePost )
1366
- }, reqSignIn , repo . MustBeNotEmpty , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , repo .CommitInfoCache )
1367
- }, optSignIn , context .RepoAssignment , reqRepoReleaseReader )
1363
+ }, reqSignIn , context .RepoMustNotBeArchived (), reqRepoReleaseWriter , repo .CommitInfoCache )
1364
+ }, optSignIn , context .RepoAssignment , repo . MustBeNotEmpty , reqRepoReleaseReader )
1368
1365
// end "/{username}/{reponame}": repo releases
1369
1366
1370
1367
m .Group ("/{username}/{reponame}" , func () { // to maintain compatibility with old attachments
@@ -1528,42 +1525,39 @@ func registerRoutes(m *web.Router) {
1528
1525
}, repo .MustBeNotEmpty , context .RepoRef ())
1529
1526
1530
1527
m .Group ("/media" , func () {
1531
- m .Get ("/branch/*" , context .RepoRefByType (context .RepoRefBranch ), repo .SingleDownloadOrLFS )
1532
- m .Get ("/tag/*" , context .RepoRefByType (context .RepoRefTag ), repo .SingleDownloadOrLFS )
1533
- m .Get ("/commit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .SingleDownloadOrLFS )
1534
1528
m .Get ("/blob/{sha}" , repo .DownloadByIDOrLFS )
1535
- // "/*" route is deprecated, and kept for backward compatibility
1536
- m .Get ("/*" , context .RepoRefByType (context .RepoRefUnknown ), repo .SingleDownloadOrLFS )
1529
+ m .Get ("/branch/*" , context .RepoRefByType (git .RefTypeBranch ), repo .SingleDownloadOrLFS )
1530
+ m .Get ("/tag/*" , context .RepoRefByType (git .RefTypeTag ), repo .SingleDownloadOrLFS )
1531
+ m .Get ("/commit/*" , context .RepoRefByType (git .RefTypeCommit ), repo .SingleDownloadOrLFS )
1532
+ m .Get ("/*" , context .RepoRefByType ("" ), repo .SingleDownloadOrLFS ) // "/*" route is deprecated, and kept for backward compatibility
1537
1533
}, repo .MustBeNotEmpty )
1538
1534
1539
1535
m .Group ("/raw" , func () {
1540
- m .Get ("/branch/*" , context .RepoRefByType (context .RepoRefBranch ), repo .SingleDownload )
1541
- m .Get ("/tag/*" , context .RepoRefByType (context .RepoRefTag ), repo .SingleDownload )
1542
- m .Get ("/commit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .SingleDownload )
1543
1536
m .Get ("/blob/{sha}" , repo .DownloadByID )
1544
- // "/*" route is deprecated, and kept for backward compatibility
1545
- m .Get ("/*" , context .RepoRefByType (context .RepoRefUnknown ), repo .SingleDownload )
1537
+ m .Get ("/branch/*" , context .RepoRefByType (git .RefTypeBranch ), repo .SingleDownload )
1538
+ m .Get ("/tag/*" , context .RepoRefByType (git .RefTypeTag ), repo .SingleDownload )
1539
+ m .Get ("/commit/*" , context .RepoRefByType (git .RefTypeCommit ), repo .SingleDownload )
1540
+ m .Get ("/*" , context .RepoRefByType ("" ), repo .SingleDownload ) // "/*" route is deprecated, and kept for backward compatibility
1546
1541
}, repo .MustBeNotEmpty )
1547
1542
1548
1543
m .Group ("/render" , func () {
1549
- m .Get ("/branch/*" , context .RepoRefByType (context . RepoRefBranch ), repo .RenderFile )
1550
- m .Get ("/tag/*" , context .RepoRefByType (context . RepoRefTag ), repo .RenderFile )
1551
- m .Get ("/commit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .RenderFile )
1544
+ m .Get ("/branch/*" , context .RepoRefByType (git . RefTypeBranch ), repo .RenderFile )
1545
+ m .Get ("/tag/*" , context .RepoRefByType (git . RefTypeTag ), repo .RenderFile )
1546
+ m .Get ("/commit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .RenderFile )
1552
1547
m .Get ("/blob/{sha}" , repo .RenderFile )
1553
1548
}, repo .MustBeNotEmpty )
1554
1549
1555
1550
m .Group ("/commits" , func () {
1556
- m .Get ("/branch/*" , context .RepoRefByType (context .RepoRefBranch ), repo .RefCommits )
1557
- m .Get ("/tag/*" , context .RepoRefByType (context .RepoRefTag ), repo .RefCommits )
1558
- m .Get ("/commit/*" , context .RepoRefByType (context .RepoRefCommit ), repo .RefCommits )
1559
- // "/*" route is deprecated, and kept for backward compatibility
1560
- m .Get ("/*" , context .RepoRefByType (context .RepoRefUnknown ), repo .RefCommits )
1551
+ m .Get ("/branch/*" , context .RepoRefByType (git .RefTypeBranch ), repo .RefCommits )
1552
+ m .Get ("/tag/*" , context .RepoRefByType (git .RefTypeTag ), repo .RefCommits )
1553
+ m .Get ("/commit/*" , context .RepoRefByType (git .RefTypeCommit ), repo .RefCommits )
1554
+ m .Get ("/*" , context .RepoRefByType ("" ), repo .RefCommits ) // "/*" route is deprecated, and kept for backward compatibility
1561
1555
}, repo .MustBeNotEmpty )
1562
1556
1563
1557
m .Group ("/blame" , func () {
1564
- m .Get ("/branch/*" , context .RepoRefByType (context . RepoRefBranch ), repo .RefBlame )
1565
- m .Get ("/tag/*" , context .RepoRefByType (context . RepoRefTag ), repo .RefBlame )
1566
- m .Get ("/commit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .RefBlame )
1558
+ m .Get ("/branch/*" , context .RepoRefByType (git . RefTypeBranch ), repo .RefBlame )
1559
+ m .Get ("/tag/*" , context .RepoRefByType (git . RefTypeTag ), repo .RefBlame )
1560
+ m .Get ("/commit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .RefBlame )
1567
1561
}, repo .MustBeNotEmpty )
1568
1562
1569
1563
m .Get ("/blob_excerpt/{sha}" , repo .SetEditorconfigIfExists , repo .SetDiffViewStyle , repo .ExcerptBlob )
@@ -1575,20 +1569,20 @@ func registerRoutes(m *web.Router) {
1575
1569
m .Get ("/cherry-pick/{sha:([a-f0-9]{7,64})$}" , repo .SetEditorconfigIfExists , repo .CherryPick )
1576
1570
}, repo .MustBeNotEmpty , context .RepoRef ())
1577
1571
1578
- m .Get ("/rss/branch/*" , context .RepoRefByType (context . RepoRefBranch ), feedEnabled , feed .RenderBranchFeed )
1579
- m .Get ("/atom/branch/*" , context .RepoRefByType (context . RepoRefBranch ), feedEnabled , feed .RenderBranchFeed )
1572
+ m .Get ("/rss/branch/*" , context .RepoRefByType (git . RefTypeBranch ), feedEnabled , feed .RenderBranchFeed )
1573
+ m .Get ("/atom/branch/*" , context .RepoRefByType (git . RefTypeBranch ), feedEnabled , feed .RenderBranchFeed )
1580
1574
1581
1575
m .Group ("/src" , func () {
1582
1576
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
1583
- m .Get ("/branch/*" , context .RepoRefByType (context . RepoRefBranch ), repo .Home )
1584
- m .Get ("/tag/*" , context .RepoRefByType (context . RepoRefTag ), repo .Home )
1585
- m .Get ("/commit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .Home )
1586
- m .Get ("/*" , context .RepoRefByType (context . RepoRefUnknown ), repo .Home ) // "/*" route is deprecated, and kept for backward compatibility
1577
+ m .Get ("/branch/*" , context .RepoRefByType (git . RefTypeBranch ), repo .Home )
1578
+ m .Get ("/tag/*" , context .RepoRefByType (git . RefTypeTag ), repo .Home )
1579
+ m .Get ("/commit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .Home )
1580
+ m .Get ("/*" , context .RepoRefByType ("" ), repo .Home ) // "/*" route is deprecated, and kept for backward compatibility
1587
1581
}, repo .SetEditorconfigIfExists )
1588
1582
1589
1583
m .Get ("/forks" , context .RepoRef (), repo .Forks )
1590
1584
m .Get ("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}" , repo .MustBeNotEmpty , repo .RawDiff )
1591
- m .Post ("/lastcommit/*" , context .RepoRefByType (context . RepoRefCommit ), repo .LastCommit )
1585
+ m .Post ("/lastcommit/*" , context .RepoRefByType (git . RefTypeCommit ), repo .LastCommit )
1592
1586
}, optSignIn , context .RepoAssignment , reqUnitCodeReader )
1593
1587
// end "/{username}/{reponame}": repo code
1594
1588
0 commit comments