permissions page - if admin check a permission father its children will be hidden
This commit is contained in:
parent
d7a9382df4
commit
0112361eec
@ -112,12 +112,17 @@ class Crunchbutton_Admin extends Cana_Table {
|
|||||||
return $this->_permissions;
|
return $this->_permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasPermission( $permission ){
|
public function hasPermission( $permission, $useRegex = false ){
|
||||||
$permissions = $this->permissions();
|
$permissions = $this->permissions();
|
||||||
foreach( $permissions as $_permission ){
|
foreach( $permissions as $_permission ){
|
||||||
if( $_permission->permission == $permission && $_permission->allow == 1 ){
|
if( $_permission->permission == $permission && $_permission->allow == 1 ){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if( $useRegex ){
|
||||||
|
if( preg_match( $permission, $_permission->permission ) && $_permission->allow == 1 ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -134,6 +139,8 @@ class Crunchbutton_Admin extends Cana_Table {
|
|||||||
$_permission->permission = trim( $key );
|
$_permission->permission = trim( $key );
|
||||||
$_permission->allow = 1;
|
$_permission->allow = 1;
|
||||||
$_permission->save();
|
$_permission->save();
|
||||||
|
// reset the permissions
|
||||||
|
$this->_permissions = false;
|
||||||
$dependencies = $_permission->getDependency( $key );
|
$dependencies = $_permission->getDependency( $key );
|
||||||
if( $dependencies ){
|
if( $dependencies ){
|
||||||
foreach( $dependencies as $dependency ){
|
foreach( $dependencies as $dependency ){
|
||||||
|
|||||||
@ -19,19 +19,32 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Restaurants's permissions */
|
/* Restaurants's permissions */
|
||||||
$_permissions[ 'restaurant' ] = array( 'description' => 'Restaurant\'s permissions' );
|
$_permissions[ 'restaurant' ] = array( 'description' => 'Restaurant\'s permissions' );
|
||||||
|
$_permissions[ 'restaurant' ][ 'doAllPermission' ] = 'restaurants-all';
|
||||||
$_permissions[ 'restaurant' ][ 'permissions' ] = array(
|
$_permissions[ 'restaurant' ][ 'permissions' ] = array(
|
||||||
'restaurants-all' => array( 'description' => 'Can perform any action with ALL restaurants' ),
|
'restaurants-all' => array( 'description' => 'Can perform any action with ALL restaurants' ),
|
||||||
'restaurants-list-page' => array( 'description' => 'View restaurants he has access to' ),
|
'restaurants-list-page' => array( 'description' => 'View restaurants he has access to' ),
|
||||||
'restaurants-crud' => array( 'description' => 'Create, update, retrieve and delete ALL restaurants' ),
|
'restaurants-crud' => array( 'description' => 'Create, update, retrieve and delete ALL restaurants' ),
|
||||||
'restaurant-ID-all' => array( 'description' => 'Create, update, retrieve and delete ONLY these restaurants', 'type' => 'combo', 'element' => 'Restaurant', 'dependency' => array( 'restaurants-list-page' ) ),
|
'restaurant-ID-all' => array( 'description' => 'Create, update, retrieve and delete ONLY these restaurants', 'type' => 'combo', 'element' => 'Restaurant', 'dependency' => array( 'restaurants-list-page' ) ),
|
||||||
'restaurant-ID-edit' => array( 'description' => 'Edit the info about the restaurant ID, it does not include payment and send fax', 'type' => 'combo', 'element' => 'Restaurant', 'dependency' => array( 'restaurants-list-page' ) ),
|
'restaurant-ID-edit' => array(
|
||||||
'restaurant-ID-pay' => array( 'description' => 'Make the payment of the restaurant ID', 'type' => 'combo', 'element' => 'Restaurant', 'dependency' => array( 'restaurants-list-page' ) ),
|
'description' => 'Edit the info about the restaurant ID, it does not include payment and send fax',
|
||||||
'restaurant-ID-fax' => array( 'description' => 'Send fax to the restaurant ID', 'type' => 'combo', 'element' => 'Restaurant', 'dependency' => array( 'restaurants-list-page' ) ),
|
'type' => 'combo',
|
||||||
'restaurants-weight-adj-page' => array( 'description' => 'Adjust weight (user can edit just restaurants he has access to)', 'dependency' => array( 'restaurants-list-page' ) ),
|
'element' => 'Restaurant',
|
||||||
|
'dependency' => array( 'restaurants-list-page' ),
|
||||||
|
'additional' => array(
|
||||||
|
'label' => 'Additional restaurant permissions:',
|
||||||
|
'permissions' => array(
|
||||||
|
'restaurants-weight-adj-page' => array( 'description' => 'View the adjustment weight page, the user will be able to edit just the restaurant he has the permission', 'dependency' => array( 'restaurants-list-page' ) ),
|
||||||
|
'restaurant-ID-pay' => array( 'description' => 'Payment', 'dependency' => array( 'restaurants-list-page' ) ),
|
||||||
|
'restaurant-ID-fax' => array( 'description' => 'Fax', 'dependency' => array( 'restaurants-list-page' ) ),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Orders's permissions */
|
/* Orders's permissions */
|
||||||
$_permissions[ 'order' ] = array( 'description' => 'Orders\'s permissions' );
|
$_permissions[ 'order' ] = array( 'description' => 'Orders\'s permissions' );
|
||||||
|
$_permissions[ 'order' ][ 'doAllPermission' ] = 'orders-all';
|
||||||
$_permissions[ 'order' ][ 'permissions' ] = array(
|
$_permissions[ 'order' ][ 'permissions' ] = array(
|
||||||
'orders-all' => array( 'description' => 'Can perform any action with orders' ),
|
'orders-all' => array( 'description' => 'Can perform any action with orders' ),
|
||||||
'orders-list-page' => array( 'description' => 'View new users page for restaurants he has access to' ),
|
'orders-list-page' => array( 'description' => 'View new users page for restaurants he has access to' ),
|
||||||
@ -44,6 +57,7 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Gift card's permissions */
|
/* Gift card's permissions */
|
||||||
$_permissions[ 'giftcard' ] = array( 'description' => 'Gift card\'s permissions' );
|
$_permissions[ 'giftcard' ] = array( 'description' => 'Gift card\'s permissions' );
|
||||||
|
$_permissions[ 'giftcard' ][ 'doAllPermission' ] = 'gift-card-all';
|
||||||
$_permissions[ 'giftcard' ][ 'permissions' ] = array(
|
$_permissions[ 'giftcard' ][ 'permissions' ] = array(
|
||||||
'gift-card-all' => array( 'description' => 'Can perform any action with gift cards' ),
|
'gift-card-all' => array( 'description' => 'Can perform any action with gift cards' ),
|
||||||
'gift-card-list-page' => array( 'description' => 'View main gift card page' ),
|
'gift-card-list-page' => array( 'description' => 'View main gift card page' ),
|
||||||
@ -60,6 +74,7 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Metric's permissions */
|
/* Metric's permissions */
|
||||||
$_permissions[ 'metrics' ] = array( 'description' => 'Metric\'s permissions' );
|
$_permissions[ 'metrics' ] = array( 'description' => 'Metric\'s permissions' );
|
||||||
|
$_permissions[ 'metrics' ][ 'doAllPermission' ] = 'metrics-all';
|
||||||
$_permissions[ 'metrics' ][ 'permissions' ] = array(
|
$_permissions[ 'metrics' ][ 'permissions' ] = array(
|
||||||
'metrics-all' => array( 'description' => 'View all metrics' ),
|
'metrics-all' => array( 'description' => 'View all metrics' ),
|
||||||
'metrics-main' => array( 'description' => 'View the `Main` charts' ),
|
'metrics-main' => array( 'description' => 'View the `Main` charts' ),
|
||||||
@ -74,6 +89,7 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Support's permissions */
|
/* Support's permissions */
|
||||||
$_permissions[ 'support' ] = array( 'description' => 'Support\'s permissions' );
|
$_permissions[ 'support' ] = array( 'description' => 'Support\'s permissions' );
|
||||||
|
$_permissions[ 'support' ][ 'doAllPermission' ] = 'support-all';
|
||||||
$_permissions[ 'support' ][ 'permissions' ] = array(
|
$_permissions[ 'support' ][ 'permissions' ] = array(
|
||||||
'support-all' => array( 'description' => 'Can perform ALL support related actions' ),
|
'support-all' => array( 'description' => 'Can perform ALL support related actions' ),
|
||||||
'support-crud' => array( 'description' => 'Create, update and delete any support ticket' ),
|
'support-crud' => array( 'description' => 'Create, update and delete any support ticket' ),
|
||||||
@ -83,6 +99,7 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Suggestions's permissions */
|
/* Suggestions's permissions */
|
||||||
$_permissions[ 'suggestion' ] = array( 'description' => 'Suggestions\'s permissions' );
|
$_permissions[ 'suggestion' ] = array( 'description' => 'Suggestions\'s permissions' );
|
||||||
|
$_permissions[ 'suggestion' ][ 'doAllPermission' ] = 'suggestions-all';
|
||||||
$_permissions[ 'suggestion' ][ 'permissions' ] = array(
|
$_permissions[ 'suggestion' ][ 'permissions' ] = array(
|
||||||
'suggestions-all' => array( 'description' => 'Can perform any action with suggestions' ),
|
'suggestions-all' => array( 'description' => 'Can perform any action with suggestions' ),
|
||||||
'suggestions-list-page' => array( 'description' => 'View suggestions page' ),
|
'suggestions-list-page' => array( 'description' => 'View suggestions page' ),
|
||||||
@ -91,6 +108,7 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
|
|
||||||
/* Other's permissions */
|
/* Other's permissions */
|
||||||
$_permissions[ 'permissions' ] = array( 'description' => 'Admin user\'s permissions' );
|
$_permissions[ 'permissions' ] = array( 'description' => 'Admin user\'s permissions' );
|
||||||
|
$_permissions[ 'permissions' ][ 'doAllPermission' ] = 'permission-all';
|
||||||
$_permissions[ 'permissions' ][ 'permissions' ] = array(
|
$_permissions[ 'permissions' ][ 'permissions' ] = array(
|
||||||
'permission-all' => array( 'description' => 'Can perform ALL actions with admin users and groups (i.e. create, update, delete, assign permissions)' ),
|
'permission-all' => array( 'description' => 'Can perform ALL actions with admin users and groups (i.e. create, update, delete, assign permissions)' ),
|
||||||
'permission-users' => array( 'description' => 'Can perform actions with ONLY admin users (create, update, delete, assign permissions) ' ),
|
'permission-users' => array( 'description' => 'Can perform actions with ONLY admin users (create, update, delete, assign permissions) ' ),
|
||||||
@ -130,11 +148,21 @@ class Crunchbutton_Admin_Permission extends Cana_Table {
|
|||||||
$all_permissions = $this->_permissions;
|
$all_permissions = $this->_permissions;
|
||||||
foreach( $all_permissions as $group ){
|
foreach( $all_permissions as $group ){
|
||||||
$permissions = $group[ 'permissions' ];
|
$permissions = $group[ 'permissions' ];
|
||||||
foreach( $permissions as $key => $val ){
|
foreach( $permissions as $key => $meta ){
|
||||||
$regex = str_replace( 'ID' , '(.)*', $key );
|
$regex = str_replace( 'ID' , '(.)*', $key );
|
||||||
$regex = '/' . $regex . '/';
|
$regex = '/' . $regex . '/';
|
||||||
if( preg_match( $regex, $permission ) > 0 ){
|
if( preg_match( $regex, $permission ) > 0 ){
|
||||||
return $val;
|
return $meta;
|
||||||
|
}
|
||||||
|
if( $meta[ 'additional' ] ){
|
||||||
|
$additional_permissions = $meta[ 'additional' ][ 'permissions' ];
|
||||||
|
foreach( $additional_permissions as $_key => $_meta ){
|
||||||
|
$regex = str_replace( 'ID' , '(.)*', $_key );
|
||||||
|
$regex = '/' . $regex . '/';
|
||||||
|
if( preg_match( $regex, $permission ) > 0 ){
|
||||||
|
return $_meta;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,16 +17,22 @@ class Crunchbutton_Group extends Cana_Table {
|
|||||||
return $this->_permissions;
|
return $this->_permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasPermission( $permission ){
|
public function hasPermission( $permission, $useRegex = false ){
|
||||||
$permissions = $this->permissions();
|
$permissions = $this->permissions();
|
||||||
foreach( $permissions as $_permission ){
|
foreach( $permissions as $_permission ){
|
||||||
if( $_permission->permission == $permission && $_permission->allow == 1 ){
|
if( $_permission->permission == $permission && $_permission->allow == 1 ){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if( $useRegex ){
|
||||||
|
if( preg_match( $permission, $_permission->permission ) && $_permission->allow == 1 ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function find($search = []) {
|
public static function find($search = []) {
|
||||||
|
|
||||||
$query = 'SELECT `group`.* FROM `group` WHERE id_group IS NOT NULL ';
|
$query = 'SELECT `group`.* FROM `group` WHERE id_group IS NOT NULL ';
|
||||||
@ -60,13 +66,14 @@ class Crunchbutton_Group extends Cana_Table {
|
|||||||
$_permission->permission = trim( $key );
|
$_permission->permission = trim( $key );
|
||||||
$_permission->allow = 1;
|
$_permission->allow = 1;
|
||||||
$_permission->save();
|
$_permission->save();
|
||||||
|
// reset the permissions
|
||||||
|
$this->_permissions = false;
|
||||||
$dependencies = $_permission->getDependency( $key );
|
$dependencies = $_permission->getDependency( $key );
|
||||||
if( $dependencies ){
|
if( $dependencies ){
|
||||||
foreach( $dependencies as $dependency ){
|
foreach( $dependencies as $dependency ){
|
||||||
$this->addPermissions( array( $dependency => 1 ) );
|
$this->addPermissions( array( $dependency => 1 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
<?
|
<?
|
||||||
$this->title = 'Permissions';
|
$this->title = 'Permissions';
|
||||||
$this->titleicon = 'lock';
|
$this->titleicon = 'lock';
|
||||||
$this->titleLink = '/permissions/groups';
|
$this->titleLink = '/permissions/groups';
|
||||||
|
|
||||||
$this->title2 = 'Groups permissions';
|
$this->title2 = 'Groups permissions';
|
||||||
$this->title2icon = 'group';
|
$this->title2icon = 'group';
|
||||||
|
|
||||||
$group = $this->group;
|
$group = $this->group;
|
||||||
$_permissions = $this->permissions;
|
$_permissions = $this->permissions;
|
||||||
$_elements = $this->elements;
|
$_elements = $this->elements;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="container-fluid padded">
|
<div class="container-fluid padded">
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="span6">
|
<div class="span6">
|
||||||
@ -18,11 +18,12 @@
|
|||||||
Permissions of Group <?php echo $group->name ?>
|
Permissions of Group <?php echo $group->name ?>
|
||||||
</h4>
|
</h4>
|
||||||
<?php
|
<?php
|
||||||
foreach( $_permissions as $permission_group ){
|
foreach( $_permissions as $_group => $permission_group ){
|
||||||
$description = $permission_group[ 'description' ];
|
$description = $permission_group[ 'description' ];
|
||||||
$permissions = $permission_group[ 'permissions' ];
|
$permissions = $permission_group[ 'permissions' ];
|
||||||
|
$doAllPermission = $permission_group[ 'doAllPermission' ];
|
||||||
?>
|
?>
|
||||||
<div class="box">
|
<div class="box box-<?php echo $_group; ?> permission-box">
|
||||||
<div class="box-header">
|
<div class="box-header">
|
||||||
<span class="title">
|
<span class="title">
|
||||||
<?php echo $description; ?>
|
<?php echo $description; ?>
|
||||||
@ -46,14 +47,18 @@
|
|||||||
$type = 'checkbox';
|
$type = 'checkbox';
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
$isPermissionFather = false;
|
||||||
|
if( $doAllPermission ){
|
||||||
|
$isPermissionFather = ( $doAllPermission == $permission );
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<li>
|
<li class="permission-row row-<?php echo $permission; ?> <?php if( $isPermissionFather ) { ?>row-father-<?php echo $doAllPermission;?><?php } else { ?>row-child-<?php echo $doAllPermission;?><?php } ?>">
|
||||||
<label for="<?php echo $permission; ?>">
|
<label for="<?php echo $permission; ?>">
|
||||||
<?php if( $type == 'checkbox' ) {
|
<?php if( $type == 'checkbox' ) {
|
||||||
$checked = ( $group->hasPermission( $permission ) ) ? 'checked="checked"' : '' ;
|
$checked = ( $group->hasPermission( $permission ) ) ? 'checked="checked"' : '' ;
|
||||||
?>
|
?>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
<input type="checkbox" <?php echo $checked; ?> class="icheck permissions" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
<input type="checkbox" <?php echo $checked; ?> class="icheck permissions <?php if( $isPermissionFather ) { ?>do-all-father <?php } ?>" family-name="<?php echo $doAllPermission;?>" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
||||||
</span>
|
</span>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php echo $description; ?>
|
<?php echo $description; ?>
|
||||||
@ -61,7 +66,7 @@
|
|||||||
(<?php echo $permission; ?>)
|
(<?php echo $permission; ?>)
|
||||||
</span>
|
</span>
|
||||||
<?php if( $type == 'combo' ) { ?>
|
<?php if( $type == 'combo' ) { ?>
|
||||||
<select id="<?php echo $permission; ?>" class="chzn-select permissions" multiple name="<?php echo $permission; ?>" data-placeholder="Choose" style="width:100%;">
|
<select id="<?php echo $permission; ?>" class="chzn-select permission-input permissions" multiple name="<?php echo $permission; ?>" data-placeholder="Choose" style="width:100%;">
|
||||||
<?php
|
<?php
|
||||||
$elements = $_elements[ $element ];
|
$elements = $_elements[ $element ];
|
||||||
foreach ( $elements as $element ) {
|
foreach ( $elements as $element ) {
|
||||||
@ -73,6 +78,32 @@
|
|||||||
</select>
|
</select>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</label>
|
</label>
|
||||||
|
<?php if ( $meta[ 'additional' ] ) {
|
||||||
|
$adicional = $meta[ 'additional' ];
|
||||||
|
$adicional_permissions = $adicional[ 'permissions' ];
|
||||||
|
$father = $permission;
|
||||||
|
?>
|
||||||
|
<b><?php echo $adicional[ 'label' ]; ?></b><br/>
|
||||||
|
<?php
|
||||||
|
foreach( $adicional_permissions as $permission => $meta ){
|
||||||
|
$description = $meta[ 'description' ];
|
||||||
|
$pattern = '/' . str_replace( 'ID' , '.*', $permission ) . '/';
|
||||||
|
$checked = ( $group->hasPermission( $pattern, true ) ) ? 'checked="checked"' : '' ;
|
||||||
|
?>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<label for="<?php echo $permission; ?>">
|
||||||
|
<span class="pull-right">
|
||||||
|
<input type="checkbox" <?php echo $checked; ?> class="icheck additional-permissions" father="<?php echo $father; ?>" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
||||||
|
</span>
|
||||||
|
<?php echo $description; ?>
|
||||||
|
<span class="note">
|
||||||
|
(<?php echo $permission; ?>)
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
</li>
|
</li>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@ -86,7 +117,7 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header">
|
<div class="box-header">
|
||||||
<span class="title">
|
<span class="title">
|
||||||
Save all changes
|
Save
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-content ">
|
<div class="box-content ">
|
||||||
@ -104,11 +135,48 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$(document).on('click', '.admin-save', function() {
|
$(document).on( 'click', '.admin-save', function() {
|
||||||
sendForm();
|
sendForm();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
$( '#global' ).on( 'ifChanged', function(event){
|
||||||
|
validateChecked( '#global' );
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '.do-all-father' ).on( 'ifChanged', function( event ){
|
||||||
|
validateDoAllPermissions( $( '#' + event.target.id ) );
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '.do-all-father' ).each( function( index, el ){
|
||||||
|
validateDoAllPermissions( $( el ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
validateChecked( '#global' );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function validateDoAllPermissions( el ){
|
||||||
|
if( el.is( ':checked' ) ){
|
||||||
|
$( '.row-child-' + el.attr( 'family-name' ) ).hide();
|
||||||
|
} else {
|
||||||
|
$( '.row-child-' + el.attr( 'family-name' ) ).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateChecked( id ){
|
||||||
|
var el = $( id );
|
||||||
|
switch( id ){
|
||||||
|
case '#global':
|
||||||
|
if( el.is( ':checked' ) ){
|
||||||
|
$( '.permission-box' ).hide();
|
||||||
|
$( '.box-global' ).show();
|
||||||
|
} else {
|
||||||
|
$( '.permission-box' ).show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function sendForm(){
|
function sendForm(){
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
@ -116,22 +184,35 @@
|
|||||||
$('.permissions').each( function(){
|
$('.permissions').each( function(){
|
||||||
var el = $( this );
|
var el = $( this );
|
||||||
var type = null;
|
var type = null;
|
||||||
if( el.is( 'input' ) ){
|
if( el.is( 'input' ) && el.is( ':visible' ) ){
|
||||||
type = el.attr( 'type' );
|
type = el.attr( 'type' );
|
||||||
if( type == 'checkbox' ){
|
if( type == 'checkbox' ){
|
||||||
if( el.is( ':checked' ) ){
|
if( el.is( ':checked' ) ){
|
||||||
data[ el.attr( 'name' ) ] = 1;
|
data[ el.attr( 'name' ) ] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( el.is( 'select' ) ){
|
} else if( el.is( 'select' ) && el.is( ':visible' ) ){
|
||||||
var options = el.val();
|
var options = el.val();
|
||||||
$( options ).each( function( index, val ){
|
$( options ).each( function( index, val ){
|
||||||
data[ val ] = 1;
|
data[ val ] = 1;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
$('.additional-permissions').each( function(){
|
||||||
|
var el = $( this );
|
||||||
|
if( el.is( ':checked' ) && el.is( ':visible' ) ){
|
||||||
|
var father = el.attr( 'father' );
|
||||||
|
var pattern = new RegExp( father.replace( 'ID', '((.)*)' ) ,'gm');
|
||||||
|
var values = $( '#' + father ).val();
|
||||||
|
$( values ).each( function( index, val ){
|
||||||
|
var id = val.replace( pattern, "\$1");
|
||||||
|
var permission = el.attr( 'name' ).replace( 'ID', id );
|
||||||
|
data[ permission ] = 1;
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
var url = App.service + 'permissions/groups/<?php echo $group->id_group; ?>/permissions';
|
var url = App.service + 'permissions/groups/<?php echo $group->id_group; ?>/permissions';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -157,4 +238,4 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -19,11 +19,12 @@
|
|||||||
"<?php echo $admin->name ?>" has these permissions in addition to his group permissions.
|
"<?php echo $admin->name ?>" has these permissions in addition to his group permissions.
|
||||||
</h4>
|
</h4>
|
||||||
<?php
|
<?php
|
||||||
foreach( $_permissions as $permission_group ){
|
foreach( $_permissions as $group => $permission_group ){
|
||||||
$description = $permission_group[ 'description' ];
|
$description = $permission_group[ 'description' ];
|
||||||
$permissions = $permission_group[ 'permissions' ];
|
$permissions = $permission_group[ 'permissions' ];
|
||||||
|
$doAllPermission = $permission_group[ 'doAllPermission' ];
|
||||||
?>
|
?>
|
||||||
<div class="box">
|
<div class="box box-<?php echo $group; ?> permission-box">
|
||||||
<div class="box-header">
|
<div class="box-header">
|
||||||
<span class="title">
|
<span class="title">
|
||||||
<?php echo $description; ?>
|
<?php echo $description; ?>
|
||||||
@ -47,14 +48,18 @@
|
|||||||
$type = 'checkbox';
|
$type = 'checkbox';
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
$isPermissionFather = false;
|
||||||
|
if( $doAllPermission ){
|
||||||
|
$isPermissionFather = ( $doAllPermission == $permission );
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<li>
|
<li class="permission-row row-<?php echo $permission; ?> <?php if( $isPermissionFather ) { ?>row-father-<?php echo $doAllPermission;?><?php } else { ?>row-child-<?php echo $doAllPermission;?><?php } ?>">
|
||||||
<label for="<?php echo $permission; ?>">
|
<label for="<?php echo $permission; ?>">
|
||||||
<?php if( $type == 'checkbox' ) {
|
<?php if( $type == 'checkbox' ) {
|
||||||
$checked = ( $admin->hasPermission( $permission ) ) ? 'checked="checked"' : '' ;
|
$checked = ( $admin->hasPermission( $permission ) ) ? 'checked="checked"' : '' ;
|
||||||
?>
|
?>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
<input type="checkbox" <?php echo $checked; ?> class="icheck permissions" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
<input type="checkbox" <?php echo $checked; ?> class="icheck permissions <?php if( $isPermissionFather ) { ?>do-all-father <?php } ?>" family-name="<?php echo $doAllPermission;?>" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
||||||
</span>
|
</span>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php echo $description; ?>
|
<?php echo $description; ?>
|
||||||
@ -62,7 +67,7 @@
|
|||||||
(<?php echo $permission; ?>)
|
(<?php echo $permission; ?>)
|
||||||
</span>
|
</span>
|
||||||
<?php if( $type == 'combo' ) { ?>
|
<?php if( $type == 'combo' ) { ?>
|
||||||
<select id="<?php echo $permission; ?>" class="chzn-select permissions" multiple name="<?php echo $permission; ?>" data-placeholder="Choose" style="width:100%;">
|
<select id="<?php echo $permission; ?>" class="chzn-select permission-input permissions" multiple name="<?php echo $permission; ?>" data-placeholder="Choose" style="width:100%;">
|
||||||
<?php
|
<?php
|
||||||
$elements = $_elements[ $element ];
|
$elements = $_elements[ $element ];
|
||||||
foreach ( $elements as $element ) {
|
foreach ( $elements as $element ) {
|
||||||
@ -74,6 +79,32 @@
|
|||||||
</select>
|
</select>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</label>
|
</label>
|
||||||
|
<?php if ( $meta[ 'additional' ] ) {
|
||||||
|
$adicional = $meta[ 'additional' ];
|
||||||
|
$adicional_permissions = $adicional[ 'permissions' ];
|
||||||
|
$father = $permission;
|
||||||
|
?>
|
||||||
|
<b><?php echo $adicional[ 'label' ]; ?></b><br/>
|
||||||
|
<?php
|
||||||
|
foreach( $adicional_permissions as $permission => $meta ){
|
||||||
|
$description = $meta[ 'description' ];
|
||||||
|
$pattern = '/' . str_replace( 'ID' , '.*', $permission ) . '/';
|
||||||
|
$checked = ( $admin->hasPermission( $pattern, true ) ) ? 'checked="checked"' : '' ;
|
||||||
|
?>
|
||||||
|
<div class="row-fluid">
|
||||||
|
<label for="<?php echo $permission; ?>">
|
||||||
|
<span class="pull-right">
|
||||||
|
<input type="checkbox" <?php echo $checked; ?> class="icheck additional-permissions" father="<?php echo $father; ?>" value="1" name="<?php echo $permission; ?>" id="<?php echo $permission; ?>">
|
||||||
|
</span>
|
||||||
|
<?php echo $description; ?>
|
||||||
|
<span class="note">
|
||||||
|
(<?php echo $permission; ?>)
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
</li>
|
</li>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@ -153,11 +184,48 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$(document).on('click', '.admin-save', function() {
|
$(document).on( 'click', '.admin-save', function() {
|
||||||
sendForm();
|
sendForm();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
$( '#global' ).on( 'ifChanged', function(event){
|
||||||
|
validateChecked( '#global' );
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '.do-all-father' ).on( 'ifChanged', function( event ){
|
||||||
|
validateDoAllPermissions( $( '#' + event.target.id ) );
|
||||||
|
});
|
||||||
|
|
||||||
|
$( '.do-all-father' ).each( function( index, el ){
|
||||||
|
validateDoAllPermissions( $( el ) );
|
||||||
|
} );
|
||||||
|
|
||||||
|
validateChecked( '#global' );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function validateDoAllPermissions( el ){
|
||||||
|
if( el.is( ':checked' ) ){
|
||||||
|
$( '.row-child-' + el.attr( 'family-name' ) ).hide();
|
||||||
|
} else {
|
||||||
|
$( '.row-child-' + el.attr( 'family-name' ) ).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateChecked( id ){
|
||||||
|
var el = $( id );
|
||||||
|
switch( id ){
|
||||||
|
case '#global':
|
||||||
|
if( el.is( ':checked' ) ){
|
||||||
|
$( '.permission-box' ).hide();
|
||||||
|
$( '.box-global' ).show();
|
||||||
|
} else {
|
||||||
|
$( '.permission-box' ).show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function sendForm(){
|
function sendForm(){
|
||||||
|
|
||||||
var data = {};
|
var data = {};
|
||||||
@ -165,22 +233,35 @@
|
|||||||
$('.permissions').each( function(){
|
$('.permissions').each( function(){
|
||||||
var el = $( this );
|
var el = $( this );
|
||||||
var type = null;
|
var type = null;
|
||||||
if( el.is( 'input' ) ){
|
if( el.is( 'input' ) && el.is( ':visible' ) ){
|
||||||
type = el.attr( 'type' );
|
type = el.attr( 'type' );
|
||||||
if( type == 'checkbox' ){
|
if( type == 'checkbox' ){
|
||||||
if( el.is( ':checked' ) ){
|
if( el.is( ':checked' ) ){
|
||||||
data[ el.attr( 'name' ) ] = 1;
|
data[ el.attr( 'name' ) ] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if( el.is( 'select' ) ){
|
} else if( el.is( 'select' ) && el.is( ':visible' ) ){
|
||||||
var options = el.val();
|
var options = el.val();
|
||||||
$( options ).each( function( index, val ){
|
$( options ).each( function( index, val ){
|
||||||
data[ val ] = 1;
|
data[ val ] = 1;
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
$('.additional-permissions').each( function(){
|
||||||
|
var el = $( this );
|
||||||
|
if( el.is( ':checked' ) && el.is( ':visible' ) ){
|
||||||
|
var father = el.attr( 'father' );
|
||||||
|
var pattern = new RegExp( father.replace( 'ID', '((.)*)' ) ,'gm');
|
||||||
|
var values = $( '#' + father ).val();
|
||||||
|
$( values ).each( function( index, val ){
|
||||||
|
var id = val.replace( pattern, "\$1");
|
||||||
|
var permission = el.attr( 'name' ).replace( 'ID', id );
|
||||||
|
data[ permission ] = 1;
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
var url = App.service + 'permissions/users/<?php echo $admin->id_admin; ?>/permissions';
|
var url = App.service + 'permissions/users/<?php echo $admin->id_admin; ?>/permissions';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user