diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 88 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 16 | ||||
-rw-r--r-- | t/app/controller/admin.t | 1 | ||||
-rw-r--r-- | t/app/controller/report_as_other.t | 1 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 57 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 30 | ||||
-rw-r--r-- | templates/web/base/report/updates.html | 50 |
9 files changed, 185 insertions, 60 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 61982c47a..aad91429a 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -713,6 +713,7 @@ sub available_permissions { planned_reports => _("Manage shortlist"), contribute_as_another_user => _("Create reports/updates on a user's behalf"), contribute_as_body => _("Create reports/updates as the council"), + view_body_contribute_details => _("See user detail for reports created as the council"), # NB this permission is special in that it can be assigned to users # without their from_body being set. It's included here for diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 64ca7fc62..4e900e653 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -200,6 +200,7 @@ sub available_permissions { my $perms = $self->next::method(); $perms->{Problems}->{contribute_as_body} = "Create reports/updates as " . $self->council_name; + $perms->{Problems}->{view_body_contribute_details} = "See user detail for reports created as " . $self->council_name; $perms->{Users}->{user_assign_areas} = "Assign users to areas in " . $self->council_name; return $perms; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index f5601639a..fb41bc7f0 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -6,6 +6,7 @@ package FixMyStreet::DB::Result::Comment; use strict; use warnings; +use FixMyStreet::Template; use base 'DBIx::Class::Core'; __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); @@ -199,7 +200,7 @@ __PACKAGE__->has_many( "admin_log_entries", "FixMyStreet::DB::Result::AdminLog", { "foreign.object_id" => "self.id" }, - { + { cascade_copy => 0, cascade_delete => 0, where => { 'object_type' => 'update' }, } @@ -223,4 +224,89 @@ __PACKAGE__->might_have( { cascade_copy => 0, cascade_delete => 1 }, ); +=head2 meta_line + +Returns a string to be used on a report update, describing some of the metadata +about an update + +=cut + +sub meta_line { + my ( $self, $c ) = @_; + + my $meta = ''; + + $c->stash->{last_state} ||= ''; + + if ($self->anonymous or !$self->name) { + $meta = sprintf( _( 'Posted anonymously at %s' ), Utils::prettify_dt( $self->confirmed ) ) + } elsif ($self->user->from_body) { + my $user_name = FixMyStreet::Template::html_filter($self->user->name); + my $body = $self->user->body; + if ($body eq 'Bromley Council') { + $body = "$body <img src='/cobrands/bromley/favicon.png' alt=''>"; + } + if ($c->user_exists and $c->user->has_permission_to('view_body_contribute_details', $self->problem->bodies_str_ids)) { + $meta = sprintf( _( 'Posted by <strong>%s</strong> (%s) at %s' ), $body, $user_name, Utils::prettify_dt( $self->confirmed ) ); + } else { + $meta = sprintf( _( 'Posted by <strong>%s</strong> at %s' ), $body, Utils::prettify_dt( $self->confirmed ) ); + } + } else { + $meta = sprintf( _( 'Posted by %s at %s' ), FixMyStreet::Template::html_filter($self->name), Utils::prettify_dt( $self->confirmed ) ) + } + + my $update_state = ''; + + if ($self->mark_fixed) { + $update_state = _( 'marked as fixed' ); + } elsif ($self->mark_open) { + $update_state = _( 'reopened' ); + } elsif ($self->problem_state) { + my $state = $self->problem_state_display; + + if ($state eq 'confirmed') { + if ($c->stash->{last_state}) { + $update_state = _( 'reopened' ) + } + } elsif ($state eq 'investigating') { + $update_state = _( 'marked as investigating' ) + } elsif ($state eq 'planned') { + $update_state = _( 'marked as planned' ) + } elsif ($state eq 'in progress') { + $update_state = _( 'marked as in progress' ) + } elsif ($state eq 'action scheduled') { + $update_state = _( 'marked as action scheduled' ) + } elsif ($state eq 'closed') { + $update_state = _( 'marked as closed' ) + } elsif ($state eq 'fixed') { + $update_state = _( 'marked as fixed' ) + } elsif ($state eq 'unable to fix') { + $update_state = _( 'marked as unable to fix' ) + } elsif ($state eq 'not responsible') { + $update_state = _( "marked as not the council's responsibility" ) + } elsif ($state eq 'duplicate') { + $update_state = _( 'closed as a duplicate report' ) + } elsif ($state eq 'internal referral') { + $update_state = _( 'marked as an internal referral' ) + } + + if ($c->cobrand->moniker eq 'bromley' || $self->problem->bodies_str eq '2482') { + if ($state eq 'unable to fix') { + $update_state = 'marked as no further action'; + } elsif ($state eq 'not responsible') { + $update_state = 'marked as third party responsibility' + } + } + + } + + if ($update_state ne $c->stash->{last_state} and $update_state) { + $meta .= ", $update_state"; + } + + $c->stash->{last_state} = $update_state; + + return $meta; +}; + 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 203e72fae..92c5c160a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -606,20 +606,28 @@ sub meta_line { $meta = sprintf( _('Reported anonymously at %s'), $date_time ); } } else { + my $problem_name = $problem->name; + + if ($c->user_exists and + $c->user->has_permission_to('view_body_contribute_details', $problem->bodies_str_ids) and + $problem->name ne $problem->user->name) { + $problem_name = sprintf( _('%s (%s)'), $problem->name, $problem->user->name ); + } + if ( $problem->service and $category && $category ne _('Other') ) { $meta = sprintf( _('Reported via %s in the %s category by %s at %s'), $problem->service, $category, - $problem->name, $date_time + $problem_name, $date_time ); } elsif ( $problem->service ) { $meta = sprintf( _('Reported via %s by %s at %s'), - $problem->service, $problem->name, $date_time ); + $problem->service, $problem_name, $date_time ); } elsif ( $category and $category ne _('Other') ) { $meta = sprintf( _('Reported in the %s category by %s at %s'), - $category, $problem->name, $date_time ); + $category, $problem_name, $date_time ); } else { - $meta = sprintf( _('Reported by %s at %s'), $problem->name, $date_time ); + $meta = sprintf( _('Reported by %s at %s'), $problem_name, $date_time ); } } diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 1ab0cb488..ab6cac842 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1190,6 +1190,7 @@ my %default_perms = ( "permissions[report_instruct]" => undef, "permissions[contribute_as_another_user]" => undef, "permissions[contribute_as_body]" => undef, + "permissions[view_body_contribute_details]" => undef, "permissions[user_edit]" => undef, "permissions[user_manage_permissions]" => undef, "permissions[user_assign_body]" => undef, diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index 505a1bf6b..b4405be57 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -191,4 +191,3 @@ sub dropdown_shown { my ($shown, $name) = @_; is grep({ $_ eq 'form_as' } keys %{$mech->visible_form_values($name)}), $shown, "Dropdown shown = $shown"; } - diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index fad8b2bbb..b35a4a026 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -210,13 +210,13 @@ foreach my $meta ( $report->update; subtest "test correct problem meta information" => sub { $mech->get_ok("/report/$report_id"); - + is $mech->extract_problem_meta, $meta->{meta}; }; } -for my $test ( +for my $test ( { description => 'new report', date => DateTime->now, @@ -385,7 +385,7 @@ for my $test ( my $body_westminster = $mech->create_body_ok(2504, 'Westminster City Council'); my $body_camden = $mech->create_body_ok(2505, 'Camden Borough Council'); -for my $test ( +for my $test ( { desc => 'no state dropdown if user not from authority', from_body => undef, @@ -530,6 +530,57 @@ subtest "Zurich banners are displayed correctly" => sub { }; }; +my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); +my $oxfordshireuser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxfordshire); + +subtest "check user details show when a user has correct permissions" => sub { + $report->update( { + name => 'Oxfordshire County Council', + user_id => $oxfordshireuser->id, + service => '', + anonymous => 'f', + bodies_str => $oxfordshire->id, + confirmed => '2012-01-10 15:17:00' + }); + + ok $oxfordshireuser->user_body_permissions->create({ + body => $oxfordshire, + permission_type => 'view_body_contribute_details', + }); + + $mech->log_in_ok( $oxfordshireuser->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council (Council User) at 15:17, Tue 10 January 2012', + 'correct problem meta information'; + + ok $oxfordshireuser->user_body_permissions->delete_all, "Remove view_body_contribute_details permissions"; + + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012', + 'correct problem meta information for user without relevant permissions'; + + $mech->log_out_ok; + + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Oxfordshire County Council at 15:17, Tue 10 January 2012', + 'correct problem meta information for logged out user'; + +}; + +subtest "check brackets don't appear when username and report name are the same" => sub { + $report->update( { + name => 'Council User' + }); + + $mech->log_in_ok( $oxfordshireuser->email ); + ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; + is $mech->extract_problem_meta, + 'Reported in the Roads category by Council User at 15:17, Tue 10 January 2012', + 'correct problem meta information'; +}; END { $mech->delete_user('test@example.com'); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f7544f0a1..6fc7bb8e1 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -653,6 +653,18 @@ for my $test ( state => 'fixed - council', report_bodies => $body->id . ',2505', }, + { + desc => 'from authority user show username for users with correct permissions', + fields => { + name => $user->name, + may_show_name => 1, + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + report_bodies => $body->id . ',2505', + view_username => 1 + }, ) { subtest $test->{desc} => sub { $report->comments->delete; @@ -662,6 +674,14 @@ for my $test ( } $mech->log_in_ok( $user->email ); + + if ($test->{view_username}) { + ok $user->user_body_permissions->create({ + body => $body, + permission_type => 'view_body_contribute_details' + }), 'Give user view_body_contribute_details permissions'; + } + $user->from_body( $body->id ); $user->update; @@ -690,8 +710,14 @@ for my $test ( } else { like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change'; } - like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name'; - $mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold'); + + if ($test->{view_username}) { + like $update_meta->[0], qr{Westminster City Council \(Test User\)}, 'update meta includes council and user name'; + $user->user_body_permissions->delete_all; + } else { + like $update_meta->[0], qr{Westminster City Council}, 'update meta includes council name'; + $mech->content_contains( '<strong>Westminster City Council</strong>', 'council name in bold'); + } $report->discard_changes; is $report->state, $test->{state}, 'state set'; diff --git a/templates/web/base/report/updates.html b/templates/web/base/report/updates.html index ff48ecbca..75e94b1d5 100644 --- a/templates/web/base/report/updates.html +++ b/templates/web/base/report/updates.html @@ -11,54 +11,6 @@ [% RETURN %] [% END %] - [% IF update.anonymous || update.name == '' %] - [% tprintf( loc( 'Posted anonymously at %s' ), prettify_dt( update.confirmed ) ) -%] - [%- ELSIF update.user.from_body; - user_name = update.user.name | html; - body = update.user.body; - IF body == 'Bromley Council'; - body = "$body <img src='/cobrands/bromley/favicon.png' alt=''>"; - END %] - [% tprintf( loc( 'Posted by %s (<strong>%s</strong>) at %s' ), user_name, body, prettify_dt( update.confirmed ) ) -%] - [%- ELSE %] - [% tprintf( loc( 'Posted by %s at %s' ), update.name, prettify_dt( update.confirmed ) ) | html -%] - [%- END -%] + [% update.meta_line(c) %] - [%- update_state = '' %] - [%- IF update.mark_fixed %][% update_state = loc( 'marked as fixed' ) %][% END %] - [%- IF update.mark_open %][% update_state = loc( 'reopened' ) %][% END %] - [%- IF !update_state && update.problem_state %] - [%- state = update.problem_state_display %] - [%- IF c.cobrand.moniker == 'bromley' OR problem.bodies_str == '2482' %] - [%- SET update_state = 'marked as no further action' IF state == 'unable to fix' %] - [%- SET update_state = 'marked as third party responsibility' IF state == 'not responsible' %] - [%- END %] - [%- END %] - [%- IF !update_state && update.problem_state %] - [%- IF state == 'confirmed' AND global.last_state != '' %] - [%- update_state = loc( 'reopened' ) %] - [%- ELSIF state == 'investigating' %] - [%- update_state = loc( 'marked as investigating' ) %] - [%- ELSIF state == 'planned' %] - [%- update_state = loc( 'marked as planned' ) %] - [%- ELSIF state == 'in progress' %] - [%- update_state = loc( 'marked as in progress' ) %] - [%- ELSIF state == 'action scheduled' %] - [%- update_state = loc( 'marked as action scheduled' ) %] - [%- ELSIF state == 'closed' %] - [%- update_state = loc( 'marked as closed' ) %] - [%- ELSIF state == 'fixed' %] - [%- update_state = loc( 'marked as fixed' ) %] - [%- ELSIF state == 'unable to fix' %] - [%- update_state = loc( 'marked as unable to fix' ) %] - [%- ELSIF state == 'not responsible' %] - [%- update_state = loc( "marked as not the council's responsibility" ) %] - [%- ELSIF state == 'duplicate' %] - [%- update_state = loc( 'closed as a duplicate report' ) %] - [%- ELSIF state == 'internal referral' %] - [%- update_state = loc( 'marked as an internal referral' ) %] - [%- END %] - [%- END %] - [%- ", " _ update_state IF update_state != global.last_state %] - [%- global.last_state = update_state %] [% END %] |