Skip to content

Commit 59b9147

Browse files
committed
Use middleware for DisableStars check on actions too
1 parent df4f803 commit 59b9147

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

routers/web/repo/repo.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,8 @@ func Action(ctx *context.Context) {
348348
case "unwatch":
349349
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
350350
case "star", "unstar":
351-
if setting.Repository.DisableStars {
352-
err = errors.New("stars are disabled")
353-
} else {
354-
err = repo_model.StarRepo(ctx, ctx.Doer,
355-
ctx.Repo.Repository, ctx.PathParam("action") == "star")
356-
}
351+
err = repo_model.StarRepo(ctx, ctx.Doer,
352+
ctx.Repo.Repository, ctx.PathParam("action") == "star")
357353
case "accept_transfer":
358354
acceptTransfer(ctx)
359355
return

routers/web/web.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,12 @@ func registerRoutes(m *web.Router) {
851851
}
852852
}
853853

854+
reqStarsEnabled := func(ctx *context.Context) {
855+
if setting.Repository.DisableStars {
856+
ctx.Error(http.StatusForbidden, "stars are disabled")
857+
}
858+
}
859+
854860
individualPermsChecker := func(ctx *context.Context) {
855861
// org permissions have been checked in context.OrgAssignment(), but individual permissions haven't been checked.
856862
if ctx.ContextUser.IsIndividual() {
@@ -1603,7 +1609,9 @@ func registerRoutes(m *web.Router) {
16031609
m.Get("/stars", starsEnabled, repo.Stars)
16041610
m.Get("/watchers", repo.Watchers)
16051611
m.Get("/search", reqUnitCodeReader, repo.Search)
1606-
m.Post("/action/{action}", reqSignIn, repo.Action)
1612+
m.Post("/action/{action:star|unstar}", reqSignIn, reqStarsEnabled, repo.Action)
1613+
m.Post("/action/{action:watch|unwatch}", reqSignIn, repo.Action)
1614+
m.Post("/action/{action:accept_transfer|reject_transfer}", reqSignIn, repo.Action)
16071615
}, optSignIn, context.RepoAssignment)
16081616

16091617
common.AddOwnerRepoGitLFSRoutes(m, optSignInIgnoreCsrf, lfsServerEnabled) // "/{username}/{reponame}/{lfs-paths}": git-lfs support

0 commit comments

Comments
 (0)