mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: refactor user -> rbac.subject into a function (#13624)
* chore: refactor user subject logic to be in 1 place * test: implement test to assert deleted custom roles are omitted * add unit test for deleted role
This commit is contained in:
@@ -75,6 +75,17 @@ type Subject struct {
|
||||
cachedASTValue ast.Value
|
||||
}
|
||||
|
||||
// RegoValueOk is only used for unit testing. There is no easy way
|
||||
// to get the error for the unexported method, and this is intentional.
|
||||
// Failed rego values can default to the backup json marshal method,
|
||||
// so errors are not fatal. Unit tests should be aware when the custom
|
||||
// rego marshaller fails.
|
||||
func (s Subject) RegoValueOk() error {
|
||||
tmp := s
|
||||
_, err := tmp.regoValue()
|
||||
return err
|
||||
}
|
||||
|
||||
// WithCachedASTValue can be called if the subject is static. This will compute
|
||||
// the ast value once and cache it for future calls.
|
||||
func (s Subject) WithCachedASTValue() Subject {
|
||||
|
||||
@@ -39,6 +39,8 @@ func roleCache(ctx context.Context) *syncmap.Map[string, rbac.Role] {
|
||||
}
|
||||
|
||||
// Expand will expand built in roles, and fetch custom roles from the database.
|
||||
// If a custom role is defined, but does not exist, the role will be omitted on
|
||||
// the response. This means deleted roles are silently dropped.
|
||||
func Expand(ctx context.Context, db database.Store, names []rbac.RoleIdentifier) (rbac.Roles, error) {
|
||||
if len(names) == 0 {
|
||||
// That was easy
|
||||
|
||||
Reference in New Issue
Block a user