diff --git a/htdocs/user/group/perms.php b/htdocs/user/group/perms.php index 3ccbcf94d05..4bb95b46a89 100644 --- a/htdocs/user/group/perms.php +++ b/htdocs/user/group/perms.php @@ -22,9 +22,13 @@ /** * \file htdocs/user/group/perms.php - * \brief Onglet user et permissions de la fiche utilisateur + * \brief Page to set permissions of a user group record */ +if (!defined('CSRFCHECK_WITH_TOKEN')) { + define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET +} + require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; @@ -41,6 +45,10 @@ $module = GETPOST('module', 'alpha'); $rights = GETPOST('rights', 'int'); $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'groupperms'; // To manage different context of search +if (!isset($id) || empty($id)) { + accessforbidden(); +} + // Define if user can read permissions $canreadperms = ($user->admin || $user->rights->user->user->lire); // Define if user can modify group permissions @@ -53,12 +61,15 @@ if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $caneditperms = ($user->admin || $user->rights->user->group_advance->write); } +// Security check +//$result = restrictedArea($user, 'user', $id, 'usergroup', ''); if (!$canreadperms) { accessforbidden(); } $object = new Usergroup($db); $object->fetch($id); +$object->getrights(); $entity = $conf->entity; @@ -79,7 +90,7 @@ if ($reshook < 0) { if (empty($reshook)) { if ($action == 'addrights' && $caneditperms) { $editgroup = new Usergroup($db); - $result = $editgroup->fetch($id); + $result = $editgroup->fetch($object->id); if ($result > 0) { $result = $editgroup->addrights($rights, $module, '', $entity); if ($result < 0) { @@ -88,6 +99,9 @@ if (empty($reshook)) { } else { dol_print_error($db); } + + $object->clearrights(); + $object->getrights(); } if ($action == 'delrights' && $caneditperms) { @@ -101,11 +115,14 @@ if (empty($reshook)) { } else { dol_print_error($db); } + + $object->clearrights(); + $object->getrights(); } } -/** +/* * View */ @@ -114,11 +131,6 @@ $form = new Form($db); llxHeader('', $langs->trans("Permissions")); if ($object->id > 0) { - /* - * Affichage onglets - */ - $object->getrights(); // Reload permission - $head = group_prepare_head($object); $title = $langs->trans("Group"); print dol_get_fiche_head($head, 'rights', $title, -1, 'group'); @@ -165,8 +177,8 @@ if ($object->id > 0) { $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r,"; $sql .= " ".MAIN_DB_PREFIX."usergroup_rights as gr"; $sql .= " WHERE gr.fk_id = r.id"; - $sql .= " AND gr.entity = ".$entity; - $sql .= " AND gr.fk_usergroup = ".$object->id; + $sql .= " AND gr.entity = ".((int) $entity); + $sql .= " AND gr.fk_usergroup = ".((int) $object->id); dol_syslog("get user perms", LOG_DEBUG); $result = $db->query($sql); @@ -186,6 +198,10 @@ if ($object->id > 0) { dol_print_error($db); } + /* + * Part to add/remove permissions + */ + $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin); @@ -193,9 +209,6 @@ if ($object->id > 0) { print '
| '.$langs->trans("Module").' | '; if ($caneditperms) { print ''; - print 'id.'&action=addrights&entity='.$entity.'&module=allmodules&token='.newToken().'">'.$langs->trans("All").""; + print 'id.'&action=addrights&entity='.$entity.'&module=allmodules&confirm=yes&token='.newToken().'">'.$langs->trans("All").""; print '/'; - print 'id.'&action=delrights&entity='.$entity.'&module=allmodules&token='.newToken().'">'.$langs->trans("None").""; + print 'id.'&action=delrights&entity='.$entity.'&module=allmodules&confirm=yes&token='.newToken().'">'.$langs->trans("None").""; print ' | '; } print ''; print ' | '.$langs->trans("Permissions").' | '; if ($user->admin) { - print ''.$langs->trans("ID").' | '; + print ''; } print ''."\n"; - $sql = "SELECT r.id, r.libelle as label, r.module"; + $sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault"; $sql .= " FROM ".MAIN_DB_PREFIX."rights_def as r"; $sql .= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous" - $sql .= " AND r.entity = ".$entity; + $sql .= " AND r.entity = ".((int) $entity); if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { $sql .= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is disable } - $sql .= " ORDER BY r.module, r.id"; + $sql .= " ORDER BY r.family_position, r.module_position, r.module, r.id"; $result = $db->query($sql); if ($result) { @@ -265,13 +278,16 @@ if ($object->id > 0) { while ($i < $num) { $obj = $db->fetch_object($result); - // If line is for a module that doe snot existe anymore (absent of includes/module), we ignore it + // If line is for a module that does not exist anymore (absent of includes/module), we ignore it if (empty($modules[$obj->module])) { $i++; continue; } - if ($oldmod <> $obj->module) { + $objMod = $modules[$obj->module]; + + // Break found, it's a new module to catch + if (isset($obj->module) && ($oldmod <> $obj->module)) { $oldmod = $obj->module; // Break detected, we get objMod @@ -286,21 +302,22 @@ if ($object->id > 0) { print ''; if ($caneditperms) { print ' | '; - print 'id.'&action=addrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("All").""; + print 'id.'&action=addrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("All").""; print '/'; - print 'id.'&action=delrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("None").""; + print 'id.'&action=delrights&entity='.$entity.'&module='.$obj->module.'&token='.newToken().'">'.$langs->trans("None").""; print ' | '; } else { print ''; } - print ' | '; - + print ' | '; + print ' | '; + // Permission id if ($user->admin) { print ' | '; } - print ''; + print ''."\n"; } print ''."\n"; @@ -315,7 +332,7 @@ if ($object->id > 0) { if (in_array($obj->id, $permsgroupbyentity[$entity])) { // Own permission by group if ($caneditperms) { - print ' | id.'&action=delrights&entity='.$entity.'&rights='.$obj->id.'&token='.newToken().'">'; + print ' | id.'&action=delrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'">'; //print img_edit_remove($langs->trans("Remove")); print img_picto($langs->trans("Remove"), 'switch_on'); print ' | '; @@ -326,7 +343,7 @@ if ($object->id > 0) { } else { // Do not own permission if ($caneditperms) { - print 'id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&token='.newToken().'">'; + print ' | id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'">'; //print img_edit_add($langs->trans("Add")); print img_picto($langs->trans("Add"), 'switch_off'); print ' | '; @@ -336,7 +353,7 @@ if ($object->id > 0) { } else { // Do not own permission if ($caneditperms) { - print 'id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&token='.newToken().'">'; + print ' | id.'&action=addrights&entity='.$entity.'&rights='.$obj->id.'&confirm=yes&token='.newToken().'">'; //print img_edit_add($langs->trans("Add")); print img_picto($langs->trans("Add"), 'switch_off'); print ' | '; @@ -344,12 +361,25 @@ if ($object->id > 0) { print ''; } - $permlabel = ($conf->global->MAIN_USE_ADVANCED_PERMS && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label))); - print ' | '.$permlabel.' | '; + // Description of permission + $permlabel = (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($langs->trans("PermissionAdvanced".$obj->id) != ("PermissionAdvanced".$obj->id)) ? $langs->trans("PermissionAdvanced".$obj->id) : (($langs->trans("Permission".$obj->id) != ("Permission".$obj->id)) ? $langs->trans("Permission".$obj->id) : $langs->trans($obj->label))); + print ''; + print $permlabel; + if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) { + if (preg_match('/_advance$/', $obj->perms)) { + print ' ('.$langs->trans("AdvancedModeOnly").')'; + } + } + print ' | '; // Permission id if ($user->admin) { - print ''.$obj->id.' | '; + print '';
+ $htmltext = $langs->trans("ID").': '.$obj->id;
+ $htmltext .= ' '.$langs->trans("Permission").': user->rights->'.$obj->module.'->'.$obj->perms.($obj->subperms ? '->'.$obj->subperms : ''); + print $form->textwithpicto('', $htmltext); + //print ''.$obj->id.''; + print ' | ';
}
print ''."\n";
diff --git a/htdocs/user/perms.php b/htdocs/user/perms.php
index 957c7a3a819..5e96a76119c 100644
--- a/htdocs/user/perms.php
+++ b/htdocs/user/perms.php
@@ -90,7 +90,7 @@ $hookmanager->initHooks(array('usercard', 'userperms', 'globalcard'));
* Actions
*/
-$parameters = array('id'=>$socid);
+$parameters = array('socid'=>$socid);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
@@ -193,7 +193,7 @@ $permsuser = array();
$sql = "SELECT DISTINCT ur.fk_id";
$sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
-$sql .= " WHERE ur.entity = ".$entity;
+$sql .= " WHERE ur.entity = ".((int) $entity);
$sql .= " AND ur.fk_user = ".((int) $object->id);
dol_syslog("get user perms", LOG_DEBUG);
@@ -386,7 +386,7 @@ if ($result) {
// Picto and label of module
print ''; - //print img_object('', $picto, 'class="pictoobjectwidth"').' '.$objMod->getName(); + //print img_object('', $picto, 'class="inline-block pictoobjectwidth"').' '.$objMod->getName(); print ' | '; // Permission and tick