aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm184
-rw-r--r--t/app/controller/moderate.t20
-rw-r--r--templates/web/base/report/_main.html2
-rw-r--r--templates/web/base/report/update.html6
4 files changed, 71 insertions, 141 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index 86143b5ea..b32f38e13 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -72,10 +72,10 @@ sub moderate_report : Chained('report') : PathPart('') : Args(0) {
$c->forward('report_moderate_hide');
my @types = grep $_,
- $c->forward('report_moderate_title'),
- $c->forward('report_moderate_detail'),
- $c->forward('report_moderate_anon'),
- $c->forward('report_moderate_photo');
+ $c->forward('moderate_text', [ 'title' ]),
+ $c->forward('moderate_text', [ 'detail' ]),
+ $c->forward('moderate_boolean', [ 'anonymous', 'show_name' ]),
+ $c->forward('moderate_boolean', [ 'photo' ]);
$c->detach( 'report_moderate_audit', \@types )
}
@@ -135,82 +135,71 @@ sub report_moderate_hide : Private {
}
}
-sub report_moderate_title : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $original = $c->stash->{problem_original};
+sub moderate_text : Private {
+ my ($self, $c, $thing) = @_;
+
+ my ($object, $original, $param);
+ my $thing_for_original_table = $thing;
+ if (my $comment = $c->stash->{comment}) {
+ $object = $comment;
+ $original = $c->stash->{comment_original};
+ $param = 'update_';
+ # Update 'text' field is stored in original table's 'detail' field
+ $thing_for_original_table = 'detail' if $thing eq 'text';
+ } else {
+ $object = $c->stash->{problem};
+ $original = $c->stash->{problem_original};
+ $param = 'problem_';
+ }
- my $old_title = $problem->title;
- my $original_title = $original->title;
+ my $old = $object->$thing;
+ my $original_thing = $original->$thing_for_original_table;
- my $title = $c->get_param('problem_revert_title') ?
- $original_title
- : $c->get_param('problem_title');
+ my $new = $c->get_param($param . 'revert_' . $thing) ?
+ $original_thing
+ : $c->get_param($param . $thing);
- if ($title ne $old_title) {
+ if ($new ne $old) {
$original->insert unless $original->in_storage;
- $problem->update({ title => $title });
- return 'title';
+ $object->update({ $thing => $new });
+ return $thing_for_original_table;
}
return;
}
-sub report_moderate_detail : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $original = $c->stash->{problem_original};
-
- my $old_detail = $problem->detail;
- my $original_detail = $original->detail;
- my $detail = $c->get_param('problem_revert_detail') ?
- $original_detail
- : $c->get_param('problem_detail');
-
- if ($detail ne $old_detail) {
- $original->insert unless $original->in_storage;
- $problem->update({ detail => $detail });
- return 'detail';
+sub moderate_boolean : Private {
+ my ( $self, $c, $thing, $reverse ) = @_;
+
+ my ($object, $original, $param);
+ if (my $comment = $c->stash->{comment}) {
+ $object = $comment;
+ $original = $c->stash->{comment_original};
+ $param = 'update_';
+ } else {
+ $object = $c->stash->{problem};
+ $original = $c->stash->{problem_original};
+ $param = 'problem_';
}
- return;
-}
-
-sub report_moderate_anon : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $original = $c->stash->{problem_original};
-
- my $show_user = $c->get_param('problem_show_name') ? 1 : 0;
- my $anonymous = $show_user ? 0 : 1;
- my $old_anonymous = $problem->anonymous ? 1 : 0;
- if ($anonymous != $old_anonymous) {
+ return if $thing eq 'photo' && !$original->photo;
- $original->insert unless $original->in_storage;
- $problem->update({ anonymous => $anonymous });
- return 'anonymous';
+ my $new;
+ if ($reverse) {
+ $new = $c->get_param($param . $reverse) ? 0 : 1;
+ } else {
+ $new = $c->get_param($param . $thing) ? 1 : 0;
}
- return;
-}
-
-sub report_moderate_photo : Private {
- my ( $self, $c ) = @_;
+ my $old = $object->$thing ? 1 : 0;
- my $problem = $c->stash->{problem} or die;
- my $original = $c->stash->{problem_original};
-
- return unless $original->photo;
-
- my $show_photo = $c->get_param('problem_show_photo') ? 1 : 0;
- my $old_show_photo = $problem->photo ? 1 : 0;
-
- if ($show_photo != $old_show_photo) {
+ if ($new != $old) {
$original->insert unless $original->in_storage;
- $problem->update({ photo => $show_photo ? $original->photo : undef });
- return 'photo';
+ if ($thing eq 'photo') {
+ $object->update({ $thing => $new ? $original->photo : undef });
+ } else {
+ $object->update({ $thing => $new });
+ }
+ return $thing;
}
return;
}
@@ -234,9 +223,9 @@ sub moderate_update : Chained('update') : PathPart('') : Args(0) {
$c->forward('update_moderate_hide');
my @types = grep $_,
- $c->forward('update_moderate_detail'),
- $c->forward('update_moderate_anon'),
- $c->forward('update_moderate_photo');
+ $c->forward('moderate_text', [ 'text' ]),
+ $c->forward('moderate_boolean', [ 'anonymous', 'show_name' ]),
+ $c->forward('moderate_boolean', [ 'photo' ]);
$c->detach( 'update_moderate_audit', \@types )
}
@@ -274,65 +263,6 @@ sub update_moderate_hide : Private {
return;
}
-sub update_moderate_detail : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $comment = $c->stash->{comment} or die;
- my $original = $c->stash->{comment_original};
-
- my $old_detail = $comment->text;
- my $original_detail = $original->detail;
- my $detail = $c->get_param('update_revert_detail') ?
- $original_detail
- : $c->get_param('update_detail');
-
- if ($detail ne $old_detail) {
- $original->insert unless $original->in_storage;
- $comment->update({ text => $detail });
- return 'detail';
- }
- return;
-}
-
-sub update_moderate_anon : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $comment = $c->stash->{comment} or die;
- my $original = $c->stash->{comment_original};
-
- my $show_user = $c->get_param('update_show_name') ? 1 : 0;
- my $anonymous = $show_user ? 0 : 1;
- my $old_anonymous = $comment->anonymous ? 1 : 0;
-
- if ($anonymous != $old_anonymous) {
- $original->insert unless $original->in_storage;
- $comment->update({ anonymous => $anonymous });
- return 'anonymous';
- }
- return;
-}
-
-sub update_moderate_photo : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem} or die;
- my $comment = $c->stash->{comment} or die;
- my $original = $c->stash->{comment_original};
-
- return unless $original->photo;
-
- my $show_photo = $c->get_param('update_show_photo') ? 1 : 0;
- my $old_show_photo = $comment->photo ? 1 : 0;
-
- if ($show_photo != $old_show_photo) {
- $original->insert unless $original->in_storage;
- $comment->update({ photo => $show_photo ? $original->photo : undef });
- return 'photo';
- }
-}
-
sub return_text : Private {
my ($self, $c, $text) = @_;
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index 4b2f0cfe3..c2ac3ad5a 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -86,7 +86,7 @@ subtest 'Auth' => sub {
my %problem_prepopulated = (
problem_show_name => 1,
- problem_show_photo => 1,
+ problem_photo => 1,
problem_title => 'Good bad good',
problem_detail => 'Good bad bad bad good bad',
);
@@ -146,7 +146,7 @@ subtest 'Problem moderation' => sub {
$mech->submit_form_ok({ with_fields => {
%problem_prepopulated,
- problem_show_photo => 0,
+ problem_photo => 0,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -154,7 +154,7 @@ subtest 'Problem moderation' => sub {
$mech->submit_form_ok({ with_fields => {
%problem_prepopulated,
- problem_show_photo => 1,
+ problem_photo => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -251,8 +251,8 @@ sub create_update {
}
my %update_prepopulated = (
update_show_name => 1,
- update_show_photo => 1,
- update_detail => 'update good good bad good',
+ update_photo => 1,
+ update_text => 'update good good bad good',
);
my $update = create_update();
@@ -263,7 +263,7 @@ subtest 'updates' => sub {
$mech->get_ok($REPORT_URL);
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_detail => 'update good good good',
+ update_text => 'update good good good',
}}) or die $mech->content;
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -274,7 +274,7 @@ subtest 'updates' => sub {
subtest 'Revert text' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_revert_detail => 1,
+ update_revert_text => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -314,7 +314,7 @@ subtest 'updates' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_show_photo => 0,
+ update_photo => 0,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -322,7 +322,7 @@ subtest 'updates' => sub {
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_show_photo => 1,
+ update_photo => 1,
}});
$mech->base_like( qr{\Q$REPORT_URL\E} );
@@ -348,7 +348,7 @@ subtest 'Update 2' => sub {
$mech->get_ok($REPORT_URL);
$mech->submit_form_ok({ with_fields => {
%update_prepopulated,
- update_detail => 'update good good good',
+ update_text => 'update good good good',
}}) or die $mech->content;
$update2->discard_changes;
diff --git a/templates/web/base/report/_main.html b/templates/web/base/report/_main.html
index fe0fe74d5..1c63cb53c 100644
--- a/templates/web/base/report/_main.html
+++ b/templates/web/base/report/_main.html
@@ -75,7 +75,7 @@
[% IF problem.photo or original.photo %]
<p class="moderate-edit">
<label>
- <input type="checkbox" name="problem_show_photo" [% problem.photo ? 'checked' : '' %]>
+ <input type="checkbox" name="problem_photo" [% problem.photo ? 'checked' : '' %]>
[% loc('Show photo') %]
</label>
</p>
diff --git a/templates/web/base/report/update.html b/templates/web/base/report/update.html
index 4a2642c9a..1d6fb9c01 100644
--- a/templates/web/base/report/update.html
+++ b/templates/web/base/report/update.html
@@ -15,7 +15,7 @@
<label><input type="checkbox" name="update_show_name" [% update.anonymous ? '' : 'checked' %]>
[% loc('Show name publicly?') %]</label>
[% IF update.photo or original_update.photo %]
- <label><input type="checkbox" name="update_show_photo" [% update.photo ? 'checked' : '' %]>
+ <label><input type="checkbox" name="update_photo" [% update.photo ? 'checked' : '' %]>
[% loc('Show Photo?') %]</label>
[% END %]
</div>
@@ -34,10 +34,10 @@
[% IF permissions.moderate %]
<div class="moderate-edit">
[% IF update.text != original.detail %]
- <label><input type="checkbox" name="update_revert_detail" class="revert-textarea">
+ <label><input type="checkbox" name="update_revert_text" class="revert-textarea">
[% loc('Revert to original') %]</label>
[% END %]
- <textarea class="form-control" name="update_detail">[% update.text | add_links %]</textarea>
+ <textarea class="form-control" name="update_text">[% update.text | add_links %]</textarea>
</div>
[% END %]