diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-10 14:49:30 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-13 08:33:24 +0100 |
commit | f2a5d899308634fb06605a1d8035e19eadb8932a (patch) | |
tree | fe7ecbb80f9699ca8a26eef8dca63acaabf7938f | |
parent | 42bbac994c625e24a6eb645de9c47a7dd2b226ef (diff) |
Add cobrand hook for disallowing title moderation.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Moderate.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 11 | ||||
-rw-r--r-- | t/app/controller/moderate.t | 25 | ||||
-rw-r--r-- | templates/web/base/report/_main.html | 10 |
5 files changed, 48 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 53807228b..508c4b426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Bugfixes: - Fix display of area/pins on body page when using Bing or TonerLite map. - Do not scan through all problems to show /_dev pages. + - Development improvements: + - Cobrand hook for disallowing title moderation. #2228 * v2.4 (6th September 2018) - Security diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm index 45a303309..c47c34f37 100644 --- a/perllib/FixMyStreet/App/Controller/Moderate.pm +++ b/perllib/FixMyStreet/App/Controller/Moderate.pm @@ -75,7 +75,9 @@ sub moderate_report : Chained('report') : PathPart('') : Args(0) { $c->forward('report_moderate_hide'); my @types = grep $_, - $c->forward('moderate_text', [ 'title' ]), + ($c->user->can_moderate_title($c->stash->{problem}, 1) + ? $c->forward('moderate_text', [ 'title' ]) + : ()), $c->forward('moderate_text', [ 'detail' ]), $c->forward('moderate_boolean', [ 'anonymous', 'show_name' ]), $c->forward('moderate_boolean', [ 'photo' ]); diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 246159009..c50f8834c 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -350,6 +350,17 @@ sub can_moderate { return $cobrand->call_hook('moderate_permission', $self, $type => $object); } +sub can_moderate_title { + my ($self, $problem, $perm) = @_; + + # Must have main permission, this is to potentially restrict only + return 0 unless $perm; + + # If hook returns anything use it, otherwise default to yes + my $cobrand = $self->result_source->schema->cobrand; + return $cobrand->call_hook('moderate_permission_title', $self, $problem) // 1; +} + has body_permissions => ( is => 'ro', lazy => 1, diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index c2ac3ad5a..c3aba0ebb 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -4,6 +4,12 @@ use parent 'FixMyStreet::Cobrand::Default'; sub send_moderation_notifications { 0 } +package FixMyStreet::Cobrand::TestTitle; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub moderate_permission_title { 0 } + package main; use FixMyStreet::TestMech; @@ -208,6 +214,25 @@ subtest 'Problem moderation' => sub { $report->update({ state => 'confirmed' }); } }; + + subtest 'Try and moderate title when not allowed' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'testtitle' + }, sub { + $mech->get_ok($REPORT_URL); + $mech->submit_form_ok({ with_fields => { + problem_show_name => 1, + problem_photo => 1, + problem_detail => 'Changed detail', + }}); + $mech->base_like( qr{\Q$REPORT_URL\E} ); + $mech->content_like(qr/Moderated by Bromley Council/); + + $report->discard_changes; + is $report->title, 'Good bad good'; + is $report->detail, 'Changed detail'; + } + }; }; $mech->content_lacks('Posted anonymously', 'sanity check'); diff --git a/templates/web/base/report/_main.html b/templates/web/base/report/_main.html index 1e427fd86..6c5537fb4 100644 --- a/templates/web/base/report/_main.html +++ b/templates/web/base/report/_main.html @@ -1,4 +1,7 @@ -[% can_moderate = permissions.moderate OR c.user.can_moderate(problem, staff = permissions.moderate) %] +[% +can_moderate = permissions.moderate OR c.user.can_moderate(problem, staff = permissions.moderate) +can_moderate_title = c.user.can_moderate_title(problem, can_moderate) +%] <a href="[% c.uri_for( '/around', { lat => latitude, lon => longitude } ) %]" class="problem-back js-back-to-report-list">[% loc('Back to all reports') %]</a> @@ -38,9 +41,8 @@ <input type="hidden" name="token" value="[% csrf_token %]"> [% END %] + [% IF can_moderate_title %] <h1 class="moderate-display">[% problem.title | html %]</h1> - - [% IF can_moderate %] <div class="moderate-edit"> [% IF problem.title != original.title %] <label> @@ -50,6 +52,8 @@ [% END %] <h1><input class="form-control" type="text" name="problem_title" value="[% problem.title | html %]" data-original-value="[% original.title | html %]"></h1> </div> + [% ELSE %] + <h1>[% problem.title | html %]</h1> [% END %] <div class="moderate-edit"> |