diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | docs/_includes/admin-tasks-content.md | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm | 9 | ||||
-rw-r--r-- | t/app/controller/moderate.t | 8 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 20 | ||||
-rw-r--r-- | templates/web/base/admin/report_edit.html | 13 | ||||
-rw-r--r-- | templates/web/base/report/update.html | 6 | ||||
-rw-r--r-- | templates/web/base/report/update/moderation.html | 6 | ||||
-rw-r--r-- | templates/web/base/report/update/moderation_diff.html | 9 | ||||
-rw-r--r-- | templates/web/base/report/update/moderation_meta.html | 3 | ||||
-rw-r--r-- | templates/web/oxfordshire/footer_extra_js.html | 1 | ||||
-rw-r--r-- | web/cobrands/fixmystreet-uk-councils/council_validation_rules.js | 10 |
14 files changed, 103 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index abca4a7c9..054b8c3ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Unreleased - Admin improvements: + - Include moderation history in report updates. #2379 - Allow moderation to potentially change state. #2381 - Bugfixes - Check cached reports do still have photos before being shown. #2374 diff --git a/docs/_includes/admin-tasks-content.md b/docs/_includes/admin-tasks-content.md index 3a6b60ab9..3a93b284f 100644 --- a/docs/_includes/admin-tasks-content.md +++ b/docs/_includes/admin-tasks-content.md @@ -215,6 +215,9 @@ update. Clicking this button gives you the ability to: You can also add a note to indicate the reason for the change to the report. +Moderation history will be shown within the report updates, and is only visible to people with +the moderate permission. + #### Hiding reports Clicking the moderation button also gives you the option to hide an entire report or its updates. diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 58ce64af6..3078a4a2e 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -233,6 +233,24 @@ sub load_updates : Private { next if $questionnaires_with_updates{$q->id}; push @combined, [ $q->whenanswered, $q ]; } + + # And include moderation changes... + my $problem = $c->stash->{problem}; + my $public_history = $c->cobrand->call_hook(public_moderation_history => $problem); + my $user_can_moderate = $c->user_exists && $c->user->can_moderate($problem); + if ($public_history || $user_can_moderate) { + my @history = $problem->moderation_history; + my $last_history = $problem; + foreach my $history (@history) { + push @combined, [ $history->created, { + type => 'moderation', + last => $last_history, + entry => $history, + } ]; + $last_history = $history; + } + } + @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; $c->stash->{updates} = \@combined; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 9c1e541d4..bc85bb090 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -17,6 +17,18 @@ sub report_validation { $errors->{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 ); } + if ( length( $report->name ) > 70 ) { + $errors->{name} = sprintf( 'Names are limited to %d characters in length.', 70 ); + } + + if ( length( $report->user->phone ) > 30 ) { + $errors->{phone} = sprintf( 'Phone numbers are limited to %s characters in length.', 30 ); + } + + if ( length( $report->user->email ) > 50 ) { + $errors->{username} = sprintf( 'Emails are limited to %s characters in length.', 50 ); + } + return $errors; } diff --git a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm index 01ae1d6e1..1e61b946a 100644 --- a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm +++ b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm @@ -167,7 +167,14 @@ sub compare_extra { push @s, string_diff("$_ = $old->{$_}", ""); } } - return join ', ', @s; + return join ', ', grep { $_ } @s; +} + +sub extra_diff { + my ($self, $other, $key) = @_; + my $o = $self->get_extra_metadata($key); + my $n = $other->get_extra_metadata($key); + return string_diff($o, $n); } sub string_diff { diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index a3474449f..438a81b25 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -257,8 +257,12 @@ subtest 'Problem moderation' => sub { $report->discard_changes; is $report->get_extra_metadata('weather'), 'snow'; is $report->get_extra_metadata('moon'), 'waning full'; - is $report->moderation_original_data->get_extra_metadata('moon'), 'waxing full'; - is $report->moderation_original_data->get_extra_metadata('weather'), undef; + my $mod = $report->moderation_original_data; + is $mod->get_extra_metadata('moon'), 'waxing full'; + is $mod->get_extra_metadata('weather'), undef; + + my $diff = $mod->extra_diff($report, 'moon'); + is $diff, "wa<del style='background-color:#fcc'>x</del><ins style='background-color:#cfc'>n</ins>ing full", 'Correct diff'; }; subtest 'Moderate category' => sub { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 8290faac0..6dc659c19 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -594,6 +594,26 @@ foreach my $test ( changes => { }, errors => [ 'Please enter a subject', 'Please enter some details', 'Names are limited to 40 characters in length.' ], }, + { + msg => 'Oxfordshire validation', + pc => 'OX20 1SZ', + fields => { + title => '', + detail => '', + photo1 => '', + photo2 => '', + photo3 => '', + name => 'This is a really extraordinarily long name that definitely should fail validation', + may_show_name => '1', + username => 'bob.has.a.very.long.email@thisisalonghostname.example.com', + phone => '01234 5678910 09876 54321 ext 203', + category => 'Trees', + password_sign_in => '', + password_register => '', + }, + changes => { }, + errors => [ 'Please enter a subject', 'Please enter some details', 'Emails are limited to 50 characters in length.', 'Phone numbers are limited to 30 characters in length.', 'Names are limited to 70 characters in length.'], + }, ) { subtest "check form errors where $test->{msg}" => sub { diff --git a/templates/web/base/admin/report_edit.html b/templates/web/base/admin/report_edit.html index 175863549..a28950e27 100644 --- a/templates/web/base/admin/report_edit.html +++ b/templates/web/base/admin/report_edit.html @@ -189,17 +189,8 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a> [% last_history = problem %] <ul> [% FOR history IN moderation_history %] - [% SET diff = history.compare_with(last_history) %] - [% SET log = history.admin_log %] - <li><i>[% tprintf(loc('Moderated by %s at %s'), log.user.name OR loc('an administrator'), prettify_dt(history.created)) %] - [%~ IF log.reason %]<br>“[% log.reason %]”[% END %]</i> - [% IF diff.title %]<br>[% loc('Subject:') %] [% diff.title %][% END %] - [% IF diff.detail %]<br>[% loc('Details:') %] [% diff.detail %][% END %] - [% IF diff.photo %]<br>[% loc('Photo') %]: [% diff.photo %][% END %] - [% IF diff.anonymous %]<br>[% loc('Anonymous:') %] [% diff.anonymous %][% END %] - [% IF diff.coords %]<br>[% loc('Latitude/Longitude:') %] [% diff.coords %][% END %] - [% IF diff.category %]<br>[% loc('Category:') %] [% diff.category %][% END %] - [% IF diff.extra %]<br>[% loc('Extra data:') %] [% diff.extra %][% END %] + <li><i>[% INCLUDE 'report/update/moderation_meta.html' %]</i> + [% INCLUDE 'report/update/moderation_diff.html' diff=history.compare_with(last_history) %] </li> [% last_history = history %] [% END %] diff --git a/templates/web/base/report/update.html b/templates/web/base/report/update.html index bac28dd11..6c837b07c 100644 --- a/templates/web/base/report/update.html +++ b/templates/web/base/report/update.html @@ -1,11 +1,11 @@ -[% can_moderate = NOT update.whenanswered AND (permissions.moderate OR c.user.can_moderate(update, staff = permissions.moderate)) %] +[% can_moderate = NOT update.whenanswered AND update.type != 'moderation' AND (permissions.moderate OR c.user.can_moderate(update, staff = permissions.moderate)) %] [% IF loop.first %] <section class="full-width"> <h4 class="static-with-rule">[% loc('Updates') %]</h4> <ul class="item-list item-list--updates"> [% END %] <li class="item-list__item item-list__item--updates - [%~ ' show-moderation' IF show_moderation == update.id ~%] + [%~ ' show-moderation' IF update.id AND show_moderation == update.id ~%] "> <a name="update_[% update.id %]" class="internal-link-fixed-header"></a> [% IF can_moderate; original_update = update.moderation_original_data %] @@ -29,6 +29,8 @@ <div class="item-list__update-text"> <p class="meta-2">[% INCLUDE meta_line %]</p> </div> + [% ELSIF update.type == 'moderation' %] + [% PROCESS 'report/update/moderation.html' %] [% ELSE %] [% INCLUDE 'report/photo.html' object=update %] <div class="item-list__update-text"> diff --git a/templates/web/base/report/update/moderation.html b/templates/web/base/report/update/moderation.html new file mode 100644 index 000000000..3ec9572ef --- /dev/null +++ b/templates/web/base/report/update/moderation.html @@ -0,0 +1,6 @@ +<div class="item-list__update-text"> + [% INCLUDE 'report/update/moderation_diff.html' diff=update.entry.compare_with(update.last) %] + <p class="meta-2"> + [% INCLUDE 'report/update/moderation_meta.html' history=update.entry %] + </p> +</div> diff --git a/templates/web/base/report/update/moderation_diff.html b/templates/web/base/report/update/moderation_diff.html new file mode 100644 index 000000000..1d53736f0 --- /dev/null +++ b/templates/web/base/report/update/moderation_diff.html @@ -0,0 +1,9 @@ +<ul> + [% IF diff.title %]<li>[% loc('Subject:') %] [% diff.title %][% END %] + [% IF diff.detail %]<li>[% loc('Details:') %] [% diff.detail %][% END %] + [% IF diff.photo %]<li>[% loc('Photo') %]: [% diff.photo %][% END %] + [% IF diff.anonymous %]<li>[% loc('Anonymous:') %] [% diff.anonymous %][% END %] + [% IF diff.coords %]<li>[% loc('Latitude/Longitude:') %] [% diff.coords %][% END %] + [% IF diff.category %]<li>[% loc('Category:') %] [% diff.category %][% END %] + [% IF diff.extra %]<li>[% loc('Extra data:') %] [% diff.extra %][% END %] +</ul> diff --git a/templates/web/base/report/update/moderation_meta.html b/templates/web/base/report/update/moderation_meta.html new file mode 100644 index 000000000..571b04850 --- /dev/null +++ b/templates/web/base/report/update/moderation_meta.html @@ -0,0 +1,3 @@ +[% SET log = history.admin_log %] +[%~ tprintf(loc('Moderated by %s at %s'), log.user.name OR loc('an administrator'), prettify_dt(history.created)) %] +[%~ IF log.reason %], “[% log.reason %]”[% END %] diff --git a/templates/web/oxfordshire/footer_extra_js.html b/templates/web/oxfordshire/footer_extra_js.html index 5e24e7321..d95ed2c8e 100644 --- a/templates/web/oxfordshire/footer_extra_js.html +++ b/templates/web/oxfordshire/footer_extra_js.html @@ -4,4 +4,5 @@ version('/cobrands/oxfordshire/js.js'), version('/cobrands/oxfordshire/assets.js'), version('/cobrands/highways/assets.js'), + version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'), ) %] diff --git a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js index b9a4ed252..855d23de9 100644 --- a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js +++ b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js @@ -32,6 +32,16 @@ body_validation_rules = { detail: { required: true, maxlength: 1700 + }, + name: { + required: true, + maxlength: 70 + }, + phone: { + maxlength: 30 + }, + email: { + maxlength: 50 } } }; |