From 9315d9c423ee9b4ffbbee194ffbf399f5886f132 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 10 May 2018 18:56:21 +0200 Subject: [PATCH] NEW Introduce permission "approve" for "leave request" like for "expense report" --- htdocs/core/modules/modHoliday.class.php | 19 +++++++---- htdocs/expensereport/card.php | 2 ++ htdocs/holiday/card.php | 28 +++++++++++++--- htdocs/holiday/class/holiday.class.php | 42 ++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 11 deletions(-) diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 3fd056b525e..e60be690ce4 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -108,42 +108,49 @@ class modHoliday extends DolibarrModules $r=0; $this->rights[$r][0] = 20001; // Permission id (must not be already used) - $this->rights[$r][1] = 'Read your own holidays'; // Permission label + $this->rights[$r][1] = 'Read your own leave requests'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20002; // Permission id (must not be already used) - $this->rights[$r][1] = 'Create/modify your own holidays'; // Permission label + $this->rights[$r][1] = 'Create/modify your own leave requests'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20003; // Permission id (must not be already used) - $this->rights[$r][1] = 'Delete holidays'; // Permission label + $this->rights[$r][1] = 'Delete leave requests'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; + $this->rights[$r][0] = 20007; + $this->rights[$r][1] = 'Approve leave requests'; + $this->rights[$r][2] = 'w'; + $this->rights[$r][3] = 0; + $this->rights[$r][4] = 'approve'; + $r++; + $this->rights[$r][0] = 20004; // Permission id (must not be already used) - $this->rights[$r][1] = 'Read holidays for everybody'; // Permission label + $this->rights[$r][1] = 'Read leave requests for everybody'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'read_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20005; // Permission id (must not be already used) - $this->rights[$r][1] = 'Create/modify holidays for everybody'; // Permission label + $this->rights[$r][1] = 'Create/modify leave requests for everybody'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'write_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20006; // Permission id (must not be already used) - $this->rights[$r][1] = 'Setup holidays of users (setup and update balance)'; // Permission label + $this->rights[$r][1] = 'Setup leave requests of users (setup and update balance)'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index a2d67d627c0..d17ae2eb095 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1346,6 +1346,7 @@ if ($action == 'create') print ''; print ''; + // User for expense report print ''; print ''.$langs->trans("User").''; print ''; @@ -1358,6 +1359,7 @@ if ($action == 'create') print ''; print ''; + // Approver print ''; print ''.$langs->trans("VALIDATOR").''; print ''; diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index e5b35b5a434..18039a1d47e 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -38,7 +38,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/holiday.lib.php'; require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; // Get parameters -$myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); $fuserid = (GETPOST('fuserid','int')?GETPOST('fuserid','int'):$user->id); @@ -864,7 +863,7 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; print ''; - // User + // User for leave request print ''; print ''; print ''; print ''; - // Approved by + // Approver print ''; print ''; print ''; print ''; @@ -1181,7 +1193,13 @@ else print ''; print ''; print ''; print ''; } diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index f0b36f910d9..03b2491ab59 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -1569,6 +1569,48 @@ class Holiday extends CommonObject } } + + /** + * Return list of people with permission to validate leave requests. + * Search for permission "approve leave requests" + * + * @return array Array of user ids + */ + function fetch_users_approver_holiday() + { + $users_validator=array(); + + $sql = "SELECT DISTINCT ur.fk_user"; + $sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; + $sql.= " WHERE ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve'; + $sql.= "UNION"; + $sql.= " SELECT DISTINCT ugu.fk_user"; + $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; + $sql.= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'holiday' AND rd.perms = 'approve'"; // Permission 'Approve'; + //print $sql; + + dol_syslog(get_class($this)."::fetch_users_approver_holiday sql=".$sql); + $result = $this->db->query($sql); + if($result) + { + $num_lignes = $this->db->num_rows($result); $i = 0; + while ($i < $num_lignes) + { + $objp = $this->db->fetch_object($result); + array_push($users_validator,$objp->fk_user); + $i++; + } + return $users_validator; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch_users_approver_holiday Error ".$this->error, LOG_ERR); + return -1; + } + } + + /** * Compte le nombre d'utilisateur actifs dans Dolibarr *
'.$langs->trans("User").''; @@ -932,11 +931,24 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print '
'.$langs->trans("ReviewedByCP").''; - print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent + + $object = new Holiday($db); + $include_users = $object->fetch_users_approver_holiday(); + if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); + else + { + $defaultselectuser=$user->fk_user; // Will work only if supervisor has permission to approve so is inside include_users + if (! empty($conf->global->HOLIDAY_DEFAULT_VALIDATOR)) $defaultselectuser=$conf->global->HOLIDAY_DEFAULT_VALIDATOR; // Can force default approver + if (GETPOST('valideur', 'int') > 0) $defaultselectuser=GETPOST('valideur', 'int'); + $s=$form->select_dolusers($defaultselectuser, "valideur", 1, "", 0, $include_users); + print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); + } + + //print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent print '
'.$langs->trans('ReviewedByCP').''; - print $form->select_dolusers($object->fk_validator, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent + $include_users = $object->fetch_users_approver_holiday(); + if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); + else + { + $s=$form->select_dolusers($object->fk_validator, "valideur", 1, ($user->admin ? '' : array($user->id)), 0, $include_users); + print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); + } print '