Skip to content
Open
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 .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
glpi-version: "11.0.x"
glpi-version: "12.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

- GLPI 12 Compatibility

### Fixed
- Fixed the issue where a ticket could be solved without a solution

Expand Down
50 changes: 50 additions & 0 deletions rector.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
* -------------------------------------------------------------------------
*/

declare(strict_types=1);

require_once __DIR__ . '/../../src/Plugin.php';

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/front',
__DIR__ . '/src',
__DIR__ . '/tests',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
4 changes: 2 additions & 2 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

// Minimal GLPI version, inclusive
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define("PLUGIN_MOREOPTIONS_MIN_GLPI_VERSION", "11.0.0");
define("PLUGIN_MOREOPTIONS_MIN_GLPI_VERSION", "12.0.0");

// Maximum GLPI version, exclusive
/** @phpstan-ignore theCodingMachineSafe.function (safe to assume this isn't already defined) */
define("PLUGIN_MOREOPTIONS_MAX_GLPI_VERSION", "11.0.99");
define("PLUGIN_MOREOPTIONS_MAX_GLPI_VERSION", "12.0.99");

/**
* Init hooks of the plugin.
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

class Config extends CommonDBTM
{
public $dohistory = true;
public static $rightname = 'config';
public bool $dohistory = true;
public static string $rightname = 'config';
public const CONFIG_PARENT = \Entity::CONFIG_PARENT;
public static function getMenuName(): string
{
Expand Down
18 changes: 8 additions & 10 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

class Controller extends CommonDBTM
{
public $dohistory = true;
public static $rightname = 'config';
public bool $dohistory = true;
public static string $rightname = 'config';
private static bool $solution_check_done = false;
public static function getTypeName($nb = 0): string
{
Expand Down Expand Up @@ -554,12 +554,11 @@ public static function checkTaskRequirements(CommonDBTM $item): CommonDBTM
/**
* Hooked on {@link \Glpi\Plugin\Hooks::POST_ITEM_FORM}. Renders, into the task creation/edit
* form, a script that marks the fields configured as mandatory in moreoptions (category,
* duration, technician, technician group) with the usual red "required" marker and blocks
* client-side submission of the form until they are filled.
* duration, technician, technician group) with the usual red "required" marker.
*
* The server-side block already performed by {@see self::checkTaskRequirements()} on actual
* submission (PRE_ITEM_ADD) is kept as-is; this only prevents the user from submitting an
* incomplete task in the first place.
* This is purely a visual hint: the actual block on submission is performed server-side by
* {@see self::checkTaskRequirements()} (PRE_ITEM_ADD), whose message is what gets shown to
* the user.
*
* @param array<string, mixed> $params
*/
Expand Down Expand Up @@ -596,9 +595,8 @@ public static function markMandatoryTaskFields(array $params): void

TemplateRenderer::getInstance()->display('@moreoptions/timeline_task_mandatory_fields.html.twig', [
// Unique per-call anchor: lets the injected script find its own <form> reliably.
'marker_id' => 'moreoptions-task-mandatory-' . bin2hex(random_bytes(6)),
'field_labels' => $labels,
'error_message' => __('To create this task, you must fill in the following fields:', 'moreoptions'),
'marker_id' => 'moreoptions-task-mandatory-' . bin2hex(random_bytes(6)),
'field_labels' => $labels,
]);
}

Expand Down
22 changes: 14 additions & 8 deletions templates/timeline_solution_warning.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,20 @@
// A tooltip (not a popover) so it keeps GLPI's dark bubble style: core deliberately
// styles popovers with a light background (see `.popover .popover-body` in
// _base.scss), while tooltips stay dark. Tooltips support HTML content too.
solutionToggle.setAttribute('data-bs-toggle', 'tooltip');
solutionToggle.setAttribute('data-bs-placement', 'right');
solutionToggle.setAttribute('data-bs-trigger', 'hover focus');
solutionToggle.setAttribute('data-bs-html', 'true');
solutionToggle.setAttribute('title', {{ tooltip_content|json_encode|raw }});

