diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 50d5c0e90d7..54a4b4fb470 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -304,6 +304,7 @@ ErrorValueCantBeNull=Value for %s can't be null ErrorDateOfMovementLowerThanDateOfFileTransmission=The date of the bank transaction can't be lower than the date of the file transmission ErrorTooMuchFileInForm=Too much files in form, the maximum number is %s file(s) ErrorSessionInvalidatedAfterPasswordChange=The session was been invalidated following a change of password, status or dates of validity. Please relogin. +ErrorExistingPermission = Permission %s for object %s already exists # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. @@ -342,6 +343,7 @@ WarningPaypalPaymentNotCompatibleWithStrict=The value 'Strict' makes the online WarningThemeForcedTo=Warning, theme has been forced to %s by hidden constant MAIN_FORCETHEME WarningPagesWillBeDeleted=Warning, this will also delete all existing pages/containers of the website. You should export your website before, so you have a backup to re-import it later. WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal=Automatic validation is disabled when option to decrease stock is set on "Invoice validation". +WarningModuleNeedRefrech = Module %s has been disabled. Don't forget to enable it # Validate RequireValidValue = Value not valid diff --git a/htdocs/langs/en_US/modulebuilder.lang b/htdocs/langs/en_US/modulebuilder.lang index cefdfaa1b41..600dfba7227 100644 --- a/htdocs/langs/en_US/modulebuilder.lang +++ b/htdocs/langs/en_US/modulebuilder.lang @@ -165,3 +165,8 @@ BadValueForType=Bad value for type %s DefinePropertiesFromExistingTable=Define properties from an existing table DefinePropertiesFromExistingTableDesc=If a table in the database (for the object to create) already exists, you can use it to define the properties of the object. DefinePropertiesFromExistingTableDesc2=Keep empty if the table does not exist yet. The code generator will use different kinds of fields to build an example of table that you can edit later. +GeneratePermissions=I want to add the rights for this object +GeneratePermissionsHelp=generate default rights for this object +PermissionDeletedSuccesfuly=Permission has been successfully removed +PermissionUpdatedSuccesfuly=Permission has been successfully updated +PermissionAddedSuccesfuly=Permission has been successfully added \ No newline at end of file diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 9d27c0e671b..cbf69ff2aa8 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -303,8 +303,10 @@ ErrorValueForTooLow=La valeur pour %s est trop faible ErrorValueCantBeNull=La valeur pour %s ne peut pas être nulle ErrorDateOfMovementLowerThanDateOfFileTransmission=La date de l'opération bancaire ne peut être inférieure à la date de transmission du fichier ErrorTooMuchFileInForm=Trop de fichiers dans le formulaire, le nombre maximum est de %s fichier(s) +ErrorExistingPermission = La permission %s pour l'objet %s est dejà existante ErrorSessionInvalidatedAfterPasswordChange=La session a été invalidée suite à un changement de mot de passe, d'état ou de dates de validité. Veuillez vous reconnecter. + # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Votre paramètre PHP upload_max_filesize (%s) est supérieur au paramètre PHP post_max_size (%s). Ceci n'est pas une configuration cohérente. WarningPasswordSetWithNoAccount=Un mot de passe a défini pour cet adhérent. Cependant, aucun compte d'utilisateur n'a été créé. Ce mot de passe a donc été stocké, mais ne peut être utilisé pour accéder à Dolibarr. Il peut être utilisé par un module/interface externe, mais si vous n'avez pas besoin de définir ni login ni mot de passe pour un adhérent, vous pouvez désactiver l'option «Gérer un login pour chaque adhérent" depuis la configuration du module Adhérents. Si vous avez besoin de gérer un login, mais pas de mot de passe, vous pouvez laisser ce champ vide pour éviter cet avertissement. Remarque: L'email peut également être utilisé comme login si l'adhérent est lié à un utilisateur. @@ -342,6 +344,7 @@ WarningPaypalPaymentNotCompatibleWithStrict=La valeur 'Strict' fait que les fonc WarningThemeForcedTo=Attention, le choix du thème a été forcé à %s par la constante cachée MAIN_FORCETHEME WarningPagesWillBeDeleted=Attention, cela supprimera également toutes les pages/conteneurs existants du site. Vous devriez exporter votre site Web avant, afin d'avoir une sauvegarde pour le réimporter plus tard. WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal=La validation automatique est désactivée lorsque l'option de diminution du stock est définie sur "Validation de la facture". +WarningModuleNeedRefrech = Module %s desactivé. N'oublier pas de le réactivé # Validate RequireValidValue = Valeur non valide diff --git a/htdocs/langs/fr_FR/modulebuilder.lang b/htdocs/langs/fr_FR/modulebuilder.lang index 9cd5fe23a00..3c4161941e8 100644 --- a/htdocs/langs/fr_FR/modulebuilder.lang +++ b/htdocs/langs/fr_FR/modulebuilder.lang @@ -165,3 +165,8 @@ BadValueForType=Mauvaise valeur pour le type %s DefinePropertiesFromExistingTable=Définir des propriétés à partir d'une table existante DefinePropertiesFromExistingTableDesc=Si une table dans la base de données (pour l'objet à créer) existe déjà, vous pouvez l'utiliser pour définir les propriétés de l'objet. DefinePropertiesFromExistingTableDesc2=Laisser vide si la table n'existe pas encore. Le générateur de code utilisera différents types de champs pour créer un exemple de table que vous pourrez modifier ultérieurement. +GeneratePermissions=Je souhaite ajouter les droits pour cet objet +GeneratePermissionsHelp=générer les droits par défault pour cet objet +PermissionDeletedSuccesfuly=La permission a été supprimée avec succès +PermissionUpdatedSuccesfuly=La permission a été mise à jour avec succès +PermissionAddedSuccesfuly= La permission a été ajoutée avec succès \ No newline at end of file diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 0d2137928ac..6d47b51d36e 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -1218,6 +1218,42 @@ if ($dirins && $action == 'initobject' && $module && $objectname) { 'core/modules/mymodule/doc/pdf_standard_myobject.modules.php'=>'core/modules/'.strtolower($module).'/doc/pdf_standard_'.strtolower($objectname).'.modules.php' ); } + if (GETPOST('generatepermissions', 'aZ09')) { + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + dol_include_once($pathtofile); + $class = 'mod'.$module; + if (class_exists($class)) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + if (empty($firstobjectname)) { + $rightToadd = preg_replace('/myobject/', $objectname, $rightToadd); + } + if ($objectname != $firstobjectname) { + $rightToadd = " + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Read objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'read'; + \$r++; + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Create/Update objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'write'; + \$r++; + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Delete objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'delete'; + \$r++; + "; + dolReplaceInFile($moduledescriptorfile, array('/* END MODULEBUILDER PERMISSIONS */' => '/*'.strtoupper($objectname).'*/'.$rightToadd."/*END ".strtoupper($objectname).'*/'."\n\t\t".'/* END MODULEBUILDER PERMISSIONS */')); + } + } if (!$error) { @@ -1778,6 +1814,36 @@ if ($dirins && $action == 'confirm_deleteobject' && $objectname) { dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($objectname).'*/' => '')); } + // regenerate permissions and delete them + $rights = " + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Read objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'read'; + \$r++; + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Create/Update objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'write'; + \$r++; + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = 'Delete objects of ".$module."'; + \$this->rights[\$r][4] = '".strtolower($objectname)."'; + \$this->rights[\$r][5] = 'delete'; + \$r++; + "; + + $deleteright = dolReplaceInFile($moduledescriptorfile, array('/*'.strtoupper($objectname).'*/' => '', $rights => '', "/*END ".strtoupper($objectname).'*/'."\n\t\t" => ''."\n\t\t")); + if ($deleteright > 0) { + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + if ($result) { + setEventMessages($result, null, 'errors'); + } + setEventMessages($langs->trans("WarningModuleNeedRefrech", $langs->transnoentities($module)), null, 'warnings'); + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?index.php?tab=description&module='.$module); + } + } $resultko = 0; foreach ($filetodelete as $tmpfiletodelete) { $resulttmp = dol_delete_file($dir.'/'.$tmpfiletodelete, 0, 0, 1); @@ -1876,6 +1942,114 @@ if ($dirins && $action == 'generatepackage') { } +// Update permission +if ($dirins && GETPOST('action') == 'update_right' && GETPOST('modifyright')&& empty($cancel)) { + $error = 0; + // load class and check if right exist + $pathtofile = $listofmodules[strtolower($module)]['moduledescriptorrelpath']; + dol_include_once($pathtofile); + $class = 'mod'.$module; + if (class_exists($class)) { + try { + $moduleobj = new $class($db); + } catch (Exception $e) { + $error++; + dol_print_error($db, $e->getMessage()); + } + } + // verify informations entred + if (!GETPOST('label', 'alpha')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); + } + if (!GETPOST('permissionObj', 'alpha')) { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Rights")), null, 'errors'); + } + + $label = GETPOST('label', 'alpha'); + $objectForPerms = strtolower(GETPOST('permissionObj', 'alpha')); + $crud = GETPOST('crud', 'alpha'); + + + if ($label == "Read objects of $module" && $crud != "read") { + $crud = "read"; + $label == "Read objects of $module"; + } + if ($label == "Create/Update objects of $module" && $crud != "write") { + $crud = "write"; + $label == "Create/Update objects of $module"; + } + if ($label == "Delete objects of $module" && $crud != "delete") { + $crud = "delete"; + $label == "Delete objects of $module"; + } + + $permissions = $moduleobj->rights; + $r =(int) GETPOST('counter'); + //get permission want to delete from permissions array + $x1 = $permissions[$r-1][1]; + $x2 = $permissions[$r-1][4]; + $x3 = $permissions[$r-1][5]; + //check existing object permission + $permsForObject =array(); + + $allObject = array(); + $nbOfPermissions = count($permissions); + for ($i =0; $i<$nbOfPermissions; $i++) { + if ($permissions[$i][4] == $objectForPerms) { + if (count($permsForObject) < 3) { + $permsForObject[] = $permissions[$i]; + } + } + $allObject[] = $permissions[$i][4]; + } + + if ($label != $x1 && $crud != $x3) { + $x = count($permsForObject); + for ($j = 0; $j<$x; $j++) { + if (in_array($label, $permsForObject[$j])) { + $error++; + setEventMessages($langs->trans("ErrorExistingPermission", $langs->transnoentities($label), $langs->transnoentities($objectForPerms)), null, 'errors'); + } + } + } + + //prepare right want to delete + $right = " + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = '$x1'; + \$this->rights[\$r][4] = '$x2'; + \$this->rights[\$r][5] = '$x3'; + \$r++; + "; + // right after editing + $rightUpdated = " + \$this->rights[\$r][0] = \$this->numero . sprintf('%02d', \$r + 1); + \$this->rights[\$r][1] = '$label'; + \$this->rights[\$r][4] = '$objectForPerms'; + \$this->rights[\$r][5] = '$crud'; + \$r++; + "; + if (!$error) { + if (isModEnabled(strtolower($module))) { + $result = unActivateModule(strtolower($module)); + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", (int) $conf->global->MAIN_IHM_PARAMS_REV + 1, 'chaine', 0, '', $conf->entity); + if ($result) { + setEventMessages($result, null, 'errors'); + } + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('WarningModuleNeedRefrech', $langs->transnoentities($module)), null, 'warnings'); + } + + $moduledescriptorfile = $dirins.'/'.strtolower($module).'/core/modules/mod'.$module.'.class.php'; + $check = dolReplaceInFile($moduledescriptorfile, array($right => $rightUpdated)); + + header("Location: ".DOL_URL_ROOT.'/modulebuilder/index.php?tab=permissions&module='.$module); + setEventMessages($langs->trans('PermissionUpdatedSuccesfuly'), null); + exit; + } +} // Save file if ($action == 'savefile' && empty($cancel)) { $relofcustom = basename($dirins); @@ -2760,6 +2934,7 @@ if ($module == 'initmodule') { print '
'; print '
'; print '
'; + print '
'; print '
'; print ''; print '
'; @@ -3820,6 +3995,36 @@ if ($module == 'initmodule') { $perms = $moduleobj->rights; + // Scan for object class files + $dir = $dirread.'/'.$modulelowercase.'/class'; + $listofobject = dol_dir_list($dir, 'files', 0, '\.class\.php$'); + $objects = array('myobject'); + $reg =array(); + foreach ($listofobject as $fileobj) { + $tmpcontent = file_get_contents($fileobj['fullname']); + if (preg_match('/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) { + $objects[] = $reg[1]; + } + } + // declared select list for actions and labels permissions + $crud = array('Read','Write','Delete'); + $labels = array("Read objects of $module","Create/Update objects of $module","Delete objects of $module"); + + $action = GETPOST('action', 'alpha'); + + if ($action == 'deleteright') { + $formconfirm = $form->formconfirm( + $_SERVER["PHP_SELF"].'?permskey='.urlencode(GETPOST('permskey', 'int')).'&tab='.urlencode($tab).'&module='.urlencode($module).'&tabobj='.urlencode($tabobj), + $langs->trans('Delete'), + $langs->trans('Confirm Delete Right', GETPOST('permskey', 'alpha')), + 'confirm_deleteright', + '', + 0, + 1 + ); + print $formconfirm; + } + if ($action != 'editfile' || empty($file)) { print ''; $htmlhelp = $langs->trans("PermissionsDefDescTooltip", '{s1}'); @@ -3846,33 +4051,128 @@ if ($module == 'initmodule') { print ''; print ''; - print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); - print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder); + print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("Label", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("Permission", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("CRUD", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); + print_liste_field_titre("", $_SERVER["PHP_SELF"], '', "", $param, '', $sortfield, $sortorder, "center"); print "\n"; + //form for add new right + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + if (count($perms)) { + $i = 0; foreach ($perms as $perm) { - print ''; + $i++; + // section for editing right + if ($action == 'edit_right' && $perm[0] == (int) GETPOST('permskey', 'int')) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; + + print ''; + + print ''; + + print ''; + print ''; + } else { + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + } } } else { print '';
'; + print ''; + print ''; + print '
'; - print $perm[0]; - print ''; - print $langs->trans($perm[1]); - print ''; - print $perm[4]; - print ''; + print ''; + print ''; - print $perm[5]; - print ''; + print '
'; + print ''; + print ''; + print ''; + print '
'; + print ''; + print '
'; + print $perm[0]; + print ''; + print $langs->trans($perm[1]); + print ''; + print $perm[4]; + print ''; + print $perm[5]; + print ''; + if ($perm[4] != 'myobject') { + print ''.img_edit().''; + print ''.img_delete().''; + } + print '
'.$langs->trans("None").'