(manager task.Manager[T], callback func(c *gin.Context, task T))
| 78 | } |
| 79 | |
| 80 | func 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 | |
| 102 | func getBatchHandler[T task.TaskExtensionInfo](manager task.Manager[T], callback func(task T)) gin.HandlerFunc { |
| 103 | return func(c *gin.Context) { |
no test coverage detected