Class: ACLUtils#

Common utility functions for working with AccessControlList objects and validating user permissions.

Hierarchy#

  • ACLUtils

Index#

Properties#

Methods#

Properties#

cachedACLs#

Private cachedACLs: Map<string, CachedACL> = new Map()

Defined in src/utils/ACLUtils.ts:24


config#

Private config: Configuration = new Configuration()

Defined in src/utils/ACLUtils.ts:25


service#

Private Optional service: AccessControlListService

Defined in src/utils/ACLUtils.ts:26

Methods#

findACL#

findACL(entityId: string): Promise<AccessControlList | undefined>

Defined in src/utils/ACLUtils.ts:142

Retrieves the access control list with the associated identifier and populates the parent(s).

Parameters:#

Name

Type

Description

entityId

string

The unique identifier of the ACL to retrieve.

Returns: Promise<AccessControlList | undefined>


getRecord#

getRecord(acl: AccessControlList, user: JWTUser | User | undefined): ACLRecord | undefined

Defined in src/utils/ACLUtils.ts:180

Retrieves the first available record in the provided ACL associated with the provided user.

Parameters:#

Name

Type

Description

acl

AccessControlList

The access control list that will be searched.

user

JWTUser | User | undefined

The user to find a record for.

Returns: ACLRecord | undefined

The ACL record associated with the given user if found, otherwise undefined.


hasPermission#

hasPermission(user: JWTUser | User | undefined, acl: AccessControlList | string, action: ACLAction, bypassTrustedRolesCheck: boolean): Promise<boolean>

Defined in src/utils/ACLUtils.ts:69

Validates that the user has permission to perform the provided action using the given access control list.

Parameters:#

Name

Type

Default value

Description

user

JWTUser | User | undefined

-

The user to validate permissions of.

acl

AccessControlList | string

-

The ACL or uid of an ACL to validate permissions against.

action

ACLAction

-

The action that the user desires permission for.

bypassTrustedRolesCheck

boolean

false

Whether or not to bypass the trusted role check - defaults to false

Returns: Promise<boolean>

true if the user has at least one of the permissions granted for the given entity, otherwise false.


init#

init(config: Configuration, service: AccessControlListService): void

Defined in src/utils/ACLUtils.ts:28

Parameters:#

Name

Type

config

Configuration

service

AccessControlListService

Returns: void


userMatchesId#

PrivateuserMatchesId(user: JWTUser | User | undefined, userOrRoleId: string): boolean

Defined in src/utils/ACLUtils.ts:39

Checks to see if the provided user matches the providedUserOrRoleId.

Parameters:#

Name

Type

Description

user

JWTUser | User | undefined

The user to check.

userOrRoleId

string

The ACL record id to check against.

Returns: boolean

true if the user contains a uid or role that matches the userOrRoleId, otherwise false.