aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm16
-rw-r--r--t/app/controller/report_inspect.t61
3 files changed, 71 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d56976aec..e2a49dcc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,8 @@
- Inspector panel shows nearest address if available #1850
- Return a 200 rather than 404 for ref ID lookup.
- Public report page shows state changes made in admin interface #1846
+ - Marking an item as a duplicate enforces providing duplicate id or
+ a public update #1873
* v2.2 (13th September 2017)
- New features:
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index c72c75d3a..138098d5f 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -377,15 +377,15 @@ sub inspect : Private {
if ( $problem->state eq 'hidden' ) {
$problem->get_photoset->delete_cached;
}
- if ( $problem->state eq 'duplicate' && $old_state ne 'duplicate' ) {
- # If the report is being closed as duplicate, make sure the
- # update records this.
- $update_params{problem_state} = "duplicate";
- }
- if ( $problem->state ne 'duplicate' ) {
+ if ( $problem->state eq 'duplicate') {
+ if (my $duplicate_of = $c->get_param('duplicate_of')) {
+ $problem->set_duplicate_of($duplicate_of);
+ } elsif (not $c->get_param('public_update')) {
+ $valid = 0;
+ push @{ $c->stash->{errors} }, _('Please provide a duplicate ID or public update for this report.');
+ }
+ } else {
$problem->unset_extra_metadata('duplicate_of');
- } elsif (my $duplicate_of = $c->get_param('duplicate_of')) {
- $problem->set_duplicate_of($duplicate_of);
}
if ( $problem->state ne $old_state ) {
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index f74c94c34..b3a3990a3 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -148,6 +148,67 @@ FixMyStreet::override_config {
$report2->update;
};
+ subtest "can mark a report as duplicate without supplying a duplicate and a public update" => sub {
+ my $old_state = $report->state;
+ $report->comments->delete_all;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } });
+
+ $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, $old_state, 'report not marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left';
+
+ is $report->get_extra_metadata('duplicate_of'), undef;
+
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', public_update => 'This is a duplicate', include_update => "1" } });
+ $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, 'duplicate', 'report marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left';
+ is $report->get_extra_metadata('duplicate_of'), undef;
+ is_deeply $report2->get_extra_metadata('duplicates'), undef;
+
+ $report->update({ state => $old_state });
+ };
+
+ subtest "can mark a report as duplicate without supplying a public update and a duplicate id" => sub {
+ my $old_state = $report->state;
+ $report->comments->delete_all;
+
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', include_update => "0" } });
+
+ $mech->content_contains('provide a duplicate ID', "error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, $old_state, 'report not marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 0, 'no update marking report as duplicate was left';
+
+ is $report->get_extra_metadata('duplicate_of'), undef;
+
+ $mech->submit_form_ok({ button => 'save', with_fields => { state => 'Duplicate', duplicate_of => $report2->id, include_update => "0" } });
+ $mech->content_lacks('provide a duplicate ID', "no error message about missing duplicate id");
+ $report->discard_changes;
+ $report2->discard_changes;
+
+ is $report->state, 'duplicate', 'report marked as duplicate';
+ is $report->comments->search({ problem_state => 'duplicate' })->count, 1, 'update marking report as duplicate was left';
+ is $report->get_extra_metadata('duplicate_of'), $report2->id;
+ is_deeply $report2->get_extra_metadata('duplicates'), [ $report->id ];
+
+ $report->set_extra_metadata('duplicate_of', undef);
+ $report->update({ state => $old_state });
+ $report2->set_extra_metadata('duplicates', undef);
+ $report2->update;
+ };
+
subtest "marking a report as a duplicate with update correctly sets update status" => sub {
my $old_state = $report->state;
$report->comments->delete_all;