Clean code and label of permission

This commit is contained in:
Laurent Destailleur 2023-02-06 13:12:34 +01:00
parent ecddf3164d
commit 5a25126117
2 changed files with 15 additions and 13 deletions

View File

@ -46,12 +46,14 @@ $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
$securitykey = GETPOST('securitykey', 'alpha');
$permissiontoadd = $user->rights->cron->create;
if (!$user->rights->cron->create) {
if (!$user->hasRights('cron', 'create')) {
accessforbidden();
}
$permissiontoadd = $user->hasRights('cron', 'create');
$permissiontoexecute = $user->hasRights('cron', 'execute');
$permissiontodelete = $user->hasRights('cron', 'delete');
/*
* Actions
@ -80,7 +82,7 @@ if (!empty($cancel)) {
}
// Delete jobs
if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete) {
if ($action == 'confirm_delete' && $confirm == "yes" && $permissiontodelete) {
$result = $object->delete($user);
if ($result < 0) {
@ -93,7 +95,7 @@ if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->del
}
// Execute jobs
if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->execute) {
if ($action == 'confirm_execute' && $confirm == "yes" && $permissiontoexecute) {
if (!empty($conf->global->CRON_KEY) && $conf->global->CRON_KEY != $securitykey) {
setEventMessages('Security key '.$securitykey.' is wrong', null, 'errors');
$action = '';
@ -123,7 +125,7 @@ if ($action == 'confirm_execute' && $confirm == "yes" && $user->rights->cron->ex
}
if ($action == 'add') {
if ($action == 'add' && $permissiontoadd) {
$object->jobtype = GETPOST('jobtype');
$object->label = GETPOST('label');
$object->command = GETPOST('command');
@ -157,7 +159,7 @@ if ($action == 'add') {
}
// Save parameters
if ($action == 'update') {
if ($action == 'update' && $permissiontoadd) {
$object->id = $id;
$object->jobtype = GETPOST('jobtype');
$object->label = GETPOST('label');
@ -191,7 +193,7 @@ if ($action == 'update') {
}
}
if ($action == 'activate') {
if ($action == 'activate' && $permissiontoadd) {
$object->status = 1;
// Add cron task
@ -207,7 +209,7 @@ if ($action == 'activate') {
}
}
if ($action == 'inactive') {
if ($action == 'inactive' && $permissiontoadd) {
$object->status = 0;
$object->processing = 0;
@ -225,7 +227,7 @@ if ($action == 'inactive') {
}
// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd)) {
if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
} else {
@ -799,7 +801,7 @@ if (($action == "create") || ($action == "edit")) {
} elseif (empty($object->status)) {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("JobDisabled")).'">'.$langs->trans("CronExecute").'</a>';
} else {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=execute&token='.newToken().'&id='.$object->id.(empty($conf->global->CRON_KEY) ? '' : '&securitykey='.$conf->global->CRON_KEY).'">'.$langs->trans("CronExecute").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=execute&token='.newToken().'&id='.$object->id.(empty($conf->global->CRON_KEY) ? '' : '&securitykey='.urlencode($conf->global->CRON_KEY)).'">'.$langs->trans("CronExecute").'</a>';
}
if (!$user->rights->cron->create) {

View File

@ -705,7 +705,7 @@ Module62000Desc=Add features to manage Incoterms
Module63000Name=Resources
Module63000Desc=Manage resources (printers, cars, rooms, ...) for allocating to events
Module94160Name=Receptions
Permission11=Read customer invoices
Permission11=Read customer invoices (and payments)
Permission12=Create/modify customer invoices
Permission13=Invalidate customer invoices
Permission14=Validate customer invoices
@ -947,7 +947,7 @@ Permission1190=Approve (second approval) purchase orders
Permission1191=Export supplier orders and their attributes
Permission1201=Get result of an export
Permission1202=Create/Modify an export
Permission1231=Read vendor invoices
Permission1231=Read vendor invoices (and payments)
Permission1232=Create/modify vendor invoices
Permission1233=Validate vendor invoices
Permission1234=Delete vendor invoices