Skip to content

Commit

Permalink
Merge pull request #6 from Probesys/5-mise-en-place-de-restrictions-d…
Browse files Browse the repository at this point in the history
…accès-aux-fonctionnalités-offertes-par-le-plugin-via-des-habilitations

5 mise en place de restrictions daccès aux fonctionnalités offertes par le plugin via des habilitations
  • Loading branch information
pgodot authored Jun 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 0609554 + f8d40a2 commit a2b15f2
Showing 3 changed files with 70 additions and 47 deletions.
74 changes: 40 additions & 34 deletions front/rgpdtools.form.php
Original file line number Diff line number Diff line change
@@ -29,45 +29,51 @@

include('../../../inc/includes.php');

$PluginRgpdtoolsRgpdtools = new PluginRgpdtoolsRgpdtools();
if (!Session::haveRight('user', PURGE)) {
Html::header(__('RgpdTools', 'rgpdtools'), $_SERVER['PHP_SELF'], 'tools', 'rgpdtools');
echo '<h4 class="alert-title">'. __('Access denied', 'glpi') .'</h4>';
Html::footer();
} else {
$PluginRgpdtoolsRgpdtools = new PluginRgpdtoolsRgpdtools();

if (isset($_REQUEST['generate'])) {
if ($PluginRgpdtoolsRgpdtools::generateExport($_POST)) {
Session::addMessageAfterRedirect(__('Export successfully generated.', 'rgpdtools'), true);
}
//Html::back();
}
if (isset($_REQUEST['generate'])) {
if ($PluginRgpdtoolsRgpdtools::generateExport($_POST)) {
Session::addMessageAfterRedirect(__('Export successfully generated.', 'rgpdtools'), true);
}
//Html::back();
}

if (isset($_REQUEST['deleteItems'])) {
$nbUnlinkedElmts = $PluginRgpdtoolsRgpdtools::deleteUserLinkItems($_POST);
if (isset($_REQUEST['deleteItems'])) {
$nbUnlinkedElmts = $PluginRgpdtoolsRgpdtools::deleteUserLinkItems($_POST);

if ($nbUnlinkedElmts) {
$message = $nbUnlinkedElmts.__(' link(s) with the user where deleted successfully', 'rgpdtools');
} else {
$message = __('No links matching criteria were founded, no update query were executed.', 'rgpdtools');
}
if ($nbUnlinkedElmts) {
$message = $nbUnlinkedElmts.__(' link(s) with the user where deleted successfully', 'rgpdtools');
} else {
$message = __('No links matching criteria were founded, no update query were executed.', 'rgpdtools');
}

Session::addMessageAfterRedirect(__($message, 'rgpdtools'), true);
Html::back();
}
Session::addMessageAfterRedirect(__($message, 'rgpdtools'), true);
Html::back();
}

if (isset($_REQUEST['purgeUserLogs'])) {
if ($PluginRgpdtoolsRgpdtools::anonymizeUserLogs($_POST)) {
Session::addMessageAfterRedirect(__('Logs contains information about the user were anonymize successfully.', 'rgpdtools'), true);
}
Html::back();
}
if (isset($_REQUEST['purgeUserLogs'])) {
if ($PluginRgpdtoolsRgpdtools::anonymizeUserLogs($_POST)) {
Session::addMessageAfterRedirect(__('Logs contains information about the user were anonymize successfully.', 'rgpdtools'), true);
}
Html::back();
}

if (isset($_REQUEST['deleteDocuments'])) {
$nbDeleteDocuments = $PluginRgpdtoolsRgpdtools::deleteUploadedDocuments($_POST);
Session::addMessageAfterRedirect($nbDeleteDocuments.' '.__('documents were deleted on server and database successfully.', 'rgpdtools'), true);
Html::back();
}
if (isset($_REQUEST['deleteDocuments'])) {
$nbDeleteDocuments = $PluginRgpdtoolsRgpdtools::deleteUploadedDocuments($_POST);
Session::addMessageAfterRedirect($nbDeleteDocuments.' '.__('documents were deleted on server and database successfully.', 'rgpdtools'), true);
Html::back();
}

// standard form
if (!isset($_REQUEST['generate'])) {
Html::header(__('RgpdTools', 'rgpdtools'), $_SERVER['PHP_SELF'], 'tools', 'rgpdtools');
$PluginRgpdtoolsRgpdtools = new PluginRgpdtoolsRgpdtools();
$PluginRgpdtoolsRgpdtools->getFormsForCompleteForm();
Html::footer();
// standard form
if (!isset($_REQUEST['generate'])) {
Html::header(__('RgpdTools', 'rgpdtools'), $_SERVER['PHP_SELF'], 'tools', 'rgpdtools');
$PluginRgpdtoolsRgpdtools = new PluginRgpdtoolsRgpdtools();
$PluginRgpdtoolsRgpdtools->getFormsForCompleteForm();
Html::footer();
}
}
37 changes: 26 additions & 11 deletions inc/rgpdtools.class.php
Original file line number Diff line number Diff line change
@@ -198,21 +198,26 @@ private static function displayTabContentForUser(User $item) {
}

public function getFormsForCompleteForm() {
$itemsTypes = self::getUserAssociableItemTypes();

$html = '<div class="row">';
$users_id = null;

$html .= self::generateExportForm($users_id, $itemsTypes);
$html .= self::generateAnonymiseForm($users_id);
$html .= self::generateUnlinkItemsForm($users_id, $itemsTypes);
$html .= self::generateDeleteDocumentsForm($users_id, $itemsTypes);
$html .= self::generateExportForm($users_id);
if(Session::haveRight(strtolower('logs'), READ)) {
$html .= self::generateAnonymiseForm($users_id);
}
$html .= self::generateUnlinkItemsForm($users_id);
if(Session::haveRight(strtolower('document'), UPDATE)) {
$html .= self::generateDeleteDocumentsForm($users_id);
}

$html .= '</div>';

echo $html;
}

private static function generateExportForm($users_id, $itemsTypes) {
private static function generateExportForm($users_id) {
$itemsTypes = self::getUserAssociableItemTypes(READ);
$html = '';
$rand = mt_rand();
$idForm = "useritemsexport_form$rand";
@@ -271,7 +276,8 @@ private static function generateExportForm($users_id, $itemsTypes) {
return $html;
}

private static function generateUnlinkItemsForm($users_id, $itemsTypes) {
private static function generateUnlinkItemsForm($users_id) {
$itemsTypes = self::getUserAssociableItemTypes(UPDATE);
$html = '';
$rand = mt_rand();

@@ -421,7 +427,8 @@ private static function generateAnonymiseForm($users_id) {
return $html;
}

private static function generateDeleteDocumentsForm($users_id, $itemsTypes) {
private static function generateDeleteDocumentsForm($users_id) {
$itemsTypes = self::getUserAssociableItemTypes(UPDATE);
$html = '';
$rand = mt_rand();

@@ -609,12 +616,20 @@ private static function getAllUsedItemsForUser($ID) {
return $items;
}

private static function getUserAssociableItemTypes() {
private static function getUserAssociableItemTypes($permissionAccess = READ) {
global $CFG_GLPI;

$moreTypes = ['Ticket', 'ITILFollowup', 'TicketTask'];
$itemsTypes = ['Ticket', 'Followup', 'Task'];

return array_merge($CFG_GLPI['linkuser_types'], $moreTypes);
$linkuser_types = array_merge($CFG_GLPI['linkuser_types'], $itemsTypes);;
foreach($linkuser_types as $itemsType){
if(Session::haveRight(strtolower($itemsType), $permissionAccess)){
$itemsTypes[]= $itemsType;
}
}
$itemsTypes = array_unique($itemsTypes);

return $itemsTypes;
}

private static function injectRowHeader($spreadsheet, $objectInfos, $itemType) {
6 changes: 4 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
* ---------------------------------------------------------------------
*/

define('PLUGIN_RGPDTOOLS_VERSION', '1.1.0');
define('PLUGIN_RGPDTOOLS_VERSION', '1.1.1');
define('PLUGIN_RGPDTOOLS_GLPI_MIN_VERSION', '9.5');
define('PLUGIN_RGPDTOOLS_GLPI_MAX_VERSION', '11');
if (!defined("PLUGIN_RGPDTOOLS_DIR")) {
@@ -54,7 +54,9 @@ function plugin_init_rgpdtools() {
'addtabon' => ['User'],
]
);
$PLUGIN_HOOKS['menu_toadd']['rgpdtools'] = ['tools' => 'PluginRgpdtoolsRgpdTools'];
if (Session::haveRight('user', PURGE)) {
$PLUGIN_HOOKS['menu_toadd']['rgpdtools'] = ['tools' => 'PluginRgpdtoolsRgpdTools'];
}
}

/**

0 comments on commit a2b15f2

Please sign in to comment.