[-] BO : BugFix : #PSTEST-1054 : Employees and permission updated
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14401 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -48,6 +48,41 @@
|
||||
var tabnumber = tout[4];
|
||||
var table = 'table#table_'+id_profile;
|
||||
|
||||
if (perm == 'all' && $(this).parent().parent().hasClass('parent'))
|
||||
{
|
||||
checked = enabled ? 'checked': '';
|
||||
$(this).parent().parent().parent().find('.child-'+id_tab+' input[type=checkbox]').attr('checked', checked);
|
||||
$.ajax({
|
||||
url: "{$link->getAdminLink('AdminAccess')}",
|
||||
cache: false,
|
||||
data : {
|
||||
ajaxMode : '1',
|
||||
id_tab: id_tab,
|
||||
id_profile: id_profile,
|
||||
perm: perm,
|
||||
enabled: enabled,
|
||||
submitAddAccess: '1',
|
||||
addFromParent: '1',
|
||||
action: 'updateAccess',
|
||||
ajax: '1',
|
||||
token: '{getAdminToken tab='AdminAccess'}'
|
||||
},
|
||||
success : function(res,textStatus,jqXHR)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (res == 'ok')
|
||||
showSuccessMessage("{l s='Update successful'}");
|
||||
else
|
||||
showErrorMessage("{l s='Update error'}");
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
jAlert('Technical error');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table, '{$id_tab_access}');
|
||||
|
||||
$.ajax({
|
||||
@@ -236,7 +271,7 @@
|
||||
{if !$tab.id_parent OR $tab.id_parent == -1}
|
||||
{assign var=is_child value=false}
|
||||
{assign var=result_accesses value=0}
|
||||
<tr>
|
||||
<tr{if !$is_child} class="parent"{/if}>
|
||||
<td{if !$is_child} class="bold"{/if}>{if $is_child} » {/if}<strong>{$tab.name}</strong></td>
|
||||
{foreach $perms as $perm}
|
||||
{if $access_edit == 1}
|
||||
@@ -275,7 +310,7 @@
|
||||
{if isset($access[$child.id_tab])}
|
||||
{assign var=is_child value=true}
|
||||
{assign var=result_accesses value=0}
|
||||
<tr>
|
||||
<tr class="child-{$child.id_parent}">
|
||||
<td{if !$is_child} class="bold"{/if}>{if $is_child} » {/if}<strong>{$child.name}</strong></td>
|
||||
{foreach $perms as $perm}
|
||||
{if $access_edit == 1}
|
||||
|
||||
@@ -59,8 +59,34 @@
|
||||
$(document).ready(function(){
|
||||
$('select[name=id_profile]').change(function(){
|
||||
ifSuperAdmin($(this));
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
url: "{$link->getAdminLink('AdminEmployees')}",
|
||||
cache: false,
|
||||
data : {
|
||||
ajax : '1',
|
||||
action : 'getTabByIdProfile',
|
||||
id_profile : $(this).val()
|
||||
},
|
||||
dataType : 'json',
|
||||
success : function(resp,textStatus,jqXHR)
|
||||
{
|
||||
if (resp != false)
|
||||
{
|
||||
$('select[name=default_tab]').html('');
|
||||
$.each(resp, function(key, r){
|
||||
if (r.id_parent == 0)
|
||||
{
|
||||
$('select[name=default_tab]').append('<optgroup label="'+r.name+'"></optgroup>');
|
||||
$.each(r.children, function(k, value){
|
||||
$('select[name=default_tab]').append('<option value="'+r.id_tab+'">'+value.name+'</option>')
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ifSuperAdmin($('select[name=id_profile]'));
|
||||
});
|
||||
|
||||
|
||||
@@ -464,4 +464,23 @@ class TabCore extends ObjectModel
|
||||
|
||||
return parent::update($null_values);
|
||||
}
|
||||
|
||||
public static function getTabByIdProfile($id_parent, $id_profile)
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT t.`id_tab`, t.`id_parent`, tl.`name`, a.`id_profile`
|
||||
FROM `'._DB_PREFIX_.'tab` t
|
||||
LEFT JOIN `'._DB_PREFIX_.'access` a
|
||||
ON (a.`id_tab` = t.`id_tab`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl
|
||||
ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)Context::getContext()->language->id.')
|
||||
WHERE a.`id_profile` = '.(int)$id_profile.'
|
||||
AND t.`id_parent` = '.(int)$id_parent.'
|
||||
AND a.`view` = 1
|
||||
AND a.`edit` = 1
|
||||
AND a.`delete` = 1
|
||||
AND a.`add` = 1
|
||||
ORDER BY t.`id_parent` ASC
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,33 +150,42 @@ class AdminAccessControllerCore extends AdminController
|
||||
$enabled = (int)Tools::getValue('enabled');
|
||||
$id_tab = (int)Tools::getValue('id_tab');
|
||||
$id_profile = (int)Tools::getValue('id_profile');
|
||||
$where = '`id_tab`';
|
||||
$join = '';
|
||||
if (Tools::isSubmit('addFromParent'))
|
||||
{
|
||||
$where = 't.`id_parent`';
|
||||
$join = 'LEFT JOIN `'._DB_PREFIX_.'tab` t ON (t.`id_tab` = a.`id_tab`)';
|
||||
}
|
||||
|
||||
if ($id_tab == -1 && $perm == 'all' && $enabled == 0)
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
UPDATE `'._DB_PREFIX_.'access` a
|
||||
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != '.(int)$this->id_tab_access;
|
||||
else if ($id_tab == -1 && $perm == 'all')
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
UPDATE `'._DB_PREFIX_.'access` a
|
||||
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile;
|
||||
else if ($id_tab == -1)
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
UPDATE `'._DB_PREFIX_.'access` a
|
||||
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||
WHERE `id_profile` = '.(int)$id_profile;
|
||||
else if ($perm == 'all')
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
UPDATE `'._DB_PREFIX_.'access` a
|
||||
'.$join.'
|
||||
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||
WHERE `id_tab` = '.(int)$id_tab.'
|
||||
WHERE '.bqSQL($where).' = '.(int)$id_tab.'
|
||||
AND `id_profile` = '.(int)$id_profile;
|
||||
else
|
||||
$sql = '
|
||||
UPDATE `'._DB_PREFIX_.'access`
|
||||
UPDATE `'._DB_PREFIX_.'access` a
|
||||
'.$join.'
|
||||
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||
WHERE `id_tab` = '.(int)$id_tab.'
|
||||
WHERE '.bqSQL($where).' = '.(int)$id_tab.'
|
||||
AND `id_profile` = '.(int)$id_profile;
|
||||
|
||||
$res = Db::getInstance()->execute($sql) ? 'ok' : 'error';
|
||||
|
||||
@@ -421,6 +421,24 @@ class AdminEmployeesControllerCore extends AdminController
|
||||
|
||||
return parent::initContent();
|
||||
}
|
||||
|
||||
public function ajaxProcessGetTabByIdProfile()
|
||||
{
|
||||
$id_profile = Tools::getValue('id_profile');
|
||||
$tabs = Tab::getTabByIdProfile(0, $id_profile);
|
||||
$this->tabs_list = array();
|
||||
foreach ($tabs as $tab)
|
||||
{
|
||||
if (Tab::checkTabRights($tab['id_tab']))
|
||||
{
|
||||
$this->tabs_list[$tab['id_tab']] = $tab;
|
||||
foreach (Tab::getTabByIdProfile($tab['id_tab'], $id_profile) as $children)
|
||||
if (Tab::checkTabRights($children['id_tab']))
|
||||
$this->tabs_list[$tab['id_tab']]['children'][] = $children;
|
||||
}
|
||||
}
|
||||
die(Tools::jsonEncode($this->tabs_list));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user