changed arhitecture
This commit is contained in:
1 parent
7e3a5cebcc
commit
585ba63bc2
95 files changed
+4985
-1360
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// Package rbac provides permission-check capability on top of the existing
|
||||
// permissions/permission_user tables. It is not wired into any route yet —
|
||||
// today every route is still gated only by appresult.JwtTokenCheck()'s
|
||||
// admin-claim check. RequirePermission is available for routes to opt into
|
||||
// once permission data is populated and specific routes are chosen.
|
||||
//
|
||||
// Note: the schema has no role_permission pivot table, so role-based
|
||||
// permission resolution isn't possible yet — HasPermission only resolves
|
||||
// permissions granted directly via permission_user.
|
||||
package rbac
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"online-back/pkg/client/postgresql"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
client postgresql.Client
|
||||
}
|
||||
|
||||
func NewService(client postgresql.Client) *Service {
|
||||
return &Service{client: client}
|
||||
}
|
||||
|
||||
// HasPermission reports whether userID has been directly granted the
|
||||
// permission identified by code (permissions.code) via permission_user.
|
||||
func (s *Service) HasPermission(ctx context.Context, userID int64, code string) (bool, error) {
|
||||
const query = `
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM permission_user pu
|
||||
JOIN permissions p ON p.id = pu.permission_id
|
||||
WHERE pu.user_id = $1 AND p.code = $2
|
||||
)`
|
||||
|
||||
var granted bool
|
||||
if err := s.client.QueryRow(ctx, query, userID, code).Scan(&granted); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return granted, nil
|
||||
}
|
||||
Reference in new issue
Block a user