diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-01 17:29:16 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-01 17:29:16 +0100 |
commit | b3746b6d37d7214c016cf9f39bcec8847b379721 (patch) | |
tree | 57daf0e0580fed8afc9befe6a82cea6f23a872eb | |
parent | a2d9fe2659a1723824c58d7e3d663d1725bcab56 (diff) | |
parent | 2e4241ef11e600dcdf898ca1542f865c0972e4bc (diff) |
Merge branch 'migrate_to_catalyst' of ssh://git.mysociety.org/data/git/public/fixmystreet into migrate_to_catalyst
-rw-r--r-- | conf/httpd.conf | 3 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 204 | ||||
-rw-r--r-- | templates/web/default/around/around_map_list_items.html | 2 | ||||
-rwxr-xr-x | web/ajax.cgi | 107 | ||||
-rwxr-xr-x | web/faq.cgi | 24 | ||||
-rwxr-xr-x | web/tms-signup.cgi | 120 | ||||
-rwxr-xr-x | web/upload.cgi | 56 |
7 files changed, 120 insertions, 396 deletions
diff --git a/conf/httpd.conf b/conf/httpd.conf index 2b352f643..00532a3ab 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -53,7 +53,6 @@ RewriteRule ^(.+)/$ $1 [R=permanent] # RewriteRule ^/[Cc]/([0-9A-Za-z]{16,18}).*$ /confirm.cgi?type=update;token=$1 [QSA,L] # RewriteRule ^/[Qq]/([0-9A-Za-z]{16,18}).*$ /questionnaire.cgi?token=$1 [QSA,L] RewriteRule ^/[Ff]/([0-9A-Za-z]{16,18}).*$ /flickr.cgi?token=$1 [L] -RewriteRule ^/[Tt]/([0-9A-Za-z]{16,18}).*$ /tms-signup.cgi?token=$1 [L] # RSS feeds for updates on a problem #RewriteRule ^/rss/([0-9]+)$ /rss.cgi?type=new_updates;id=$1 [QSA,L] @@ -115,8 +114,6 @@ RewriteRule ^/flickr(.*) /flickr.cgi$1 [L] # RewriteRule ^/reports(.*) /reports.cgi$1 [L] # RewriteRule ^/rss(.*) /rss.cgi$1 [L] RewriteRule ^/test(.*) /test.cgi$1 [L] -RewriteRule ^/tms-signup(.*) /tms-signup.cgi$1 [L] -RewriteRule ^/upload(.*) /upload.cgi$1 [L] RewriteRule ^/jslib(.*) /jslib$1 [L,PT] diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 160d1a156..760dfacc6 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -20,6 +20,36 @@ subtest "test that bare requests to /report/new get redirected" => sub { "pc correctly transferred"; }; +my %contact_params = ( + confirmed => 1, + deleted => 0, + editor => 'Test', + whenedited => \'current_timestamp', + note => 'Created for test', +); +# Let's make some contacts to send things to! +my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2651, # Edinburgh + category => 'Street lighting', + email => 'highways@example.com', +} ); +my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2226, # Gloucestershire + category => 'Potholes', + email => 'potholes@example.com', +} ); +my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2326, # Cheltenham + category => 'Trees', + email => 'trees@example.com', +} ); +ok $contact1, "created test contact 1"; +ok $contact2, "created test contact 2"; +ok $contact3, "created test contact 3"; + # test that the various bit of form get filled in and errors correctly # generated. foreach my $test ( @@ -259,7 +289,7 @@ subtest "test report creation for a user who does not have an account" => sub { # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); # click through to the report page @@ -298,6 +328,9 @@ subtest "test report creation for a user who does not have an account" => sub { is $report->state, 'unconfirmed', "report not confirmed"; is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + # Check the report has been assigned appropriately + is $report->council, 2651; + # receive token my $email = $mech->get_email; ok $email, "got an email"; @@ -312,10 +345,7 @@ subtest "test report creation for a user who does not have an account" => sub { is $report->state, 'confirmed', "Report is now confirmed"; is $report->state, 'confirmed', "report is now confirmed"; - TODO: { - local $TODO = "'/report/<<id>>' not handled by catalyst yet"; - $mech->get_ok( '/report/' . $report->id ); - } + $mech->get_ok( '/report/' . $report->id ); # user is created and logged in $mech->logged_in_ok; @@ -332,92 +362,92 @@ subtest "test report creation for a user who does not have an account" => sub { # report is confirmed #### test report creation for user with account and logged in -subtest "test report creation for a user who is logged in" => sub { - - # check that the user does not exist - my $test_email = 'test-2@example.com'; - - $mech->clear_emails_ok; - my $user = $mech->log_in_ok($test_email); - - # setup the user. - ok $user->update( - { - name => 'Test User', - phone => '01234 567 890', - } - ), - "set users details"; - - # submit initial pc form - $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } }, - "submit location" ); - - # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, - "follow 'skip this step' link" ); - - # check that the fields are correctly prefilled - is_deeply( - $mech->visible_form_values, - { - title => '', - detail => '', - may_show_name => '1', - email => $test_email, - name => 'Test User', - phone => '01234 567 890', - photo => '', - category => '-- Pick a category --', - }, - "user's details prefilled" - ); - - TODO: { - local $TODO = -"'/report/<<id>>' not handled by catalyst yet - form creation redirects to there on success if logged in"; - eval { - $mech->submit_form_ok( - { - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - phone => '07903 123 456', - category => 'Street lighting', - } - }, - "submit good details" - ); - }; - } - - # find the report - my $report = $user->problems->first; - ok $report, "Found the report"; +foreach my $test ( + { category => 'Trees', council => 2326 }, + { category => 'Potholes', council => 2226 }, +) { + subtest "test report creation for a user who is logged in" => sub { + + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; - # check that we got redirected to /report/ - is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); - # check that no emails have been sent - $mech->email_count_is(0); + # click through to the report page + $mech->follow_link_ok( { text => 'skip this step', }, + "follow 'skip this step' link" ); - # check report is confirmed and available - is $report->state, 'confirmed', "report is now confirmed"; - TODO: { - local $TODO = "'/report/<<id>>' not handled by catalyst yet"; + # check that the fields are correctly prefilled + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', + may_show_name => '1', + email => $test_email, + name => 'Test User', + phone => '01234 567 890', + photo => '', + category => '-- Pick a category --', + }, + "user's details prefilled" + ); + + $mech->submit_form_ok( + { + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => $test->{category}, + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # Check the report has been assigned appropriately + is $report->council, $test->{council}; + + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + # check that no emails have been sent + $mech->email_count_is(0); + + # check report is confirmed and available + is $report->state, 'confirmed', "report is now confirmed"; $mech->get_ok( '/report/' . $report->id ); - } - # user is still logged in - $mech->logged_in_ok; + # user is still logged in + $mech->logged_in_ok; - # cleanup - $mech->delete_user($user); -}; + # cleanup + $mech->delete_user($user); + }; + +} #### test uploading an image @@ -449,4 +479,8 @@ subtest "check that a lat/lon off coast leads to /around" => sub { }; +$contact1->delete; +$contact2->delete; +$contact3->delete; + done_testing(); diff --git a/templates/web/default/around/around_map_list_items.html b/templates/web/default/around/around_map_list_items.html index b6c2e6d9c..87416f7a1 100644 --- a/templates/web/default/around/around_map_list_items.html +++ b/templates/web/default/around/around_map_list_items.html @@ -5,7 +5,7 @@ <li> <a href="[% c.uri_for('/report', p.id ) %]">[% p.title | html %]</a> - <small>([% prettify_epoch( p.time, 1 ) %], [% dist %]km)</small>)</small> + <small>([% prettify_epoch( p.time, 1 ) %], [% dist %]km)</small> [% IF p.state == 'fixed' %] <small>[% loc('(fixed)') %]</small> [% END %] diff --git a/web/ajax.cgi b/web/ajax.cgi deleted file mode 100755 index a25269070..000000000 --- a/web/ajax.cgi +++ /dev/null @@ -1,107 +0,0 @@ -# #!/usr/bin/perl -w -I../perllib -# -# # ajax.cgi: -# # Updating the pins as you drag the map -# # -# # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# # Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# # -# # $Id: ajax.cgi,v 1.19 2009-12-15 17:53:52 louise Exp $ -# -# use strict; -# use Standard; -# use mySociety::Web qw(ent NewURL); -# -# sub main { -# my $q = shift; -# -# my @vars = qw(x y sx sy all_pins); -# my %input = map { $_ => $q->param($_) || '' } @vars; -# my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; -# -# # Our current X/Y middle of visible map -# my $x = $input{x}; -# my $y = $input{y}; -# $x ||= 0; $x += 0; -# $y ||= 0; $y += 0; -# -# # Where we started as that's the (0,0) we have to work to -# my $sx = $input{sx}; -# my $sy = $input{sy}; -# $sx ||= 0; $sx += 0; -# $sy ||= 0; $sy += 0; -# -# my $interval; -# unless ($input{all_pins}) { -# $interval = '6 months'; -# } -# my ($pins, $on_map, $around_map, $dist) = FixMyStreet::Map::map_pins($q, $x, $y, $sx, $sy, $interval); -# my $cobrand = Page::get_cobrand($q); -# my $list = ''; -# my $link = ''; -# foreach (@$on_map) { -# $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, -# -url => '/report/' . $_->{id}, -# pc => undef, -# x => undef, -# y => undef, -# sx => undef, -# sy => undef, -# all_pins => undef, -# no_pins => undef), $q); -# $list .= '<li><a href="' . $link . '">'; -# $list .= ent($_->{title}) . '</a> <small>('; -# $list .= Page::prettify_epoch($q, $_->{time}, 1) . ')</small>'; -# $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; -# $list .= '</li>'; -# } -# my $om_list = $list; -# -# $list = ''; -# foreach (@$around_map) { -# my $dist = int($_->{distance}*10+.5)/10; -# $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, -# -url => '/report/' . $_->{id}, -# pc => undef, -# x => undef, -# y => undef, -# sx => undef, -# sy => undef, -# all_pins => undef, -# no_pins => undef), $q); -# $list .= '<li><a href="' . $link . '">'; -# $list .= ent($_->{title}) . '</a> <small>('; -# $list .= Page::prettify_epoch($q, $_->{time}, 1) . ', '; -# $list .= $dist . 'km)</small>'; -# $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; -# $list .= '</li>'; -# } -# my $am_list = $list; -# -# #$list = ''; -# #foreach (@$fixed) { -# # $list .= '<li><a href="/report/' . $_->{id} . '">'; -# # $list .= $_->{title} . ' <small>(' . int($_->{distance}*10+.5)/10 . 'km)</small>'; -# # $list .= '</a></li>'; -# #} -# #my $f_list = $list; -# -# # For now, assume this is not cacheable - may need to be more fine-grained later -# print $q->header(-charset => 'utf-8', -content_type => 'text/javascript', -Cache_Control => 'max-age=0'); -# -# -# $pins =~ s/'/\\'/g; -# $om_list =~ s/'/\\'/g; -# $am_list =~ s/'/\\'/g; -# #$f_list =~ s/'/\\'/g; -# print <<EOF; -# ({ -# 'pins': '$pins', -# 'current': '$om_list', -# 'current_near': '$am_list' -# }) -# EOF -# } -# -# Page::do_fastcgi(\&main); -# diff --git a/web/faq.cgi b/web/faq.cgi deleted file mode 100755 index 4d9c7413a..000000000 --- a/web/faq.cgi +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/perl -w -I../perllib - -# faq.cgi: -# FAQ page for FixMyStreet -# -# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: faq.cgi,v 1.42 2009-07-10 16:10:22 matthew Exp $ - -use strict; -use Standard -db; -use mySociety::Locale; - -my $lastmodified = (stat $0)[9]; -sub main { - my $q = shift; - print Page::header($q, title=>_('Frequently Asked Questions')); - my $lang = $mySociety::Locale::lang; - print Page::template_include("faq-$lang", $q, Page::template_root($q)); - print Page::footer($q); -} -Page::do_fastcgi(\&main, $lastmodified); - diff --git a/web/tms-signup.cgi b/web/tms-signup.cgi deleted file mode 100755 index 5975a324f..000000000 --- a/web/tms-signup.cgi +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/perl -w -I../perllib - -# tms-signup.cgi -# Showing interest in TextMyStreet -# -# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: tms-signup.cgi,v 1.5 2009-11-11 14:23:05 louise Exp $ - -use strict; -use Standard; -use Digest::SHA1 qw(sha1_hex); -use CrossSell; -use mySociety::AuthToken; -use mySociety::Config; -use mySociety::EmailUtil qw(is_valid_email); -use mySociety::PostcodeUtil qw(is_valid_postcode); -use mySociety::Web qw(ent); - - #dbh()->'insert into textmystreet (name, email, postcode, mobile) values ()'; - -sub main { - my $q = shift; - my $out = ''; - my $title = 'Confirmation'; - if (my $token = $q->param('token')) { - my $data = mySociety::AuthToken::retrieve('tms', $token); - if ($data->{email}) { - $out = tms_token($q, $data); - } else { - $out = $q->p(<<EOF); -Thank you for trying to confirm your interest. We seem to have a problem ourselves -though, so <a href="/contact">please let us know what went on</a> and we'll look into it. -EOF - } - } elsif ($q->param('email')) { - $out = tms_do_subscribe($q); - } else { - $out = tms_updates_form($q); - } - - print Page::header($q, title => $title); - print $out; - print Page::footer($q); -} -Page::do_fastcgi(\&main); - -sub tms_updates_form { - my ($q, @errors) = @_; - my @vars = qw(email name postcode mobile signed_email); - my %input = map { $_ => $q->param($_) || '' } @vars; - my $out = ''; - if (@errors) { - $out .= '<ul class="error"><li>' . join('</li><li>', @errors) . '</li></ul>'; - } - my $cobrand = Page::get_cobrand($q); - my $display_advert = Cobrand::allow_crosssell_adverts($cobrand); - if ($display_advert) { - $out .= CrossSell::display_tms_form(%input); - } - return $out; -} - -sub tms_token { - my ($q, $data) = @_; - my $type = $data->{type}; - my $out = ''; - if ($type eq 'subscribe') { - tms_confirm(%$data); - $out = $q->p('You have successfully registered your interest.'); - $out .= CrossSell::display_advert($q, $data->{email}, $data->{name}, done_tms => 1); - } - return $out; -} - -sub tms_do_subscribe { - my ($q) = @_; - my @vars = qw(email name postcode mobile signed_email); - my %input = map { $_ => $q->param($_) || '' } @vars; - - my @errors; - push @errors, 'Please enter your name' unless $input{name}; - push @errors, 'Please enter a valid email address' unless is_valid_email($input{email}); - push @errors, 'Please enter a valid postcode' unless is_valid_postcode($input{postcode}); - push @errors, 'Please enter a mobile number' unless $input{mobile}; - if (@errors) { - return tms_updates_form($q, @errors); - } - - # See if email address has been signed - if ($input{signed_email}) { - my $out; - if (mySociety::AuthToken::verify_with_shared_secret($input{email}, mySociety::Config::get('AUTH_SHARED_SECRET'), $input{signed_email})) { - tms_confirm(%input); - $out = $q->p('You have successfully registered your interest.'); - return $out; - } - } - - my %h = (); - $h{url} = mySociety::Config::get('BASE_URL') . '/T/' - . mySociety::AuthToken::store('tms', { - type => 'subscribe', - name => $input{name}, - email => $input{email}, - postcode => $input{postcode}, - mobile => $input{mobile}, - }); - dbh()->commit(); - return Page::send_confirmation_email($q, $input{email}, $input{name}, 'tms', %h); -} - -sub tms_confirm { - my %input = @_; - dbh()->do("insert into textmystreet (name, email, postcode, mobile) values (?, ?, ?, ?)", {}, - $input{name}, $input{email}, $input{postcode}, $input{mobile}); - dbh()->commit(); -} - diff --git a/web/upload.cgi b/web/upload.cgi deleted file mode 100755 index aa3f8ce61..000000000 --- a/web/upload.cgi +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/perl -w -I../perllib -I../commonlib/perllib - -# upload.cgi: -# Receiver of flash upload files -# -# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: upload.cgi,v 1.2 2008-10-09 14:20:54 matthew Exp $ - -use strict; -use Standard -db; - -use Error qw(:try); -use Image::Magick; -use mySociety::Random qw(random_bytes); - -# Main code for index.cgi -sub main { - my $q = shift; - - print $q->header(-type => 'text/plain'); - my $out = ' '; - try { - my $fh = $q->upload('Filedata'); - my $image; - if ($fh) { - $q->delete('photo'); # Can't check content/type when uploaded with Flash - $image = process_photo($fh); - my $name = unpack('H*', random_bytes(12, 1)); - open FP, '>/data/vhost/matthew.bci.mysociety.org/photos/' . $name or throw Error::Simple('could not open file'); - print FP $image; - close FP; - $out = $name; - }; - } catch Error::Simple with { - my $e = shift; - }; - print $out; -} -Page::do_fastcgi(\&main); - -sub process_photo { - my $fh = shift; - my $photo = Image::Magick->new; - my $err = $photo->Read(file => \*$fh); # Mustn't be stringified - close $fh; - throw Error::Simple("read failed: $err") if "$err"; - $err = $photo->Scale(geometry => "250x250>"); - throw Error::Simple("resize failed: $err") if "$err"; - my @blobs = $photo->ImageToBlob(); - undef $photo; - $photo = $blobs[0]; - return $photo; -} - |