[-] BO : fixed right permissions for new tabs #PSCFV-3640

This commit is contained in:
dMetzger
2012-08-16 12:20:46 +00:00
parent 33758c413e
commit 882bf386dd
+5 -12
View File
@@ -117,27 +117,20 @@ class TabCore extends ObjectModel
$context = Context::getContext();
if (!$context->employee || !$context->employee->id_profile)
return false;
/* Profile selection */
$profiles = Db::getInstance()->executeS('
SELECT `id_profile`
FROM '._DB_PREFIX_.'profile
WHERE `id_profile` != 1
');
$profiles = Db::getInstance()->executeS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile WHERE `id_profile` != 1');
if (!$profiles || empty($profiles))
return false;
return true;
/* Query definition */
// note : insert ignore should be avoided
$query = 'INSERT IGNORE INTO `'._DB_PREFIX_.'access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) VALUES ';
// default admin
$query = 'REPLACE INTO `'._DB_PREFIX_.'access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) VALUES ';
$query .= '(1, '.(int)$id_tab.', 1, 1, 1, 1),';
foreach ($profiles as $profile)
{
// no cast needed for profile[id_profile], which cames from db
// And we disable all profile but current one
$rights = $profile['id_profile'] == $context->employee->id_profile ? 1 : 0;
$query .= '('.$profile['id_profile'].', '.(int)$id_tab.', '.$rights.', '.$rights.', '.$rights.', '.$rights.'),';
$query .= '('.(int)$profile['id_profile'].', '.(int)$id_tab.', '.(int)$rights.', '.(int)$rights.', '.(int)$rights.', '.(int)$rights.'),';
}
$query = trim($query, ', ');
return Db::getInstance()->execute($query);