aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-05-15 13:05:17 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-23 18:55:10 +0100
commit15678f4923a3395fc3bb4b6c6cc82cf38d09021e (patch)
treea8ae0b8b0a1d48f79e41fcaedcd5dd155620e8ec
parenteb58ad65f8b25be9dc4321ca5914ad1d89f8bf3a (diff)
Add ability to close updates on reports.
The inactive report script can mark matched reports as closed for updates. This removes the update form and signing up for updates from a report page.
-rw-r--r--CHANGELOG.md2
-rwxr-xr-xbin/process-inactive-reports7
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm1
-rw-r--r--perllib/FixMyStreet/Script/Inactive.pm24
-rw-r--r--t/script/inactive.t8
-rw-r--r--templates/web/base/report/display.html4
-rw-r--r--templates/web/base/report/display_tools.html2
-rw-r--r--templates/web/base/report/update-form.html2
-rw-r--r--templates/web/bromley/report/update-form.html3
9 files changed, 45 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c5baa0408..78b50e945 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,7 +55,7 @@
- Display contents of report's extra field #1809
- Store user creation and last active times.
- Add scripts to anonymize inactive users and reports,
- or email inactive users.
+ email inactive users, or to close reports to new updates.
- Development improvements:
- Add HTML email previewer.
- Add CORS header to Open311 output. #2022
diff --git a/bin/process-inactive-reports b/bin/process-inactive-reports
index 3f133d11a..d2c030c2c 100755
--- a/bin/process-inactive-reports
+++ b/bin/process-inactive-reports
@@ -15,9 +15,9 @@ use FixMyStreet::Script::Inactive;
use Pod::Usage;
my %h;
-GetOptions(\%h, 'anonymize=i', 'verbose|v', 'help|h', 'dry-run|n');
+GetOptions(\%h, 'anonymize=i', 'close=i', 'verbose|v', 'help|h', 'dry-run|n');
pod2usage(0) if $h{help};
-pod2usage(1) unless $h{anonymize};
+pod2usage(1) unless $h{anonymize} || $h{close};
FixMyStreet::Script::Inactive->new(%h)->reports;
@@ -29,10 +29,11 @@ process-inactive-reports - deal with anonymizing inactive non-open reports
=head1 SYNOPSIS
-process-inactive-reports --anonymize N
+process-inactive-reports [--anonymize N] [--close N]
Options:
--anonymize Anonymize non-open reports (and related) inactive longer than this time (months)
+ --close Close comments on non-open reports inactive longer than this time (months)
--dry-run Don't actually anonymize anything or send any emails
--verbose Output as to which reports are being affected
--help This help message
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 13eceadb0..4a5b8db5d 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -240,6 +240,7 @@ This makes sure we only proceed to processing if we've had the form submitted
sub check_form_submitted : Private {
my ( $self, $c ) = @_;
+ return if $c->stash->{problem}->get_extra_metadata('closed_updates');
return $c->get_param('submit_update') || '';
}
diff --git a/perllib/FixMyStreet/Script/Inactive.pm b/perllib/FixMyStreet/Script/Inactive.pm
index 3c6be9901..0468d2a52 100644
--- a/perllib/FixMyStreet/Script/Inactive.pm
+++ b/perllib/FixMyStreet/Script/Inactive.pm
@@ -11,6 +11,7 @@ use FixMyStreet::DB;
use FixMyStreet::Email;
has anonymize => ( is => 'ro' );
+has close => ( is => 'ro' );
has email => ( is => 'ro' );
has verbose => ( is => 'ro' );
has dry_run => ( is => 'ro' );
@@ -53,6 +54,29 @@ sub reports {
my $self = shift;
say "DRY RUN" if $self->dry_run;
+ $self->anonymize_reports if $self->anonymize;
+ $self->close_updates if $self->close;
+}
+
+sub close_updates {
+ my $self = shift;
+
+ my $problems = FixMyStreet::DB->resultset("Problem")->search({
+ lastupdate => { '<', interval($self->close) },
+ state => [ FixMyStreet::DB::Result::Problem->closed_states(), FixMyStreet::DB::Result::Problem->fixed_states() ],
+ extra => [ undef, { -not_like => '%closed_updates%' } ],
+ });
+
+ while (my $problem = $problems->next) {
+ say "Closing updates on problem #" . $problem->id if $self->verbose;
+ next if $self->dry_run;
+ $problem->set_extra_metadata( closed_updates => 1 );
+ $problem->update;
+ }
+}
+
+sub anonymize_reports {
+ my $self = shift;
# Need to look though them all each time, in case any new updates/alerts
my $problems = FixMyStreet::DB->resultset("Problem")->search({
diff --git a/t/script/inactive.t b/t/script/inactive.t
index 9d1e3f4bd..4d78b385f 100644
--- a/t/script/inactive.t
+++ b/t/script/inactive.t
@@ -50,6 +50,14 @@ subtest 'Anonymization of inactive fixed/closed reports' => sub {
is $comment->user->email, 'removed-automatically@example.org', 'Comment user anonymized';
};
+subtest 'Closing updates on inactive fixed/closed reports' => sub {
+ my $in = FixMyStreet::Script::Inactive->new( close => 1 );
+ $in->reports;
+ $problems[2]->discard_changes;
+ is $problems[2]->get_extra_metadata('closed_updates'), 1, 'Closed to updates';
+ # TODO Visit page, check closed for updates
+};
+
subtest 'Anonymization of inactive users' => sub {
$in->users;
diff --git a/templates/web/base/report/display.html b/templates/web/base/report/display.html
index f9c42b35d..8c461dced 100644
--- a/templates/web/base/report/display.html
+++ b/templates/web/base/report/display.html
@@ -53,7 +53,7 @@
[% TRY %][% INCLUDE 'report/sharing.html' %][% CATCH file %][% END %]
[% INCLUDE 'report/updates.html' %]
-[% IF two_column_sidebar %]
+[% IF two_column_sidebar AND NOT problem.extra.closed_updates %]
<button class="btn btn--provide-update js-provide-update hidden-nojs">[% loc('Provide an update') %]</button>
<div class="hidden-js">
[% END %]
@@ -62,7 +62,7 @@
[% ELSIF NOT shown_form %]
[% INCLUDE 'report/update-form.html' %]
[% END %]
-[% IF two_column_sidebar %]
+[% IF two_column_sidebar AND NOT problem.extra.closed_updates %]
</div>
[% END %]
diff --git a/templates/web/base/report/display_tools.html b/templates/web/base/report/display_tools.html
index 8ed86c228..e0d8e3f99 100644
--- a/templates/web/base/report/display_tools.html
+++ b/templates/web/base/report/display_tools.html
@@ -10,7 +10,7 @@
c.cobrand.moniker == 'fixmystreet' ? 'Unsuitable?' : loc('Report abuse')
%]</a></li>
[% END %]
- [% IF c.cobrand.moniker != 'zurich' %]
+ [% IF NOT problem.extra.closed_updates AND c.cobrand.moniker != 'zurich' %]
<li><a rel="nofollow" id="key-tool-report-updates" class="feed js-feed" href="[% c.uri_for( '/alert/subscribe', { id => problem.id } ) %]">[% loc('Get updates' ) %]</a></li>
[% END %]
[% IF c.cobrand.moniker == 'fixmystreet' %]
diff --git a/templates/web/base/report/update-form.html b/templates/web/base/report/update-form.html
index 1e67c2072..9276acde9 100644
--- a/templates/web/base/report/update-form.html
+++ b/templates/web/base/report/update-form.html
@@ -1,5 +1,5 @@
[% allow_creation = !c.cobrand.only_authed_can_create || (c.user && c.user.from_body) %]
-[% RETURN IF NOT allow_creation %]
+[% RETURN IF NOT allow_creation OR problem.extra.closed_updates %]
<div id="update_form">
[% IF NOT login_success AND NOT oauth_need_email %]
diff --git a/templates/web/bromley/report/update-form.html b/templates/web/bromley/report/update-form.html
index bdabe12c5..6c3ca9298 100644
--- a/templates/web/bromley/report/update-form.html
+++ b/templates/web/bromley/report/update-form.html
@@ -1,3 +1,6 @@
+[% allow_creation = !c.cobrand.only_authed_can_create || (c.user && c.user.from_body) %]
+[% RETURN IF NOT allow_creation OR problem.extra.closed_updates %]
+
<div id="update_form">
[% UNLESS hide_header %]
<h2[% IF two_column_sidebar %] class="hidden-js"[% END %]>[% loc('Provide an update') %]</h2>