aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm473
1 files changed, 275 insertions, 198 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index e14c7dc66..a3a241590 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -4,8 +4,9 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
+use Path::Class;
use POSIX qw(strftime strcoll);
-use Digest::MD5 qw(md5_hex);
+use Digest::SHA1 qw(sha1_hex);
use mySociety::EmailUtil qw(is_valid_email);
use if !$ENV{TRAVIS}, 'Image::Magick';
@@ -23,23 +24,32 @@ Admin pages
=cut
-=head2 summary
-
-Redirect to index page. There to make the allowed pages stuff neater
-
-=cut
-
sub begin : Private {
my ( $self, $c ) = @_;
$c->uri_disposition('relative');
- if ( $c->cobrand->moniker eq 'seesomething' ) {
+ if ( $c->cobrand->moniker eq 'zurich' || $c->cobrand->moniker eq 'seesomething' ) {
$c->detach( '/auth/redirect' ) unless $c->user_exists;
- $c->detach( '/auth/redirect' ) unless $c->user->from_council;
+ $c->detach( '/auth/redirect' ) unless $c->user->from_body;
+ }
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ $c->cobrand->admin_type();
}
}
+sub auto : Private {
+ my ( $self, $c ) = @_;
+
+ $c->forward('check_page_allowed');
+}
+
+=head2 summary
+
+Redirect to index page. There to make the allowed pages stuff neater
+
+=cut
+
sub summary : Path( 'summary' ) : Args(0) {
my ( $self, $c ) = @_;
$c->go( 'index' );
@@ -54,7 +64,9 @@ Displays some summary information for the requests.
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
+ if ($c->cobrand->moniker eq 'zurich' && $c->stash->{admin_type} ne 'super') {
+ return $c->cobrand->admin();
+ }
my $site_restriction = $c->cobrand->site_restriction();
@@ -124,8 +136,6 @@ sub index : Path : Args(0) {
sub timeline : Path( 'timeline' ) : Args(0) {
my ($self, $c) = @_;
- $c->forward('check_page_allowed');
-
my $site_restriction = $c->cobrand->site_restriction();
my %time;
@@ -175,8 +185,6 @@ sub timeline : Path( 'timeline' ) : Args(0) {
sub questionnaire : Path('questionnaire') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
-
my $questionnaires = $c->model('DB::Questionnaire')->search(
{ whenanswered => { '!=', undef } },
{ group_by => [ 'ever_reported' ],
@@ -207,10 +215,10 @@ sub questionnaire : Path('questionnaire') : Args(0) {
return 1;
}
-sub council_list : Path('council_list') : Args(0) {
+sub bodies : Path('bodies') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
+ $c->forward( 'get_token' );
my $edit_activity = $c->model('DB::ContactsHistory')->search(
undef,
@@ -224,54 +232,74 @@ sub council_list : Path('council_list') : Args(0) {
$c->stash->{edit_activity} = $edit_activity;
- # Not London, as treated separately
- my $area_types = $c->cobrand->moniker eq 'emptyhomes'
- ? $c->cobrand->area_types
- : [ grep { $_ ne 'LBO' } @{ $c->cobrand->area_types } ];
- my $areas = mySociety::MaPit::call('areas', $area_types);
+ my $posted = $c->req->param('posted') || '';
+ if ( $posted eq 'body' ) {
+ $c->forward('check_token');
- my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas;
- @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids );
+ my $params = $c->forward('body_params');
+ my $body = $c->model('DB::Body')->create( $params );
+ my $area_ids = $c->req->params->{area_ids};
+ if ($area_ids) {
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
+ $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
+ }
+ }
+
+ $c->stash->{updated} = _('New body added');
+ }
+
+ $c->forward( 'fetch_all_bodies' );
+
+ # XXX For fixmystreet.com, need to exclude bodies that are covering London.
+ # But soon, this means just don't have bodies covering London.
my $contacts = $c->model('DB::Contact')->search(
undef,
{
- select => [ 'area_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' },
+ select => [ 'body_id', { count => 'id' }, { count => \'case when deleted then 1 else null end' },
{ count => \'case when confirmed then 1 else null end' } ],
- as => [qw/area_id c deleted confirmed/],
- group_by => [ 'area_id' ],
+ as => [qw/body_id c deleted confirmed/],
+ group_by => [ 'body_id' ],
result_class => 'DBIx::Class::ResultClass::HashRefInflator'
}
);
- my %council_info = map { $_->{area_id} => $_ } $contacts->all;
+ my %council_info = map { $_->{body_id} => $_ } $contacts->all;
- my @no_info = grep { !$council_info{$_} } @councils_ids;
- my @one_plus_deleted = grep { $council_info{$_} && $council_info{$_}->{deleted} } @councils_ids;
- my @unconfirmeds = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} != $council_info{$_}->{c} } @councils_ids;
- my @all_confirmed = grep { $council_info{$_} && !$council_info{$_}->{deleted} && $council_info{$_}->{confirmed} == $council_info{$_}->{c} } @councils_ids;
-
- $c->stash->{areas} = $areas;
$c->stash->{counts} = \%council_info;
- $c->stash->{no_info} = \@no_info;
- $c->stash->{one_plus_deleted} = \@one_plus_deleted;
- $c->stash->{unconfirmeds} = \@unconfirmeds;
- $c->stash->{all_confirmed} = \@all_confirmed;
+
+ $c->forward( 'body_form_dropdowns' );
return 1;
}
-sub council_contacts : Path('council_contacts') : Args(1) {
- my ( $self, $c, $area_id ) = @_;
+sub body_form_dropdowns : Private {
+ my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
+ my $areas;
+ if ($c->cobrand->moniker eq 'zurich') {
+ $areas = mySociety::MaPit::call('areas', 274456);
+ } else {
+ $areas = mySociety::MaPit::call('areas', $c->cobrand->area_types);
+ }
+ $c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$areas ];
- my $posted = $c->req->param('posted') || '';
- $c->stash->{area_id} = $area_id;
+ my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders };
+ $c->stash->{send_methods} = \@methods;
+}
+
+sub body : Path('body') : Args(1) {
+ my ( $self, $c, $body_id ) = @_;
+
+ $c->stash->{body_id} = $body_id;
$c->forward( 'get_token' );
+ $c->forward( 'lookup_body' );
+ $c->forward( 'fetch_all_bodies' );
+ $c->forward( 'body_form_dropdowns' );
- if ( $posted ) {
+ if ( $c->req->param('posted') ) {
$c->log->debug( 'posted' );
$c->forward('update_contacts');
}
@@ -285,7 +313,7 @@ sub update_contacts : Private {
my ( $self, $c ) = @_;
my $posted = $c->req->param('posted');
- my $editor = $c->req->remote_user || _('*unknown*');
+ my $editor = $c->forward('get_user');
if ( $posted eq 'new' ) {
$c->forward('check_token');
@@ -297,7 +325,7 @@ sub update_contacts : Private {
my $contact = $c->model('DB::Contact')->find_or_new(
{
- area_id => $c->stash->{area_id},
+ body_id => $c->stash->{body_id},
category => $category,
}
);
@@ -331,7 +359,7 @@ sub update_contacts : Private {
my $contacts = $c->model('DB::Contact')->search(
{
- area_id => $c->stash->{area_id},
+ body_id => $c->stash->{body_id},
category => { -in => \@categories },
}
);
@@ -346,69 +374,50 @@ sub update_contacts : Private {
);
$c->stash->{updated} = _('Values updated');
- } elsif ( $posted eq 'open311' ) {
+ } elsif ( $posted eq 'body' ) {
$c->forward('check_token');
- my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts extended_statuses comment_user_id devolved/;
-
- if ( $params{open311_id} ) {
- my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } );
-
- $conf->endpoint( $params{endpoint} );
- $conf->jurisdiction( $params{jurisdiction} );
- $conf->api_key( $params{api_key} );
- $conf->send_method( $params{send_method} );
- $conf->send_comments( $params{send_comments} || 0);
- $conf->suppress_alerts( $params{suppress_alerts} || 0);
- $conf->comment_user_id( $params{comment_user_id} || undef );
- $conf->can_be_devolved( $params{devolved} || 0 );
- $conf->send_extended_statuses( $params{extended_statuses} || 0 );
-
- $conf->update();
-
- $c->stash->{updated} = _('Configuration updated');
- } else {
- my $conf = $c->model('DB::Open311Conf')->find_or_new( { area_id => $params{area_id} } );
-
- $conf->endpoint( $params{endpoint} );
- $conf->jurisdiction( $params{jurisdiction} );
- $conf->api_key( $params{api_key} );
- $conf->send_method( $params{send_method} );
- $conf->send_comments( $params{send_comments} || 0);
- $conf->suppress_alerts( $params{suppress_alerts} || 0);
- $conf->comment_user_id( $params{comment_user_id} || undef );
- $conf->can_be_devolved( $params{devolved} || 0 );
- $conf->send_extended_statuses( $params{extended_statuses} || 0 );
-
- $conf->insert();
-
- $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later');
+ my $params = $c->forward( 'body_params' );
+ $c->stash->{body}->update( $params );
+ my @current = $c->stash->{body}->body_areas->all;
+ my %current = map { $_->area_id => 1 } @current;
+ my $area_ids = $c->req->params->{area_ids};
+ if ($area_ids) {
+ $area_ids = [ $area_ids ] unless ref $area_ids;
+ foreach (@$area_ids) {
+ $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } );
+ delete $current{$_};
+ }
}
+ # Remove any others
+ $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete;
+
+ $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later');
}
}
-sub display_contacts : Private {
+sub body_params : Private {
my ( $self, $c ) = @_;
- $c->forward('setup_council_details');
-
- my $area_id = $c->stash->{area_id};
-
- my $contacts = $c->model('DB::Contact')->search(
- { area_id => $area_id },
- { order_by => ['category'] }
+ my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts send_extended_statuses comment_user_id can_be_devolved parent/;
+ my %defaults = map { $_ => '' } @fields;
+ %defaults = ( %defaults,
+ send_comments => 0,
+ suppress_alerts => 0,
+ comment_user_id => undef,
+ send_extended_statuses => 0,
+ can_be_devolved => 0,
+ parent => undef,
);
+ my %params = map { $_ => $c->req->param($_) || $defaults{$_} } @fields;
+ return \%params;
+}
- $c->stash->{contacts} = $contacts;
-
- my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders };
- $c->stash->{send_methods} = \@methods;
-
- my $open311 = $c->model('DB::Open311Conf')->search(
- { area_id => $area_id }
- );
+sub display_contacts : Private {
+ my ( $self, $c ) = @_;
- $c->stash->{open311} = $open311;
+ my $contacts = $c->stash->{body}->contacts->search(undef, { order_by => [ 'category' ] } );
+ $c->stash->{contacts} = $contacts;
if ( $c->req->param('text') && $c->req->param('text') == 1 ) {
$c->stash->{template} = 'admin/council_contacts.txt';
@@ -419,59 +428,52 @@ sub display_contacts : Private {
return 1;
}
-sub setup_council_details : Private {
+sub lookup_body : Private {
my ( $self, $c ) = @_;
- my $area_id = $c->stash->{area_id};
-
- my $mapit_data = mySociety::MaPit::call('area', $area_id);
-
- $c->stash->{council_name} = $mapit_data->{name};
-
- my $example_postcode = mySociety::MaPit::call('area/example_postcode', $area_id);
-
- if ($example_postcode && ! ref $example_postcode) {
- $c->stash->{example_pc} = $example_postcode;
+ my $body_id = $c->stash->{body_id};
+ my $body = $c->model('DB::Body')->find($body_id);
+ $c->detach( '/page_error_404_not_found' )
+ unless $body;
+ $c->stash->{body} = $body;
+
+ if ($body->body_areas->first) {
+ my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
+ if ($example_postcode && ! ref $example_postcode) {
+ $c->stash->{example_pc} = $example_postcode;
+ }
}
return 1;
}
-sub council_edit_all : Path('council_edit') {
- my ( $self, $c, $area_id, @category ) = @_;
+# This is for if the category name contains a '/'
+sub body_edit_all : Path('body_edit') {
+ my ( $self, $c, $body_id, @category ) = @_;
my $category = join( '/', @category );
- $c->go( 'council_edit', [ $area_id, $category ] );
+ $c->go( 'body_edit', [ $body_id, $category ] );
}
-sub council_edit : Path('council_edit') : Args(2) {
- my ( $self, $c, $area_id, $category ) = @_;
+sub body_edit : Path('body_edit') : Args(2) {
+ my ( $self, $c, $body_id, $category ) = @_;
- $c->forward('check_page_allowed');
-
- $c->stash->{area_id} = $area_id;
+ $c->stash->{body_id} = $body_id;
$c->forward( 'get_token' );
- $c->forward('setup_council_details');
-
- my $contact = $c->model('DB::Contact')->search(
- {
- area_id => $area_id,
- category => $category
- }
- )->first;
+ $c->forward( 'lookup_body' );
+ my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first;
$c->stash->{contact} = $contact;
my $history = $c->model('DB::ContactsHistory')->search(
{
- area_id => $area_id,
+ body_id => $body_id,
category => $category
},
{
order_by => ['contacts_history_id']
},
);
-
$c->stash->{history} = $history;
my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders };
@@ -480,13 +482,11 @@ sub council_edit : Path('council_edit') : Args(2) {
return 1;
}
-sub search_reports : Path('search_reports') {
+sub reports : Path('reports') {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
-
if (my $search = $c->req->param('search')) {
- $c->stash->{searched} = 1;
+ $c->stash->{searched} = $search;
my $site_restriction = $c->cobrand->site_restriction;
@@ -523,7 +523,7 @@ sub search_reports : Path('search_reports') {
'me.name' => { ilike => $like_search },
'me.title' => { ilike => $like_search },
detail => { ilike => $like_search },
- council => { like => $like_search },
+ bodies_str => { like => $like_search },
cobrand_data => { like => $like_search },
];
}
@@ -542,8 +542,8 @@ sub search_reports : Path('search_reports') {
# will have been turned off
$c->stash->{problems} = [ $problems->all ];
- $c->stash->{edit_council_contacts} = 1
- if ( grep {$_ eq 'councilcontacts'} keys %{$c->stash->{allowed_pages}});
+ $c->stash->{edit_body_contacts} = 1
+ if ( grep {$_ eq 'body'} keys %{$c->stash->{allowed_pages}});
if (is_valid_email($search)) {
$query = [
@@ -574,7 +574,7 @@ sub search_reports : Path('search_reports') {
-or => $query,
},
{
- -select => [ 'me.*', qw/problem.council problem.state/ ],
+ -select => [ 'me.*', qw/problem.bodies_str problem.state/ ],
prefetch => [qw/user problem/],
order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created']
}
@@ -592,11 +592,7 @@ sub report_edit : Path('report_edit') : Args(1) {
my $site_restriction = $c->cobrand->site_restriction;
- my $problem = $c->cobrand->problems->search(
- {
- id => $id,
- }
- )->first;
+ my $problem = $c->cobrand->problems->search( { id => $id } )->first;
$c->detach( '/page_error_404_not_found' )
unless $problem;
@@ -604,7 +600,32 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->stash->{problem} = $problem;
$c->forward('get_token');
- $c->forward('check_page_allowed');
+
+ if ( $c->req->param('rotate_photo') ) {
+ $c->forward('rotate_photo');
+ return 1;
+ }
+
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+
+ FixMyStreet::Map::display_map(
+ $c,
+ latitude => $problem->latitude,
+ longitude => $problem->longitude,
+ pins => $problem->used_map
+ ? [ {
+ latitude => $problem->latitude,
+ longitude => $problem->longitude,
+ colour => 'yellow',
+ type => 'big',
+ } ]
+ : [],
+ );
+
+ my $done = $c->cobrand->admin_report_edit();
+ return if $done;
+ }
+
$c->forward('check_email_for_abuse', [ $problem->user->email ] );
$c->stash->{updates} =
@@ -633,9 +654,6 @@ sub report_edit : Path('report_edit') : Args(1) {
elsif ( $c->req->param('banuser') ) {
$c->forward('ban_user');
}
- elsif ( $c->req->param('rotate_photo') ) {
- $c->forward('rotate_photo');
- }
elsif ( $c->req->param('submit') ) {
$c->forward('check_token');
@@ -664,6 +682,7 @@ sub report_edit : Path('report_edit') : Args(1) {
|| $c->req->param('email') ne $problem->user->email
|| $c->req->param('title') ne $problem->title
|| $c->req->param('detail') ne $problem->detail
+ || ($c->req->param('body') && $c->req->param('body') ne $problem->bodies_str)
|| $flagged != $problem->flagged
|| $non_public != $problem->non_public )
{
@@ -673,8 +692,10 @@ sub report_edit : Path('report_edit') : Args(1) {
$problem->anonymous( $c->req->param('anonymous') );
$problem->title( $c->req->param('title') );
$problem->detail( $c->req->param('detail') );
- $problem->state( $c->req->param('state') );
+ $problem->state( $new_state );
$problem->name( $c->req->param('name') );
+ $problem->bodies_str( $c->req->param('body') ) if $c->req->param('body');
+
$problem->flagged( $flagged );
$problem->non_public( $non_public );
@@ -721,26 +742,22 @@ sub report_edit : Path('report_edit') : Args(1) {
return 1;
}
-sub search_users: Path('search_users') : Args(0) {
+sub users: Path('users') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
-
if (my $search = $c->req->param('search')) {
- $c->stash->{searched} = 1;
+ $c->stash->{searched} = $search;
- my $search = $c->req->param('search');
my $isearch = '%' . $search . '%';
-
my $search_n = 0;
$search_n = int($search) if $search =~ /^\d+$/;
my $users = $c->model('DB::User')->search(
{
-or => [
- email => { ilike => $isearch },
- name => { ilike => $isearch },
- from_council => $search_n,
+ email => { ilike => $isearch },
+ name => { ilike => $isearch },
+ from_body => $search_n,
]
}
);
@@ -762,6 +779,9 @@ sub search_users: Path('search_users') : Args(0) {
}
}
+ } else {
+ $c->forward('get_token');
+ $c->forward('fetch_all_bodies');
}
return 1;
@@ -782,7 +802,6 @@ sub update_edit : Path('update_edit') : Args(1) {
unless $update;
$c->forward('get_token');
- $c->forward('check_page_allowed');
$c->stash->{update} = $update;
@@ -837,6 +856,11 @@ sub update_edit : Path('update_edit') : Args(1) {
if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) {
$update->confirmed( \'ms_current_timestamp()' );
+ if ( $update->problem_state && $update->created > $update->problem->lastupdate ) {
+ $update->problem->state( $update->problem_state );
+ $update->problem->lastupdate( \'ms_current_timestamp()' );
+ $update->problem->update;
+ }
}
$update->update;
@@ -868,16 +892,44 @@ sub update_edit : Path('update_edit') : Args(1) {
return 1;
}
+sub user_add : Path('user_edit') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{template} = 'admin/user_edit.html';
+ $c->forward('get_token');
+ $c->forward('fetch_all_bodies');
+
+ return 1 unless $c->req->param('submit');
+
+ $c->forward('check_token');
+
+ my $user = $c->model('DB::User')->find_or_create( {
+ name => $c->req->param('name'),
+ email => $c->req->param('email'),
+ from_body => $c->req->param('body') || undef,
+ flagged => $c->req->param('flagged') || 0,
+ }, {
+ key => 'users_email_key'
+ } );
+ $c->stash->{user} = $user;
+
+ $c->forward( 'log_edit', [ $user->id, 'user', 'edit' ] );
+
+ $c->stash->{status_message} =
+ '<p><em>' . _('Updated!') . '</em></p>';
+
+ return 1;
+}
+
sub user_edit : Path('user_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
- $c->forward('check_page_allowed');
$c->forward('get_token');
my $user = $c->model('DB::User')->find( { id => $id } );
$c->stash->{user} = $user;
- $c->forward('set_up_council_details');
+ $c->forward('fetch_all_bodies');
if ( $c->req->param('submit') ) {
$c->forward('check_token');
@@ -886,13 +938,15 @@ sub user_edit : Path('user_edit') : Args(1) {
if ( $user->email ne $c->req->param('email') ||
$user->name ne $c->req->param('name' ) ||
- $user->from_council != $c->req->param('council') ) {
+ ($user->from_body && $user->from_body->id ne $c->req->param('body')) ||
+ (!$user->from_body && $c->req->param('body'))
+ ) {
$edited = 1;
}
$user->name( $c->req->param('name') );
$user->email( $c->req->param('email') );
- $user->from_council( $c->req->param('council') || undef );
+ $user->from_body( $c->req->param('body') || undef );
$user->flagged( $c->req->param('flagged') || 0 );
$user->update;
@@ -907,11 +961,9 @@ sub user_edit : Path('user_edit') : Args(1) {
return 1;
}
-sub list_flagged : Path('list_flagged') : Args(0) {
+sub flagged : Path('flagged') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
-
my $problems = $c->model('DB::Problem')->search( { flagged => 1 } );
# pass in as array ref as using same template as search_reports
@@ -928,9 +980,7 @@ sub list_flagged : Path('list_flagged') : Args(0) {
sub stats : Path('stats') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('check_page_allowed');
-
- $c->forward('set_up_council_details');
+ $c->forward('fetch_all_bodies');
if ( $c->cobrand->moniker eq 'seesomething' ) {
return $c->cobrand->admin_stats();
@@ -970,11 +1020,11 @@ sub stats : Path('stats') : Args(0) {
my $bymonth = $c->req->param('bymonth');
$c->stash->{bymonth} = $bymonth;
- my ( %council, %dates );
- $council{council} = { like => $c->req->param('council') }
- if $c->req->param('council');
+ my ( %body, %dates );
+ $body{bodies_str} = { like => $c->req->param('body') }
+ if $c->req->param('body');
- $c->stash->{selected_council} = $c->req->param('council');
+ $c->stash->{selected_body} = $c->req->param('body');
my $field = 'confirmed';
@@ -1009,7 +1059,7 @@ sub stats : Path('stats') : Args(0) {
$field => { '>=', $start_date},
$field => { '<=', $end_date + $one_day },
],
- %council,
+ %body,
%dates,
},
\%select,
@@ -1038,16 +1088,16 @@ sub set_allowed_pages : Private {
if( !$pages ) {
$pages = {
'summary' => [_('Summary'), 0],
- 'council_list' => [_('Bodies'), 1],
- 'search_reports' => [_('Reports'), 2],
+ 'bodies' => [_('Bodies'), 1],
+ 'reports' => [_('Reports'), 2],
'timeline' => [_('Timeline'), 3],
'questionnaire' => [_('Survey'), 4],
- 'search_users' => [_('Users'), 5],
- 'list_flagged' => [_('Flagged'), 6],
+ 'users' => [_('Users'), 5],
+ 'flagged' => [_('Flagged'), 6],
'stats' => [_('Stats'), 6],
'user_edit' => [undef, undef],
- 'council_contacts' => [undef, undef],
- 'council_edit' => [undef, undef],
+ 'body' => [undef, undef],
+ 'body_edit' => [undef, undef],
'report_edit' => [undef, undef],
'update_edit' => [undef, undef],
'abuse_edit' => [undef, undef],
@@ -1062,6 +1112,16 @@ sub set_allowed_pages : Private {
return 1;
}
+sub get_user : Private {
+ my ( $self, $c ) = @_;
+
+ my $user = $c->req->remote_user();
+ $user ||= ($c->user && $c->user->name);
+ $user ||= '';
+
+ return $user;
+}
+
=item get_token
Generate a token based on user and secret
@@ -1072,12 +1132,8 @@ sub get_token : Private {
my ( $self, $c ) = @_;
my $secret = $c->model('DB::Secret')->search()->first;
-
- my $user = $c->req->remote_user();
- $user ||= '';
-
- my $token = md5_hex(($user . $secret->secret));
-
+ my $user = $c->forward('get_user');
+ my $token = sha1_hex($user . $secret->secret);
$c->stash->{token} = $token;
return 1;
@@ -1104,7 +1160,7 @@ sub check_token : Private {
$c->forward( 'log_edit', [ $object_id, $object_type, $action_performed ] );
-Adds an entry into the admin_log table using the current remote_user.
+Adds an entry into the admin_log table using the current user.
=cut
@@ -1112,7 +1168,7 @@ sub log_edit : Private {
my ( $self, $c, $id, $object_type, $action ) = @_;
$c->model('DB::AdminLog')->create(
{
- admin_user => ( $c->req->remote_user() || '' ),
+ admin_user => $c->forward('get_user'),
object_type => $object_type,
action => $action,
object_id => $id,
@@ -1232,21 +1288,42 @@ sub rotate_photo : Private {
my ( $self, $c ) =@_;
my $direction = $c->req->param('rotate_photo');
-
return unless $direction =~ /Left/ or $direction =~ /Right/;
- my $photo = _rotate_image( $c->stash->{problem}->photo, $direction =~ /Left/ ? -90 : 90 );
+ my $photo = $c->stash->{problem}->photo;
+ my $file;
+
+ # If photo field contains a hash
+ if ( length($photo) == 40 ) {
+ $file = file( $c->config->{UPLOAD_DIR}, "$photo.jpeg" );
+ $photo = $file->slurp;
+ }
- if ( $photo ) {
- $c->stash->{rotated} = 1;
- $c->stash->{problem}->photo( $photo );
+ $photo = _rotate_image( $photo, $direction =~ /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;
+
+ my $fh = $file->open('w');
+ print $fh $photo;
+ close $fh;
+
+ unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' );
+
+ if ( $fileid ) {
+ $c->stash->{problem}->photo( $fileid );
$c->stash->{problem}->update();
}
return 1;
}
-
=head2 check_page_allowed
Checks if the current catalyst action is in the list of allowed pages and
@@ -1270,16 +1347,16 @@ sub check_page_allowed : Private {
return 1;
}
-sub set_up_council_details : Private {
+sub fetch_all_bodies : Private {
my ($self, $c ) = @_;
- my $areas = mySociety::MaPit::call('areas', $c->cobrand->area_types);
-
- my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas;
- @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids );
-
- $c->stash->{council_ids} = \@councils_ids;
- $c->stash->{council_details} = $areas;
+ my @bodies = $c->model('DB::Body')->all;
+ if ( $c->cobrand->moniker eq 'zurich' ) {
+ @bodies = $c->cobrand->admin_fetch_all_bodies( @bodies );
+ } else {
+ @bodies = sort { strcoll($a->name, $b->name) } @bodies;
+ }
+ $c->stash->{bodies} = \@bodies;
return 1;
}