From 00663dc1bed13a586ed4555086463f51be38ed4e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 23 Mar 2012 13:43:06 +0000 Subject: initial code to display user title if council is Bromley --- perllib/FixMyStreet/App/Controller/Report/New.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index af4cdd5aa..68a30ca2c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -124,12 +124,14 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $category = $c->render_fragment( 'report/new/category.html'); my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); my $has_open311 = keys %{ $c->stash->{category_extras} }; + my $extra_name_info = $c->render_fragment('report/new/extra_name.html'); my $body = JSON->new->utf8(1)->encode( { councils_text => $councils_text, category => $category, has_open311 => $has_open311, + extra_name_info => $extra_name_info, } ); @@ -542,7 +544,7 @@ sub setup_categories_and_councils : Private { ); $category_label = _('Property type:'); - } elsif ($first_council->{type} eq 'LBO') { + } elsif ($first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { $area_ids_to_list{ $first_council->{id} } = 1; @category_options = ( @@ -589,6 +591,7 @@ sub setup_categories_and_councils : Private { $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{category_extras_json} = encode_json \%category_extras; + $c->stash->{extra_name_info} = $first_council->{id} == 2482 ? 1 : 0; my @missing_details_councils = grep { !$area_ids_to_list{$_} } # @@ -733,7 +736,7 @@ sub process_report : Private { $councils = join( ',', @{ $c->stash->{area_ids_to_list} } ) || -1; $report->council( $councils ); - } elsif ( $first_council->{type} eq 'LBO') { + } elsif ( $first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); @@ -785,6 +788,16 @@ sub process_report : Private { }; } + if ( $contacts[0]->area_id == 2482 ) { + for my $field ( qw/ fms_extra_title / ) { + push @extra, { + name => $field, + description => uc( $field), + value => $c->request->param( $field ) || '', + }; + } + } + if ( @extra ) { $c->stash->{report_meta} = \@extra; $report->extra( \@extra ); @@ -916,6 +929,8 @@ sub check_for_errors : Private { %{ $c->stash->{report}->check_for_errors }, ); + # FIXME: need to check for required bromley fields here + # if they're got the login details wrong when signing in then # we don't care about the name field even though it's validated # by the user object -- cgit v1.2.3 From fe7ea6cdb3d8dd64d7d644870476b9cc33c9cf86 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 23 Mar 2012 14:52:19 +0000 Subject: save extra comment details for bromley --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 15444f556..772a0b8ee 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -185,6 +185,13 @@ sub process_update : Private { $update->problem_state( $params{state} ); } + if ( $c->req->param('fms_extra_title') ) { + my %extras = (); + $extras{title} = $c->req->param('fms_extra_title'); + $extras{email_alerts_required} = $c->req->param('add_alert'); + $update->extra( \%extras ); + } + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); -- cgit v1.2.3 From afc0d9423f53180629ba1fa9c3605b9d2528d57d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 27 Mar 2012 23:38:26 +0100 Subject: Put template in default so other cobrands can find it, but make code only look for it if necessary too. --- perllib/FixMyStreet/App/Controller/Report/New.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 68a30ca2c..ff0c64dc9 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -124,7 +124,9 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $category = $c->render_fragment( 'report/new/category.html'); my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); my $has_open311 = keys %{ $c->stash->{category_extras} }; - my $extra_name_info = $c->render_fragment('report/new/extra_name.html'); + my $extra_name_info = $c->stash->{extra_name_info} + ? $c->render_fragment('report/new/extra_name.html') + : ''; my $body = JSON->new->utf8(1)->encode( { -- cgit v1.2.3 From 58908e67709f7a584712296dad93ae873f7ecef4 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 28 Mar 2012 17:45:10 +0100 Subject: Tweaks to category display. --- perllib/FixMyStreet/App/Controller/Report/New.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ff0c64dc9..9baee5eb4 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -553,7 +553,7 @@ sub setup_categories_and_councils : Private { _('-- Pick a category --'), sort keys %{ Utils::london_categories() } ); - $category_label = _('Category:'); + $category_label = _('Category'); } else { @@ -583,7 +583,7 @@ sub setup_categories_and_councils : Private { if (@category_options) { @category_options = ( _('-- Pick a category --'), @category_options, _('Other') ); - $category_label = _('Category:'); + $category_label = _('Category'); } } -- cgit v1.2.3 From 32a74ddaf0f203ef9c9a28dc08c650c643e09de1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 30 Mar 2012 12:44:59 +0100 Subject: add first name and last name boxes for bromley --- perllib/FixMyStreet/App/Controller/Report/New.pm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 9baee5eb4..ac462e293 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -398,6 +398,13 @@ sub initialize_report : Private { } + if ( $c->req->param('first_name') && $c->req->param('last_name') ) { + $c->stash->{first_name} = $c->req->param('first_name'); + $c->stash->{last_name} = $c->req->param('last_name'); + + $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) ); + } + # Capture whether the map was used $report->used_map( $c->req->param('skipped') ? 0 : 1 ); @@ -791,13 +798,22 @@ sub process_report : Private { } if ( $contacts[0]->area_id == 2482 ) { - for my $field ( qw/ fms_extra_title / ) { + for my $field ( qw/ fms_extra_title first_name last_name / ) { + my $value = $c->request->param( $field ); + if ( !$value ) { + $c->stash->{field_errors}->{ $field } = _('This information is required'); + } push @extra, { name => $field, description => uc( $field), - value => $c->request->param( $field ) || '', + value => $value || '', }; } + + if ( $c->request->param('fms_extra_title') ) { + $c->stash->{fms_extra_title} = $c->request->param('fms_extra_title'); + $c->stash->{extra_name_info} = 1; + } } if ( @extra ) { -- cgit v1.2.3 From d0ad2aa1df43fcdbb853eb2d53c9618084c9ba46 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 30 Mar 2012 17:45:12 +0100 Subject: add in first and last name to updates --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 772a0b8ee..114c86c28 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -153,6 +153,15 @@ want to move adding these elsewhere sub process_update : Private { my ( $self, $c ) = @_; + if ( $c->req->param('first_name' ) && $c->req->param('last_name' ) ) { + my $first_name = $c->req->param('first_name'); + my $last_name = $c->req->param('last_name'); + $c->req->param('name', sprintf( '%s %s', $first_name, $last_name ) ); + + $c->stash->{first_name} = $first_name; + $c->stash->{last_name} = $last_name; + } + my %params = map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); @@ -190,8 +199,19 @@ sub process_update : Private { $extras{title} = $c->req->param('fms_extra_title'); $extras{email_alerts_required} = $c->req->param('add_alert'); $update->extra( \%extras ); + + $c->stash->{fms_extra_title} = $c->req->param('fms_extra_title'); } + if ( $c->stash->{ first_name } && $c->stash->{ last_name } ) { + my $extra = $update->extra || {}; + $extra->{first_name} = $c->stash->{ first_name }; + $extra->{last_name} = $c->stash->{ last_name }; + $update->extra( $extra ); + } + + $c->log->debug( 'name is ' . $c->req->param('name') ); + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); -- cgit v1.2.3 From cfa337b7d1165d81a1eb1907f8555df1a55633c1 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 2 Apr 2012 17:08:05 +0100 Subject: tests for title, first and last name for bromley issues some fixes for handling this on main site --- perllib/FixMyStreet/App/Controller/Report/New.pm | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ac462e293..003de943d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -800,6 +800,11 @@ sub process_report : Private { if ( $contacts[0]->area_id == 2482 ) { for my $field ( qw/ fms_extra_title first_name last_name / ) { my $value = $c->request->param( $field ); + next if ( + $c->cobrand->moniker ne 'bromley' && + ( $field eq 'first_name' || $field eq 'last_name' ) + ); + if ( !$value ) { $c->stash->{field_errors}->{ $field } = _('This information is required'); } -- cgit v1.2.3 From d3e033d5426144dcc7bf0da3170fbf2361d22ba6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 2 Apr 2012 17:38:21 +0100 Subject: move special field processing out to cobrands --- perllib/FixMyStreet/App/Controller/Report/New.pm | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 003de943d..7b630d36f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -797,29 +797,7 @@ sub process_report : Private { }; } - if ( $contacts[0]->area_id == 2482 ) { - for my $field ( qw/ fms_extra_title first_name last_name / ) { - my $value = $c->request->param( $field ); - next if ( - $c->cobrand->moniker ne 'bromley' && - ( $field eq 'first_name' || $field eq 'last_name' ) - ); - - if ( !$value ) { - $c->stash->{field_errors}->{ $field } = _('This information is required'); - } - push @extra, { - name => $field, - description => uc( $field), - value => $value || '', - }; - } - - if ( $c->request->param('fms_extra_title') ) { - $c->stash->{fms_extra_title} = $c->request->param('fms_extra_title'); - $c->stash->{extra_name_info} = 1; - } - } + $c->cobrand->process_extras( $c, \@contacts, \@extra ); if ( @extra ) { $c->stash->{report_meta} = \@extra; -- cgit v1.2.3 From be55b3690d50cd84de0088b9d91d29e8a2e146ed Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 Apr 2012 16:51:35 +0100 Subject: Editing interface to set send method for council --- perllib/FixMyStreet/App/Controller/Admin.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 83f77f401..7fc6fe6a5 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -7,6 +7,8 @@ BEGIN { extends 'Catalyst::Controller'; } use POSIX qw(strftime strcoll); use Digest::MD5 qw(md5_hex); +use FixMyStreet::SendReport; + =head1 NAME FixMyStreet::App::Controller::Admin- Catalyst Controller @@ -345,6 +347,9 @@ sub update_contacts : Private { $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} ); + $conf->comment_user_id( $params{comment_user_id} ); $conf->update(); @@ -355,6 +360,9 @@ sub update_contacts : Private { $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} ); + $conf->comment_user_id( $params{comment_user_id} ); $conf->insert(); @@ -377,6 +385,9 @@ sub display_contacts : Private { $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 } ); -- cgit v1.2.3 From 58f598580a1179fe8d1910087e9562230d230713 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 Apr 2012 11:53:51 +0100 Subject: actually grab params before we use them --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7fc6fe6a5..0fa38747a 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -339,7 +339,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $c->forward('check_token'); - my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id/; + my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments comment_user_id/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); -- cgit v1.2.3 From c84e7651e0c8a888495205ad1c19b7f3e89f95ea Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 24 Apr 2012 17:52:40 +0100 Subject: Fewer photos on /alert for Bromley. --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 2698c6ac0..c127b7460 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -470,6 +470,7 @@ sub add_recent_photos : Private { { $c->stash->{photos} = $c->cobrand->recent_photos( + 'alert', $num_photos, $c->stash->{latitude}, $c->stash->{longitude}, @@ -477,7 +478,7 @@ sub add_recent_photos : Private { ); } else { - $c->stash->{photos} = $c->cobrand->recent_photos($num_photos); + $c->stash->{photos} = $c->cobrand->recent_photos('alert', $num_photos); } return 1; -- cgit v1.2.3 From ea4e2e7439af48f7fa4382fa1fe15a1fa2f1c8c7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 Apr 2012 16:47:11 +0100 Subject: unset comment user if none passed in --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0fa38747a..b1ef2f0f3 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -349,7 +349,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); - $conf->comment_user_id( $params{comment_user_id} ); + $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->update(); @@ -362,7 +362,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); - $conf->comment_user_id( $params{comment_user_id} ); + $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->insert(); -- cgit v1.2.3 From 0eec3a2bbe1eb94267a9694baa10d13a5fb484be Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 1 May 2012 13:53:18 +0100 Subject: Fix CM8 Bromley pin colours. --- perllib/FixMyStreet/App/Controller/Around.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index e110cf8d7..6fbfad5dc 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -186,10 +186,11 @@ sub display_location : Private { @pins = map { # Here we might have a DB::Problem or a DB::Nearby, we always want the problem. my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_; + my $colour = $c->cobrand->pin_colour( $p ); { latitude => $p->latitude, longitude => $p->longitude, - colour => 'yellow', # $p->is_fixed ? 'green' : 'red', + colour => $colour, id => $p->id, title => $p->title, } -- cgit v1.2.3 From 4b08e5136db27ab0d69d070e77dcd92193f86752 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 1 May 2012 19:17:38 +0100 Subject: store title in users table so we can persist it for bromley --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- perllib/FixMyStreet/App/Controller/Report/New.pm | 9 +++++++-- perllib/FixMyStreet/App/Controller/Report/Update.pm | 8 +++++++- perllib/FixMyStreet/App/Controller/Tokens.pm | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b1ef2f0f3..42e218f61 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -490,7 +490,7 @@ sub search_reports : Path('search_reports') { 'me.id' => $search_n, 'user.email' => { ilike => $like_search }, 'me.name' => { ilike => $like_search }, - title => { ilike => $like_search }, + 'me.title' => { ilike => $like_search }, detail => { ilike => $like_search }, council => { like => $like_search }, cobrand_data => { like => $like_search }, diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 7b630d36f..ca2dfc6b5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -643,9 +643,10 @@ sub process_user : Private { # The user is already signed in if ( $c->user_exists ) { my $user = $c->user->obj; - my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone' ); + my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' ); $user->name( Utils::trim_text( $params{name} ) ) if $params{name}; $user->phone( Utils::trim_text( $params{phone} ) ); + $user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->user( $user ); $report->name( $user->name ); return 1; @@ -653,7 +654,7 @@ sub process_user : Private { # Extract all the params to a hash to make them easier to work with my %params = map { $_ => scalar $c->req->param($_) } - ( 'email', 'name', 'phone', 'password_register' ); + ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{email} ? lc $params{email} : ''; @@ -681,6 +682,7 @@ sub process_user : Private { $report->user->phone( Utils::trim_text( $params{phone} ) ); $report->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $report->user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->name( Utils::trim_text( $params{name} ) ); return 1; @@ -973,10 +975,12 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->name( undef ); $report->user->phone( undef ); $report->user->password( '', 1 ); + $report->user->title( undef ); $report->user->insert(); $c->log->info($report->user->id . ' created for this report'); } @@ -992,6 +996,7 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->discard_changes(); $c->log->info($report->user->id . ' exists, but is not logged in for this report'); diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 114c86c28..8be513b08 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -104,13 +104,16 @@ sub process_user : Private { my $user = $c->user->obj; my $name = scalar $c->req->param('name'); $user->name( Utils::trim_text( $name ) ) if $name; + my $title = scalar $c->req->param('fms_extra_title'); + $c->log->debug( 'user exists and title is ' . $title ); + $user->title( Utils::trim_text( $title ) ) if $title; $update->user( $user ); return 1; } # Extract all the params to a hash to make them easier to work with my %params = map { $_ => scalar $c->req->param($_) } - ( 'rznvy', 'name', 'password_register' ); + ( 'rznvy', 'name', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{rznvy} ? lc $params{rznvy} : ''; @@ -136,6 +139,8 @@ sub process_user : Private { if $params{name}; $update->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $update->user->title( Utils::trim_text( $params{fms_extra_title} ) ) + if $params{fms_extra_title}; return 1; } @@ -295,6 +300,7 @@ sub save_update : Private { } elsif ( $c->user && $c->user->id == $update->user->id ) { # Logged in and same user, so can confirm update straight away + $c->log->debug( 'user exists' ); $update->user->update; $update->confirm; } else { diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index b974f94e6..1434838f2 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -71,6 +71,7 @@ sub confirm_problem : Path('/P') { $problem->user->name( $data->{name} ) if $data->{name}; $problem->user->phone( $data->{phone} ) if $data->{phone}; $problem->user->password( $data->{password}, 1 ) if $data->{password}; + $problem->user->title( $data->{title} ) if $data->{title}; $problem->user->update; } $c->authenticate( { email => $problem->user->email }, 'no_password' ); -- cgit v1.2.3 From beb06981bbddf1113688532d80a83e181d52d762 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 2 May 2012 16:56:21 +0100 Subject: Enable council user to remove report from site using front end button. --- perllib/FixMyStreet/App/Controller/Report.pm | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index afe180c29..cca625bd5 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -153,6 +153,36 @@ sub generate_map_tags : Private { return 1; } +sub delete :Local :Args(1) { + my ( $self, $c, $id ) = @_; + + $c->forward( 'load_problem_or_display_error', [ $id ] ); + my $p = $c->stash->{problem}; + + my $uri = $c->uri_for( '/report', $id ); + + return $c->res->redirect($uri) unless $c->user_exists; + + my $council = $c->user->obj->from_council; + return $c->res->redirect($uri) unless $council; + + my %councils = map { $_ => 1 } @{$p->councils}; + return $c->res->redirect($uri) unless $councils{$council}; + + $p->state('hidden'); + $p->lastupdate( \'ms_current_timestamp()' ); + $p->update; + + $c->model('DB::AdminLog')->create( { + admin_user => $c->user->email, + object_type => 'problem', + action => 'state_change', + object_id => $id, + } ); + + return $c->res->redirect($uri); +} + __PACKAGE__->meta->make_immutable; 1; -- cgit v1.2.3 From de24857f0b0c440cad69974c7c1d7f91fbb79a21 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 4 May 2012 20:32:59 +0100 Subject: Dashboard initial start. --- perllib/FixMyStreet/App/Controller/Admin.pm | 10 +- perllib/FixMyStreet/App/Controller/Dashboard.pm | 124 ++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 perllib/FixMyStreet/App/Controller/Dashboard.pm (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 42e218f61..d11f1645e 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -547,8 +547,7 @@ sub report_edit : Path('report_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $problem; $c->stash->{problem} = $problem; @@ -710,8 +709,7 @@ sub update_edit : Path('update_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $update; $c->forward('get_token'); @@ -1044,7 +1042,7 @@ sub check_token : Private { my ( $self, $c ) = @_; if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; @@ -1214,7 +1212,7 @@ sub check_page_allowed : Private { $page ||= 'summary'; if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm new file mode 100644 index 000000000..74588df36 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -0,0 +1,124 @@ +package FixMyStreet::App::Controller::Dashboard; +use Moose; +use namespace::autoclean; + +use DateTime; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Dashboard - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +=head2 check_page_allowed + +Checks if we can view this page, and if not redirect to 404. + +=cut + +sub check_page_allowed : Private { + my ( $self, $c ) = @_; + + $c->detach( '/page_error_404_not_found' ) + unless $c->user_exists && $c->user->from_council; + + return $c->user->from_council; +} + +=head2 index + +Show the dashboard table. + +=cut + +sub index : Path : Args(0) { + my ( $self, $c ) = @_; + + my $council = $c->forward('check_page_allowed'); + + my $children = mySociety::MaPit::call('area/children', $council, + type => $mySociety::VotingArea::council_child_types, + ); + $c->stash->{children} = $children; + + my %counts; + my $t = DateTime->today; + + $counts{wtd} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 ) + } } ] ); + + $counts{week} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 ) + } } ] ); + + $counts{weeks} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 ) + } } ] ); + + $counts{ytd} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 ) + } } ] ); + + $c->stash->{problems} = \%counts; +} + +sub updates_search : Private { + my ( $self, $c, $params ) = @_; + + my $comments = $c->model('DB::Comment')->search( + $params, + { + group_by => [ 'problem_state' ], + select => [ 'problem_state', { count => 'me.id' } ], + as => [ qw/state state_count/ ], + join => 'problem' + } + ); + + my %counts = + map { ($_->state||'-') => $_->get_column('state_count') } $comments->all; + %counts = + map { $_ => $counts{$_} || 0 } + ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', + 'fixed - user', 'fixed', 'unconfirmed', 'hidden', + 'partial', 'planned'); + + $counts{fixed_user} = $c->model('DB::Comment')->search( + { %$params, mark_fixed => 1 }, { join => 'problem' } + )->count; + + $counts{total} = $c->cobrand->problems->search( + { %$params, state => [ FixMyStreet::DB::Result::Problem::visible_states() ] } + )->count; + + return \%counts; +} + +=head1 AUTHOR + +Matthew Somerville + +=head1 LICENSE + +Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. +Licensed under the Affero GPL. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; + -- cgit v1.2.3 From 5231c0cda1b90c172dd65c3e0d19c4c4bb84e508 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 8 May 2012 13:20:07 +0100 Subject: Redirect to login page if not logged in. --- perllib/FixMyStreet/App/Controller/Dashboard.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 74588df36..6c327d479 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -27,6 +27,8 @@ Checks if we can view this page, and if not redirect to 404. sub check_page_allowed : Private { my ( $self, $c ) = @_; + $c->detach( '/auth/redirect' ) unless $c->user_exists; + $c->detach( '/page_error_404_not_found' ) unless $c->user_exists && $c->user->from_council; -- cgit v1.2.3 From 5e2a8889e27340dee9207d2360077973c9f8ba38 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 8 May 2012 17:46:50 +0100 Subject: Get data for dashboard dropdowns and enable faceted lookup using them. --- perllib/FixMyStreet/App/Controller/Dashboard.pm | 40 ++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 6c327d479..0273e0eda 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -46,31 +46,57 @@ sub index : Path : Args(0) { my $council = $c->forward('check_page_allowed'); + # Set up the data for the dropdowns + my $children = mySociety::MaPit::call('area/children', $council, type => $mySociety::VotingArea::council_child_types, ); $c->stash->{children} = $children; + # XXX Hmm, this is probably the best way to go + $c->stash->{all_councils} = { $council => { id => $council } }; + $c->forward( '/report/new/setup_categories_and_councils' ); + + # See if we've had anything from the dropdowns + + $c->stash->{ward} = $c->req->param('ward'); + $c->stash->{category} = $c->req->param('category'); + $c->stash->{q_state} = $c->req->param('state'); + + my %where = ( + council => $council, # XXX This will break in a two tier council. Restriction needs looking at... + 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ], + ); + $where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' } + if $c->stash->{ward}; + $where{category} = $c->stash->{category} + if $c->stash->{category}; + if ( $c->stash->{q_state} eq 'fixed' ) { + $where{'problem.state'} = [ FixMyStreet::DB::Result::Problem->fixed_states() ]; + } elsif ( $c->stash->{q_state} ) { + $where{'problem.state'} = $c->stash->{q_state} + } + my %counts; my $t = DateTime->today; $counts{wtd} = $c->forward( 'updates_search', [ { - council => $council, + %where, 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 ) } } ] ); $counts{week} = $c->forward( 'updates_search', [ { - council => $council, + %where, 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 ) } } ] ); $counts{weeks} = $c->forward( 'updates_search', [ { - council => $council, + %where, 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 ) } } ] ); $counts{ytd} = $c->forward( 'updates_search', [ { - council => $council, + %where, 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 ) } } ] ); @@ -102,9 +128,9 @@ sub updates_search : Private { { %$params, mark_fixed => 1 }, { join => 'problem' } )->count; - $counts{total} = $c->cobrand->problems->search( - { %$params, state => [ FixMyStreet::DB::Result::Problem::visible_states() ] } - )->count; + $params->{state} = $params->{'problem.state'}; + delete $params->{'problem.state'}; + $counts{total} = $c->cobrand->problems->search( $params )->count; return \%counts; } -- cgit v1.2.3 From 5accaad402d24f37851d8b85084fda2859b1ae16 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 11 May 2012 13:17:27 +0100 Subject: add ability to suppress alerts to report creator on comments updated from open311 --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d11f1645e..d6f613fd3 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -339,7 +339,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $c->forward('check_token'); - my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments comment_user_id/; + my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -349,6 +349,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); + $conf->suppress_alerts( $params{suppress_alerts} ); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->update(); @@ -362,6 +363,7 @@ sub update_contacts : Private { $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); $conf->send_comments( $params{send_comments} ); + $conf->suppress_alerts( $params{suppress_alerts} ); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->insert(); -- cgit v1.2.3 From be802c7a8f1e7c7dc134281b76680f3a7d592441 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 14 May 2012 15:59:33 +0100 Subject: Log content type if it's bad. --- perllib/FixMyStreet/App/Controller/Report/New.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ca2dfc6b5..e7468986b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -856,6 +856,7 @@ sub process_photo_upload : Private { # check that the photo is a jpeg my $ct = $upload->type; unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { + $c->log->info('Bad photo tried to upload, type=' . $ct); $c->stash->{photo_error} = _('Please upload a JPEG image only'); return; } -- cgit v1.2.3 From 23aa50cd6e1fb77de2d1e3ae8d29a8f8408a7930 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 16 May 2012 15:47:42 +0100 Subject: Fixes and improvements for tests. --- perllib/FixMyStreet/App/Controller/Admin.pm | 10 +++++----- perllib/FixMyStreet/App/Controller/Report/Update.pm | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index bbfa8170f..998cb83a8 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -340,7 +340,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $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 comment_user_id/; + my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -349,8 +349,8 @@ sub update_contacts : Private { $conf->jurisdiction( $params{jurisdiction} ); $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); - $conf->send_comments( $params{send_comments} ); - $conf->suppress_alerts( $params{suppress_alerts} ); + $conf->send_comments( $params{send_comments} || 0); + $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->update(); @@ -363,8 +363,8 @@ sub update_contacts : Private { $conf->jurisdiction( $params{jurisdiction} ); $conf->api_key( $params{api_key} ); $conf->send_method( $params{send_method} ); - $conf->send_comments( $params{send_comments} ); - $conf->suppress_alerts( $params{suppress_alerts} ); + $conf->send_comments( $params{send_comments} || 0); + $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->insert(); diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 8be513b08..7542fbe96 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -105,8 +105,10 @@ sub process_user : Private { my $name = scalar $c->req->param('name'); $user->name( Utils::trim_text( $name ) ) if $name; my $title = scalar $c->req->param('fms_extra_title'); - $c->log->debug( 'user exists and title is ' . $title ); - $user->title( Utils::trim_text( $title ) ) if $title; + if ( $title ) { + $c->log->debug( 'user exists and title is ' . $title ); + $user->title( Utils::trim_text( $title ) ); + } $update->user( $user ); return 1; } -- cgit v1.2.3 From 513c31baa905c8f39a1230306d2c6a06f4cacc76 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 18 May 2012 15:54:04 +0100 Subject: Try and work if given a JPEG but with an incorrect MIME type, thanks Citrix. --- perllib/FixMyStreet/App/Controller/Report/New.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 6d22a0556..d0e6880fb 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -854,6 +854,7 @@ sub process_photo_upload : Private { # check that the photo is a jpeg my $ct = $upload->type; + $ct =~ s/x-citrix-//; unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { $c->stash->{photo_error} = _('Please upload a JPEG image only'); return; -- cgit v1.2.3 From 2f43c89731477628576d94cfcd6ae93394ad3473 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 21 May 2012 18:23:22 +0100 Subject: Don't have URL path passed through to 404 as error message. --- perllib/FixMyStreet/App/Controller/Root.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 9cdf0b523..7f7d7f5fd 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -68,7 +68,7 @@ Forward to the standard 404 error page sub default : Path { my ( $self, $c ) = @_; - $c->detach('/page_error_404_not_found'); + $c->detach('/page_error_404_not_found', []); } =head2 page_error_404_not_found, page_error_410_gone -- cgit v1.2.3 From f7e8651ed36a5579c4025345212d74df01eb2c6d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 22 May 2012 13:33:20 +0100 Subject: Move photo processing functions to the photo controller. --- perllib/FixMyStreet/App/Controller/Photo.pm | 88 +++++++++++++++++++++ .../FixMyStreet/App/Controller/Questionnaire.pm | 2 +- perllib/FixMyStreet/App/Controller/Report/New.pm | 91 +--------------------- .../FixMyStreet/App/Controller/Report/Update.pm | 2 +- 4 files changed, 92 insertions(+), 91 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 5d5832b08..a070d71db 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN {extends 'Catalyst::Controller'; } use DateTime::Format::HTTP; +use Digest::SHA1 qw(sha1_hex); use Path::Class; =head1 NAME @@ -136,6 +137,93 @@ sub _crop { return $blobs[0]; } +=head2 process_photo + +Handle the photo - either checking and storing it after an upload or retrieving +it from the cache. + +Store any error message onto 'photo_error' in stash. +=cut + +sub process_photo : Private { + my ( $self, $c ) = @_; + + return + $c->forward('process_photo_upload') + || $c->forward('process_photo_cache') + || 1; # always return true +} + +sub process_photo_upload : Private { + my ( $self, $c ) = @_; + + # check for upload or return + my $upload = $c->req->upload('photo') + || return; + + # check that the photo is a jpeg + my $ct = $upload->type; + $ct =~ s/x-citrix-//; + unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { + $c->stash->{photo_error} = _('Please upload a JPEG image only'); + return; + } + + # get the photo into a variable + my $photo_blob = eval { + my $filename = $upload->tempname; + my $out = `jhead -se -autorot $filename`; + my $photo = $upload->slurp; + return $photo; + }; + if ( my $error = $@ ) { + my $format = _( +"That image doesn't appear to have uploaded correctly (%s), please try again." + ); + $c->stash->{photo_error} = sprintf( $format, $error ); + return; + } + + # we have an image we can use - save it to the upload dir for storage + my $cache_dir = dir( $c->config->{UPLOAD_DIR} ); + $cache_dir->mkpath; + unless ( -d $cache_dir && -w $cache_dir ) { + warn "Can't find/write to photo cache directory '$cache_dir'"; + return; + } + + my $fileid = sha1_hex($photo_blob); + $upload->copy_to( file($cache_dir, $fileid . '.jpeg') ); + + # stick the hash on the stash, so don't have to reupload in case of error + $c->stash->{upload_fileid} = $fileid; + + return 1; +} + +=head2 process_photo_cache + +Look for the upload_fileid parameter and check it matches a file on disk. If it +does return true and put fileid on stash, otherwise false. + +=cut + +sub process_photo_cache : Private { + my ( $self, $c ) = @_; + + # get the fileid and make sure it is just a hex number + my $fileid = $c->req->param('upload_fileid') || ''; + $fileid =~ s{[^0-9a-f]}{}gi; + return unless $fileid; + + my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); + return unless -e $file; + + $c->stash->{upload_fileid} = $fileid; + return 1; +} + + =head1 AUTHOR Struan Donald diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 6ed7ddd9d..fe71f3fbb 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -244,7 +244,7 @@ sub process_questionnaire : Private { push @errors, _('Please provide some explanation as to why you\'re reopening this report') if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update}; - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); push @errors, $c->stash->{photo_error} if $c->stash->{photo_error}; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index d0e6880fb..096deda7b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -5,7 +5,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Geocode; -use Digest::SHA1 qw(sha1_hex); use Encode; use Image::Magick; use List::MoreUtils qw(uniq); @@ -99,7 +98,7 @@ sub report_new : Path : Args(0) { return unless $c->forward('check_form_submitted'); $c->forward('process_user'); $c->forward('process_report'); - $c->forward('process_photo'); + $c->forward('/photo/process_photo'); return unless $c->forward('check_for_errors'); $c->forward('save_user_and_report'); $c->forward('redirect_or_confirm_creation'); @@ -211,7 +210,7 @@ sub report_import : Path('/import') { } # handle the photo upload - $c->forward( 'process_photo_upload' ); + $c->forward( '/photo/process_photo_upload' ); my $fileid = $c->stash->{upload_fileid}; if ( my $error = $c->stash->{photo_error} ) { push @errors, $error; @@ -828,92 +827,6 @@ sub process_report : Private { return 1; } -=head2 process_photo - -Handle the photo - either checking and storing it after an upload or retrieving -it from the cache. - -Store any error message onto 'photo_error' in stash. -=cut - -sub process_photo : Private { - my ( $self, $c ) = @_; - - return - $c->forward('process_photo_upload') - || $c->forward('process_photo_cache') - || 1; # always return true -} - -sub process_photo_upload : Private { - my ( $self, $c ) = @_; - - # check for upload or return - my $upload = $c->req->upload('photo') - || return; - - # check that the photo is a jpeg - my $ct = $upload->type; - $ct =~ s/x-citrix-//; - unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { - $c->stash->{photo_error} = _('Please upload a JPEG image only'); - return; - } - - # get the photo into a variable - my $photo_blob = eval { - my $filename = $upload->tempname; - my $out = `jhead -se -autorot $filename`; - my $photo = $upload->slurp; - return $photo; - }; - if ( my $error = $@ ) { - my $format = _( -"That image doesn't appear to have uploaded correctly (%s), please try again." - ); - $c->stash->{photo_error} = sprintf( $format, $error ); - return; - } - - # we have an image we can use - save it to the upload dir for storage - my $cache_dir = dir( $c->config->{UPLOAD_DIR} ); - $cache_dir->mkpath; - unless ( -d $cache_dir && -w $cache_dir ) { - warn "Can't find/write to photo cache directory '$cache_dir'"; - return; - } - - my $fileid = sha1_hex($photo_blob); - $upload->copy_to( file($cache_dir, $fileid . '.jpeg') ); - - # stick the hash on the stash, so don't have to reupload in case of error - $c->stash->{upload_fileid} = $fileid; - - return 1; -} - -=head2 process_photo_cache - -Look for the upload_fileid parameter and check it matches a file on disk. If it -does return true and put fileid on stash, otherwise false. - -=cut - -sub process_photo_cache : Private { - my ( $self, $c ) = @_; - - # get the fileid and make sure it is just a hex number - my $fileid = $c->req->param('upload_fileid') || ''; - $fileid =~ s{[^0-9a-f]}{}gi; - return unless $fileid; - - my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - return unless -e $file; - - $c->stash->{upload_fileid} = $fileid; - return 1; -} - =head2 check_for_errors Examine the user and the report for errors. If found put them on stash and diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 15444f556..8a87fe7a2 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -23,7 +23,7 @@ sub report_update : Path : Args(0) { $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ); $c->forward('process_update'); $c->forward('process_user'); - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); -- cgit v1.2.3 From 58365c1fc883f64e6a8c9b4cd70869013c179b69 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 22 May 2012 14:31:56 +0100 Subject: Allow through octet-stream uploads, catch error from jhead better. --- perllib/FixMyStreet/App/Controller/Photo.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index a070d71db..a84c538cc 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -163,8 +163,9 @@ sub process_photo_upload : Private { # check that the photo is a jpeg my $ct = $upload->type; - $ct =~ s/x-citrix-//; - unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { + $ct =~ s/x-citrix-//; # Thanks, Citrix + # Had a report of a JPEG from an Android 2.1 coming through as a byte stream + unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' || $ct eq 'application/octet-stream' ) { $c->stash->{photo_error} = _('Please upload a JPEG image only'); return; } @@ -172,7 +173,8 @@ sub process_photo_upload : Private { # get the photo into a variable my $photo_blob = eval { my $filename = $upload->tempname; - my $out = `jhead -se -autorot $filename`; + my $out = `jhead -se -autorot $filename 2>&1`; + die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; my $photo = $upload->slurp; return $photo; }; -- cgit v1.2.3 From a27a999d381957e448d1d4e10f2a476f7ae2c268 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 22 May 2012 16:50:45 +0100 Subject: Pins yellow on /my for Bromley. --- perllib/FixMyStreet/App/Controller/Around.pm | 2 +- perllib/FixMyStreet/App/Controller/My.pm | 2 +- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 6fbfad5dc..3047b195c 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -186,7 +186,7 @@ sub display_location : Private { @pins = map { # Here we might have a DB::Problem or a DB::Nearby, we always want the problem. my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_; - my $colour = $c->cobrand->pin_colour( $p ); + my $colour = $c->cobrand->pin_colour( $p, 'around' ); { latitude => $p->latitude, longitude => $p->longitude, diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 3de83b265..c00264315 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -48,7 +48,7 @@ sub my : Path : Args(0) { push @$pins, { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->is_fixed ? 'green' : 'red', + colour => $c->cobrand->pin_colour( $problem, 'my' ), id => $problem->id, title => $problem->title, }; diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index fe71f3fbb..6aa4f7604 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -294,7 +294,7 @@ sub display : Private { pins => [ { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->is_fixed() ? 'green' : 'red', + colour => $c->cobrand->pin_colour( $problem, 'questionnaire' ), } ], ); } -- cgit v1.2.3 From cc7c785bf5a96efa883565f03cfadd35ada6177b Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 23 May 2012 23:56:01 +0100 Subject: Assume alert is not confirmed if not logged in. --- perllib/FixMyStreet/App/Controller/Alert.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 2698c6ac0..4407e06ce 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -191,7 +191,11 @@ sub create_alert : Private { $alert->insert(); } - $alert->confirm() if $c->user && $c->user->id == $alert->user->id; + if ( $c->user && $c->user->id == $alert->user->id ) { + $alert->confirm(); + } else { + $alert->confirmed(0); + } $c->stash->{alert} = $alert; } -- cgit v1.2.3 From 7f4279e44fa11aa2aa4a5f95b50c9e16d1d6e9e3 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 25 May 2012 17:04:20 +0100 Subject: Bromley details in cobrand. --- perllib/FixMyStreet/App/Controller/Contact.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index f28d37989..91580f05a 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -183,7 +183,7 @@ generally required to stash sub setup_request : Private { my ( $self, $c ) = @_; - $c->stash->{contact_email} = $c->cobrand->contact_email; + $c->stash->{contact_email} = $c->cobrand->contact_email( 'contact' ); $c->stash->{contact_email} =~ s/\@/@/; for my $param (qw/em subject message/) { @@ -205,7 +205,7 @@ Sends the email sub send_email : Private { my ( $self, $c ) = @_; - my $recipient = $c->cobrand->contact_email(); + my $recipient = $c->cobrand->contact_email( 'contact' ); my $recipient_name = $c->cobrand->contact_name(); $c->stash->{host} = $c->req->header('HOST'); -- cgit v1.2.3 From 0ff2c1689fafab7ed533b3989075c34f3c1a8779 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 25 May 2012 18:06:42 +0100 Subject: do not put empty arrays into extra field of contacts and ignore them if they are there --- perllib/FixMyStreet/App/Controller/Report/New.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 5f067573b..37ff1ae76 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -159,7 +159,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->forward('setup_categories_and_councils'); my $category_extra = ''; - if ( $c->stash->{category_extras}->{ $c->req->param('category') } ) { + if ( $c->stash->{category_extras}->{ $c->req->param('category') } && @{ $c->stash->{category_extras}->{ $c->req->param('category') } } >= 1 ) { $c->stash->{report_meta} = {}; $c->stash->{report} = { category => $c->req->param('category') }; $c->stash->{category_extras} = { $c->req->param('category' ) => $c->stash->{category_extras}->{ $c->req->param('category') } }; -- cgit v1.2.3