mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
[FIX/BE-US]add feature restrict by location and areas in roles
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
m "gitlab.com/mbugroup/lti-api.git/internal/middleware"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/repports/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/repports/validations"
|
||||
@@ -49,6 +50,21 @@ func (c *RepportController) GetExpense(ctx *fiber.Ctx) error {
|
||||
RealizationDate: ctx.Query("realization_date", ""),
|
||||
}
|
||||
|
||||
locationScope, err := m.ResolveLocationScope(ctx, c.RepportService.DB())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
areaScope, err := m.ResolveAreaScope(ctx, c.RepportService.DB())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if locationScope.Restrict {
|
||||
query.AllowedLocationIDs = toInt64Slice(locationScope.IDs)
|
||||
}
|
||||
if areaScope.Restrict {
|
||||
query.AllowedAreaIDs = toInt64Slice(areaScope.IDs)
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
@@ -130,6 +146,14 @@ func (c *RepportController) GetPurchaseSupplier(ctx *fiber.Ctx) error {
|
||||
FilterBy: ctx.Query("filter_by", ""),
|
||||
}
|
||||
|
||||
areaScope, err := m.ResolveAreaScope(ctx, c.RepportService.DB())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if areaScope.Restrict {
|
||||
query.AllowedAreaIDs = toInt64Slice(areaScope.IDs)
|
||||
}
|
||||
|
||||
if query.Page < 1 || query.Limit < 1 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
@@ -306,3 +330,14 @@ func parseCommaSeparatedInt64s(raw string) ([]int64, error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func toInt64Slice(ids []uint) []int64 {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]int64, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
out = append(out, int64(id))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user