if (typeof initTooltips === 'function') {
initTooltips(footer);
//
// The toggle already carries `data-bs-toggle="collapse"` (it's still a working
// "Add a solution" action): it can't also be set to "tooltip", as Bootstrap only
// honors one `data-bs-toggle` value per element and would silently drop the
// collapse behavior. The tooltip is instantiated directly through the JS API
// instead of going through `initTooltips()`'s `[data-bs-toggle="tooltip"]` selector.
if (typeof bootstrap !== 'undefined' && bootstrap.Tooltip) {
new bootstrap.Tooltip(solutionToggle, {
delay: {show: 50, hide: 50},
html: true,
placement: 'right',
trigger: 'hover focus',
title: {{ tooltip_content|json_encode|raw }},
});
}
})();
</script>
31 changes: 8 additions & 23 deletions templates/timeline_task_mandatory_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,25 @@
{#
# Rendered through the core `Hooks::POST_ITEM_FORM` hook (see Controller::markMandatoryTaskFields),
# right before the task form's closing tag. Marks the configured fields as required (red asterisk
# on their label, matching GLPI's own convention) and blocks client-side submission until they
# are filled.
# on their label, matching GLPI's own convention).
#
# This is purely a visual hint: submission itself is left to go through normally so the existing
# server-side block ({@see Controller::checkTaskRequirements()}, on PRE_ITEM_ADD) can render its
# usual accessible, styled message. An earlier version of this script also intercepted the
# form's `submit` event to reject it client-side through a `window.alert()`: that stopped the
# AJAX round-trip entirely, so the styled server-side message never got a chance to show, and a
# native `alert()` popup isn't reachable through accessible/role-based locators anyway.
#}
<span id="{{ marker_id }}" style="display: none;" aria-hidden="true"></span>
<script>
(function() {
var fieldLabels = {{ field_labels|json_encode|raw }};
var errorMessage = {{ error_message|json_encode|raw }};
var marker = document.getElementById({{ marker_id|json_encode|raw }});
var form = marker ? marker.closest('form') : null;
if (!form) {
return;
}

function isEmpty(value) {
return value === null || value === undefined || value === '' || value === '0';
}

Object.keys(fieldLabels).forEach(function(name) {
var fieldContainer = form.querySelector('[data-testid="form-field-' + name + '"]');
var label = fieldContainer ? fieldContainer.querySelector('label') : null;
Expand All @@ -61,21 +62,5 @@
label.appendChild(mark);
}
});

form.addEventListener('submit', function(e) {
var missing = [];
Object.keys(fieldLabels).forEach(function(name) {
var field = form.querySelector('[name="' + name + '"]');
var value = field ? field.value : '';
if (isEmpty(value)) {
missing.push(fieldLabels[name]);
}
});
if (missing.length > 0) {
e.preventDefault();
e.stopPropagation();
window.alert(errorMessage + '\n- ' + missing.join('\n- '));
}
});
})();
</script>
34 changes: 34 additions & 0 deletions tests/e2e/fixtures/moreoptions_fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* -------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------
*/

// Re-export the core GLPI fixture so plugin specs share the same authenticated
// `test`/`expect` and the worker/profile/api helpers.
export * from '../../../../../tests/e2e/fixtures/glpi_fixture';
72 changes: 72 additions & 0 deletions tests/e2e/pages/MoreOptionsConfigPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* -------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------
*/

import { Locator, Page } from '@playwright/test';
// eslint-disable-next-line playwright/no-raw-locators
import { GlpiPage } from '../../../../../tests/e2e/pages/GlpiPage';

// The plugin registers a single tab (index 1) on the Entity item.
const CONFIG_TAB = 'GlpiPlugin\\Moreoptions\\Config$1';

export class MoreOptionsConfigPage extends GlpiPage
{
public readonly save_button: Locator;

public constructor(page: Page)
{
super(page);

this.save_button = this.getButton('Save');
}

public async goto(entities_id: number): Promise<void>
{
await this.page.goto(
`/front/entity.form.php?id=${entities_id}&forcetab=${CONFIG_TAB}`
);
}

/**
* The config fields are rendered without an associated <label> (they sit
* in a table, one row per setting, with a column per itemtype), so they
* can't be located with `getDropdownByLabel`. The underlying <select>
* keeps the field name though, which select2 renders as an adjacent span.
*/
// eslint-disable-next-line playwright/no-raw-locators
public getConfigDropdown(field: string): Locator
{
return this.page
.locator(`select[name="${field}"]`)
.locator('+ span')
.getByRole('combobox')
;
}
}
67 changes: 67 additions & 0 deletions tests/e2e/specs/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* -------------------------------------------------------------------------
* 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
* -------------------------------------------------------------------------
*/

import { randomUUID } from 'crypto';
import { test, expect } from '../fixtures/moreoptions_fixture';
import { MoreOptionsConfigPage } from '../pages/MoreOptionsConfigPage';
// eslint-disable-next-line playwright/no-raw-locators
import { Profiles } from '../../../../../tests/e2e/utils/Profiles';
// eslint-disable-next-line playwright/no-raw-locators
import { getWorkerEntityId } from '../../../../../tests/e2e/utils/WorkerEntities';

test.describe('MoreOptions - Entity configuration tab', () => {
test('a new sub-entity inherits its parent config and can override it', async ({ page, profile, api, entity }) => {
await profile.set(Profiles.SuperAdmin);

const entities_id = await api.createItem('Entity', {
'name': `MoreOptions config ${randomUUID()}`,
'entities_id': getWorkerEntityId(),
});
// A freshly created entity is not immediately usable otherwise: its
// recursive rights are only picked up on the next explicit entity
// switch.
await entity.switchToWithRecursion(entities_id);

const config_page = new MoreOptionsConfigPage(page);
await config_page.goto(entities_id);

const dropdown = config_page.getConfigDropdown('require_solution_to_close_ticket');
await expect(dropdown).toHaveText('Inheritance of the parent entity');

await config_page.doSetDropdownValue(dropdown, 'Yes');
await config_page.save_button.click();
await expect(dropdown).toHaveText('Yes');

// The override survives a reload.
await config_page.goto(entities_id);
await expect(config_page.getConfigDropdown('require_solution_to_close_ticket')).toHaveText('Yes');
});
});
Loading
Loading