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
28 changes: 14 additions & 14 deletions install/empty_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -6003,7 +6003,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_TECHNICIAN,
'name' => 'changevalidation',
'rights' => CREATE | PURGE,
'rights' => READ | CREATE | PURGE,
], [
'profiles_id' => self::PROFILE_SELF_SERVICE,
'name' => 'ticketvalidation',
Expand Down Expand Up @@ -6307,15 +6307,15 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_SUPER_ADMIN,
'name' => 'changevalidation',
'rights' => CREATE | PURGE | CommonITILValidation::VALIDATE,
'rights' => READ | CREATE | PURGE | CommonITILValidation::VALIDATE,
], [
'profiles_id' => self::PROFILE_HOTLINER,
'name' => 'changevalidation',
'rights' => CREATE | PURGE,
'rights' => READ | CREATE | PURGE,
], [
'profiles_id' => self::PROFILE_OBSERVER,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
], [
'profiles_id' => self::PROFILE_ADMIN,
'name' => 'computer',
Expand Down Expand Up @@ -6618,15 +6618,15 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_OBSERVER,
'name' => 'changevalidation',
'rights' => CREATE | PURGE | CommonITILValidation::VALIDATE,
'rights' => READ | CREATE | PURGE | CommonITILValidation::VALIDATE,
], [
'profiles_id' => self::PROFILE_ADMIN,
'name' => 'changevalidation',
'rights' => CREATE | PURGE | CommonITILValidation::VALIDATE,
'rights' => READ | CREATE | PURGE | CommonITILValidation::VALIDATE,
], [
'profiles_id' => self::PROFILE_ADMIN,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT
| TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
], [
'profiles_id' => self::PROFILE_SUPER_ADMIN,
Expand Down Expand Up @@ -6935,7 +6935,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_SUPER_ADMIN,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
], [
'profiles_id' => self::PROFILE_HOTLINER,
'name' => 'computer',
Expand Down Expand Up @@ -7229,7 +7229,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_HOTLINER,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT,
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT,
], [
'profiles_id' => self::PROFILE_TECHNICIAN,
'name' => 'computer',
Expand Down Expand Up @@ -7524,7 +7524,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_TECHNICIAN,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT,
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT,
], [
'profiles_id' => self::PROFILE_SUPERVISOR,
'name' => 'computer',
Expand Down Expand Up @@ -7755,7 +7755,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_SUPERVISOR,
'name' => 'changevalidation',
'rights' => CREATE | PURGE | CommonITILValidation::VALIDATE,
'rights' => READ | CREATE | PURGE | CommonITILValidation::VALIDATE,
], [
'profiles_id' => self::PROFILE_ADMIN,
'name' => 'state',
Expand Down Expand Up @@ -7811,7 +7811,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_SUPERVISOR,
'name' => 'ticketvalidation',
'rights' => PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
'rights' => READ | PURGE | TicketValidation::CREATEREQUEST | TicketValidation::CREATEINCIDENT | TicketValidation::VALIDATEREQUEST | TicketValidation::VALIDATEINCIDENT,
], [
'profiles_id' => self::PROFILE_READ_ONLY,
'name' => 'backup',
Expand Down Expand Up @@ -7839,7 +7839,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_READ_ONLY,
'name' => 'changevalidation',
'rights' => self::RIGHT_NONE,
'rights' => READ,
], [
'profiles_id' => self::PROFILE_READ_ONLY,
'name' => 'computer',
Expand Down Expand Up @@ -8095,7 +8095,7 @@ public function getEmptyData(): array
], [
'profiles_id' => self::PROFILE_READ_ONLY,
'name' => 'ticketvalidation',
'rights' => self::RIGHT_NONE,
'rights' => READ,
], [
'profiles_id' => self::PROFILE_READ_ONLY,
'name' => 'transfer',
Expand Down
138 changes: 138 additions & 0 deletions install/migrations/update_11.0.5_to_11.0.6/validation_read_right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2026 Teclib' and contributors.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

use Glpi\DBAL\QueryExpression;

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2026 Teclib' and contributors.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

/** @var DBmysql $DB */
global $DB;

// Add READ right to profiles that already have any ticketvalidation or changevalidation rights.
// Previously, the READ right was explicitly removed from CommonITILValidation::getRights(),
// making it impossible to view validations in read-only contexts (e.g. Object Lock mode).
foreach (['ticketvalidation', 'changevalidation'] as $right_name) {
$DB->update(
'glpi_profilerights',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, we do not change existing "configuration" on update. There is no reliable way to know if it's not been changed, or set on purpose.

[
'rights' => new QueryExpression(
$DB->quoteName('rights') . ' | ' . READ
),
],
[
'name' => $right_name,
['NOT' => ['rights' => 0]],
]
);
}

// Ensure the Object Lock profile also has READ for validation rights,
// so validations remain visible when a ticket/change is viewed in read-only lock mode.
// This is needed separately from the above query because the lock profile may have
// rights = 0 (excluded by the NOT condition above) or may not have an entry at all.
$lock_profile_row = $DB->request([
'SELECT' => 'value',
'FROM' => 'glpi_configs',
'WHERE' => [
'name' => 'lock_lockprofile_id',
'context' => 'core',
],
])->current();

$lock_profile_id = (int) ($lock_profile_row['value'] ?? 0);
if ($lock_profile_id > 0) {
foreach (['ticketvalidation', 'changevalidation'] as $right_name) {
$existing = $DB->request([
'FROM' => 'glpi_profilerights',
'WHERE' => [
'profiles_id' => $lock_profile_id,
'name' => $right_name,
],
]);

if (count($existing) > 0) {
$DB->update(
'glpi_profilerights',
[
'rights' => new QueryExpression(
$DB->quoteName('rights') . ' | ' . READ
),
],
[
'profiles_id' => $lock_profile_id,
'name' => $right_name,
]
);
} else {
$DB->insert(
'glpi_profilerights',
[
'profiles_id' => $lock_profile_id,
'name' => $right_name,
'rights' => READ,
]
);
}
}
}
14 changes: 3 additions & 11 deletions src/CommonITILValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static function canView(): bool
return Session::haveRightsOr(
static::$rightname,
array_merge(
[READ],
static::getCreateRights(),
static::getValidateRights(),
static::getPurgeRights()
Expand Down Expand Up @@ -1026,16 +1027,7 @@ private function showSummary(CommonITILObject $itil): void
{
global $CFG_GLPI, $DB;

if (
!Session::haveRightsOr(
static::$rightname,
array_merge(
static::getCreateRights(),
static::getValidateRights(),
static::getPurgeRights()
)
)
) {
if (!static::canView()) {
return;
}

Expand Down Expand Up @@ -1795,7 +1787,7 @@ public function getRights($interface = 'central')
{

$values = parent::getRights();
unset($values[UPDATE], $values[READ]);
unset($values[UPDATE]);

$values[self::VALIDATE] = __('Validate');

Expand Down
2 changes: 1 addition & 1 deletion src/TicketValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getRights($interface = 'central')
{

$values = parent::getRights();
unset($values[UPDATE], $values[CREATE], $values[READ]);
unset($values[UPDATE], $values[CREATE]);

$values[self::CREATEREQUEST]
= ['short' => __('Create for request'),
Expand Down
Loading