Skip to content

Commit

Permalink
The start to user permissions cleanup, including "Manage" checkbox wh…
Browse files Browse the repository at this point in the history
…ich will check all permissions (edit, create, delete) below it. If a user is granted permission to manage a page, permissions will visually show when managing permission on container and module. This still need to be done when permission is granted n the container level.
  • Loading branch information
illiphilli committed Jun 15, 2011
1 parent 1438be8 commit dcae016
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
9 changes: 8 additions & 1 deletion framework/core/controllers/expController.php
Expand Up @@ -25,7 +25,14 @@
class expController {
protected $basemodel = null;
protected $classname = '';
protected $permissions = array('create'=>'Create', 'edit'=>'Edit', 'delete'=>'Delete', 'configure'=>'Configure', 'perms'=>'Manage Permissions', 'manage'=>'Manage Module');
protected $permissions = array(
'manage'=>'Manage',
'create'=>'Create',
'edit'=>'Edit',
'delete'=>'Delete',
'configure'=>'Configure',
//'perms'=>'Manage Permissions',
);
protected $remove_permissions = array();
protected $add_permissions = array();

Expand Down
63 changes: 60 additions & 3 deletions modules/common/views/_permissions.tpl
Expand Up @@ -15,7 +15,12 @@
*}

{css unique="permissions" corecss="tables"}

{literal}
.exp-skin-table thead th {
white-space:nowrap;
border-right:1px solid #D4CBBA;
}
{/literal}
{/css}

<form method="post">
Expand Down Expand Up @@ -57,7 +62,7 @@

{foreach from=$perms item=perm key=pkey name=perms}
<td>
<input type="checkbox"{if $user->$pkey==1||$user->$pkey==2} checked{/if} name="permdata[{$user->id}][{$pkey}]" value="1"{if $user->$pkey==2} disabled=1{/if} id="permdata[{$user->id}][{$pkey}]">
<input class="{$pkey}" type="checkbox"{if $user->$pkey==1||$user->$pkey==2} checked{/if} name="permdata[{$user->id}][{$pkey}]" value="1"{if $user->$pkey==2} disabled=1{/if} id="permdata[{$user->id}][{$pkey}]">
</td>
{/foreach}
</tr>
Expand All @@ -68,4 +73,56 @@
{$page->links}

{control type="buttongroup" submit="Save Permissions"|gettext cancel="Cancel"|gettext}
</form>
</form>


{script unique="permission-checking" yui3mods=1}
{literal}
YUI(EXPONENT.YUI3_CONFIG).use('node', function(Y) {
var manage = Y.all('input.manage');
var admin = Y.all('input.administrate');
var checkSubs = function(row) {
row.each(function(n,k){
if (!n.hasClass('manage') && !n.hasClass('administrate')) {
n.insertBefore('<input type="hidden" name="'+n.get("name")+'" value="1">',n);
n.setAttrs({'checked':1,'disabled':1});
};
});
};

var unCheckSubs = function(row) {
row.each(function(n,k){
if (!n.hasClass('manage') && !n.hasClass('administrate')) {
n.get('previousSibling').remove();
n.setAttrs({'checked':0,'disabled':0});
};
});
};

var toggleChecks = function(target,start) {
var row = target.ancestor('tr').all('input[type=checkbox]');
if(target.get('checked')&&!target.get('disabled')){
checkSubs(row);
} else {
if (!start) {
unCheckSubs(row);
}
}
};

manage.on('click',function(e){
toggleChecks(e.target);
});
admin.on('click',function(e){
toggleChecks(e.target);
});
manage.each(function(n){
toggleChecks(n,1);
});
admin.each(function(n){
toggleChecks(n,1);
});
});
{/literal}
{/script}

4 changes: 2 additions & 2 deletions modules/containermodule/class.php
Expand Up @@ -31,11 +31,11 @@ function supportsWorkflow() { return false; }
function permissions($internal = '') {
$i18n = exponent_lang_loadFile('modules/containermodule/class.php');
return array(
'administrate'=>$i18n['perm_administrate'],
'administrate'=>gt('Manage'),
'add_module'=>$i18n['perm_add_module'],
'edit_module'=>$i18n['perm_edit_module'],
'delete_module'=>$i18n['perm_delete_module'],
'order_modules'=>$i18n['perm_order_modules'],
'order_modules'=>gt('Reorder'),
);
}

Expand Down
3 changes: 2 additions & 1 deletion modules/containermodule/views/Default.tpl
Expand Up @@ -27,7 +27,8 @@
{/permissions}

{permissions}
{if $hasParent == 0 && ($permissions.edit_module == 1 || $permissions.administrate == 1)}{** top level container module **}
{if $hasParent == 0 && ($permissions.edit_module == 1 || $permissions.administrate == 1)}
{** top level container module **}
<div class="container-chrome">
<a href="#" class="trigger" title="Container">Container</a>
<ul class="container-menu">
Expand Down
4 changes: 2 additions & 2 deletions modules/navigationmodule/class.php
Expand Up @@ -32,8 +32,8 @@ function permissions($internal = '') {
$i18n = exponent_lang_loadFile('modules/navigationmodule/class.php');

return array(
'view'=>$i18n['perm_view'],
'manage'=>$i18n['perm_manage']
'manage'=>gt('Administrate'),
'view'=>gt('View Page'),
);
}

Expand Down
1 change: 1 addition & 0 deletions subsystems/permissions.php
Expand Up @@ -307,6 +307,7 @@ function exponent_permissions_checkUser($user,$permission,$location,$explicitOnl
}
}
if (!$implicit && $location->mod != 'navigationmodule') {
$location->mod = (strstr($location->mod,'module')||strstr($location->mod,'Controller')) ? $location->mod : $location->mod.'Controller';
foreach ($db->selectObjects('sectionref',"is_original=1 AND module='".$location->mod."' AND source='".$location->src."'") as $secref) {
if (exponent_permissions_checkUser($user,'manage',exponent_core_makeLocation('navigationmodule','',$secref->section))) {
$implicit = true;
Expand Down

0 comments on commit dcae016

Please sign in to comment.