Skip to content

Commit

Permalink
FEATURE: Filter users by role
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Aug 16, 2024
1 parent ed79f5f commit 0a4db9c
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,51 @@ protected function initializeAction()
* @param string $sortDirection
* @return void
*/
public function indexAction(string $searchTerm = '', string $sortBy = 'accounts.accountIdentifier', string $sortDirection = QueryInterface::ORDER_ASCENDING): void
public function indexAction(
string $searchTerm = '',
string $sortBy = 'accounts.accountIdentifier',
string $sortDirection = QueryInterface::ORDER_ASCENDING,
string $role = null,
): void
{
$allowedRoles = $this->getAllowedRoles();

if (empty($searchTerm)) {
$users = $this->userService->getUsers($sortBy, $sortDirection);
} else {
$users = $this->userService->searchUsers($searchTerm, $sortBy, $sortDirection);
}

if ($role) {
$roleExists = false;
foreach ($allowedRoles as $allowedRole) {
if ($allowedRole->getIdentifier() === $role) {
$roleExists = true;
break;
}
}
if (!$roleExists) {
throw new NoSuchRoleException(sprintf('The role "%s" does not exist.', $role), 1723796893);
}

$query = $users->getQuery();
$constraints = $query->getConstraint();
$users = $query
->matching($query->logicalAnd(
$constraints,
// FIXME: The like query could yield incorrect results if the role identifier is a substring of another role identifier
$query->like('accounts.roleIdentifiers', '%' . $role . '%', false),
))->execute();
}

$this->view->assignMultiple([
'currentUser' => $this->currentUser,
'users' => $users,
'searchTerm' => $searchTerm,
'sortBy' => $sortBy,
'sortDirection' => $sortDirection,
'allowedRoles' => $allowedRoles,
'role' => $role,
]);
}

Expand Down
9 changes: 2 additions & 7 deletions Neos.Neos/Resources/Private/Styles/Modules/_Modules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,8 @@
}

.neos-search-bar {
button.neos-button {
border-right: 1px solid $grayDark;
}

a.neos-button {
border-left: 1px solid $grayDark;
}
display: flex;
gap: 1px;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<f:form action="index">
<div class="neos-search-bar">
<f:spaceless>
<button class="neos-button"><i class="fas fa-search"></i></button>
<f:form.textfield type="search" name="searchTerm" placeholder="{neos:backend.translate(id: 'search', package: 'Neos.Neos')}" value="{searchTerm}" autofocus="autofocus" />
<f:link.action action="index" class="neos-button"><i class="fas fa-times"></i></f:link.action>
<f:form.select options="{allowedRoles}" name="role" value="{role}" optionLabelField="label" prependOptionLabel="Any role" prependOptionValue="" />
<button class="neos-button"><i class="fas fa-search"></i></button>
</f:spaceless>
</div>
</f:form>
Expand Down
2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/JavaScript/Main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/JavaScript/Main.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Lite.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Lite.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Main.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Minimal.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Neos.Neos/Resources/Public/Styles/Minimal.css.map

Large diffs are not rendered by default.

0 comments on commit 0a4db9c

Please sign in to comment.