MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / getTargetedHandler

Function getTargetedHandler

server/handles/task.go:80–100  ·  view source on GitHub ↗
(manager task.Manager[T], callback func(c *gin.Context, task T))

Source from the content-addressed store, hash-verified

78}
79
80func getTargetedHandler[T task.TaskExtensionInfo](manager task.Manager[T], callback func(c *gin.Context, task T)) gin.HandlerFunc {
81 return func(c *gin.Context) {
82 isAdmin, uid, ok := getUserInfo(c)
83 if !ok {
84 // if there is no bug, here is unreachable
85 common.ErrorStrResp(c, "user invalid", 401)
86 return
87 }
88 t, ok := manager.GetByID(c.Query("tid"))
89 if !ok {
90 common.ErrorStrResp(c, "task not found", 404)
91 return
92 }
93 if !isAdmin && uid != t.GetCreator().ID {
94 // to avoid an attacker using error messages to guess valid TID, return a 404 rather than a 403
95 common.ErrorStrResp(c, "task not found", 404)
96 return
97 }
98 callback(c, t)
99 }
100}
101
102func getBatchHandler[T task.TaskExtensionInfo](manager task.Manager[T], callback func(task T)) gin.HandlerFunc {
103 return func(c *gin.Context) {

Callers 1

taskRouteFunction · 0.85

Calls 4

ErrorStrRespFunction · 0.92
getUserInfoFunction · 0.85
GetByIDMethod · 0.80
GetCreatorMethod · 0.65

Tested by

no test coverage detected