With Joomla!'s Access Control, you can define which user groups are allowed or denied to do which actions in your component. In the database, these are stored in _assets table. You can also read the basics of Access Control Levels in Joomla.
- core.admin - edit component options and permissions (ie superuser at global config level)
- core.options - edit component options, but not permissions
- core.create - can create new
- core.delete - can delete
- core.edit - can edit existing
- core.edit.state - can change status (publish or unpublish)
- core.edit.own - can change those which the user self created
There are two actions that need to be defined at the component level:
Configure (core.admin): which groups are allowed to configure the component level permissions via the 'Options' toolbar button?
Access Component (core.manage): which groups are allowed to access the component's backend?
To add this functionality, you need to do five steps:
- Add component level actions to access.xml
- Add the permissions fieldset to config.xml
- Add the 'Options' toolbar button
- Restrict the access to the component's back-end
1. access.xml File
A basic access.xml file consists of only two basic actions: core.admin and core.manage. This file is stores in the admin subdirectory.
<?xml version="1.0" encoding="utf-8" ?>
<action name="core.admin" title="JACTION_ADMIN" description="JACTION_ADMIN_COMPONENT_DESC" />
<action name="core.manage" title="JACTION_MANAGE" description="JACTION_MANAGE_COMPONENT_DESC" />
2. config.xml File
Next, you need to add the permissions fieldset to config.xml, in order to be able to set component level permissions.
3. view.html.php File
Add the 'Options' toolbar button when user is authorised for it. In the view file, you can add the following code to check if the user can edit the preferences:
// Options button.
if (JFactory::getUser()->authorise('core.admin', 'com_helloworld'))
4. Restrict the component's back-end access
To control the access to the back-end of the component, add the following lines to the main entry file (admin/component_name.php) of the component:
// Access check: is this user allowed to access the backend of this component?
if (!JFactory::getUser()->authorise('core.manage', 'com_helloworld'))
throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'));
Each component (or part of it) has its own set of permissions that can be controlled. They are described in an access.xml file located at the root of the admin folder. The actions to which access is controlled can be divided in three sections: at the component level, the category level and the item level.
<action name="core.create" title="JACTION_CREATE" description="COM_CATEGORIES_ACCESS_CREATE_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="COM_CATEGORIES_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_CATEGORIES_ACCESS_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="COM_CATEGORIES_ACCESS_EDITOWN_DESC" />
Which toolbar buttons to display depends on the Access Control permissions for the user. The function JHelperContent::getActions() is used to find the permissions. In the view (view.html.php) file, add the following code inside the display() function:
// What Access Permissions does this user have?
$this->canDo = JHelperContent::getActions('com_helloworld');
Then, indie the addToolBar() function,
JToolBarHelper::deleteList('', 'helloworlds.delete', 'JTOOLBAR_DELETE');