PHP Class Habari\ACL

The default Habari ACL class implements groups, and group permissions Users are assigned to one or more groups. Groups are assigned one or more permissions. Membership in any group that grants a permission means you have that permission. Membership in any group that denies that permission denies the user that permission, even if another group grants that permission.
Show file Open project: habari/system

Public Methods

Method Description
__static ( ) Register plugin hooks
_filter_permission_display ( $permission ) : string function _filter_permission_display Filter to localize permission names
_filter_token_description_display ( $token ) : string function _filter_token_description_display Filter to localize token descriptions
_filter_token_group_display ( $group ) : string function _filter_token_group_display Filter to localize token group name
access_check ( Bitmask $bitmask, mixed $access ) : boolean Check a permission bitmask for a particular access type.
access_names ( ) : array Obtain the list of access names (CRUD) to use for permissions.
all_tokens ( string $order = 'id' ) : array Get an array of QueryRecord objects containing all permission tokens
clear_caches ( ) Clears all caches used to hold permissions
create_default_tokens ( ) Creates the default set of permissions.
create_token ( string $name, string $description, string $group, boolean $crud = false ) : mixed Create a new permission token, and save it to the permission tokens table
deny_group ( integer $group_id, mixed $token_id ) : Result Deny permission to a group
deny_user ( integer $user_id, mixed $token_id ) : Result Deny permission to a user
destroy_token ( $token ) : boolean Remove a permission token, and any assignments of it
get_bitmask ( integer $mask ) : Bitmask Get a Bitmask object representing the supplied access integer
get_group_token_access ( integer $group, mixed $token_id ) : an Get the access bitmask of a group for a specific permission token
get_user_token_access ( User | integer $user, string | integer $token ) : Bitmask Return the access bitmask to a specific token for a specific user
grant_group ( integer $group_id, mixed $token_id, string $access = 'full' ) : Result Grant a permission to a group
grant_user ( integer $user_id, integer $token_id, string $access = 'full' ) : Result Grant a permission to a user
group_can ( mixed $group, mixed $token_id, string $access = 'full' ) : boolean Determine whether a group can perform a specific action
group_cannot ( $group, mixed $token_id ) : boolean Determine whether a group is explicitly denied permission to perform a specific action This function does not return true if the group is merely not granted a permission
normalize_token ( string $name ) : string Convert a token name into a valid format
rebuild_permissions ( $user = null ) Reset premissions to their default state
revoke_group_token ( integer $group_id, mixed $token_id ) : the Remove a permission token from the group permissions table
revoke_user_token ( integer $user_id, mixed $token_id ) : the Remove a permission token from the user permissions table
token_description ( mixed $permission ) : string Fetch a permission token's description from the DB
token_exists ( mixed $permission ) : boolean Determine whether a permission token exists
token_id ( string $name ) : integer Get a permission token's ID by its name
token_name ( integer $id ) : string Get a permission token's name by its ID
user_can ( mixed $user, mixed $token_id, string $access = 'full' ) : boolean Determine whether a user can perform a specific action
user_cannot ( mixed $user, mixed $token_id ) : boolean Determine whether a user is explicitly denied permission to perform a specific action This function does not return true if the user is merely not granted a permission
user_tokens ( mixed $user, string $access = 'full', $posts_only = false ) : array Get all the tokens for a given user with a particular kind of access

Private Methods

Method Description
cache_tokens ( ) : array Get an associative array of token ids and their name.

Method Details

__static() public static method

Register plugin hooks
public static __static ( )

_filter_permission_display() public static method

function _filter_permission_display Filter to localize permission names
public static _filter_permission_display ( $permission ) : string
return string The localized permission name

_filter_token_description_display() public static method

function _filter_token_description_display Filter to localize token descriptions
public static _filter_token_description_display ( $token ) : string
return string The localized token description

_filter_token_group_display() public static method

function _filter_token_group_display Filter to localize token group name
public static _filter_token_group_display ( $group ) : string
return string The localized token group name

access_check() public static method

Check a permission bitmask for a particular access type.
public static access_check ( Bitmask $bitmask, mixed $access ) : boolean
$bitmask Bitmask The permission bitmask
$access mixed The name of the access to check against (read, write, full)
return boolean Returns true if the given access meets exceeds the access to check against

access_names() public static method

Obtain the list of access names (CRUD) to use for permissions.
public static access_names ( ) : array
return array the list of access names available to ACL

all_tokens() public static method

Get an array of QueryRecord objects containing all permission tokens
public static all_tokens ( string $order = 'id' ) : array
$order string the order in which to sort the returning array
return array an array of QueryRecord objects containing all tokens

clear_caches() public static method

Clears all caches used to hold permissions
public static clear_caches ( )

create_default_tokens() public static method

Creates the default set of permissions.
public static create_default_tokens ( )

create_token() public static method

Create a new permission token, and save it to the permission tokens table
public static create_token ( string $name, string $description, string $group, boolean $crud = false ) : mixed
$name string The name of the permission
$description string The description of the permission
$group string The token group for organizational purposes
$crud boolean Indicates if the token is a CRUD or boolean type token (default is boolean)
return mixed the ID of the newly created permission, or boolean false

deny_group() public static method

Deny permission to a group
public static deny_group ( integer $group_id, mixed $token_id ) : Result
$group_id integer The group ID
$token_id mixed The name or ID of the permission token
return Result of the DB query

deny_user() public static method

Deny permission to a user
public static deny_user ( integer $user_id, mixed $token_id ) : Result
$user_id integer The user ID
$token_id mixed The name or ID of the permission token
return Result of the DB query

destroy_token() public static method

Remove a permission token, and any assignments of it
public static destroy_token ( $token ) : boolean
return boolean whether the permission was deleted or not

get_bitmask() public static method

Get a Bitmask object representing the supplied access integer
public static get_bitmask ( integer $mask ) : Bitmask
$mask integer The access mask, usually stored in the database
return Bitmask An object representing the access value

get_group_token_access() public static method

Get the access bitmask of a group for a specific permission token
public static get_group_token_access ( integer $group, mixed $token_id ) : an
$group integer The group ID
$token_id mixed A permission name or ID
return an access bitmask

get_user_token_access() public static method

Return the access bitmask to a specific token for a specific user
public static get_user_token_access ( User | integer $user, string | integer $token ) : Bitmask
$user User | integer A User object instance or user id
$token string | integer A permission token name or token ID
return Bitmask An access bitmask

grant_group() public static method

Grant a permission to a group
public static grant_group ( integer $group_id, mixed $token_id, string $access = 'full' ) : Result
$group_id integer The group ID
$token_id mixed The name or ID of the permission token to grant
$access string The kind of access to assign the group
return Result of the DB query

grant_user() public static method

Grant a permission to a user
public static grant_user ( integer $user_id, integer $token_id, string $access = 'full' ) : Result
$user_id integer The user ID
$token_id integer The name or ID of the permission token to grant
$access string The kind of access to assign the group
return Result of the DB query

group_can() public static method

Determine whether a group can perform a specific action
public static group_can ( mixed $group, mixed $token_id, string $access = 'full' ) : boolean
$group mixed A group ID or name
$token_id mixed A permission token ID or name
$access string Check for 'create', 'read', 'update', 'delete', or 'full' access
return boolean Whether the group can perform the action

group_cannot() public static method

Determine whether a group is explicitly denied permission to perform a specific action This function does not return true if the group is merely not granted a permission
public static group_cannot ( $group, mixed $token_id ) : boolean
$token_id mixed A permission ID or name
return boolean True if access to the token is denied to the group

normalize_token() public static method

Convert a token name into a valid format
public static normalize_token ( string $name ) : string
$name string The name of a permission
return string The permission with spaces converted to underscores and all lowercase

rebuild_permissions() public static method

Reset premissions to their default state
public static rebuild_permissions ( $user = null )

revoke_group_token() public static method

Remove a permission token from the group permissions table
public static revoke_group_token ( integer $group_id, mixed $token_id ) : the
$group_id integer The group ID
$token_id mixed The name or ID of the permission token
return the result of the DB query

revoke_user_token() public static method

Remove a permission token from the user permissions table
public static revoke_user_token ( integer $user_id, mixed $token_id ) : the
$user_id integer The user ID
$token_id mixed The name or ID of the permission token
return the result of the DB query

token_description() public static method

Fetch a permission token's description from the DB
public static token_description ( mixed $permission ) : string
$permission mixed a permission name or ID
return string the description of the permission

token_exists() public static method

Determine whether a permission token exists
public static token_exists ( mixed $permission ) : boolean
$permission mixed a permission name or ID
return boolean whether the permission exists or not

token_id() public static method

Get a permission token's ID by its name
public static token_id ( string $name ) : integer
$name string the name of the permission
return integer the permission's ID

token_name() public static method

Get a permission token's name by its ID
public static token_name ( integer $id ) : string
$id integer a token ID
return string the name of the permission, or boolean false

user_can() public static method

Determine whether a user can perform a specific action
public static user_can ( mixed $user, mixed $token_id, string $access = 'full' ) : boolean
$user mixed A user object, user ID or a username
$token_id mixed A permission ID or name
$access string Check for 'create', 'read', 'update', 'delete', or 'full' access
return boolean Whether the user can perform the action

user_cannot() public static method

Determine whether a user is explicitly denied permission to perform a specific action This function does not return true if the user is merely not granted a permission
public static user_cannot ( mixed $user, mixed $token_id ) : boolean
$user mixed A User object, user ID or a username
$token_id mixed A permission ID or name
return boolean True if access to the token is denied to the user

user_tokens() public static method

Get all the tokens for a given user with a particular kind of access
public static user_tokens ( mixed $user, string $access = 'full', $posts_only = false ) : array
$user mixed A user object, user ID or a username
$access string Check for 'create' or 'read', 'update', or 'delete' access
return array of token IDs