Access control listsAccess Control Lists, hereafter ACLs, are a powerful way to let administrators switch certain capabilities on and off for any number of people. By registering your plugin's various actions with the ACL system, you can allow your plugin to easily scale to any deployment the administrator has in mind.
Overview of the ACL terminology and model
The API is modeled in a very simple way:
There is currently no implementation of hierarchy, e.g. you cannot automatically have a page draw permissions from another page at the API level. You can, however, fetch permissions for the parent and child pages, and then merge the child's calculated rule on top of the parent's. The ACL API: Getting permissionsCertain actions apply only to certain namespaces; for example, you can't edit a special page because it's logically impossible. The $session->check_acl_scope() method can be used to test an action to see if it applies to a namespace.
Specify the action you're checking (such as edit_page) and the namespace (Special). If the action applies to that namespace, you'll get a return of true; otherwise, the return value will be false. if ( $session->check_acl_scope('post_comments', 'Article') ) echo 'The action "post_comments" applies to articles.';
Returns an instance of Session_ACLPageInfo, which contains the fully calculated permissions for the given page. You can call the get_permissions method on it to get the final decision on whether an action is permissible or not.
Returns true if the given action is permissible, and false otherwise. If you call get_permissions with an action that is not defined for the current namespace, a warning will be thrown, and the function will return false. Example of fetching permissions$perms = $session->fetch_page_acl('Main_Page', 'Article'); if ( $perms->check_acl_scope('read', 'Article') && $perms->get_permissions('read') ) echo "Looks like you're allowed to read the main page."; If you've set up your own actions and/or are on your own namespace, there's not much need to call check_acl_scope, but if your plugin deals with arbitrary pages from different namespaces you should plan to use this to avoid throwing warnings. Registering new actionsEven the Enano core uses this API to register actions. Call the $session->register_acl_type() method from the hook acl_rule_init.
Creates a new action. So long as the action applies to the namespace of the page the user is managing in the ACL editor, the action will now show up in the ACL editor where the user can edit it, and get_permissions can be called with $action_id to determine what the permissions are. Description of parameters:
Example$plugins->attachHook('acl_rule_init', 'myplugin_register_acl_actions($session);'); function myplugin_register_acl_actions(&$session) { // A simple action that applies to all namespaces and has no dependencies $session->register_acl_type('mod_misc', AUTH_DISALLOW, 'perm_mod_misc', Array(), 'All'); // A more complex action that applies only to namespaces that are database-driven, // and depends on a number of other actions. $session->register_acl_type('even_when_protected', AUTH_DISALLOW, 'perm_even_when_protected', Array('edit_page', 'rename', 'mod_comments', 'edit_cat'), 'Article|User|Project|Template|File|Help|System|Category'); } ACL scope and precedenceACL rules might be overridden by other rules. For example, a rule that applies to a whole user group will defer to a rule for one specific user. Enano handles precedence intelligently; for documentation on this behavior, please see the Administrator's Handbook, section 4.2. Categories: (Uncategorized) [ edit categorization ] |
