diff --git a/go.mod b/go.mod index 4ac3a49..01d973b 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9 gitea.pena/PenaSide/linters-golang v0.0.0-20241207122018-933207374735 gitea.pena/PenaSide/trashlog v0.0.0-20250222101337-a43552caae6f - gitea.pena/SQuiz/common v0.0.0-20250423110755-e980b87b531f + gitea.pena/SQuiz/common v0.0.0-20250423141046-a39660f6e19d github.com/caarlos0/env/v8 v8.0.0 github.com/go-redis/redis/v8 v8.11.5 github.com/gofiber/fiber/v2 v2.52.6 diff --git a/go.sum b/go.sum index 146cf5a..81f9dd4 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ gitea.pena/SQuiz/common v0.0.0-20250423105358-3f22f4c92df2 h1:a4w4+B+4UlRkBA5X6X gitea.pena/SQuiz/common v0.0.0-20250423105358-3f22f4c92df2/go.mod h1:zCrUwDh0APpztKk6NUqTZv+zhjVbWpGBJiJ5z9dAH0U= gitea.pena/SQuiz/common v0.0.0-20250423110755-e980b87b531f h1:68BRQNKrbOu/6v226qV/WYSQfGJ5DOe0dxWdA5W1Ywo= gitea.pena/SQuiz/common v0.0.0-20250423110755-e980b87b531f/go.mod h1:rQRjqLlLyM71FZcvbM95Nv3ciq44F9DFtUHPZmDK3T8= +gitea.pena/SQuiz/common v0.0.0-20250423141046-a39660f6e19d h1:sPB0k3K9mmMDIKTaNBCwRajL+21z+yLmLFXTVMd5H8M= +gitea.pena/SQuiz/common v0.0.0-20250423141046-a39660f6e19d/go.mod h1:rQRjqLlLyM71FZcvbM95Nv3ciq44F9DFtUHPZmDK3T8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0= github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= diff --git a/internal/controllers/http_controllers/account/account.go b/internal/controllers/http_controllers/account/account.go index bdf670f..a7d3a47 100644 --- a/internal/controllers/http_controllers/account/account.go +++ b/internal/controllers/http_controllers/account/account.go @@ -350,14 +350,27 @@ func (r *Account) PostLeadTarget(ctx *fiber.Ctx) error { return nil } -// todo тут возможно стоит в будущем когда будет использоваться передавать еще и id ккаунта для большей четкости func (r *Account) DeleteLeadTarget(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + leadIDStr := ctx.Params("id") leadID, err := strconv.ParseInt(leadIDStr, 10, 64) if err != nil { return ctx.Status(fiber.StatusBadRequest).SendString("Invalid lead ID format") } + isOwner, err := r.dal.AccountRepo.CheckLeadTargetOwner(ctx.Context(), accountID, leadID) + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error()) + } + + if !isOwner { + return ctx.Status(fiber.StatusUnauthorized).SendString("not the owner") + } + err = r.dal.AccountRepo.DeleteLeadTarget(ctx.Context(), leadID) if err != nil { return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error()) @@ -390,8 +403,12 @@ func (r *Account) GetLeadTarget(ctx *fiber.Ctx) error { return ctx.Status(fiber.StatusOK).JSON(result) } -// todo тут возможно стоит в будущем когда будет использоваться передавать еще и id ккаунта для большей четкости func (r *Account) UpdateLeadTarget(ctx *fiber.Ctx) error { + accountID, ok := middleware.GetAccountId(ctx) + if !ok { + return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required") + } + var req struct { ID int64 `json:"id"` Target string `json:"target"` @@ -405,6 +422,14 @@ func (r *Account) UpdateLeadTarget(ctx *fiber.Ctx) error { return ctx.Status(fiber.StatusBadRequest).SendString("ID and Target don't be nil") } + isOwner, err := r.dal.AccountRepo.CheckLeadTargetOwner(ctx.Context(), accountID, req.ID) + if err != nil { + return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error()) + } + if !isOwner { + return ctx.Status(fiber.StatusUnauthorized).SendString("not the owner") + } + result, err := r.dal.AccountRepo.UpdateLeadTarget(ctx.Context(), model.LeadTarget{ ID: req.ID, Target: req.Target, diff --git a/internal/controllers/http_controllers/question/question.go b/internal/controllers/http_controllers/question/question.go index 2b12d74..fc8ecd6 100644 --- a/internal/controllers/http_controllers/question/question.go +++ b/internal/controllers/http_controllers/question/question.go @@ -36,7 +36,6 @@ type QuestionCreateReq struct { } // CreateQuestion service handler for creating question for quiz -// todo нужна проверка на то что квиз принадлежит пользователю, не помешает func (r *Question) CreateQuestion(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { @@ -127,7 +126,6 @@ type GetQuestionListResp struct { } // GetQuestionList handler for paginated list question -// todo нужна проверка на то что квиз принадлежит пользователю, не помешает func (r *Question) GetQuestionList(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { @@ -203,7 +201,6 @@ type UpdateResp struct { } // UpdateQuestion handler for update question -// todo нужна проверка на то что квиз принадлежит пользователю, не помешает func (r *Question) UpdateQuestion(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { @@ -296,7 +293,6 @@ type CopyQuestionReq struct { } // CopyQuestion handler for copy question -// todo копирование может происходить с чужого опроса? если нет тоже проверку надо делать на принадлежность func (r *Question) CopyQuestion(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { @@ -339,7 +335,6 @@ type GetQuestionHistoryReq struct { } // GetQuestionHistory handler for history of quiz -// todo нужна проверка на то что квиз принадлежит пользователю, не помешает func (r *Question) GetQuestionHistory(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { @@ -377,7 +372,6 @@ type DeactivateResp struct { } // DeleteQuestion handler for fake delete question -// todo нужна проверка на то что квиз принадлежит пользователю, не помешает func (r *Question) DeleteQuestion(ctx *fiber.Ctx) error { accountID, ok := middleware.GetAccountId(ctx) if !ok { diff --git a/internal/controllers/http_controllers/statistic/statistic.go b/internal/controllers/http_controllers/statistic/statistic.go index 589f6dc..730cedd 100644 --- a/internal/controllers/http_controllers/statistic/statistic.go +++ b/internal/controllers/http_controllers/statistic/statistic.go @@ -25,8 +25,6 @@ func NewStatisticController(deps Deps) *Statistic { } } -// todo обсудить клиентские и админские методы, сделать проверки на принадлежность аккаунта - сущности - type DeviceStatReq struct { From uint64 // временные границы выбора статистики To uint64