diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-11-13 10:50:48 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-11-16 10:58:20 +0000 |
commit | 3796842153839b0c75f85ec8c4b2bbba60963ff3 (patch) | |
tree | ad98528bb232cae1a9f0ee852c5c36ee99193f86 | |
parent | fcd9f9943059d6f70091951c576e704e5d80b7f1 (diff) |
Store more original stuff on moderation.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rwxr-xr-x | bin/update-schema | 1 | ||||
-rw-r--r-- | db/downgrade_0063---0062.sql | 8 | ||||
-rw-r--r-- | db/schema.sql | 7 | ||||
-rw-r--r-- | db/schema_0063-add-extra-to-moderation.sql | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Moderate.pm | 41 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm | 12 | ||||
-rw-r--r-- | t/app/controller/moderate.t | 15 |
9 files changed, 88 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5930e3031..cf8ffa621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Admin improvements: - Allow moderation to potentially change category. #2320 - Add Mark/View private reports permission #2306 + - Store more original stuff on moderation. - Open311 improvements: - Fix bug in contact group handling. #2323 - Development improvements: diff --git a/bin/update-schema b/bin/update-schema index 2ae374e61..a2f20c306 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -212,6 +212,7 @@ else { # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { return 'EMPTY' if ! table_exists('problem'); + return '0063' if column_exists('moderation_original_data', 'extra'); return '0062' if column_exists('users', 'created'); return '0061' if column_exists('body', 'extra'); return '0060' if column_exists('body', 'convert_latlong'); diff --git a/db/downgrade_0063---0062.sql b/db/downgrade_0063---0062.sql new file mode 100644 index 000000000..0f875e3e4 --- /dev/null +++ b/db/downgrade_0063---0062.sql @@ -0,0 +1,8 @@ +BEGIN; + +ALTER TABLE moderation_original_data DROP extra; +ALTER TABLE moderation_original_data DROP latitude; +ALTER TABLE moderation_original_data DROP longitude; +ALTER TABLE moderation_original_data DROP category; + +COMMIT; diff --git a/db/schema.sql b/db/schema.sql index 30f5d3a30..a448e05fa 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -449,7 +449,12 @@ create table moderation_original_data ( anonymous bool not null, -- Metadata - created timestamp not null default current_timestamp + created timestamp not null default current_timestamp, + + extra text, + category text, + latitude double precision, + longitude double precision ); create table user_body_permissions ( diff --git a/db/schema_0063-add-extra-to-moderation.sql b/db/schema_0063-add-extra-to-moderation.sql new file mode 100644 index 000000000..9d003f895 --- /dev/null +++ b/db/schema_0063-add-extra-to-moderation.sql @@ -0,0 +1,9 @@ +BEGIN; + +ALTER TABLE moderation_original_data ADD extra text; +ALTER TABLE moderation_original_data ADD category text; +ALTER TABLE moderation_original_data ADD latitude double precision; +ALTER TABLE moderation_original_data ADD longitude double precision; + +COMMIT; + 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 diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index 00de29dd1..69408d600 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -346,7 +346,6 @@ subtest 'updates' => sub { $mech->base_like( qr{\Q$REPORT_URL\E} ); $update->discard_changes; - $update->discard_changes; is $update->text, 'update good good bad good', }; @@ -371,6 +370,20 @@ subtest 'updates' => sub { $mech->content_lacks('Posted anonymously'); }; + subtest 'Moderate extra data' => sub { + $update->set_extra_metadata('moon', 'waxing full'); + $update->update; + my ($csrf) = $mech->content =~ /meta content="([^"]*)" name="csrf-token"/; + $mech->post_ok('http://www.example.org/moderate/report/' . $report->id . '/update/' . $update->id, { + %update_prepopulated, + 'extra.weather' => 'snow', + 'extra.moon' => 'waxing full', + token => $csrf, + }); + $update->discard_changes; + is $update->get_extra_metadata('weather'), 'snow'; + }; + subtest 'Hide photo' => sub { $report->update({ photo => undef }); # hide the main photo so we can just look for text in comment |