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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Add
- Add rector config
- Implementation of the basic concept of escalation

## [1.0.0-rc2]

Expand Down
50 changes: 50 additions & 0 deletions ajax/escalation_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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\Escalation;

Session::checkLoginUser();

$item = getItemForItemtype($_GET['itemtype'] ?? '');
if (
!$item instanceof CommonITILObject
|| !$item->getFromDB((int) ($_GET['items_id'] ?? 0))
|| !$item->canAssign()
|| !Escalation::isEnabledFor($item)
) {
throw new AccessDeniedHttpException();
}

Escalation::showEscalationForm($item);
54 changes: 54 additions & 0 deletions front/escalation.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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\Escalation;

Session::checkLoginUser();

if (isset($_POST['add'])) {
$item = getItemForItemtype($_POST['itemtype'] ?? '');
if (
!$item instanceof CommonITILObject
|| !$item->getFromDB((int) ($_POST['items_id'] ?? 0))
|| !$item->canAssign()
|| !Escalation::isEnabledFor($item)
) {
throw new AccessDeniedHttpException();
}

(new Escalation())->add($_POST);
}

Html::back();
3 changes: 3 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
declare(strict_types=1);

use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Escalation;

function plugin_moreoptions_install(): bool
{
$migration = new Migration(PLUGIN_MOREOPTIONS_VERSION);

Config::install($migration);
Escalation::install($migration);
$migration->executeMigration();
return true;
}
Expand All @@ -49,6 +51,7 @@ function plugin_moreoptions_uninstall(): bool
$migration = new Migration(PLUGIN_MOREOPTIONS_VERSION);

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

return true;
}
85 changes: 85 additions & 0 deletions public/css/moreoptions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,88 @@
}
}
}

:root {
--mo-escalation-color: #ffdddd80;

--mo-escalation-background: var(--mo-escalation-color);
--mo-escalation-border: color-mix(in srgb, var(--mo-escalation-color), #af2020 30%);
}

// "Escalate" button, next to the "Assigned to" field (see escalation_button.html.twig).
.moreoptions-escalate-btn,
.moreoptions-escalate-btn:focus {
color: var(--mo-escalation-border) !important;
border-color: var(--mo-escalation-border) !important;
}

.moreoptions-escalate-btn:hover {
background-color: var(--mo-escalation-border) !important;
border-color: var(--mo-escalation-border) !important;
color: white !important;
}

// Escalation entries in the timeline (see Escalation::showInTimeline()): a single line, the same
// way GLPI core displays pending reason reminders (`.ITILReminder` in _timeline.scss).
.timeline-item.moreoptions-escalation {
width: 100%;

.user-part {
display: none !important;
}

.content-part {
flex-direction: row-reverse !important;
justify-content: flex-end;
margin-left: 75px;
margin-right: 83px;

.timeline-content {
border: 0;
box-shadow: none;
margin-top: 0 !important;
flex-grow: 0 !important;
background: transparent;

.card-body {
padding: 0;
display: flex;
flex-direction: row-reverse;

.timeline-header {
margin-left: 1rem;
margin-top: 0;
margin-bottom: 0;
}
}
}

.user_link {
display: none !important;
}

.itil-date-creation {
margin-left: 1rem !important;
}
}

// "Internal" icon, moved into the "Created: ... by ..." badge (see escalation_timeline.html.twig).
.moreoptions-escalation-separator {
opacity: 0.4;
}

.moreoptions-escalation-group {
color: inherit;
font-weight: normal;
background-color: var(--mo-escalation-background);
border: 1px solid var(--mo-escalation-border);

a {
color: inherit;

&:hover {
text-decoration: underline;
}
}
}
}
15 changes: 14 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Glpi\Plugin\Hooks;
use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Controller;
use GlpiPlugin\Moreoptions\Escalation;

/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define('PLUGIN_MOREOPTIONS_VERSION', '1.0.0-rc2');
Expand Down Expand Up @@ -81,10 +82,22 @@ function plugin_init_moreoptions(): void
// Both hooks below are called by GLPI core with an array of parameters (not an item
// instance), so they must be registered without an itemtype key: the callback filters
// on $params['item'] itself.
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['moreoptions'] = Controller::showSolutionRequirementsWarning(...);
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['moreoptions'] = Controller::showTimelineActions(...);


$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['moreoptions'] = Controller::markMandatoryTaskFields(...);

$PLUGIN_HOOKS[Hooks::TIMELINE_ITEMS]['moreoptions'] = Escalation::showInTimeline(...);

// Group links added with `_plugin_moreoptions_escalade => true` are escalations.
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][Group_Ticket::class] = Escalation::escalate(...);

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][Change_Group::class] = Escalation::escalate(...);

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][Group_Problem::class] = Escalation::escalate(...);

$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['moreoptions'][Ticket::class] = Controller::beforeCloseITILObject(...);

$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['moreoptions'][Ticket::class] = Controller::beforeCloseITILObject(...);

$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['moreoptions'][Change::class] = Controller::beforeCloseITILObject(...);
Expand Down
6 changes: 5 additions & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ private static function getScreenSections(): array
[
'title' => __('Escalate', 'moreoptions'),
'icon' => 'ti-arrow-up',
'rows' => [],
'rows' => [
['key' => 'escalate_is_active', 'kind' => 'yes_no', 'label' => __('Activate escalation', 'moreoptions')],
],
],
],
];
Expand Down Expand Up @@ -574,6 +576,7 @@ public static function install(Migration $migration): void
`assign_technician_from_task_ticket` tinyint NOT NULL DEFAULT '0',
`assign_technician_from_task_change` tinyint NOT NULL DEFAULT '0',
`assign_technician_from_task_problem` tinyint NOT NULL DEFAULT '0',
`escalate_is_active` tinyint NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `entities_id` (`entities_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
Expand All @@ -592,6 +595,7 @@ public static function install(Migration $migration): void
'assign_technician_from_task_ticket',
'assign_technician_from_task_change',
'assign_technician_from_task_problem',
'escalate_is_active',
] as $field
) {
if (!$DB->fieldExists($table, $field)) {
Expand Down
16 changes: 15 additions & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use CommonITILValidation;
use Glpi\Application\View\TemplateRenderer;
use GlpiPlugin\Moreoptions\Config;
use GlpiPlugin\Moreoptions\Escalation;
use Group_Item;
use Group_Problem;
use Group_Ticket;
Expand Down Expand Up @@ -489,7 +490,20 @@ public static function requireFieldsToClose(CommonDBTM $item, bool $is_solution
}

/**
* Hooked on {@link \Glpi\Plugin\Hooks::TIMELINE_ACTIONS}. Renders, into the ticket/change/
* Hooked on {@link \Glpi\Plugin\Hooks::TIMELINE_ACTIONS}, which takes a single callback per
* plugin: renders everything MoreOptions adds to the ticket/change/problem timeline footer.
*
* @param array<string, mixed> $params
*/
public static function showTimelineActions(array $params): void
{
self::showSolutionRequirementsWarning($params);
Escalation::showEscalateButton($params);
Escalation::showTimelineScripts($params);
}

/**
* Called from {@see self::showTimelineActions()}. Renders, into the ticket/change/
* problem timeline footer, a script that mutes the "Add a solution" action, adds a lock icon
* to it, and attaches a popover listing the missing fields, as soon as one of the fields
* required to close the item (technician, group, category, location...) is missing.
Expand Down
Loading
Loading