EDIT: don't use the code in this post
The following 'solutions' are a little ugly and may need a little further testing and be aware if you update in the future you will lose the changes, also they might not work with 0.8.0.
So after the disclaimer...
1.
To hide the 'Pages' tab, you need to edit the 'backend' view ( found under '/wolf/app/layouts/'), so first of all, back it up (ie: save a copy backend.ORIG.php). Edit the backend.php you'll be using and replace:
<li id="page-plugin" class="plugin"><a href="<?php echo get_url('page'); ?>"<?php if ($ctrl=='page') echo ' class="current"'; ?>><?php echo __('Pages'); ?></a></li>
found around line 128, for:
<?php if (AuthUser::hasPermission('page_view')): ?>
<li id="page-plugin" class="plugin"><a href="<?php echo get_url('page'); ?>"<?php if ($ctrl=='page') echo ' class="current"'; ?>><?php echo __('Pages'); ?></a></li>
<?php endif; ?>
This will hide the tab from being displayed but it's still 'active' and it can be accesed, so we need to do another change.
By default the backend interface is routed to the 'Pages' tab, unless you change the settings. But this setting affects all users, so I think, in your particular case, it's not an option to change it. We'll be forcing a redirect to the 'User' tab since it's all the role is supposed to do.
Sidenote: If you haven't made a plugin for the site your currently developing, you should consider it.
Anyway, there're two sections available for the 'user editor' (hidden 'Pages' and 'User'). To force redirecting any call to 'Pages' will be using the Observer system.
So in your plugin you put the following:
<?php
if (!defined('IN_CMS')) { exit(); }
Plugin::setInfos(array(
'id' => 'roles_control',
'title' => __('Roles Control'),
'description' => __('Some description.'),
'version' => '0.1.0',
'license' => '...',
'author' => 'me',
'type' => 'backend'
));
if (Plugin::isEnabled('roles_control')) {
// If you need the Controller uncomment the line below
//Plugin::addController('roles_control','Roles Control','',false);
$user = AuthUser::getRecord();
$roles = $user->roles();
// Check if the current user has only the 'user editor'
if( AuthUser::hasRole('user editor') && count($roles) == 1 ) {
define('ROLE_LIMITED', true);
}
Observer::observe('dispatch_route_found','forceUserTab');
}
function forceUserTab($uri) {
// If the user has the 'user_editor' role
// and is going to the pages section
// send him to the 'Users' section
if(ROLE_LIMITED && preg_match('/page/', $uri) )
redirect( get_url('user') );
}
* I put the whole thing in case you don't have a custom plugin, if you have one omit the Plugin::setInfos.
2.
Now to disable certains roles from the user 'edit' view, we can do the following:
First backup the '/wolf/app/views/user/edit.php' because we'll be introducing a few lines.
Open the 'edit' view and around line 58 (inside the foreach loop), introduce:
<?php
// If you want to exclude more roles, add them to the array
$omit_roles = array('administrator','developer','editor');
if( ROLE_LIMITED && in_array( $role->name, $omit_roles ) )
continue;
?>
so you'll have something like this:
<?php $user_roles = ($user instanceof User) ? $user->roles(): array(); ?>
<?php foreach ($roles as $role): ?>
<?php
// If you want to exclude more roles, add them to the array
$omit_roles = array('administrator','developer','editor');
if( ROLE_LIMITED && in_array( $role->name, $omit_roles ) )
continue;
?>
<span class="checkbox"><input<?php if (in_array($role->name, $user_roles)) echo ' checked="checked"'; ?> id="user_role<?php echo $role->name; ?>" name="user_role[<?php echo $role->name; ?>]" type="checkbox" value="<?php echo $role->id; ?>" /> <label for="user_role-<?php echo $role->name; ?>"><?php echo __(ucwords($role->name)); ?></label></span>
<?php endforeach; ?>
3.
Finally to send the email, there's an Event triggered every time a user is succesfully added, so you need to add the following to the custom plugin index:
Observer::observe('user_after_add','emailNewUser');
...
function emailNewUser($name) {
// retrieve the user data
// and send the email
}
leaving our index plugin:
<?php
if (!defined('IN_CMS')) { exit(); }
Plugin::setInfos(array(
'id' => 'roles_control',
'title' => __('Roles Control'),
'description' => __('Some description.'),
'version' => '0.1.0',
'license' => '...',
'author' => 'me',
'type' => 'backend'
));
if (Plugin::isEnabled('roles_control')) {
// If you need the Controller uncomment the line below
//Plugin::addController('roles_control','Roles Control','',false);
$user = AuthUser::getRecord();
$roles = $user->roles();
// Check if the current user has only the 'user editor'
if( AuthUser::hasRole('user editor') && count($roles) == 1 ) {
define('ROLE_LIMITED', true);
}
Observer::observe('dispatch_route_found','forceUserTab');
Observer::observe('user_after_add','emailNewUser');
}
function forceUserTab($uri) {
// If the user has the 'user_editor' role
// and is going to the pages section
// send him to the 'Users' section
if(ROLE_LIMITED && preg_match('/page/', $uri) )
redirect( get_url('user') );
}
function emailNewUser($name) {
// retrieve the user data
// and send the email
}
Last edited by andrewmman (2011-06-22 09:09)