aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm112
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm6
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm6
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm7
6 files changed, 93 insertions, 49 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index a3a241590..bb7ec2381 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -145,34 +145,34 @@ sub timeline : Path( 'timeline' ) : Args(0) {
my $probs = $c->cobrand->problems->timeline;
foreach ($probs->all) {
- push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created_local, obj => $_ };
- push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed_local, obj => $_ } if $_->confirmed;
- push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent_local, obj => $_ } if $_->whensent;
+ push @{$time{$_->created->epoch}}, { type => 'problemCreated', date => $_->created, obj => $_ };
+ push @{$time{$_->confirmed->epoch}}, { type => 'problemConfirmed', date => $_->confirmed, obj => $_ } if $_->confirmed;
+ push @{$time{$_->whensent->epoch}}, { type => 'problemSent', date => $_->whensent, obj => $_ } if $_->whensent;
}
my $questionnaires = $c->model('DB::Questionnaire')->timeline( $c->cobrand->restriction );
foreach ($questionnaires->all) {
- push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent_local, obj => $_ };
- push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered_local, obj => $_ } if $_->whenanswered;
+ push @{$time{$_->whensent->epoch}}, { type => 'quesSent', date => $_->whensent, obj => $_ };
+ push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered;
}
my $updates = $c->model('DB::Comment')->timeline( $site_restriction );
foreach ($updates->all) {
- push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created_local, obj => $_} ;
+ push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ;
}
my $alerts = $c->model('DB::Alert')->timeline_created( $c->cobrand->restriction );
foreach ($alerts->all) {
- push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed_local, obj => $_ };
+ push @{$time{$_->whensubscribed->epoch}}, { type => 'alertSub', date => $_->whensubscribed, obj => $_ };
}
$alerts = $c->model('DB::Alert')->timeline_disabled( $c->cobrand->restriction );
foreach ($alerts->all) {
- push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled_local, obj => $_ };
+ push @{$time{$_->whendisabled->epoch}}, { type => 'alertDel', date => $_->whendisabled, obj => $_ };
}
$c->model('DB')->schema->storage->sql_maker->quote_char( '' );
@@ -485,6 +485,25 @@ sub body_edit : Path('body_edit') : Args(2) {
sub reports : Path('reports') {
my ( $self, $c ) = @_;
+ my $query = {};
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ my $type = $c->stash->{admin_type};
+ my $body = $c->stash->{body};
+ if ( $type eq 'dm' ) {
+ my @children = map { $_->id } $body->bodies->all;
+ my @all = (@children, $body->id);
+ $query = { bodies_str => \@all };
+ } elsif ( $type eq 'sdm' ) {
+ $query = { bodies_str => $body->id };
+ }
+ }
+
+ my $order = $c->req->params->{o} || 'created';
+ my $dir = defined $c->req->params->{d} ? $c->req->params->{d} : 1;
+ $c->stash->{order} = $order;
+ $c->stash->{dir} = $dir;
+ $order .= ' desc' if $dir;
+
if (my $search = $c->req->param('search')) {
$c->stash->{searched} = $search;
@@ -503,21 +522,20 @@ sub reports : Path('reports') {
$c->model('DB')->schema->storage->sql_maker->quote_char( '"' );
$c->model('DB')->schema->storage->sql_maker->name_sep( '.' );
- my $query;
if (is_valid_email($search)) {
- $query = [
+ $query->{'-or'} = [
'user.email' => { ilike => $like_search },
];
} elsif ($search =~ /^id:(\d+)$/) {
- $query = [
+ $query->{'-or'} = [
'me.id' => int($1),
];
} elsif ($search =~ /^area:(\d+)$/) {
- $query = [
+ $query->{'-or'} = [
'me.areas' => { like => "%,$1,%" }
];
} else {
- $query = [
+ $query->{'-or'} = [
'me.id' => $search_n,
'user.email' => { ilike => $like_search },
'me.name' => { ilike => $like_search },
@@ -527,13 +545,12 @@ sub reports : Path('reports') {
cobrand_data => { like => $like_search },
];
}
+
my $problems = $c->cobrand->problems->search(
- {
- -or => $query,
- },
+ $query,
{
prefetch => 'user',
- order_by => [\"(state='hidden')",'created']
+ order_by => [ \"(state='hidden')", \$order ]
}
);
@@ -576,7 +593,7 @@ sub reports : Path('reports') {
{
-select => [ 'me.*', qw/problem.bodies_str problem.state/ ],
prefetch => [qw/user problem/],
- order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created']
+ order_by => [ \"(me.state='hidden')", \"(problem.state='hidden')", 'me.created' ]
}
);
$c->stash->{updates} = [ $updates->all ];
@@ -584,6 +601,15 @@ sub reports : Path('reports') {
# Switch quoting back off. See above for explanation of this.
$c->model('DB')->schema->storage->sql_maker->quote_char( '' );
+ } else {
+
+ my $page = $c->req->params->{p} || 1;
+ my $problems = $c->cobrand->problems->search(
+ $query,
+ { order_by => $order }
+ )->page( $page );
+ $c->stash->{problems} = [ $problems->all ];
+ $c->stash->{pager} = $problems->pager;
}
}
@@ -601,13 +627,8 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->forward('get_token');
- if ( $c->req->param('rotate_photo') ) {
- $c->forward('rotate_photo');
- return 1;
- }
-
if ( $c->cobrand->moniker eq 'zurich' ) {
-
+ $c->stash->{page} = 'admin';
FixMyStreet::Map::display_map(
$c,
latitude => $problem->latitude,
@@ -616,12 +637,19 @@ sub report_edit : Path('report_edit') : Args(1) {
? [ {
latitude => $problem->latitude,
longitude => $problem->longitude,
- colour => 'yellow',
+ colour => $c->cobrand->pin_colour($problem),
type => 'big',
} ]
: [],
);
+ }
+
+ if ( $c->req->param('rotate_photo') ) {
+ $c->forward('rotate_photo');
+ return 1;
+ }
+ if ( $c->cobrand->moniker eq 'zurich' ) {
my $done = $c->cobrand->admin_report_edit();
return if $done;
}
@@ -782,6 +810,16 @@ sub users: Path('users') : Args(0) {
} else {
$c->forward('get_token');
$c->forward('fetch_all_bodies');
+
+ # Admin users by default
+ my $users = $c->model('DB::User')->search(
+ { from_body => { '!=', undef } },
+ { order_by => 'name' }
+ );
+ my @users = $users->all;
+ my %email2user = map { $_->email => $_ } @users;
+ $c->stash->{users} = \@users;
+
}
return 1;
@@ -903,6 +941,8 @@ sub user_add : Path('user_edit') : Args(0) {
$c->forward('check_token');
+ return unless $c->req->param('name') && $c->req->param('email');
+
my $user = $c->model('DB::User')->find_or_create( {
name => $c->req->param('name'),
email => $c->req->param('email'),
@@ -982,7 +1022,7 @@ sub stats : Path('stats') : Args(0) {
$c->forward('fetch_all_bodies');
- if ( $c->cobrand->moniker eq 'seesomething' ) {
+ if ( $c->cobrand->moniker eq 'seesomething' || $c->cobrand->moniker eq 'zurich' ) {
return $c->cobrand->admin_stats();
}
@@ -1288,7 +1328,7 @@ sub rotate_photo : Private {
my ( $self, $c ) =@_;
my $direction = $c->req->param('rotate_photo');
- return unless $direction =~ /Left/ or $direction =~ /Right/;
+ return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right');
my $photo = $c->stash->{problem}->photo;
my $file;
@@ -1299,16 +1339,12 @@ sub rotate_photo : Private {
$photo = $file->slurp;
}
- $photo = _rotate_image( $photo, $direction =~ /Left/ ? -90 : 90 );
+ $photo = _rotate_image( $photo, $direction eq _('Rotate Left') ? -90 : 90 );
return unless $photo;
- my $fileid;
- if ( !$file ) {
- $fileid = sha1_hex($photo);
- $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" );
- }
-
- $c->stash->{rotated} = 1;
+ # Write out to new location
+ my $fileid = sha1_hex($photo);
+ $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" );
my $fh = $file->open('w');
print $fh $photo;
@@ -1316,10 +1352,8 @@ sub rotate_photo : Private {
unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' );
- if ( $fileid ) {
- $c->stash->{problem}->photo( $fileid );
- $c->stash->{problem}->update();
- }
+ $c->stash->{problem}->photo( $fileid );
+ $c->stash->{problem}->update();
return 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 9a754f063..bad269a83 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -40,9 +40,10 @@ sub around_index : Path : Args(0) {
my $partial_report = $c->forward('load_partial');
# Try to create a location for whatever we have
- return
- unless $c->forward('/location/determine_location_from_coords')
- || $c->forward('/location/determine_location_from_pc');
+ my $ret = $c->forward('/location/determine_location_from_coords')
+ || $c->forward('/location/determine_location_from_pc');
+ return unless $ret;
+ return $c->res->redirect('/') if $ret == -1 && !$partial_report;
# Check to see if the spot is covered by a area - if not show an error.
return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable');
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index f4d6d86e4..57b53a155 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -31,7 +31,7 @@ sub general : Path : Args(0) {
my $req = $c->req;
$c->detach( 'redirect_on_signin', [ $req->param('r') ] )
- if $c->user && $req->param('r') && $req->param('r') !~ /admin/;
+ if $c->user && $req->param('r');
# all done unless we have a form posted to us
return unless $req->method eq 'POST';
@@ -182,6 +182,10 @@ Used after signing in to take the person back to where they were.
sub redirect_on_signin : Private {
my ( $self, $c, $redirect ) = @_;
$redirect = 'my' unless $redirect;
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ $redirect = 'my' if $redirect eq 'admin';
+ $redirect = 'admin' if $c->user->from_body;
+ }
$c->res->redirect( $c->uri_for( "/$redirect" ) );
}
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm
index fd3fadd9f..f103ff7f9 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -50,6 +50,8 @@ sub determine_location_from_coords : Private {
User has searched for a location - try to find it for them.
+Return -1 if nothing provided.
+
If one match is found returns true and lat/lng is set.
If several possible matches are found puts an array onto stash so that user can be prompted to pick one and returns false.
@@ -62,7 +64,7 @@ sub determine_location_from_pc : Private {
my ( $self, $c, $pc ) = @_;
# check for something to search
- $pc ||= $c->req->param('pc') || return;
+ $pc ||= $c->req->param('pc') || return -1;
$c->stash->{pc} = $pc; # for template
if ( $pc =~ /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/ ) {
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index 7b8cb649f..a4e72e9bd 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -240,8 +240,8 @@ sub output_requests : Private {
'long' => [ $problem->longitude ],
'status' => [ $problem->state ],
# 'status_notes' => [ {} ],
- 'requested_datetime' => [ w3date($problem->confirmed_local) ],
- 'updated_datetime' => [ w3date($problem->lastupdate_local) ],
+ 'requested_datetime' => [ w3date($problem->confirmed) ],
+ 'updated_datetime' => [ w3date($problem->lastupdate) ],
# 'expected_datetime' => [ {} ],
# 'address' => [ {} ],
# 'address_id' => [ {} ],
@@ -260,7 +260,7 @@ sub output_requests : Private {
if ( $problem->whensent ) {
# Not in Open311 v2
$request->{'agency_sent_datetime'} =
- [ w3date($problem->whensent_local) ];
+ [ w3date($problem->whensent) ];
}
# Extract number of updates
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 460ccaec5..57b2d781e 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -173,7 +173,10 @@ sub format_problem_for_display : Private {
if ( $c->stash->{ajax} ) {
$c->res->content_type('application/json; charset=utf-8');
my $content = JSON->new->utf8(1)->encode(
- $problem->as_hashref( $c )
+ {
+ report => $c->cobrand->problem_as_hashref( $problem, $c ),
+ updates => $c->cobrand->updates_as_hashref( $problem, $c ),
+ }
);
$c->res->body( $content );
return 1;
@@ -196,7 +199,7 @@ sub generate_map_tags : Private {
? [ {
latitude => $problem->latitude,
longitude => $problem->longitude,
- colour => 'yellow',
+ colour => $c->cobrand->moniker eq 'zurich'? $c->cobrand->pin_colour($problem) : 'yellow',
type => 'big',
} ]
: [],