Skip to content

Commit dd09d1e

Browse files
committed
fix
1 parent d0f4e92 commit dd09d1e

File tree

8 files changed

+269
-284
lines changed

8 files changed

+269
-284
lines changed

routers/web/org/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func Home(ctx *context.Context) {
3434
}
3535

3636
ctx.SetPathParam("org", uname)
37-
context.HandleOrgAssignment(ctx)
37+
context.OrgAssignment(context.OrgAssignmentOptions{})(ctx)
3838
if ctx.Written() {
3939
return
4040
}

routers/web/repo/repo.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -304,31 +304,6 @@ func CreatePost(ctx *context.Context) {
304304
handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form)
305305
}
306306

307-
const (
308-
tplWatchUnwatch templates.TplName = "repo/watch_unwatch"
309-
tplStarUnstar templates.TplName = "repo/star_unstar"
310-
)
311-
312-
func acceptTransfer(ctx *context.Context) {
313-
err := repo_service.AcceptTransferOwnership(ctx, ctx.Repo.Repository, ctx.Doer)
314-
if err == nil {
315-
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success"))
316-
ctx.Redirect(ctx.Repo.Repository.Link())
317-
return
318-
}
319-
handleActionError(ctx, err)
320-
}
321-
322-
func rejectTransfer(ctx *context.Context) {
323-
err := repo_service.RejectRepositoryTransfer(ctx, ctx.Repo.Repository, ctx.Doer)
324-
if err == nil {
325-
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected"))
326-
ctx.Redirect(ctx.Repo.Repository.Link())
327-
return
328-
}
329-
handleActionError(ctx, err)
330-
}
331-
332307
func handleActionError(ctx *context.Context, err error) {
333308
if errors.Is(err, user_model.ErrBlockedUser) {
334309
ctx.Flash.Error(ctx.Tr("repo.action.blocked_user"))
@@ -339,72 +314,6 @@ func handleActionError(ctx *context.Context, err error) {
339314
}
340315
}
341316

342-
// Action response for actions to a repository
343-
func Action(ctx *context.Context) {
344-
var err error
345-
switch ctx.PathParam("action") {
346-
case "watch":
347-
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
348-
case "unwatch":
349-
err = repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
350-
case "star":
351-
err = repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
352-
case "unstar":
353-
err = repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
354-
case "accept_transfer":
355-
acceptTransfer(ctx)
356-
return
357-
case "reject_transfer":
358-
rejectTransfer(ctx)
359-
return
360-
case "desc": // FIXME: this is not used
361-
if !ctx.Repo.IsOwner() {
362-
ctx.Error(http.StatusNotFound)
363-
return
364-
}
365-
366-
ctx.Repo.Repository.Description = ctx.FormString("desc")
367-
ctx.Repo.Repository.Website = ctx.FormString("site")
368-
err = repo_service.UpdateRepository(ctx, ctx.Repo.Repository, false)
369-
}
370-
371-
if err != nil {
372-
handleActionError(ctx, err)
373-
return
374-
}
375-
376-
switch ctx.PathParam("action") {
377-
case "watch", "unwatch":
378-
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
379-
case "star", "unstar":
380-
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
381-
}
382-
383-
// see the `hx-trigger="refreshUserCards ..."` comments in tmpl
384-
ctx.RespHeader().Add("hx-trigger", "refreshUserCards")
385-
386-
switch ctx.PathParam("action") {
387-
case "watch", "unwatch", "star", "unstar":
388-
// we have to reload the repository because NumStars or NumWatching (used in the templates) has just changed
389-
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
390-
if err != nil {
391-
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.PathParam("action")), err)
392-
return
393-
}
394-
}
395-
396-
switch ctx.PathParam("action") {
397-
case "watch", "unwatch":
398-
ctx.HTML(http.StatusOK, tplWatchUnwatch)
399-
return
400-
case "star", "unstar":
401-
ctx.HTML(http.StatusOK, tplStarUnstar)
402-
return
403-
}
404-
405-
ctx.RedirectToCurrentSite(ctx.FormString("redirect_to"), ctx.Repo.RepoLink)
406-
}
407-
408317
// RedirectDownload return a file based on the following infos:
409318
func RedirectDownload(ctx *context.Context) {
410319
var (

routers/web/repo/star.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"net/http"
8+
9+
repo_model "code.gitea.io/gitea/models/repo"
10+
"code.gitea.io/gitea/modules/templates"
11+
"code.gitea.io/gitea/services/context"
12+
)
13+
14+
const tplStarUnstar templates.TplName = "repo/star_unstar"
15+
16+
func ActionStar(ctx *context.Context) {
17+
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "star")
18+
if err != nil {
19+
handleActionError(ctx, err)
20+
return
21+
}
22+
23+
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
24+
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
25+
if err != nil {
26+
ctx.ServerError("GetRepositoryByName", err)
27+
return
28+
}
29+
ctx.RespHeader().Add("hx-trigger", "refreshUserCards") // see the `hx-trigger="refreshUserCards ..."` comments in tmpl
30+
ctx.HTML(http.StatusOK, tplStarUnstar)
31+
}

