Bind permissions to roles and scope operator access by branch.

Replace permission_user with permission_role, enforce RBAC on admin routes, and limit operators to their assigned branches.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-24 18:24:43 +05:00
parent 427d5b4e07
commit 1fd0abbcb2
57 changed files with 1281 additions and 657 deletions

View File

@@ -13,6 +13,7 @@ import (
"online-back/internal/appresult"
"online-back/internal/config"
"online-back/internal/identity/rbac"
"online-back/pkg/logging"
minioUpload "online-back/pkg/minio"
@@ -180,6 +181,9 @@ func (h *handler) getByID(c *gin.Context) {
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
return
}
if !rbac.GuardUser(c, item.Id) {
return
}
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
}
@@ -234,6 +238,10 @@ func (h *handler) update(c *gin.Context) {
return
}
if rbac.HasBranchScope(c) && !rbac.GuardUser(c, id) {
return
}
var dto UpdateUserDTO
if err := c.ShouldBindJSON(&dto); err != nil {
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
@@ -273,6 +281,10 @@ func (h *handler) delete(c *gin.Context) {
return
}
if rbac.HasBranchScope(c) && !rbac.GuardUser(c, id) {
return
}
if err := h.repository.Delete(c.Request.Context(), id); errors.Is(err, pgx.ErrNoRows) {
c.JSON(http.StatusNotFound, appresult.ErrNotFound)
return
@@ -327,6 +339,8 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
filter.Search = raw
}
rbac.BindBranchIDs(c, &filter.BranchIds)
return filter, true
}