diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Reports.pm | 20 | ||||
-rw-r--r-- | t/app/controller/admin/report_edit.t | 17 |
3 files changed, 39 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e55461ce..4b53ca270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Unreleased - Bugfixes: - Fix issue with dashboard report CSV export. #3026 + - Admin improvements: + - Display user name/email for contributed as reports. #2990 * v3.0.1 (6th May 2020) - New features: diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm index 88c4380fc..4866a657e 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm @@ -234,6 +234,26 @@ sub edit : Path('/admin/report_edit') : Args(1) { push @fields, { name => 'Duplicates', val => join( ',', @{ $problem->get_extra_metadata('duplicates') } ) }; delete $extra->{duplicates}; } + + if ( $extra->{contributed_by} ) { + my $u = $c->cobrand->users->find({id => $extra->{contributed_by}}); + if ( $u ) { + my $uri = $c->uri_for_action('admin/users/index', { search => $u->email } ); + push @fields, { + name => _('Created By'), + val => FixMyStreet::Template::SafeString->new( "<a href=\"$uri\">@{[$u->name]} (@{[$u->email]})</a>" ) + }; + if ( $u->from_body ) { + push @fields, { name => _('Created Body'), val => $u->from_body->name }; + } elsif ( $u->is_superuser ) { + push @fields, { name => _('Created Body'), val => _('Superuser') }; + } + } else { + push @fields, { name => 'contributed_by', val => $extra->{contributed_by} }; + } + delete $extra->{contributed_by}; + } + for my $key ( keys %$extra ) { push @fields, { name => $key, val => $extra->{$key} }; } diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t index 438bcc241..01f091412 100644 --- a/t/app/controller/admin/report_edit.t +++ b/t/app/controller/admin/report_edit.t @@ -9,6 +9,7 @@ my $user2 = $mech->create_user_ok('test2@example.com', name => 'Test User 2'); my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council'); +my $user3 = $mech->create_user_ok('body_user@example.com', name => 'Body User', from_body => $oxfordshire); my $oxfordshirecontact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); @@ -707,4 +708,20 @@ subtest "Test display of fields extra data" => sub { $mech->content_contains('Report URL (report_url)</strong>: http://example.com'); }; +subtest "Test display of contributed_as data" => sub { + $report->update( { extra => undef } ); + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_contains('Extra data: No'); + + $report->set_extra_metadata( contributed_as => 'another_user' ); + $report->set_extra_metadata( contributed_by => $user3->id ); + $report->update; + + $report->discard_changes; + + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->content_like(qr!Created By</strong>: <a[^>]*>Body User \(@{[ $user3->email ]}!); + $mech->content_contains('Created Body</strong>: Oxfordshire County Council'); +}; + done_testing(); |