mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-07-01 00:08:42 +02:00
Modernize permission handling
This commit is contained in:

committed by
Johan Cwiklinski

parent
9e17e9d8fa
commit
bcdae86820
@ -46,43 +46,17 @@ use Session;
|
||||
class Example extends CommonDBTM {
|
||||
|
||||
static $tags = '[EXAMPLE_ID]';
|
||||
public static $rightname = 'plugin_example';
|
||||
|
||||
// Should return the localized name of the type
|
||||
static function getTypeName($nb = 0) {
|
||||
return 'Example Type';
|
||||
}
|
||||
|
||||
|
||||
static function canCreate() {
|
||||
|
||||
if (isset($_SESSION["glpi_plugin_example_profile"])) {
|
||||
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static function canView() {
|
||||
|
||||
if (isset($_SESSION["glpi_plugin_example_profile"])) {
|
||||
return ($_SESSION["glpi_plugin_example_profile"]['example'] == 'w'
|
||||
|| $_SESSION["glpi_plugin_example_profile"]['example'] == 'r');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see CommonGLPI::getMenuName()
|
||||
**/
|
||||
static function getMenuName() {
|
||||
return __('Example plugin');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see CommonGLPI::getAdditionalMenuLinks()
|
||||
**/
|
||||
static function getAdditionalMenuLinks() {
|
||||
global $CFG_GLPI;
|
||||
$links = [];
|
||||
@ -406,11 +380,6 @@ class Example extends CommonDBTM {
|
||||
|
||||
//////////////////////////////
|
||||
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////
|
||||
/**
|
||||
* @since version 0.85
|
||||
*
|
||||
* @see CommonDBTM::getSpecificMassiveActions()
|
||||
**/
|
||||
function getSpecificMassiveActions($checkitem = null) {
|
||||
|
||||
$actions = parent::getSpecificMassiveActions($checkitem);
|
||||
@ -423,12 +392,6 @@ class Example extends CommonDBTM {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since version 0.85
|
||||
*
|
||||
* @see CommonDBTM::showMassiveActionsSubForm()
|
||||
**/
|
||||
static function showMassiveActionsSubForm(MassiveAction $ma) {
|
||||
|
||||
switch ($ma->getAction()) {
|
||||
|
85
src/Profile.php
Normal file
85
src/Profile.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Example plugin for GLPI
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This file is part of Example.
|
||||
*
|
||||
* Example 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Example 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 Example. If not, see <http://www.gnu.org/licenses/>.
|
||||
* -------------------------------------------------------------------------
|
||||
* @copyright Copyright (C) 2006-2022 by Example plugin team.
|
||||
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @link https://github.com/pluginsGLPI/example
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonGLPI;
|
||||
use Html;
|
||||
use Session;
|
||||
|
||||
final class Profile extends \Profile
|
||||
{
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
return __('Example plugin');
|
||||
}
|
||||
|
||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||
{
|
||||
$profile = new self();
|
||||
$profile->showFormExample($item->getID());
|
||||
}
|
||||
|
||||
public function showFormExample(int $profiles_id): void
|
||||
{
|
||||
if (!$this->can($profiles_id, READ)) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo "<div class='spaced'>";
|
||||
|
||||
$can_edit = Session::haveRight(self::$rightname, UPDATE);
|
||||
if ($can_edit) {
|
||||
echo "<form method='post' action='" . htmlspecialchars(self::getFormURL()) . "'>";
|
||||
}
|
||||
|
||||
$matrix_options = [
|
||||
'canedit' => $can_edit,
|
||||
];
|
||||
$rights = [
|
||||
[
|
||||
'itemtype' => Example::class,
|
||||
'label' => Example::getTypeName(Session::getPluralNumber()),
|
||||
'field' => Example::$rightname
|
||||
]
|
||||
];
|
||||
$matrix_options['title'] = self::getTypeName(1);
|
||||
$this->displayRightsChoiceMatrix($rights, $matrix_options);
|
||||
|
||||
if ($can_edit) {
|
||||
echo "<div class='text-center'>";
|
||||
echo Html::hidden('id', ['value' => $profiles_id]);
|
||||
echo Html::submit(_sx('button', 'Save'), ['name' => 'update']);
|
||||
echo "</div>\n";
|
||||
Html::closeForm();
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user