Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Add rector config
- Implementation of the basic concept of escalation
- Add the "Escalate to group" action to the ticket, change and problem business rules, and a page to switch the rules "Technician group" actions to it

## [1.0.0-rc2]

Expand All @@ -23,4 +24,3 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed the issue where a ticket could be solved without a solution

## [1.0.0-rc1]

4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
"require": {
"php": ">=8.2"
},
"require-dev": {
"glpi-project/tools": "^0.7"
},
"config": {
"autoloader-suffix": "PluginMoreoptions",
"optimize-autoloader": true,
"platform": {
"php": "8.2.99"
Expand Down
65 changes: 65 additions & 0 deletions front/escalation_rules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* -------------------------------------------------------------------------
* MoreOptions plugin for GLPI
* -------------------------------------------------------------------------
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2025 by the MoreOptions plugin team.
* @license MIT https://opensource.org/licenses/mit-license.php
* @link https://github.com/pluginsGLPI/moreoptions
* @link https://gitlab.teclib.com/glpi-network/moreoptions/
* -------------------------------------------------------------------------
*/

use Glpi\Exception\Http\AccessDeniedHttpException;
use GlpiPlugin\Moreoptions\EscalationRule;

Session::checkLoginUser();

if (!EscalationRule::canManageRules()) {
throw new AccessDeniedHttpException();
}

if (isset($_POST['update'])) {
$result = EscalationRule::switchActions(is_array($_POST['fields'] ?? null) ? $_POST['fields'] : []);
if ($result['updated'] > 0) {
Session::addMessageAfterRedirect(htmlescape(sprintf(
_n('%d rule action has been updated.', '%d rule actions have been updated.', $result['updated'], 'moreoptions'),
$result['updated'],
)));
}

if ($result['failed'] > 0) {
Session::addMessageAfterRedirect(htmlescape(sprintf(
_n('%d rule action cannot be updated.', '%d rule actions cannot be updated.', $result['failed'], 'moreoptions'),
$result['failed'],
)), false, ERROR);
}

Html::back();
}

Html::header(__('Escalation in business rules', 'moreoptions'), '', 'admin', 'rule');
EscalationRule::showRulesList();
Html::footer();
14 changes: 14 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Escalation;
use GlpiPlugin\Moreoptions\EscalationRule;
use GlpiPlugin\Moreoptions\Group_Link;

function plugin_moreoptions_install(): bool
Expand All @@ -54,7 +55,20 @@ function plugin_moreoptions_uninstall(): bool

Config::uninstall($migration);
Escalation::uninstall($migration);
EscalationRule::uninstall($migration);
Group_Link::uninstall($migration);

return true;
}

/**
* Adds the "Escalate to group" action to the ticket / change / problem rules (see the `use_rules`
* hook in setup.php).
*
* @param array<string, mixed> $params
* @return array<string, array<string, mixed>>
*/
function plugin_moreoptions_getRuleActions(array $params = []): array
{
return EscalationRule::getRuleActions($params);
}
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<psalm
runTaintAnalysis="true"
cacheDirectory="var/psalm"
>
<projectFiles>
<directory name="src"/>
Expand Down
22 changes: 22 additions & 0 deletions public/css/moreoptions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,25 @@
gap: 0.25rem;
}
}

// "Review rules" page (see escalation_rules.html.twig): fixed column widths, so that every rule type
// table lines up the same way, and the field dropdown fills its column.
.moreoptions-escalation-rules {
table {
table-layout: fixed;
}

// Name, Active, Field, Action type, Value
$column-widths: 30%, 8%, 27%, 12%, 23%;
@each $width in $column-widths {
th:nth-child(#{index($column-widths, $width)}) {
width: $width;
}
}

// Active
th:nth-child(2),
td:nth-child(2) {
text-align: center;
}
}
20 changes: 20 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Controller;
use GlpiPlugin\Moreoptions\Escalation;
use GlpiPlugin\Moreoptions\EscalationRule;
use GlpiPlugin\Moreoptions\Group_Link;

/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
Expand Down Expand Up @@ -135,6 +136,25 @@ function plugin_init_moreoptions(): void
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][ChangeTask::class] = Controller::assignTechnicianFromTask(...);

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][ProblemTask::class] = Controller::assignTechnicianFromTask(...);

// "Escalate to group" rule action (see EscalationRule). The PRE_ITEM_UPDATE hooks of tickets,
// changes and problems are already taken above: only one callback per itemtype is possible, so
// the existing one is called first, then the escalation one.
$PLUGIN_HOOKS[Hooks::USE_RULES]['moreoptions'] = EscalationRule::getRuleClasses();

foreach ([Ticket::class, Change::class, Problem::class] as $itemtype) {
$PLUGIN_HOOKS[Hooks::PRE_ITEM_ADD]['moreoptions'][$itemtype] = EscalationRule::dropFromUserInput(...);

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][$itemtype] = EscalationRule::escalateAfterAdd(...);

$pre_item_update = $PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['moreoptions'][$itemtype];
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['moreoptions'][$itemtype] = static function (CommonDBTM $item) use ($pre_item_update): void {
$pre_item_update($item);
EscalationRule::dropFromUserInput($item);
};

$PLUGIN_HOOKS[Hooks::POST_PREPAREUPDATE]['moreoptions'][$itemtype] = EscalationRule::escalateBeforeUpdate(...);
}
}

/**
Expand Down
Loading
Loading