Skip to content

Commit e9d4474

Browse files
stonebuzztrasher
authored andcommitted
add dedicated right
1 parent 433d8ff commit e9d4474

3 files changed

Lines changed: 29 additions & 10 deletions

File tree

ajax/agent.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@
3636
Html::header_nocache();
3737

3838
Session::checkLoginUser();
39-
4039
Session::checkRight("inventory", READ);
41-
42-
$computer = new Computer();
43-
$computer->check($_POST['computers_id'], UPDATE);
44-
40+
Session::checkRight("database_inventory", PluginDatabaseinventoryProfile::RUN_DATABSE_INVENTORY);
4541

4642
if (isset($_POST['action']) && isset($_POST['id'])) {
4743
$agent = new Agent();

inc/inventoryaction.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class PluginDatabaseinventoryInventoryAction extends CommonDBTM
3434
{
3535
public const MA_PARTIAL = 'partial_database_inventory';
3636
private const ENDPOINT_PARTIAL = 'now?';
37+
public static $rightname = 'database_inventory_run_inventory';
3738

3839
public static function showMassiveActionsSubForm(MassiveAction $ma)
3940
{
@@ -168,6 +169,10 @@ public static function postItemForm($item)
168169
return;
169170
}
170171

172+
if (!Session::checkRight("database_inventory", PluginDatabaseinventoryProfile::RUN_DATABSE_INVENTORY)) {
173+
return;
174+
}
175+
171176
if ($item::getType() == Computer::getType()) {
172177
if ($agent = self::findAgent($item)) {
173178
$out = '<div class="mb-3 col-12 col-sm-6">';

inc/profile.class.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class PluginDatabaseinventoryProfile extends Profile
3232
{
3333
public static $rightname = 'profile';
3434

35+
const RUN_DATABSE_INVENTORY = 256;
36+
3537
public static function getTypeName($nb = 0)
3638
{
3739
return __('Database Inventory', 'databaseinventory');
@@ -41,15 +43,31 @@ private static function getAllRights($all = false)
4143
{
4244
$rights = [
4345
[
44-
'itemtype' => PluginDatabaseinventoryDatabaseParam::getType(),
45-
'label' => PluginDatabaseinventoryProfile::getTypeName(),
46-
'field' => 'database_inventory',
46+
'itemtype' => PluginDatabaseinventoryDatabaseParam::getType(),
47+
'label' => PluginDatabaseinventoryProfile::getTypeName(),
48+
'field' => 'database_inventory',
49+
'rights' => [
50+
CREATE => __('Create'),
51+
READ => __('Read'),
52+
UPDATE => __('Update'),
53+
PURGE => ['short' => __('Purge'),
54+
'long' => _x('button', 'Delete permanently'),
55+
],
56+
self::RUN_DATABSE_INVENTORY => __("Run database inventory", "databaseinventory"),
57+
],
4758
],
4859
];
4960

5061
return $rights;
5162
}
5263

64+
function getRights($interface = 'central')
65+
{
66+
$rights = parent::getRights();
67+
$rights[self::RUN_DATABSE_INVENTORY] = __("Run database inventory", "databaseinventory");
68+
return $rights;
69+
}
70+
5371
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
5472
{
5573
if ($item->getType() == 'Profile') {
@@ -96,10 +114,10 @@ private static function showForProfile($profiles_id = 0)
96114
public static function install(Migration $migration)
97115
{
98116
// Add right for administrators
99-
$migration->addRight('database_inventory', PURGE + CREATE + UPDATE + READ, ['config' => UPDATE]);
117+
$migration->addRight('database_inventory', PURGE + CREATE + UPDATE + READ + self::RUN_DATABSE_INVENTORY, ['config' => UPDATE]);
100118

101119
// Add right to the current session
102-
$_SESSION['glpiactiveprofile']['database_inventory'] = PURGE + CREATE + UPDATE + READ;
120+
$_SESSION['glpiactiveprofile']['database_inventory'] = PURGE + CREATE + UPDATE + READ + self::RUN_DATABSE_INVENTORY;
103121

104122
return true;
105123
}

0 commit comments

Comments
 (0)