changed role permission
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled

This commit is contained in:
guwandyk committed 2026-09-26 16:34:28 +05:00
1 parent f0ecf23879
commit 323e131216
74 files changed
+2915 -4713

No files matched your search

+33 -1
View File
@@ -8,6 +8,7 @@ import (
"online-back/internal/appresult"
"online-back/internal/handlers"
"online-back/internal/identity/rbac"
"online-back/internal/identity/rbac/perm"
"online-back/pkg/logging"
"github.com/gin-gonic/gin"
@@ -30,7 +31,7 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
}
func (h *handler) Register(router *gin.RouterGroup) {
group := router.Group(baseURL, appresult.JwtTokenCheck())
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Dashboard))
group.GET("/overview", h.overview)
}
@@ -59,6 +60,7 @@ func (h *handler) overview(c *gin.Context) {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
}
redactByPermission(&result, rbac.Can(c, perm.Cards), rbac.Can(c, perm.Loans))
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
}
@@ -91,3 +93,33 @@ func parseOverviewFilter(c *gin.Context) (OverviewFilter, bool) {
rbac.BindBranchIDs(c, &filter.BranchIds)
return filter, true
}
// redactByPermission blanks the widgets of modules the caller cannot open, so
// e.g. a head of loans sees every branch's loan numbers but no card numbers.
func redactByPermission(o *OverviewDTO, cards, loans bool) {
if !cards {
o.Stats.ActiveCards = StatMetricDTO{}
o.Stats.OnlinePayments = StatMetricDTO{}
}
if !loans {
o.Stats.LoanOrders = StatMetricDTO{}
o.LoanStatus = []LoanStatusShareDTO{}
o.RecentActivity = []RecentActivityDTO{}
}
for i := range o.Trend.Points {
if !cards {
o.Trend.Points[i].Cards = 0
}
if !loans {
o.Trend.Points[i].Loans = 0
}
}
for i := range o.WeeklyOrders {
if !cards {
o.WeeklyOrders[i].Cards = 0
}
if !loans {
o.WeeklyOrders[i].Loans = 0
}
}
}