routers/web/repo/transfer.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"code.gitea.io/gitea/services/context"
8+
repo_service "code.gitea.io/gitea/services/repository"
9+
)
10+
11+
func acceptTransfer(ctx *context.Context) {
12+
err := repo_service.AcceptTransferOwnership(ctx, ctx.Repo.Repository, ctx.Doer)
13+
if err == nil {
14+
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success"))
15+
ctx.Redirect(ctx.Repo.Repository.Link())
16+
return
17+
}
18+
handleActionError(ctx, err)
19+
}
20+
21+
func rejectTransfer(ctx *context.Context) {
22+
err := repo_service.RejectRepositoryTransfer(ctx, ctx.Repo.Repository, ctx.Doer)
23+
if err == nil {
24+
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected"))
25+
ctx.Redirect(ctx.Repo.Repository.Link())
26+
return
27+
}
28+
handleActionError(ctx, err)
29+
}
30+
31+
func ActionTransfer(ctx *context.Context) {
32+
switch ctx.PathParam("action") {
33+
case "accept_transfer":
34+
acceptTransfer(ctx)
35+
case "reject_transfer":
36+
rejectTransfer(ctx)
37+
}
38+
}

routers/web/repo/watch.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"net/http"
8+
9+
repo_model "code.gitea.io/gitea/models/repo"
10+
"code.gitea.io/gitea/modules/templates"
11+
"code.gitea.io/gitea/services/context"
12+
)
13+
14+
const tplWatchUnwatch templates.TplName = "repo/watch_unwatch"
15+
16+
func ActionWatch(ctx *context.Context) {
17+
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "watch")
18+
if err != nil {
19+
handleActionError(ctx, err)
20+
return
21+
}
22+
23+
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
24+
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name)
25+
if err != nil {
26+
ctx.ServerError("GetRepositoryByName", err)
27+
return
28+
}
29+
ctx.RespHeader().Add("hx-trigger", "refreshUserCards") // see the `hx-trigger="refreshUserCards ..."` comments in tmpl
30+
ctx.HTML(http.StatusOK, tplWatchUnwatch)
31+
}

routers/web/user/profile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
313313
ctx.Data["Page"] = pager
314314
}
315315

316-
// Action response for follow/unfollow user request
317-
func Action(ctx *context.Context) {
316+
// ActionUserFollow is for follow/unfollow user request
317+
func ActionUserFollow(ctx *context.Context) {
318318
var err error
319319
switch ctx.FormString("action") {
320320
case "follow":
@@ -339,6 +339,6 @@ func Action(ctx *context.Context) {
339339
ctx.HTML(http.StatusOK, tplFollowUnfollow)
340340
return
341341
}
342-
log.Error("Failed to apply action %q: unsupport context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
342+
log.Error("Failed to apply action %q: unsupported context user type: %s", ctx.FormString("action"), ctx.ContextUser.Type)
343343
ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action")))
344344
}

routers/web/web.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ func registerRoutes(m *web.Router) {
822822
m.Methods("GET, OPTIONS", "/attachments/{uuid}", optionsCorsHandler(), repo.GetAttachment)
823823
}, optSignIn)
824824

825-
m.Post("/{username}", reqSignIn, context.UserAssignmentWeb(), user.Action)
825+
m.Post("/{username}", reqSignIn, context.UserAssignmentWeb(), user.ActionUserFollow)
826826

827827
reqRepoAdmin := context.RequireRepoAdmin()
828828
reqRepoCodeWriter := context.RequireUnitWriter(unit.TypeCode)
@@ -872,7 +872,7 @@ func registerRoutes(m *web.Router) {
872872
m.Group("/org", func() {
873873
m.Group("/{org}", func() {
874874
m.Get("/members", org.Members)
875-
}, context.OrgAssignment())
875+
}, context.OrgAssignment(context.OrgAssignmentOptions{}))
876876
}, optSignIn)
877877
// end "/org": members
878878

@@ -898,19 +898,19 @@ func registerRoutes(m *web.Router) {
898898
m.Get("/milestones/{team}", reqMilestonesDashboardPageEnabled, user.Milestones)
899899
m.Post("/members/action/{action}", org.MembersAction)
900900
m.Get("/teams", org.Teams)
901-
}, context.OrgAssignment(true, false, true))
901+
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireMember: true, RequireTeamMember: true}))
902902

