fix ownership for leadtarget handlers
Some checks failed
Lint / Lint (push) Failing after 1m59s
Deploy / CreateImage (push) Successful in 2m51s
Deploy / ValidateConfig (push) Successful in 23s
Deploy / MigrateDatabase (push) Successful in 38s
Deploy / DeployService (push) Successful in 23s

This commit is contained in:
Pasha 2025-04-23 17:15:08 +03:00 committed by skeris
parent 612062a1f2
commit 76d06eb2fb
5 changed files with 30 additions and 11 deletions

2
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

2
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=

@ -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,

@ -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 {

@ -25,8 +25,6 @@ func NewStatisticController(deps Deps) *Statistic {
}
}
// todo обсудить клиентские и админские методы, сделать проверки на принадлежность аккаунта - сущности
type DeviceStatReq struct {
From uint64 // временные границы выбора статистики
To uint64