mirror of
https://github.com/simon987/task_tracker.git
synced 2025-12-14 07:19:02 +00:00
update API dependencies
This commit is contained in:
20
api/auth.go
20
api/auth.go
@@ -33,8 +33,9 @@ func (api *WebAPI) Login(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
sess.Set("manager", manager)
|
||||
api.Session.Save(r.Ctx, sess)
|
||||
|
||||
r.OkJson(JsonResponse{
|
||||
Content: LoginResponse{
|
||||
@@ -50,8 +51,8 @@ func (api *WebAPI) Login(r *Request) {
|
||||
|
||||
func (api *WebAPI) Logout(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess.Clear()
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
sess.Flush()
|
||||
r.Ctx.Response.SetStatusCode(204)
|
||||
}
|
||||
|
||||
@@ -93,8 +94,9 @@ func (api *WebAPI) Register(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
sess.Set("manager", manager)
|
||||
api.Session.Save(r.Ctx, sess)
|
||||
|
||||
r.OkJson(JsonResponse{
|
||||
Ok: true,
|
||||
@@ -107,7 +109,7 @@ func (api *WebAPI) Register(r *Request) {
|
||||
|
||||
func (api *WebAPI) GetAccountDetails(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
@@ -134,7 +136,7 @@ func (api *WebAPI) GetAccountDetails(r *Request) {
|
||||
|
||||
func (api *WebAPI) GetManagerList(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if manager == nil {
|
||||
@@ -166,7 +168,7 @@ func (api *WebAPI) GetManagerListWithRoleOn(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if manager == nil {
|
||||
@@ -198,7 +200,7 @@ func (api *WebAPI) PromoteManager(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !manager.(*storage.Manager).WebsiteAdmin || manager.(*storage.Manager).Id == id {
|
||||
@@ -236,7 +238,7 @@ func (api *WebAPI) DemoteManager(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if manager == nil {
|
||||
|
||||
19
api/main.go
19
api/main.go
@@ -3,7 +3,8 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/buaazp/fasthttprouter"
|
||||
"github.com/kataras/go-sessions"
|
||||
"github.com/fasthttp/session"
|
||||
"github.com/fasthttp/session/memory"
|
||||
"github.com/robfig/cron"
|
||||
"github.com/simon987/task_tracker/config"
|
||||
"github.com/simon987/task_tracker/storage"
|
||||
@@ -16,8 +17,8 @@ type WebAPI struct {
|
||||
server *fasthttp.Server
|
||||
router *fasthttprouter.Router
|
||||
Database *storage.Database
|
||||
SessionConfig sessions.Config
|
||||
Session *sessions.Sessions
|
||||
SessionConfig *session.Config
|
||||
Session *session.Session
|
||||
Cron *cron.Cron
|
||||
AssignLimiters sync.Map
|
||||
SubmitLimiters sync.Map
|
||||
@@ -69,14 +70,14 @@ func New() *WebAPI {
|
||||
|
||||
api.router = &fasthttprouter.Router{}
|
||||
|
||||
api.SessionConfig = sessions.Config{
|
||||
Cookie: config.Cfg.SessionCookieName,
|
||||
Expires: config.Cfg.SessionCookieExpiration,
|
||||
CookieSecureTLS: false,
|
||||
DisableSubdomainPersistence: false,
|
||||
api.SessionConfig = &session.Config{
|
||||
CookieName: config.Cfg.SessionCookieName,
|
||||
Expires: config.Cfg.SessionCookieExpiration,
|
||||
Secure: false,
|
||||
}
|
||||
|
||||
api.Session = sessions.New(api.SessionConfig)
|
||||
api.Session = session.New(api.SessionConfig)
|
||||
_ = api.Session.SetProvider("memory", &memory.Config{})
|
||||
|
||||
api.server = &fasthttp.Server{
|
||||
Handler: api.router.Handler,
|
||||
|
||||
@@ -20,7 +20,7 @@ func (api *WebAPI) GetProject(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
project := api.Database.GetProject(id)
|
||||
@@ -51,7 +51,7 @@ func (api *WebAPI) GetProject(r *Request) {
|
||||
|
||||
func (api *WebAPI) CreateProject(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
createReq := &CreateProjectRequest{}
|
||||
@@ -186,7 +186,7 @@ func (api *WebAPI) UpdateProject(r *Request) {
|
||||
SubmitRate: updateReq.SubmitRate,
|
||||
Version: updateReq.Version,
|
||||
}
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(project.Id, manager, storage.RoleEdit, api.Database) {
|
||||
@@ -294,7 +294,7 @@ func isProjectReadAuthorized(project *storage.Project, manager interface{}, db *
|
||||
|
||||
func (api *WebAPI) GetProjectList(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
var id int64
|
||||
@@ -337,7 +337,7 @@ func (api *WebAPI) GetAssigneeStatsForProject(r *Request) {
|
||||
|
||||
func (api *WebAPI) GetWorkerAccessListForProject(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
id, err := strconv.ParseInt(r.Ctx.UserValue("id").(string), 10, 64)
|
||||
@@ -435,7 +435,7 @@ func (api *WebAPI) AcceptAccessRequest(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleManageAccess, api.Database) {
|
||||
@@ -515,7 +515,7 @@ func (api *WebAPI) SetManagerRoleOnProject(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleManageAccess, api.Database) {
|
||||
@@ -543,7 +543,7 @@ func (api *WebAPI) SetSecret(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleSecret, api.Database) {
|
||||
@@ -603,7 +603,7 @@ func (api *WebAPI) GetSecret(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleSecret, api.Database) {
|
||||
@@ -634,7 +634,7 @@ func (api *WebAPI) GetWebhookSecret(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleSecret, api.Database) {
|
||||
@@ -675,7 +675,7 @@ func (api *WebAPI) SetWebhookSecret(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleSecret, api.Database) {
|
||||
@@ -710,7 +710,7 @@ func (api *WebAPI) ResetFailedTasks(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleMaintenance, api.Database) {
|
||||
@@ -742,7 +742,7 @@ func (api *WebAPI) HardReset(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleMaintenance, api.Database) {
|
||||
@@ -774,7 +774,7 @@ func (api *WebAPI) ReclaimAssignedTasks(r *Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if !isActionOnProjectAuthorized(pid, manager, storage.RoleMaintenance, api.Database) {
|
||||
|
||||
@@ -72,7 +72,7 @@ func (api *WebAPI) GetWorker(r *Request) {
|
||||
|
||||
if worker != nil {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
var secret []byte = nil
|
||||
@@ -138,7 +138,7 @@ func (api *WebAPI) UpdateWorker(r *Request) {
|
||||
|
||||
func (api *WebAPI) WorkerSetPaused(r *Request) {
|
||||
|
||||
sess := api.Session.StartFasthttp(r.Ctx)
|
||||
sess, _ := api.Session.Get(r.Ctx)
|
||||
manager := sess.Get("manager")
|
||||
|
||||
if manager == nil || !manager.(*storage.Manager).WebsiteAdmin {
|
||||
|
||||
Reference in New Issue
Block a user