Boost:Admin Interface Privileges
From Metro Studios Knowledgebase
The Boost administrative interface has a built in privilege system that can be used to restrict the functions that each user can access. Privileges are configured per administrator group, and in turn each administrative user can be assigned to a specific group.
 Defining Privileges
The administrative interface privileges are defined in the AdminPrivileges class which is located in the site/lib/Admin/Privileges.php file. In that class there are a number of array instance variables where you can set options to control the privileges that can be assigned to an administrator group.
Each element of this array is the name of a model class which will be controlled by the privilege system. When a model is added to this list, it will add 4 options to the administrator group privileges for that model: view, create, update, and delete.
protected $models = array( '_Product', '_ProductCategory', '_ProductBrand' );
An associative array containing the views that will be controlled by the privilege system. Each view that you want to be controlled by privileges must be added to this array individually. The array key will be the name of the view as it appears in the v= request paramater; the value will be the label as you want it to appear in the administrator group create/update interface.
protected $views = array( 'appointments' => 'View Appointments', 'orders' => 'View Orders' );
An associative array containing the actions that will be controlled by the privilege system. Each action that you want to be controlled by privileges must be added to this array individually. The array key will be the name of the action as it appears in the a= request paramater; the value will be the label as you want it to appear in the administrator group create/update interface.
protected $views = array( 'createAppointment' => 'Create Appointments', 'updateAppointment' => 'Update Appointments', 'createOrder' => 'Create Orders', 'updateOrder' => 'Update Orders' );
 Privilege Verification
Privileges are checked on every administrative interface request. If a user does not have the necessary privileges to access a function, an error message will be displayed letting them know that they are not allowed to access the function.
 Superuser Accounts
The privilege system does not apply to administrator accounts defined as being a superuser. In that case the privilege check is always skipped and the superuser is allowed to access all of the administrative interface functions.
 Filtering Admin Tabs Based On Priveleges
Sometimes clients will want certain people to be able to access certain pieces of the admin section. In order to accomplish this, you'll need to create groups and assign privileges to those groups. Follow the instructions below to properly set up these new groups.
 Adding models to list of privileges
- Open "Privileges.php" in the _boost/site/lib directory.
- Add the models you wish to assign privileges for to the $models array.
 Setting up privileges and limiting access to models
 Creating the groups and setting permissions
- Create the new group in the Administrators > Groups menu in the boost admin panel.
- Assign permissions to the new group.
(By default the groups will now be restricted from accessing those models they do not have permissions for. However, they will still see them in the admin tabs.)
 Hiding admin tabs from limited groups
- Open "global-menu.php" in the _boost/site/admin/includes directory
- Add the following lines of code to the top of the file to fetch the logged in admin and unserialize the privileges for the associated group. (We'll use the $is_super variable in our conditional statements on the next step):
- Use the following code-snippet template to check if the privileges for the current admin contain the model and then show the tab if true or move on to the next model if false.
$admin = bstAdminAuth::getAdministrator(); $is_super = ($admin->is_superuser == '1' ? TRUE:FALSE); $privileges = unserialize($admin->group->privileges);
<? if($is_super || isset($privileges['models']['_SiteAdministrator']) && $privileges['models']['_SiteAdministrator']['manage'] == '1' ): ?> <li> <a>Administrators</a> <ul> <li><a href="index.php?v=manage&m=<?php echo ADMINISTRATOR_MODEL; ?>">Manage</a></li> <li><a href="index.php?v=create&m=<?php echo ADMINISTRATOR_MODEL; ?>" class="dialog">Create</a></li> <li> <a class="sub">Groups</a> <ul> <li><a href="index.php?v=manage&m=_AdministratorGroup">Manage</a></li> <li><a href="index.php?v=create&m=_AdministratorGroup" class="dialog">Create</a></li> </ul> </li> </ul> </li> <?endif;?>