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 492947e
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 19 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 Expand Up @@ -83,7 +84,7 @@
<button class="neos-button neos-button-danger" title="{neos:backend.translate(id: 'users.tooltip.delete', source: 'Modules', package: 'Neos.Neos')}" data-toggle="modal" href="#user-{index}" data-neos-toggle="tooltip">
<i class="fas fa-trash-alt icon-white"></i>
</button>
<div class="neos-hide" id="user-{index}">
<span class="neos-hide" id="user-{index}">
<div class="neos-modal-centered">
<div class="neos-modal-content">
<div class="neos-modal-header">
Expand Down Expand Up @@ -111,7 +112,7 @@
</div>
</div>
<div class="neos-modal-backdrop neos-in"></div>
</div>
</span>
</f:else>
</f:if>
</div>
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 492947e

Please sign in to comment.