aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Users.pm17
-rw-r--r--t/app/controller/admin/users.t8
-rw-r--r--templates/web/base/admin/users/index.html49
3 files changed, 63 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
index 898399cd1..e55a3d111 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
@@ -27,6 +27,23 @@ Admin pages for editing users
sub index :Path : Args(0) {
my ( $self, $c ) = @_;
+ if ($c->req->method eq 'POST') {
+ my @uids = $c->get_param_list('uid');
+ my @role_ids = $c->get_param_list('roles');
+ my $user_rs = FixMyStreet::DB->resultset("User")->search({ id => \@uids });
+ foreach my $user ($user_rs->all) {
+ $user->admin_user_body_permissions->delete;
+ $user->user_roles->search({
+ role_id => { -not_in => \@role_ids },
+ })->delete;
+ foreach my $role (@role_ids) {
+ $user->user_roles->find_or_create({
+ role_id => $role,
+ });
+ }
+ }
+ $c->stash->{status_message} = _('Updated!');
+ }
my $search = $c->get_param('search');
my $role = $c->get_param('role');
diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t
index 534034f1d..ce29a5f7c 100644
--- a/t/app/controller/admin/users.t
+++ b/t/app/controller/admin/users.t
@@ -88,6 +88,14 @@ subtest 'user search' => sub {
$mech->content_contains('test@example.com');
};
+subtest 'user assign role' => sub {
+ $user->remove_from_roles($role);
+ is $user->roles->count, 0;
+ $mech->get_ok('/admin/users');
+ $mech->submit_form_ok({ with_fields => { uid => $user->id, roles => $role->id } });
+ is $user->roles->count, 1;
+};
+
subtest 'search does not show user from another council' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire' ],
diff --git a/templates/web/base/admin/users/index.html b/templates/web/base/admin/users/index.html
index fc4abdfb8..880b4a417 100644
--- a/templates/web/base/admin/users/index.html
+++ b/templates/web/base/admin/users/index.html
@@ -1,6 +1,21 @@
[% INCLUDE 'admin/header.html' title=loc('Search Users') %]
[% PROCESS 'admin/report_blocks.html' %]
+[% BLOCK role_select %]
+<select name="[% label %]" id="[% label %]" class="form-control">
+ <option value="">---</option>
+ [% FOR role IN roles %]
+ [% IF c.user.is_superuser AND last_name != role.body.name %]
+ <optgroup label="[% role.body.name %]">
+ [% SET last_name = role.body.name %]
+ [% END %]
+ <option value="[% role.id %]"[% ' selected' IF role.id == role_selected %]>[% role.name | html %]</option>
+ [% END %]
+</select>
+[% END %]
+
+[% INCLUDE status_message %]
+
<div class="fms-admin-info">
[% loc("User search finds matches in users' names and email addresses.") %]
</div>
@@ -12,16 +27,7 @@
<input class="form-control" type="text" name="search" size="30" id="search" value="[% searched | html %]">
[% IF roles %]
<p><label for="role">[% loc('Role:') %]</label>
- <select name="role" id="role" class="form-control">
- <option value="">---</option>
- [% FOR role IN roles %]
- [% IF c.user.is_superuser AND last_name != role.body.name %]
- <optgroup label="[% role.body.name %]">
- [% SET last_name = role.body.name %]
- [% END %]
- <option value="[% role.id %]"[% ' selected' IF role.id == role_selected %]>[% role.name | html %]</option>
- [% END %]
- </select>
+ [% INCLUDE role_select label='role' %]
[% END %]
<p class="no-label"><input type="submit" value="[% loc('Go') %]" class="btn">
@@ -30,8 +36,10 @@
[% IF users.size %]
+<form method="post">
<table cellspacing="0" cellpadding="2" border="1">
<tr>
+ <th>*</th>
<th>[% loc('Name') %]</th>
<th>[% loc('Email') %]</th>
<th>[% loc('Body') %]</th>
@@ -42,7 +50,13 @@
</tr>
[%- FOREACH user IN users %]
<tr>
- <td>[% PROCESS value_or_nbsp value=user.name %]</td>
+ <td align="center">[% IF user.from_body %]
+ <input type="checkbox" name="uid" value="[% user.id %]" id="uid[% user.id %]">
+ [% END %]</td>
+ <td>[% IF user.from_body %]<label class="inline" for="uid[% user.id %]">[% END %]
+ [% PROCESS value_or_nbsp value=user.name %]
+ [% IF user.from_body %]</label>[% END %]
+ </td>
<td><a href="[% c.uri_for_action( 'admin/reports', search => user.email ) %]">[% PROCESS value_or_nbsp value=user.email %]</a></td>
<td>[% PROCESS value_or_nbsp value=user.from_body.name %]
[% IF user.is_superuser %] * [% END %]
@@ -55,6 +69,19 @@
[%- END -%]
</table>
+<p><label for="roles">[% loc('Assign selected to role:') %]</label>
+[% IF c.user.is_superuser %]
+[% INCLUDE role_select label='roles' %]
+[% ELSE %]
+<select class="form-control js-multiple" id="roles" name="roles" multiple>
+ [% FOREACH role IN roles %]
+ <option value="[% role.id %]">[% role.name | html %]</option>
+ [% END %]
+</select>
+[% END %]
+<p><input class="btn" type="submit" value="[% loc('Save changes') %]">
+</form>
+
[% ELSIF searched || role_selected %]
<div class="fms-admin-warning">