Skip to content

Commit

Permalink
Filter out restricted permissions in enterprise mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Jun 14, 2024
1 parent 1bbd028 commit c4bdc30
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class UserGroupOptionACPSearchResultProvider extends AbstractCategorizedACPSearc
*/
protected $listClassName = UserGroupOptionCategoryList::class;

private array $restrictedOptionNames = [
'admin.configuration.package.canUpdatePackage',
'admin.configuration.package.canEditServer',
'admin.user.canMailUser',
'admin.management.canManageCronjob',
'admin.management.canRebuildData',
'admin.management.canImportData',
];

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -89,6 +98,10 @@ public function search($query)
continue;
}

if ($this->isUnavailableOption($userGroupOption)) {
continue;
}

$link = LinkHandler::getInstance()->getLink('UserGroupOption', ['id' => $userGroupOption->optionID]);
$categoryName = $userGroupOption->categoryName;
$parentCategories = [];
Expand Down Expand Up @@ -119,4 +132,29 @@ public function search($query)

return $results;
}

/**
* @since 6.0
*/
private function isUnavailableOption(UserGroupOption $userGroupOption): bool
{
if (!\defined('ENABLE_ENTERPRISE_MODE') || !\ENABLE_ENTERPRISE_MODE) {
return false;
}

if (!\in_array($userGroupOption->optionName, $this->restrictedOptionNames, true)) {
return false;
}

if (WCF::getUser()->hasOwnerAccess()) {
return false;
}

// Allow the option to appear if the user has this permission.
if (WCF::getSession()->getPermission($userGroupOption->optionName)) {
return false;
}

return true;
}
}

0 comments on commit c4bdc30

Please sign in to comment.