aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-11-13 10:50:48 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-11-16 10:58:20 +0000
commit3796842153839b0c75f85ec8c4b2bbba60963ff3 (patch)
treead98528bb232cae1a9f0ee852c5c36ee99193f86 /perllib
parentfcd9f9943059d6f70091951c576e704e5d80b7f1 (diff)
Store more original stuff on moderation.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm41
-rw-r--r--perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm12
3 files changed, 49 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 3bf4f911c..df9cc9aac 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1009,6 +1009,7 @@ sub report_edit : Path('report_edit') : Args(1) {
=head2 report_edit_category
Handles changing a problem's category and the complexity that comes with it.
+Returns 1 if category changed, 0 if no change.
=cut
@@ -1053,7 +1054,9 @@ sub report_edit_category : Private {
anonymous => 0,
});
}
+ return 1;
}
+ return 0;
}
=head2 report_edit_location
@@ -1062,7 +1065,8 @@ Handles changing a problem's location and the complexity that comes with it.
For now, we reject the new location if the new location and old locations aren't
covered by the same body.
-Returns 1 if the new position (if any) is acceptable, undef otherwise.
+Returns 2 if the new position (if any) is acceptable and changed,
+1 if acceptable and unchanged, undef otherwise.
NB: This must be called before report_edit_category, as that might modify
$problem->bodies_str.
@@ -1095,6 +1099,7 @@ sub report_edit_location : Private {
$problem->longitude($c->stash->{longitude});
my $areas = $c->stash->{all_areas_mapit};
$problem->areas( ',' . join( ',', sort keys %$areas ) . ',' );
+ return 2;
}
return 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index 5ab4b940e..90396fa07 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -60,6 +60,10 @@ sub report : Chained('moderate') : PathPart('report') : CaptureArgs(1) {
detail => $problem->detail,
photo => $problem->photo,
anonymous => $problem->anonymous,
+ longitude => $problem->longitude,
+ latitude => $problem->latitude,
+ category => $problem->category,
+ extra => $problem->extra,
});
$c->stash->{problem} = $problem;
$c->stash->{problem_original} = $original;
@@ -237,7 +241,15 @@ sub moderate_boolean : Private {
sub moderate_extra : Private {
my ($self, $c) = @_;
- my $object = $c->stash->{comment} || $c->stash->{problem};
+ my ($object, $original);
+ if (my $comment = $c->stash->{comment}) {
+ $object = $comment;
+ $original = $c->stash->{comment_original};
+ } else {
+ $object = $c->stash->{problem};
+ $original = $c->stash->{problem_original};
+ }
+
my $changed;
my @extra = grep { /^extra\./ } keys %{$c->req->params};
foreach (@extra) {
@@ -245,6 +257,7 @@ sub moderate_extra : Private {
my $old = $object->get_extra_metadata($field_name) || '';
my $new = $c->get_param($_);
if ($new ne $old) {
+ $original->insert unless $original->in_storage;
$object->set_extra_metadata($field_name, $new);
$changed = 1;
}
@@ -259,15 +272,21 @@ sub moderate_location : Private {
my ($self, $c) = @_;
my $problem = $c->stash->{problem};
- if ( !$c->forward( '/admin/report_edit_location', [ $problem ] ) ) {
+ my $original = $c->stash->{problem_original};
+
+ my $moved = $c->forward('/admin/report_edit_location', [ $problem ]);
+ if (!$moved) {
# New lat/lon isn't valid, show an error
$c->flash->{moderate_errors} ||= [];
push @{ $c->flash->{moderate_errors} }, _('Invalid location. New location must be covered by the same council.');
return;
}
- $problem->update;
- return 'location';
+ if ($moved == 2) {
+ $original->insert unless $original->in_storage;
+ $problem->update;
+ return 'location';
+ }
}
# No update left at present
@@ -280,11 +299,15 @@ sub moderate_category : Private {
$c->forward('/admin/categories_for_point');
my $problem = $c->stash->{problem};
- $c->forward( '/admin/report_edit_category', [ $problem, 1 ] );
- # It might need to set_report_extras in future
+ my $original = $c->stash->{problem_original};
- $problem->update;
- return 'category';
+ my $changed = $c->forward( '/admin/report_edit_category', [ $problem, 1 ] );
+ # It might need to set_report_extras in future
+ if ($changed) {
+ $original->insert unless $original->in_storage;
+ $problem->update;
+ return 'category';
+ }
}
sub update : Chained('report') : PathPart('update') : CaptureArgs(1) {
@@ -298,6 +321,7 @@ sub update : Chained('report') : PathPart('update') : CaptureArgs(1) {
detail => $comment->text,
photo => $comment->photo,
anonymous => $comment->anonymous,
+ extra => $comment->extra,
});
$c->stash->{comment} = $comment;
$c->stash->{comment_original} = $original;
@@ -311,6 +335,7 @@ sub moderate_update : Chained('update') : PathPart('') : Args(0) {
my @types = grep $_,
$c->forward('moderate_text', [ 'text' ]),
$c->forward('moderate_boolean', [ 'anonymous', 'show_name' ]),
+ $c->forward('moderate_extra'),
$c->forward('moderate_boolean', [ 'photo' ]);
$c->detach( 'update_moderate_audit', \@types )
diff --git a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm
index d7240cd5d..bcf435352 100644
--- a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm
+++ b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm
@@ -37,6 +37,14 @@ __PACKAGE__->add_columns(
is_nullable => 0,
original => { default_value => \"now()" },
},
+ "extra",
+ { data_type => "text", is_nullable => 1 },
+ "category",
+ { data_type => "text", is_nullable => 1 },
+ "latitude",
+ { data_type => "double precision", is_nullable => 1 },
+ "longitude",
+ { data_type => "double precision", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("moderation_original_data_comment_id_key", ["comment_id"]);
@@ -59,8 +67,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DBtGjCJykDtLnGtkj638eA
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-11-13 10:48:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OQAXPriTc3G2jKFPw0TqdQ
# You can replace this text with custom code or comments, and it will be preserved on regeneration