Permissions extends AppModel
Permissions management
Controls which options are available for setting the Access Control List's Control Objects as well as offers an interface for interacting with the ACL
Table of Contents
Methods
| __construct() | Loads the ACL for processing |
| add() | Adds a new permission field to the system (also adds the permission to the ACL) |
| addGroup() | Adds a new permission group to the system (also adds the permission to the ACL) |
| authorized() | Verifies whether the given ARO is authorized to access the given ACO on the given action |
| delete() | Deletes the permission field from the system, also removes the items from the ACL |
| deleteGroup() | Deletes the permission group from the system, also removes the items from the ACL |
| edit() | Updates the permission field in the system (also adds the permission to the ACL if needed) |
| editGroup() | Updates the permission group in the system (also adds the permission to the ACL if needed) |
| fromAcl() | Fetches a set of permission groups and permission fields that the given group has access to on the provided level and company |
| get() | Fetches the given permission record from the database by ID |
| getAll() | Fetches all permission fields divided under each permission category. |
| getByAlias() | Fetches the given permission record from the database by alias |
| getGroup() | Fetches the given permission group record from the database by ID |
| getGroupByAlias() | Fetches the given permission group record from the database by alias |
| getGroupRules() | Returns add/edit rules for Permission Groups |
| getRules() | Returns add/edit rules for Permission fields |
Methods
__construct()
Loads the ACL for processing
public
__construct() : mixed
add()
Adds a new permission field to the system (also adds the permission to the ACL)
public
add(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of input fields including:
- group_id The ID of the permission group this permission belongs to
- name The name of this permission (language definition or plain-text)
- alias The ACO alias for this permission (i.e. the Class name to apply to)
- action The action this ACO may control (i.e. the Method name of the alias to control access for)
- plugin_id The ID of the plugin this action belongs to (if any)
Return values
int —The ID of the permission record on success, void one error
addGroup()
Adds a new permission group to the system (also adds the permission to the ACL)
public
addGroup(array<string|int, mixed> $vars) : int
Parameters
- $vars : array<string|int, mixed>
-
An array of input fields including:
- name The name of this permission group (language definition or plain-text)
- level The level this permission group resides on (staff or client)
- alias The ACO alias for this permission group (i.e. the Class name to apply to)
- plugin_id The ID of the plugin this permission group belongs to (if any)
Return values
int —The ID of the permission group on success, void one error
authorized()
Verifies whether the given ARO is authorized to access the given ACO on the given action
public
authorized(string $aro, string $aco, string $action, string $level, int $company_id) : bool
Parameters
- $aro : string
-
The ARO to verify can access the ACO
- $aco : string
-
The ACO to verify can be accessed by the ARO
- $action : string
-
The action permission
- $level : string
-
The permission group level
- $company_id : int
-
The ID of the company
Return values
bool —True if the ARO is authorized to access the ACO or if the permission or permission group does not exist, false otherwise
delete()
Deletes the permission field from the system, also removes the items from the ACL
public
delete(int $id) : mixed
Parameters
- $id : int
-
The ID of the permission field to delete
deleteGroup()
Deletes the permission group from the system, also removes the items from the ACL
public
deleteGroup(int $group_id) : mixed
Parameters
- $group_id : int
-
The ID of the permission group to delete
edit()
Updates the permission field in the system (also adds the permission to the ACL if needed)
public
edit(int $id, array<string|int, mixed> $vars) : mixed
Parameters
- $id : int
-
The ID of the permission field to update
- $vars : array<string|int, mixed>
-
An array of input fields including:
- group_id The ID of the permission group this permission belongs to
- name The name of this permission (language definition or plain-text)
- alias The ACO alias for this permission (i.e. the Class name to apply to)
- action The action this ACO may control (i.e. the Method name of the alias to control access for)
- plugin_id The ID of the plugin this action belongs to (if any)
editGroup()
Updates the permission group in the system (also adds the permission to the ACL if needed)
public
editGroup(int $group_id, array<string|int, mixed> $vars) : mixed
Parameters
- $group_id : int
-
The ID of the permission group to update
- $vars : array<string|int, mixed>
-
An array of input fields including:
- name The name of this permission group (language definition or plain-text)
- level The level this permission group resides on (staff or client)
- alias The ACO alias for this permission group (i.e. the Class name to apply to)
- plugin_id The ID of the plugin this permission group belongs to (if any)
fromAcl()
Fetches a set of permission groups and permission fields that the given group has access to on the provided level and company
public
fromAcl(string $aro, string $level, int $company_id) : stdClass
Parameters
- $aro : string
-
The ARO to fetch permissions for
- $level : string
-
The level to fetch permissions for ('staff' or 'client')
- $company_id : int
-
The ID of the company to fetch permissions for
Return values
stdClass —A stdClass object containing the following:
- permission_group An numerically indexed array of permission group IDs that this ARO is allowed to access
- permission A numerically indexed array of permission field IDs that this ARO is allowed to access
get()
Fetches the given permission record from the database by ID
public
get(int $id) : mixed
Parameters
- $id : int
-
The permission ID to fetch
Return values
mixed —A stdClass object representing a permission field, false if the permission field does not exist
getAll()
Fetches all permission fields divided under each permission category.
public
getAll(string $level, int $company_id) : array<string|int, mixed>
Parameters
- $level : string
-
The level to fetch permissions for ('staff', or 'client')
- $company_id : int
-
The company to fetch permissions for
Return values
array<string|int, mixed> —An array of stdClass objects each representing a permission group. Each permission group also contains an array of permission fields representing as stdClass objects
getByAlias()
Fetches the given permission record from the database by alias
public
getByAlias(string $alias[, int $plugin_id = null ][, string $action = null ]) : mixed
Parameters
- $alias : string
-
The permission alias to fetch
- $plugin_id : int = null
-
The ID of the plugin (null if not part of a plugin) the alias belongs to
- $action : string = null
-
The permission action to fetch (null fetches 1st match on alias)
Return values
mixed —A stdClass object representing a permission field, false if the permission field does not exist
getGroup()
Fetches the given permission group record from the database by ID
public
getGroup(int $group_id) : mixed
Parameters
- $group_id : int
-
The permission group ID to fetch
Return values
mixed —A stdClass object representing a permission group, false if the permission group does not exist
getGroupByAlias()
Fetches the given permission group record from the database by alias
public
getGroupByAlias(string $group_alias[, int $plugin_id = null ]) : mixed
Parameters
- $group_alias : string
-
The permission group alias to fetch
- $plugin_id : int = null
-
The ID of the plugin (null if not part of a plugin) the alias belongs to
Return values
mixed —A stdClass object representing a permission group, false if the permission group does not exist
getGroupRules()
Returns add/edit rules for Permission Groups
private
getGroupRules(array<string|int, mixed> $vars) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
An array of input vars
Return values
array<string|int, mixed> —An array containing the validation rules
getRules()
Returns add/edit rules for Permission fields
private
getRules(array<string|int, mixed> $vars) : array<string|int, mixed>
Parameters
- $vars : array<string|int, mixed>
-
An array of input vars
Return values
array<string|int, mixed> —An array containing the validation rules