903903
m.Group("/{org}", func() {
904904
m.Get("/teams/{team}", org.TeamMembers)
905905
m.Get("/teams/{team}/repositories", org.TeamRepositories)
906906
m.Post("/teams/{team}/action/{action}", org.TeamsAction)
907907
m.Post("/teams/{team}/action/repo/{action}", org.TeamsRepoAction)
908-
}, context.OrgAssignment(true, false, true))
908+
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireMember: true, RequireTeamMember: true}))
909909

910910
// require admin permission
911911
m.Group("/{org}", func() {
912912
m.Get("/teams/-/search", org.SearchTeam)
913-
}, context.OrgAssignment(true, false, false, true))
913+
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}))
914914

915915
// require owner permission
916916
m.Group("/{org}", func() {
@@ -920,7 +920,7 @@ func registerRoutes(m *web.Router) {
920920
m.Post("/teams/{team}/edit", web.Bind(forms.CreateTeamForm{}), org.EditTeamPost)
921921
m.Post("/teams/{team}/delete", org.DeleteTeam)
922922

923-
m.Get("/worktime", context.OrgAssignment(false, true), org.Worktime)
923+
m.Get("/worktime", context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}), org.Worktime)
924924

925925
m.Group("/settings", func() {
926926
m.Combo("").Get(org.Settings).
@@ -989,7 +989,7 @@ func registerRoutes(m *web.Router) {
989989
m.Post("", web.Bind(forms.BlockUserForm{}), org.BlockedUsersPost)
990990
})
991991
}, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled, "PageIsOrgSettings", true))
992-
}, context.OrgAssignment(true, true))
992+
}, context.OrgAssignment(context.OrgAssignmentOptions{RequireOwner: true}))
993993
}, reqSignIn)
994994
// end "/org": most org routes
995995

@@ -1059,7 +1059,7 @@ func registerRoutes(m *web.Router) {
10591059
m.Group("", func() {
10601060
m.Get("/code", user.CodeSearch)
10611061
}, reqUnitAccess(unit.TypeCode, perm.AccessModeRead, false), individualPermsChecker)
1062-
}, optSignIn, context.UserAssignmentWeb(), context.OrgAssignment())
1062+
}, optSignIn, context.UserAssignmentWeb(), context.OrgAssignment(context.OrgAssignmentOptions{}))
10631063
// end "/{username}/-": packages, projects, code
10641064

10651065
m.Group("/{username}/{reponame}/-", func() {
@@ -1603,9 +1603,9 @@ func registerRoutes(m *web.Router) {
16031603
m.Get("/stars", starsEnabled, repo.Stars)
16041604
m.Get("/watchers", repo.Watchers)
16051605
m.Get("/search", reqUnitCodeReader, repo.Search)
1606-
m.Post("/action/{action:star|unstar}", reqSignIn, starsEnabled, repo.Action)
1607-
m.Post("/action/{action:watch|unwatch}", reqSignIn, repo.Action)
1608-
m.Post("/action/{action:accept_transfer|reject_transfer}", reqSignIn, repo.Action)
1606+
m.Post("/action/{action:star|unstar}", reqSignIn, starsEnabled, repo.ActionStar)
1607+
m.Post("/action/{action:watch|unwatch}", reqSignIn, repo.ActionWatch)
1608+
m.Post("/action/{action:accept_transfer|reject_transfer}", reqSignIn, repo.ActionTransfer)
16091609
}, optSignIn, context.RepoAssignment)
16101610

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

0 commit comments

Comments
 (0)