Skip to content

Commit 21036ad

Browse files
committed
feat: add additional module visibility for Inventory Admins an item keepers to preferences
1 parent cd3c6c0 commit 21036ad

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

languages/en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@
880880
<string name="SYS_INVENTORY_NOTIFICATION_SUBJECT_ITEMS_IMPORTED">Items have been imported into the inventory</string>
881881
<string name="SYS_INVENTORY_NUMBER">Number</string>
882882
<string name="SYS_INVENTORY_NUMBER_DESC">Number of items to be added</string>
883+
<string name="SYS_INVENTORY_ONLY_FOR_ADMINS_AND_KEEPERS">Only for module administrators and item keepers</string>
883884
<string name="SYS_INVENTORY_PROFILE_VIEW">Profile view settings</string>
884885
<string name="SYS_INVENTORY_PROFILE_VIEW_DESC">The selected item fields will be displayed in the member's profile view when the "Display in profile view" option is enabled. By default, only the item name is shown. (Default: "Last Receiver")</string>
885886
<string name="SYS_INVENTORY_PROFILE_VIEW_ENABLED">Display in profile view</string>

modules/inventory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
throw new Exception('SYS_NO_RIGHTS');
6969
} elseif ($gSettingsManager->getInt('inventory_module_enabled') === 3 && !$gCurrentUser->isAdministratorInventory()) {
7070
throw new Exception('SYS_NO_RIGHTS');
71+
} elseif ($gSettingsManager->getInt('inventory_module_enabled') === 4 && !InventoryPresenter::isCurrentUserKeeper() && !$gCurrentUser->isAdministratorInventory()) {
72+
throw new Exception('SYS_NO_RIGHTS');
7173
}
7274

7375
// when saving folders, check whether the subfolder in adm_my_files exists with the corresponding rights

src/Components/Entity/Component.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Admidio\Infrastructure\Exception;
66
use Admidio\Infrastructure\Database;
77
use Admidio\Infrastructure\Entity\Entity;
8+
use Admidio\UI\Presenter\InventoryPresenter;
89

910
/**
1011
* @brief Handle different components of Admidio (e.g. system, plugins or modules) and manage them in the database
@@ -263,7 +264,8 @@ public static function isVisible(string $componentName): bool
263264
case 'INVENTORY':
264265
if ($gSettingsManager->getInt('inventory_module_enabled') === 1
265266
|| ($gSettingsManager->getInt('inventory_module_enabled') === 2 && $gValidLogin)
266-
|| ($gSettingsManager->getInt('inventory_module_enabled') === 3 && $gCurrentUser->isAdministratorInventory())) {
267+
|| ($gSettingsManager->getInt('inventory_module_enabled') === 3 && $gCurrentUser->isAdministratorInventory())
268+
|| ($gSettingsManager->getInt('inventory_module_enabled') === 4 && ($gCurrentUser->isAdministratorInventory() || InventoryPresenter::isCurrentUserKeeper()))) {
267269
return true;
268270
}
269271
break;

src/UI/Presenter/InventoryPresenter.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,21 @@ public static function isKeeperAuthorizedToEdit(?int $keeper = null): bool
715715
*
716716
* @return bool Returns true if the current user is a keeper, false otherwise.
717717
*/
718-
private function isCurrentUserKeeper(): bool
718+
public static function isCurrentUserKeeper(): bool
719719
{
720-
global $gCurrentUser, $gDb;
720+
global $gCurrentUser, $gDb, $gCurrentOrgId;
721721

722722
$sql = 'SELECT COUNT(*) as count FROM ' . TBL_INVENTORY_ITEM_DATA . ' WHERE ind_value = ? AND ind_inf_id = ?';
723-
$params = array($gCurrentUser->getValue('usr_id'), $this->itemsData->getProperty('KEEPER', 'inf_id'));
723+
// read the field id of the keeper field
724+
$sqlKeeperFieldId = 'SELECT inf_id FROM ' . TBL_INVENTORY_FIELDS . ' WHERE inf_name_intern = \'KEEPER\' AND (inf_org_id = ? OR inf_org_id IS NULL) LIMIT 1';
725+
$resultKeeperFieldId = $gDb->queryPrepared($sqlKeeperFieldId, array($gCurrentOrgId));
726+
$rowKeeperFieldId = $resultKeeperFieldId->fetch();
727+
if ($rowKeeperFieldId === false) {
728+
return false;
729+
}
730+
$rowKeeperFieldId = $rowKeeperFieldId['inf_id'];
731+
732+
$params = array($gCurrentUser->getValue('usr_id'), $rowKeeperFieldId);
724733
$result = $gDb->queryPrepared($sql, $params);
725734
$row = $result->fetch();
726735
if ($row['count'] > 0) {

src/UI/Presenter/PreferencesPresenter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ public function createInventoryForm(): string
810810
'0' => $gL10n->get('SYS_DISABLED'),
811811
'1' => $gL10n->get('SYS_ENABLED'),
812812
'2' => $gL10n->get('ORG_ONLY_FOR_REGISTERED_USER'),
813-
'3' => $gL10n->get('ORG_ONLY_FOR_MODULE_ADMINISTRATOR')
813+
'3' => $gL10n->get('ORG_ONLY_FOR_MODULE_ADMINISTRATOR'),
814+
'4' => $gL10n->get('SYS_INVENTORY_ONLY_FOR_ADMINS_AND_KEEPERS')
814815
);
815816
$formInventory->addSelectBox(
816817
'inventory_module_enabled',

src/Users/Entity/User.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,9 +1528,9 @@ public function isAdministratorDocumentsFiles(): bool
15281528
return $this->checkRolesRight('rol_documents_files');
15291529
}
15301530

1531-
/**
1532-
* This method checks if the current user is allowed to administrate documents and files. With this right he can
1533-
* create and edit folders, upload new files and set rights for other users in this module
1531+
/**
1532+
* This method checks if the current user is allowed to administrate the inventory. With this right he can
1533+
* administrate all inventory functionalities
15341534
* @return bool Return **true** if the user is admin of the module otherwise **false**
15351535
* @throws Exception
15361536
*/

0 commit comments

Comments
 (0)