added restrictions for load and edit files in client methods
This commit is contained in:
parent
373fbc9c89
commit
8c739607a3
@ -2,14 +2,14 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"mime/multipart"
|
|
||||||
"gitea.pena/PenaSide/common/log_mw"
|
"gitea.pena/PenaSide/common/log_mw"
|
||||||
"gitea.pena/PenaSide/verification/internal/client"
|
"gitea.pena/PenaSide/verification/internal/client"
|
||||||
"gitea.pena/PenaSide/verification/internal/models"
|
"gitea.pena/PenaSide/verification/internal/models"
|
||||||
"gitea.pena/PenaSide/verification/internal/repository"
|
"gitea.pena/PenaSide/verification/internal/repository"
|
||||||
"gitea.pena/PenaSide/verification/pkg/validate_controllers"
|
"gitea.pena/PenaSide/verification/pkg/validate_controllers"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
"mime/multipart"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VerifyUserControllerDeps struct {
|
type VerifyUserControllerDeps struct {
|
||||||
@ -57,7 +57,24 @@ func (r *VerifyUserController) CreateVerification(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusUnauthorized)
|
return fiber.NewError(fiber.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.BodyParser(&req)
|
existingVerification, err := r.repository.GetByUserID(c.Context(), userID)
|
||||||
|
if err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// чекаем только если создание уже было
|
||||||
|
if existingVerification != nil {
|
||||||
|
// если уже апрув, то 208
|
||||||
|
if existingVerification.Accepted {
|
||||||
|
return fiber.NewError(fiber.StatusAlreadyReported, "verification already completed")
|
||||||
|
}
|
||||||
|
// если не апрувнуто и при этом коммент пуст, то значит админ еще не добрался - 208
|
||||||
|
if !existingVerification.Accepted && existingVerification.Comment == "" {
|
||||||
|
return fiber.NewError(fiber.StatusAlreadyReported, "verification in progress")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.BodyParser(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
@ -124,8 +141,25 @@ func (r *VerifyUserController) SetVerificationFile(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusUnauthorized)
|
return fiber.NewError(fiber.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingVerification, err := r.repository.GetByUserID(c.Context(), userID)
|
||||||
|
if err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// если не создавалась, то говорим что надо создать
|
||||||
|
if existingVerification == nil {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound, "verification not initiated")
|
||||||
|
}
|
||||||
|
// если уже апрув, запрещаем добавлять еще файлы 208
|
||||||
|
if existingVerification.Accepted {
|
||||||
|
return fiber.NewError(fiber.StatusAlreadyReported, "verification already completed")
|
||||||
|
}
|
||||||
|
// если реджект и коммент пуст, значит админ не добрался еще, запрещаем обновлять файлы и отправляем 208
|
||||||
|
if !existingVerification.Accepted && existingVerification.Comment == "" {
|
||||||
|
return fiber.NewError(fiber.StatusAlreadyReported, "verification in progress, cannot update files")
|
||||||
|
}
|
||||||
|
|
||||||
availableFiles := []string{"inn", "rule", "certificate"}
|
availableFiles := []string{"inn", "rule", "certificate"}
|
||||||
var err error
|
|
||||||
var fileHeader *multipart.FileHeader
|
var fileHeader *multipart.FileHeader
|
||||||
var result *models.Verification
|
var result *models.Verification
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user