Revert "Revert "[FIX/BE-US]add feature restrict by location and areas in roles""

This reverts commit 26bf7f165e.
This commit is contained in:
ragilap
2026-01-14 13:34:44 +07:00
parent 26bf7f165e
commit 32772a63c8
30 changed files with 1258 additions and 37 deletions
@@ -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
}