mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-14 07:19:02 +00:00
Implement hard reset button
This commit is contained in:
@@ -105,6 +105,7 @@ func New() *WebAPI {
|
||||
api.router.GET("/project/webhook_secret/:id", LogRequestMiddleware(api.GetWebhookSecret))
|
||||
api.router.POST("/project/webhook_secret/:id", LogRequestMiddleware(api.SetWebhookSecret))
|
||||
api.router.POST("/project/reset_failed_tasks/:id", LogRequestMiddleware(api.ResetFailedTasks))
|
||||
api.router.POST("/project/hard_reset/:id", LogRequestMiddleware(api.HardReset))
|
||||
|
||||
api.router.POST("/task/submit", LogRequestMiddleware(api.SubmitTask))
|
||||
api.router.GET("/task/get/:project", LogRequestMiddleware(api.GetTaskFromProject))
|
||||
|
||||
@@ -314,3 +314,7 @@ type GetWebhookSecretResponse struct {
|
||||
type ResetFailedTaskResponse struct {
|
||||
AffectedTasks int64 `json:"affected_tasks"`
|
||||
}
|
||||
|
||||
type HardResetResponse struct {
|
||||
AffectedTasks int64 `json:"affected_tasks"`
|
||||
}
|
||||
|
||||
@@ -724,3 +724,35 @@ func (api *WebAPI) ResetFailedTasks(r *Request) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (api *WebAPI) HardReset(r *Request) {
|
||||
|
||||
pid, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
if err != nil || pid <= 0 {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Invalid project id",
|
||||
}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleMaintenance, api.Database) {
|
||||
r.Json(JsonResponse{
|
||||
Ok: false,
|
||||
Message: "Unauthorized",
|
||||
}, 403)
|
||||
return
|
||||
}
|
||||
|
||||
res := api.Database.HardReset(pid)
|
||||
|
||||
r.OkJson(JsonResponse{
|
||||
Ok: true,
|
||||
Content: HardResetResponse{
|
||||
AffectedTasks: res,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user