aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-10-15 12:09:53 +0100
committerStruan Donald <struan@exo.org.uk>2018-10-19 14:31:45 +0100
commit00db75c5734b3bd6229599e741622b25405c3b9c (patch)
tree93e27afb7b07c63dcf8d3cfbb98a0b0b46eda7c1
parent39b2948d786aaa528adbd7afb2ff6a5cbdb541cd (diff)
list user's alerts on user edit page in admin
Include a list of alerts the user is subscribed to at the bottom of the user_edit page in the admin.
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm26
-rw-r--r--templates/web/base/admin/user-alerts.html49
-rw-r--r--templates/web/base/admin/user_edit.html2
3 files changed, 77 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 8ccc5b8d3..e13a4b7ca 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1512,6 +1512,10 @@ sub user_edit : Path('user_edit') : Args(1) {
$c->forward('fetch_all_bodies');
$c->forward('fetch_body_areas', [ $user->from_body ]) if $user->from_body;
+ unless ( $c->cobrand->moniker eq 'zurich' ) {
+ $c->forward('user_alert_details');
+ }
+
if ( defined $c->flash->{status_message} ) {
$c->stash->{status_message} =
'<p><em>' . $c->flash->{status_message} . '</em></p>';
@@ -1847,6 +1851,28 @@ sub get_user : Private {
return $user;
}
+sub user_alert_details : Private {
+ my ( $self, $c ) = @_;
+
+ my @alerts = $c->stash->{user}->alerts({}, { prefetch => 'alert_type' })->all;
+ $c->stash->{alerts} = \@alerts;
+
+ my @wards;
+
+ for my $alert (@alerts) {
+ if ($alert->alert_type->ref eq 'ward_problems') {
+ push @wards, $alert->parameter2;
+ }
+ }
+
+ if (@wards) {
+ $c->stash->{alert_areas} = mySociety::MaPit::call('areas', join(',', @wards) );
+ }
+
+ my %body_names = map { $_->{id} => $_->{name} } @{ $c->stash->{bodies} };
+ $c->stash->{body_names} = \%body_names;
+}
+
=item log_edit
$c->forward( 'log_edit', [ $object_id, $object_type, $action_performed ] );
diff --git a/templates/web/base/admin/user-alerts.html b/templates/web/base/admin/user-alerts.html
new file mode 100644
index 000000000..1da9729d7
--- /dev/null
+++ b/templates/web/base/admin/user-alerts.html
@@ -0,0 +1,49 @@
+[% IF alerts.size %]
+<h3>[% loc("User's alerts") %]</h3>
+<table>
+<tr>
+ <th>[% loc('ID') %]</th>
+ <th>[% loc('Type') %]</th>
+ <th>[% loc('Confirmed') %]</th>
+ <th>[% loc('State') %]</th>
+ <th>[% loc('Details') %]</th>
+</tr>
+[% FOREACH alert IN alerts %]
+<tr>
+ <td>[% alert.id %]</td>
+ <td>[% alert.alert_type.ref %]</td>
+ <td>[% IF alert.confirmed %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td>
+ <td>[% loc('Subscribed:') %] [% alert.whensubscribed %]
+ <br>[% loc('Disabled:') %] [% alert.whendisabled %]
+ </td>
+ <td>
+ [% SWITCH alert.alert_type.ref %]
+ [% CASE 'new_updates' %]
+ [% tprintf( loc('New updates on report <a href="%s">%s</a>'), c.uri_for( '/report', alert.parameter ), alert.parameter ) %]
+ [% CASE 'local_problems' %]
+ [% tprintf( loc('New problems near <a href="%s">%s,%s</a>'), c.uri_for( '/around', { lon => alert.parameter, lat => alert.parameter2 } ), alert.parameter, alert.parameter2 ) %]
+ [% CASE 'ward_problems' %]
+ [% body = alert.parameter %]
+ [% ward = alert.parameter2 %]
+ [% IF alert_areas.$ward AND body_names.$body %]
+ [% tprintf( loc('New problems for <a href="%s">%s</a> ward in <a href="%s">%s</a>'), c.uri_for('/reports', body_names.$body, alert_areas.$ward.name), alert_areas.$ward.name, c.uri_for('/reports', body_names.$body), body_names.$body ) %]
+ [% ELSE %]
+ [% tprintf( loc('New problems for ward id %s in body id %s'), alert.parameter2, body ) %]
+ [% END %]
+ [% CASE 'council_problems' %]
+ [% body = alert.parameter %]
+ [% IF body_names.$body %]
+ [% tprintf( loc('New problems for <a href="%s">%s</a>'), c.uri_for('/reports', body_names.$body) body_names.$body ) %]
+ [% ELSE %]
+ [% tprintf( loc('New problems for %s'), body ) %]
+ [% END %]
+ [% CASE 'area_problems' %]
+ [% tprintf( loc('New problems for area id <a href="%s">%s</a>'), c.config.MAPIT_URL _ 'area/' _ alert.parameter _ '.html', alert.parameter ) %]
+ [% CASE %]
+ [% alert.parameter %] [% alert.parameter2 %]
+ [% END %]
+ </td>
+</tr>
+[% END %]
+</table>
+[% END %]
diff --git a/templates/web/base/admin/user_edit.html b/templates/web/base/admin/user_edit.html
index 5bfdf341f..cc456914d 100644
--- a/templates/web/base/admin/user_edit.html
+++ b/templates/web/base/admin/user_edit.html
@@ -10,4 +10,6 @@
[% INCLUDE 'admin/user-form.html' %]
+[% INCLUDE 'admin/user-alerts.html' %]
+
[% INCLUDE 'admin/footer.html' %]