aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm72
-rw-r--r--perllib/FixMyStreet/DB/Result/AdminLog.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm10
-rw-r--r--perllib/FixMyStreet/DB/Result/ResponseTemplate.pm5
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm46
-rw-r--r--perllib/FixMyStreet/DB/Result/UserPlannedReport.pm55
-rw-r--r--perllib/FixMyStreet/TestMech.pm1
7 files changed, 178 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 72391fee2..b15750c98 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -2,6 +2,8 @@ package FixMyStreet::App::Controller::My;
use Moose;
use namespace::autoclean;
+use JSON::MaybeXS;
+
BEGIN { extends 'Catalyst::Controller'; }
=head1 NAME
@@ -16,6 +18,11 @@ Catalyst Controller.
=cut
+sub begin : Private {
+ my ($self, $c) = @_;
+ $c->detach( '/auth/redirect' ) unless $c->user;
+}
+
=head2 index
=cut
@@ -23,10 +30,28 @@ Catalyst Controller.
sub my : Path : Args(0) {
my ( $self, $c ) = @_;
- $c->detach( '/auth/redirect' ) unless $c->user;
+ $c->stash->{problems_rs} = $c->cobrand->problems->search(
+ { user_id => $c->user->id });
+ $c->forward('get_problems');
+ $c->forward('get_updates');
+ $c->forward('setup_page_data');
+}
+
+sub planned : Local : Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->detach('/page_error_403_access_denied', [])
+ unless $c->user->from_body && $c->user->has_permission_to('planned_reports', $c->user->from_body->id);
+
+ $c->stash->{problems_rs} = $c->user->active_planned_reports;
+ $c->forward('get_problems');
+ $c->forward('setup_page_data');
+}
+
+sub get_problems : Private {
+ my ($self, $c) = @_;
my $p_page = $c->get_param('p') || 1;
- my $u_page = $c->get_param('u') || 1;
$c->forward( '/reports/stash_report_filter_status' );
@@ -36,7 +61,6 @@ sub my : Path : Args(0) {
my $states = $c->stash->{filter_problem_states};
my $params = {
state => [ keys %$states ],
- user_id => $c->user->id,
};
my $category = $c->get_param('filter_category');
@@ -45,7 +69,7 @@ sub my : Path : Args(0) {
$c->stash->{filter_category} = $category;
}
- my $rs = $c->cobrand->problems->search( $params, {
+ my $rs = $c->stash->{problems_rs}->search( $params, {
order_by => { -desc => 'confirmed' },
rows => 50
} )->page( $p_page );
@@ -57,8 +81,14 @@ sub my : Path : Args(0) {
}
$c->stash->{problems_pager} = $rs->pager;
$c->stash->{problems} = $problems;
+ $c->stash->{pins} = $pins;
+}
+
+sub get_updates : Private {
+ my ($self, $c) = @_;
- $rs = $c->user->comments->search(
+ my $u_page = $c->get_param('u') || 1;
+ my $rs = $c->user->comments->search(
{ state => 'confirmed' },
{
order_by => { -desc => 'confirmed' },
@@ -69,8 +99,12 @@ sub my : Path : Args(0) {
$c->stash->{has_content} += scalar @updates;
$c->stash->{updates} = \@updates;
$c->stash->{updates_pager} = $rs->pager;
+}
- my @categories = $c->cobrand->problems->search( { user_id => $c->user->id }, {
+sub setup_page_data : Private {
+ my ($self, $c) = @_;
+
+ my @categories = $c->stash->{problems_rs}->search({}, {
columns => [ 'category' ],
distinct => 1,
order_by => [ 'category' ],
@@ -79,6 +113,7 @@ sub my : Path : Args(0) {
$c->stash->{filter_categories} = \@categories;
$c->stash->{page} = 'my';
+ my $pins = $c->stash->{pins};
FixMyStreet::Map::display_map(
$c,
latitude => $pins->[0]{latitude},
@@ -89,6 +124,31 @@ sub my : Path : Args(0) {
if @$pins;
}
+sub planned_change : Path('planned/change') {
+ my ($self, $c) = @_;
+ $c->forward('/auth/check_csrf_token');
+
+ my $id = $c->get_param('id');
+ $c->forward( '/report/load_problem_or_display_error', [ $id ] );
+
+ my $change = $c->get_param('change');
+ $c->detach('/page_error_403_access_denied', [])
+ unless $change && $change =~ /add|remove/;
+
+ if ($change eq 'add') {
+ $c->user->add_to_planned_reports($c->stash->{problem});
+ } elsif ($change eq 'remove') {
+ $c->user->remove_from_planned_reports($c->stash->{problem});
+ }
+
+ if ($c->get_param('ajax')) {
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body(encode_json({ outcome => $change }));
+ } else {
+ $c->res->redirect( $c->uri_for_action('report/display', $id) );
+ }
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm
index d60915cfc..1c9bd3a63 100644
--- a/perllib/FixMyStreet/DB/Result/AdminLog.pm
+++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm
@@ -38,7 +38,7 @@ __PACKAGE__->add_columns(
"reason",
{ data_type => "text", default_value => "", is_nullable => 0 },
"time_spent",
- { data_type => "integer", default_value => "0", is_nullable => 0 },
+ { data_type => "integer", default_value => 0, is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
@@ -54,7 +54,7 @@ __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:RCi1FEwb9T2MZ2X+QOTTUA
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:y2xZ4BDv7H+f4vbIZyNflw
1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 010b7755b..308fba71f 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -132,10 +132,16 @@ __PACKAGE__->belongs_to(
{ id => "user_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
);
+__PACKAGE__->has_many(
+ "user_planned_reports",
+ "FixMyStreet::DB::Result::UserPlannedReport",
+ { "foreign.report_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Go+T9oFRfwQ1Ag89qPpF/g
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PMOhd1uloLTAYovW/fxgSg
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
diff --git a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
index 48a1ab3ae..d189bf3ec 100644
--- a/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponseTemplate.pm
@@ -29,6 +29,7 @@ __PACKAGE__->add_columns(
data_type => "timestamp",
default_value => \"current_timestamp",
is_nullable => 0,
+ original => { default_value => \"now()" },
},
);
__PACKAGE__->set_primary_key("id");
@@ -41,8 +42,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-02-19 16:13:43
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xzhmxtu0taAnBMZN0HBocw
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 14:38:36
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ECFQLMxOFGwv7cwfHLlszw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 7d1785c4b..cc8e050da 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -90,10 +90,21 @@ __PACKAGE__->has_many(
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->has_many(
+ "user_planned_reports",
+ "FixMyStreet::DB::Result::UserPlannedReport",
+ { "foreign.user_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-11 12:49:31
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SG86iN6Fr4/JIq7U2zYkug
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:00:41
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+pEOZ8GM14D4gqkp+fr+ZA
+
+use Moo;
+use mySociety::EmailUtil;
+
+__PACKAGE__->many_to_many( planned_reports => 'user_planned_reports', 'report' );
__PACKAGE__->add_columns(
"password" => {
@@ -104,8 +115,6 @@ __PACKAGE__->add_columns(
},
);
-use mySociety::EmailUtil;
-
sub latest_anonymity {
my $self = shift;
my $p = $self->problems->search(undef, { order_by => { -desc => 'id' } } )->first;
@@ -277,4 +286,33 @@ sub adopt {
$other->delete;
}
+# Planned reports
+
+# Override the default auto-created function as we only want one live entry per user
+around add_to_planned_reports => sub {
+ my ( $orig, $self ) = ( shift, shift );
+ my ( $report_col ) = @_;
+ my $existing = $self->user_planned_reports->search_rs({ report_id => $report_col->{id}, removed => undef })->first;
+ return $existing if $existing;
+ return $self->$orig(@_);
+};
+
+# Override the default auto-created function as we don't want to ever delete anything
+around remove_from_planned_reports => sub {
+ my ($orig, $self, $report) = @_;
+ $self->user_planned_reports
+ ->search_rs({ report_id => $report->id, removed => undef })
+ ->update({ removed => \'current_timestamp' });
+};
+
+sub active_planned_reports {
+ my $self = shift;
+ $self->planned_reports->search({ removed => undef });
+}
+
+sub is_planned_report {
+ my ($self, $problem) = @_;
+ return $self->active_planned_reports->find({ id => $problem->id });
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm b/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm
new file mode 100644
index 000000000..1e893c7a9
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/UserPlannedReport.pm
@@ -0,0 +1,55 @@
+use utf8;
+package FixMyStreet::DB::Result::UserPlannedReport;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
+__PACKAGE__->table("user_planned_reports");
+__PACKAGE__->add_columns(
+ "id",
+ {
+ data_type => "integer",
+ is_auto_increment => 1,
+ is_nullable => 0,
+ sequence => "user_planned_reports_id_seq",
+ },
+ "user_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "report_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "added",
+ {
+ data_type => "timestamp",
+ default_value => \"current_timestamp",
+ is_nullable => 0,
+ original => { default_value => \"now()" },
+ },
+ "removed",
+ { data_type => "timestamp", is_nullable => 1 },
+);
+__PACKAGE__->set_primary_key("id");
+__PACKAGE__->belongs_to(
+ "report",
+ "FixMyStreet::DB::Result::Problem",
+ { id => "report_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+__PACKAGE__->belongs_to(
+ "user",
+ "FixMyStreet::DB::Result::User",
+ { id => "user_id" },
+ { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-07-20 15:03:08
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mv7koDhvZSBW/4aQivtpAQ
+
+
+# You can replace this text with custom code or comments, and it will be preserved on regeneration
+1;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 45f32f46a..c3583bb3e 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -157,6 +157,7 @@ sub delete_user {
for my $p ( $user->problems ) {
$p->comments->delete;
$p->questionnaires->delete;
+ $p->user_planned_reports->delete;
$p->delete;
}
for my $a ( $user->alerts ) {