Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set user status, confirm user delete, select scalar value #1686

Merged
merged 3 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/js/app/editor/Components/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default {
},
},
mounted() {
const _values = this.value.map ? this.value : [];
const _values = this.value.map ? this.value : [this.value];
const _options = this.options;

let filterSelectedItems = _values.map(value => {
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/Backend/UserEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ public function edit(?User $user): Response
$this->dispatcher->dispatch($event, UserEvent::ON_EDIT);

$roles = array_merge($this->getParameter('security.role_hierarchy.roles'), $event->getRoleOptions()->toArray());
$statuses = UserStatus::all();

return $this->renderTemplate('@bolt/users/edit.html.twig', [
'display_name' => $user->getDisplayName(),
'userEdit' => $user,
'roles' => $roles,
'suggestedPassword' => $suggestedPassword,
'statuses' => $statuses,
]);
}

Expand Down Expand Up @@ -144,6 +146,7 @@ public function save(?User $user, ValidatorInterface $validator): Response
$displayName = $user->getDisplayName();
$locale = Json::findScalar($this->getFromRequest('locale'));
$roles = (array) Json::findScalar($this->getFromRequest('roles'));
$status = Json::findScalar($this->getFromRequest('ustatus', UserStatus::ENABLED));

if (empty($user->getUsername())) {
$user->setUsername($this->getFromRequest('username'));
Expand All @@ -153,7 +156,7 @@ public function save(?User $user, ValidatorInterface $validator): Response
$user->setLocale($locale);
$user->setRoles($roles);
$user->setbackendTheme($this->getFromRequest('backendTheme'));
$user->setStatus($this->getFromRequest('status', UserStatus::ENABLED));
$user->setStatus($status);

$newPassword = $this->getFromRequest('password');
// Set the plain password to check for validation
Expand Down
19 changes: 19 additions & 0 deletions templates/users/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@
'required': true,
} %}

{% set statusOptions = [] %}
{% for option in statuses ?? [] %}
{% set statusOptions = statusOptions|merge([
{
'key': option,
'value': option|capitalize
}
]) %}
{% endfor %}

{% include '@bolt/_partials/fields/select.html.twig' with {
'id': 'ustatus',
'label': 'field.status'|trans,
'name': 'ustatus',
'value': userEdit.status,
'options': statusOptions,
'required': true,
} %}

{# TODO: include form field with '@bolt/_partials/fields/select.html.twig' #}
{# Comment out for a while, until we work on this again
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion templates/users/listing.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{% if iteratedUser.status !== 'enabled' %}
{{ macro.buttonlink('action.enable', path('bolt_user_update_status', {'id': iteratedUser.id, '_csrf_token': csrf_token('useredit'), 'status': 'enabled'}), 'thumbs-up', 'secondary sm') }}
{% endif %}
{{ macro.buttonlink('action.delete', path('bolt_user_delete', {'id': iteratedUser.id, '_csrf_token': csrf_token('useredit')}), 'trash', 'danger sm') }}
{{ macro.buttonlink('action.delete', path('bolt_user_delete', {'id': iteratedUser.id, '_csrf_token': csrf_token('useredit')}), 'trash', 'danger sm', {'data-confirmation': 'action.confirm_delete'|trans }) }}
{% endif %}
</td>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Feature: Users & Permissions

#delete button for new user
When I click "body > div.admin > div.admin__body > div.admin__body--container > main > table:nth-child(1) > tbody > tr:nth-child(5) > td:nth-child(7) > a.btn.btn-danger.mb-3.text-nowrap"
And I wait 1 second
Then I should see "Are you sure you wish to delete this content?"
When I press "OK"

Then I should be on "/bolt/users"
And I should see 5 rows in the "body > div.admin > div.admin__body > div.admin__body--container > main > table:nth-child(1)" table
And I should not see "test_user"
Expand Down