Permissions

Permissions

new Permissions()

Source:

Methods

add(permission_name, user_id)

Source:
Adds a permission to a user
Parameters:
Name Type Description
permission_name string the name of the permission
user_id string the id of the user to add the permission for

check(permission_name, user_id) → {boolean}

Source:
Checks if a user has a specific permission
Parameters:
Name Type Description
permission_name string the name of the permission to check for
user_id string the id of the user to check permissions for
Returns:
true if they have the permission
Type
boolean

has_permissions(user_id) → {boolean}

Source:
Checks if a user has any permissions
Parameters:
Name Type Description
user_id string the id of the user to check permissions for.
Returns:
true if they have any permissions
Type
boolean

remove(permission_name, user_id)

Source:
Removes a permission from a user. If a user has no permissions left after the removal, they are removed from the permissions object.
Parameters:
Name Type Description
permission_name string the name of the permission
user_id string the id of the user to remove the permission from

Permissions

new Permissions(permissions)

Source:
Parameters:
Name Type Description
permissions Object a permissions data object, stored with keys as user_ids and key values as arrays of permission names.

Methods

add(permission_name, user_id)

Source:
Adds a permission to a user
Parameters:
Name Type Description
permission_name string the name of the permission
user_id string the id of the user to add the permission for

check(permission_name, user_id) → {boolean}

Source:
Checks if a user has a specific permission
Parameters:
Name Type Description
permission_name string the name of the permission to check for
user_id string the id of the user to check permissions for
Returns:
true if they have the permission
Type
boolean

has_permissions(user_id) → {boolean}

Source:
Checks if a user has any permissions
Parameters:
Name Type Description
user_id string the id of the user to check permissions for.
Returns:
true if they have any permissions
Type
boolean

remove(permission_name, user_id)

Source:
Removes a permission from a user. If a user has no permissions left after the removal, they are removed from the permissions object.
Parameters:
Name Type Description
permission_name string the name of the permission
user_id string the id of the user to remove the permission from