NEW Introduce permission "approve" for "leave request" like for "expense

report"
This commit is contained in:
Laurent Destailleur 2018-05-10 18:56:21 +02:00
parent 7f704231fe
commit 9315d9c423
4 changed files with 80 additions and 11 deletions

View File

@ -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)

View File

@ -1346,6 +1346,7 @@ if ($action == 'create')
print '</td>';
print '</tr>';
// User for expense report
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
print '<td>';
@ -1358,6 +1359,7 @@ if ($action == 'create')
print '</td>';
print '</tr>';
// Approver
print '<tr>';
print '<td>'.$langs->trans("VALIDATOR").'</td>';
print '<td>';

View File

@ -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 '<table class="border" width="100%">';
print '<tbody>';
// User
// User for leave request
print '<tr>';
print '<td class="titlefield fieldrequired">'.$langs->trans("User").'</td>';
print '<td>';
@ -932,11 +931,24 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
print '</td>';
print '</tr>';
// Approved by
// Approver
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans("ReviewedByCP").'</td>';
print '<td>';
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 '</td>';
print '</tr>';
@ -1181,7 +1193,13 @@ else
print '<tr>';
print '<td class="titlefield">'.$langs->trans('ReviewedByCP').'</td>';
print '<td>';
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 '</td>';
print '</tr>';
}

View File

@ -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
*