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:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/org/branches"
|
||||
"online-back/pkg/client/postgresql"
|
||||
"online-back/pkg/logging"
|
||||
@@ -125,6 +126,10 @@ func buildListQuery(filter branches.ListFilter) (whereClause string, args []inte
|
||||
conditions = append(conditions, fmt.Sprintf("b.unique_code ILIKE $%d", n))
|
||||
}
|
||||
|
||||
if len(filter.BranchIds) > 0 {
|
||||
conditions, args = rbac.AppendBranchIDs(conditions, args, "b.id", filter.BranchIds)
|
||||
}
|
||||
|
||||
if len(conditions) == 0 {
|
||||
return "", args
|
||||
}
|
||||
|
||||
@@ -7,23 +7,23 @@ type LocalizedText struct {
|
||||
}
|
||||
|
||||
type BranchDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
Address LocalizedText `json:"address"`
|
||||
Region string `json:"region"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
ProvinceName LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
Address LocalizedText `json:"address"`
|
||||
Region string `json:"region"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
ProvinceName LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type CreateBranchDTO struct {
|
||||
@@ -67,6 +67,7 @@ type ListFilter struct {
|
||||
ProvinceName string
|
||||
BranchName string
|
||||
UniqueCode string
|
||||
BranchIds []int64
|
||||
Page int
|
||||
Limit int
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/handlers"
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/org/province"
|
||||
"online-back/pkg/logging"
|
||||
|
||||
@@ -163,6 +164,9 @@ func (h *handler) getByID(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
if !rbac.GuardBranch(c, item.Id) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(item))
|
||||
}
|
||||
@@ -349,5 +353,6 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
|
||||
filter.UniqueCode = raw
|
||||
}
|
||||
|
||||
rbac.BindBranchIDs(c, &filter.BranchIds)
|
||||
return filter, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user