Add backups, currencies and dashboard APIs, and scope access by guard_name.
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

Web users may only CRUD their own records, operators stay in assigned branches, and admin/manager/superadmin keep full access.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
guwandykandCursor committed 2026-08-31 18:14:47 +05:00
1 parent 0d000f9af6
commit 28509eb4ca
65 files changed
+9132 -296

No files matched your search

+50 -2
View File
@@ -27,6 +27,49 @@ func HasBranchScope(c *gin.Context) bool {
return len(BranchIDsFrom(c)) > 0
}
func RoleFrom(c *gin.Context) string {
raw, _ := c.Get(contextRole)
role, _ := raw.(string)
return role
}
func GuardFrom(c *gin.Context) string {
raw, _ := c.Get(contextGuard)
guard, _ := raw.(string)
return guard
}
func IsOwnScope(c *gin.Context) bool {
return GuardFrom(c) == guardWeb
}
func SkipRecordGuard(c *gin.Context) bool {
return !HasBranchScope(c) && !IsOwnScope(c)
}
func CurrentUserID(c *gin.Context) (int64, bool) {
return parseContextUserID(c)
}
func GuardOwned(c *gin.Context, ownerID *int64) bool {
if !IsOwnScope(c) {
return true
}
current, ok := CurrentUserID(c)
if !ok || ownerID == nil || *ownerID != current {
c.JSON(http.StatusForbidden, appresult.ErrForbidden)
return false
}
return true
}
func GuardOrder(c *gin.Context, ownerID *int64, branchID int64) bool {
if IsOwnScope(c) {
return GuardOwned(c, ownerID)
}
return GuardBranch(c, branchID)
}
func AllowsBranch(c *gin.Context, branchID int64) bool {
ids := BranchIDsFrom(c)
if len(ids) == 0 {
@@ -52,6 +95,10 @@ func GuardBranch(c *gin.Context, branchID int64) bool {
}
func GuardUser(c *gin.Context, userID int64) bool {
if IsOwnScope(c) {
id := userID
return GuardOwned(c, &id)
}
ids := BranchIDsFrom(c)
if len(ids) == 0 {
return true
@@ -61,7 +108,7 @@ func GuardUser(c *gin.Context, userID int64) bool {
c.JSON(http.StatusForbidden, appresult.ErrForbidden)
return false
}
service, _ := raw.(*Service)
service, _ := raw.(Authorizer)
if service == nil {
c.JSON(http.StatusForbidden, appresult.ErrForbidden)
return false
@@ -89,9 +136,10 @@ func UserInBranchSQL(userExpr string, placeholder int) string {
OR EXISTS (SELECT 1 FROM card_orders co WHERE co.user_id = %s AND co.branch_id = ANY($%d))
OR EXISTS (SELECT 1 FROM loan_orders lo WHERE lo.user_id = %s AND lo.branch_id = ANY($%d))
OR EXISTS (SELECT 1 FROM card_pin_orders cpo WHERE cpo.user_id = %s AND cpo.branch_id = ANY($%d))
OR EXISTS (SELECT 1 FROM card_rekwizit_orders cro WHERE cro.user_id = %s AND cro.branch_id = ANY($%d))
OR EXISTS (SELECT 1 FROM visa_master_payment_orders vmo WHERE vmo.user_id = %s AND vmo.branch_id = ANY($%d))
OR EXISTS (SELECT 1 FROM loan_paid_off_letters lpl WHERE lpl.user_id = %s AND lpl.branch_id = ANY($%d))
)`, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder)
)`, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder, userExpr, placeholder)
}
func containsInt64(ids []int64, want int64) bool {