Skip to content

Commit

Permalink
feat: prevent using formcreator's dashboard as default
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Apr 25, 2022
1 parent 10a1011 commit 26f2b17
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
11 changes: 11 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,15 @@ function plugin_formcreator_hook_update_profile(CommonDBTM $item) {
'items_id' => $item->getID(),
], 1);
}
}

function plugin_formcreator_hook_update_user(CommonDBTM $item) {
if ($item::getType() != User::getType()) {
return;
}

if (isset($item->input['default_dashboard_mini_ticket']) && $item->input['default_dashboard_mini_ticket'] == 'plugin_formcreator_issue_counters') {
Session::addMessageAfterRedirect(__('Formcreator\'s mini dashboard not usable as default. This Setting has been ignored.', 'formcreator'), false, WARNING);
unset($item->input['default_dashboard_mini_ticket']);
}
}
21 changes: 13 additions & 8 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Plugin\Hooks;

global $CFG_GLPI;
// Version of the plugin (major.minor.bugfix)
define('PLUGIN_FORMCREATOR_VERSION', '2.13.0-alpha.4');
Expand Down Expand Up @@ -268,37 +270,40 @@ function plugin_formcreator_permanent_hook(): void {
global $PLUGIN_HOOKS;

// Set the plugin CSRF compliance (required since GLPI 0.84)
$PLUGIN_HOOKS['csrf_compliant']['formcreator'] = true;
$PLUGIN_HOOKS[Hooks::CSRF_COMPLIANT]['formcreator'] = true;

// Can assign FormAnswer to tickets
$PLUGIN_HOOKS['assign_to_ticket']['formcreator'] = true;

// hook to update issues when an operation occurs on a ticket
$PLUGIN_HOOKS['item_add']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_add_ticket',
ITILFollowup::class => 'plugin_formcreator_hook_update_itilFollowup',
];
$PLUGIN_HOOKS['item_update']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['formcreator'] = [
User::class => 'plugin_formcreator_hook_update_user',
];
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_update_ticket',
TicketValidation::class => 'plugin_formcreator_hook_update_ticketvalidation',
Profile::class => 'plugin_formcreator_hook_update_profile',
];
$PLUGIN_HOOKS['item_delete']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::ITEM_DELETE]['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_delete_ticket'
];
$PLUGIN_HOOKS['item_restore']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::ITEM_RESTORE]['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_restore_ticket'
];
$PLUGIN_HOOKS['item_purge']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::ITEM_PURGE]['formcreator'] = [
Ticket::class => 'plugin_formcreator_hook_purge_ticket',
TicketValidation::class => 'plugin_formcreator_hook_purge_ticketvalidation',
];
$PLUGIN_HOOKS['pre_item_purge']['formcreator'] = [
$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['formcreator'] = [
PluginFormcreatorTargetTicket::class => 'plugin_formcreator_hook_pre_purge_targetTicket',
PluginFormcreatorTargetChange::class => 'plugin_formcreator_hook_pre_purge_targetChange'
];
// hook to add custom actions on a ticket in service catalog
$PLUGIN_HOOKS['timeline_actions']['formcreator'] = 'plugin_formcreator_timelineActions';
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['formcreator'] = 'plugin_formcreator_timelineActions';
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/1-install/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

use Glpi\Dashboard\Dashboard;
use Glpi\Dashboard\Item;
use Glpi\Dashboard\Right;
use GlpiPlugin\Formcreator\Tests\CommonTestCase;
use Profile;

/**
* @engine inline
Expand Down Expand Up @@ -291,6 +293,21 @@ public function checkDashboard() {
$dashboard->getFromDB('plugin_formcreator_issue_counters');
$this->boolean($dashboard->isNewItem())->isFalse();

// Check rights on the dashboard
$right = new Right();
$profile = new Profile();
$helpdeskProfiles = $profile->find([
'interface' => 'helpdesk',
]);
foreach ($helpdeskProfiles as $helpdeskProfile) {
$rows = $right->find([
'dashboards_dashboards_id' => $dashboard->fields['id'],
'itemtype' => Profile::getType(),
'items_id' => $helpdeskProfile['id']
]);
$this->array($rows)->hasSize(1);
}

// Check there is widgets in the dashboard
$dashboardItem = new Item();
$rows = $dashboardItem->find([
Expand Down

0 comments on commit 26f2b17

Please sign in to comment.