forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expand read and update permissions for assets
- Loading branch information
Showing
16 changed files
with
177 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* | ||
* GLPI - Gestionnaire Libre de Parc Informatique | ||
* | ||
* http://glpi-project.org | ||
* | ||
* @copyright 2015-2023 Teclib' and contributors. | ||
* @copyright 2003-2014 by the INDEPNET Development Team. | ||
* @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/>. | ||
* | ||
* --------------------------------------------------------------------- | ||
*/ | ||
|
||
namespace Glpi\Features; | ||
|
||
use Glpi\DBAL\QueryExpression; | ||
use Session; | ||
|
||
trait AssignableAsset | ||
{ | ||
// TODO with PHP 8.2, we can use constants for these rights | ||
public static int $read_assigned = 256; | ||
public static int $update_assigned = 512; | ||
|
||
public static function canView() | ||
{ | ||
return Session::haveRightsOr(static::$rightname, [READ, self::$read_assigned]); | ||
} | ||
|
||
public function canViewItem() | ||
{ | ||
if (!parent::canViewItem()) { | ||
return false; | ||
} | ||
|
||
$is_assigned = $this->fields['users_id_tech'] === $_SESSION['glpiID'] || | ||
in_array((int) ($this->fields['groups_id_tech'] ?? 0), $_SESSION['glpigroups'], true); | ||
|
||
if (!Session::haveRight(static::$rightname, READ)) { | ||
return $is_assigned && Session::haveRight(static::$rightname, self::$read_assigned); | ||
} | ||
|
||
// Has global READ right | ||
return true; | ||
} | ||
|
||
public static function canUpdate() | ||
{ | ||
return Session::haveRightsOr(static::$rightname, [UPDATE, self::$update_assigned]); | ||
} | ||
|
||
public function canUpdateItem() | ||
{ | ||
if (!parent::canUpdateItem()) { | ||
return false; | ||
} | ||
|
||
$is_assigned = $this->fields['users_id_tech'] === $_SESSION['glpiID'] || | ||
in_array((int) ($this->fields['groups_id_tech'] ?? 0), $_SESSION['glpigroups'], true); | ||
|
||
if (!Session::haveRight(static::$rightname, UPDATE)) { | ||
return $is_assigned && Session::haveRight(static::$rightname, self::$update_assigned); | ||
} | ||
|
||
// Has global UPDATE right | ||
return true; | ||
} | ||
|
||
public static function canDelete() | ||
{ | ||
return parent::canDelete() && static::canUpdate(); | ||
} | ||
|
||
public function canDeleteItem() | ||
{ | ||
return parent::canDeleteItem() && $this->canUpdateItem(); | ||
} | ||
|
||
public static function canPurge() | ||
{ | ||
return parent::canPurge() && static::canUpdate(); | ||
} | ||
|
||
public function canPurgeItem() | ||
{ | ||
return parent::canPurgeItem() && $this->canUpdateItem(); | ||
} | ||
|
||
public static function getAssignableVisiblityCriteria() | ||
{ | ||
if (Session::haveRight(static::$rightname, READ)) { | ||
return [new QueryExpression('1')]; | ||
} | ||
if (Session::haveRight(static::$rightname, self::$read_assigned)) { | ||
return [ | ||
'OR' => [ | ||
'users_id_tech' => $_SESSION['glpiID'], | ||
'groups_id_tech' => $_SESSION['glpigroups'], | ||
], | ||
]; | ||
} | ||
return [new QueryExpression('0')]; | ||
} | ||
|
||
/** | ||
* @param string $interface | ||
* @phpstan-param 'central'|'helpdesk' $interface | ||
* @return array | ||
* @phpstan-return array<integer, string|array> | ||
*/ | ||
public function getRights($interface = 'central') | ||
{ | ||
$rights = parent::getRights($interface); | ||
$rights[READ] = __('View all'); | ||
$rights[self::$read_assigned] = __('View assigned'); | ||
$rights[UPDATE] = __('Update all'); | ||
$rights[self::$update_assigned] = __('Update assigned'); | ||
return $rights; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters