diff options
-rw-r--r-- | perllib/CrossSell.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 11 | ||||
-rw-r--r-- | t/app/controller/admin.t | 15 | ||||
-rw-r--r-- | t/app/controller/index.t | 6 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 6 | ||||
-rw-r--r-- | templates/web/base/admin/body.html | 77 | ||||
-rw-r--r-- | templates/web/base/admin/body_edit.html | 2 |
7 files changed, 85 insertions, 43 deletions
diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm index 5c7bf04ac..0c621e9d0 100644 --- a/perllib/CrossSell.pm +++ b/perllib/CrossSell.pm @@ -129,12 +129,15 @@ sub display_news_form { address below and we’ll send you occasional emails about what mySociety and our users have been up to.</p> -<form method="post" action="https://secure.mysociety.org/admin/lists/mailman/subscribe/news"> +<form method="post" action="//mysociety.us9.list-manage.com/subscribe/post?u=53d0d2026dea615ed488a8834&id=287dc28511"> +<label style="position: absolute; left: -5000px;"> +Leave this box empty: <input type="text" name="b_53d0d2026dea615ed488a8834_287dc28511" tabindex="-1" value="" /> +</label> <label for="name">Name:</label> -<input type="text" name="fullname" id="name" value="$input_h{name}" size="30"> +<input type="text" name="NAME" id="name" value="$input_h{name}" size="30"> <br><label for="email">Email:</label> -<input type="text" name="email" id="email" value="$input_h{email}" size="30"> - <input type="submit" value="Add me to the list"> +<input type="text" name="EMAIL" id="email" value="$input_h{email}" size="30"> + <input type="submit" name="subscribe" value="Add me to the list"> </form> <p>mySociety respects your privacy, and we'll never sell or give away your private diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index cfe165f43..c1df8622f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -343,8 +343,13 @@ sub update_contacts : Private { if ( $posted eq 'new' ) { $c->forward('check_token'); + my %errors; + my $category = $self->trim( $c->req->param( 'category' ) ); + $errors{category} = _("Please choose a category") unless $category; my $email = $self->trim( $c->req->param( 'email' ) ); + $errors{email} = _('Please enter a valid email') unless is_valid_email($email); + $errors{note} = _('Please enter a message') unless $c->req->param('note'); $category = 'Empty property' if $c->cobrand->moniker eq 'emptyhomes'; @@ -367,7 +372,11 @@ sub update_contacts : Private { $contact->api_key( $c->req->param('api_key') ); $contact->send_method( $c->req->param('send_method') ); - if ( $contact->in_storage ) { + if ( %errors ) { + $c->stash->{updated} = _('Please correct the errors below'); + $c->stash->{contact} = $contact; + $c->stash->{errors} = \%errors; + } elsif ( $contact->in_storage ) { $c->stash->{updated} = _('Values updated'); # NB: History is automatically stored by a trigger in the database diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index bf7a9ed70..1757e386f 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -181,9 +181,9 @@ subtest 'check contact creation' => sub { } } ); $mech->content_contains( 'test category' ); - $mech->content_contains( '<td>test@example.com' ); + $mech->content_contains( 'test@example.com' ); $mech->content_contains( '<td>test note' ); - $mech->content_contains( '<td>Public' ); + $mech->content_contains( 'Private: No' ); $mech->submit_form_ok( { with_fields => { category => 'private category', @@ -193,7 +193,7 @@ subtest 'check contact creation' => sub { } } ); $mech->content_contains( 'private category' ); - $mech->content_contains( '<td>Non Public' ); + $mech->content_contains( 'Private: Yes' ); $mech->submit_form_ok( { with_fields => { category => 'test/category', @@ -215,17 +215,18 @@ subtest 'check contact editing' => sub { } } ); $mech->content_contains( 'test category' ); - $mech->content_contains( '<td>test2@example.com' ); + $mech->content_contains( 'test2@example.com' ); $mech->content_contains( '<td>test2 note' ); - $mech->content_contains( '<td>Public' ); + $mech->content_contains( 'Private: No' ); + $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', note => 'test2 note', non_public => 'on', } } ); - $mech->content_contains( '<td>Non Public' ); + $mech->content_contains( 'Private: Yes' ); $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->content_contains( '<td><strong>test2@example.com' ); @@ -241,7 +242,7 @@ subtest 'check contact updating' => sub { $mech->tick( 'confirmed', 'test category' ); $mech->submit_form_ok({form_number => 1}); - $mech->content_like(qr'test2@example.com</td>[^<]*<td>Yes's); + $mech->content_like(qr'test2@example.com</td>[^<]*<td>\s*Confirmed: Yes's); $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s); }; diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 7fc15ab4b..308dd2c32 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -13,7 +13,11 @@ subtest "check that the form goes to /around" => sub { is $mech->uri->path, '/', "still on '/'"; # submit form - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); + }; # check that we are at /around is $mech->uri->path, '/around', "Got to /around"; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 79072bcfe..92bc54ba4 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -25,7 +25,11 @@ subtest "test that bare requests to /report/new get redirected" => sub { is $mech->uri->path, '/', "went to /"; is_deeply { $mech->uri->query_form }, {}, "query empty"; - $mech->get_ok('/report/new?pc=SW1A%201AA'); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok('/report/new?pc=SW1A%201AA'); + }; is $mech->uri->path, '/around', "went to /around"; is_deeply { $mech->uri->query_form }, { pc => 'SW1A 1AA' }, "pc correctly transferred"; diff --git a/templates/web/base/admin/body.html b/templates/web/base/admin/body.html index b207d18ca..e67cb2b07 100644 --- a/templates/web/base/admin/body.html +++ b/templates/web/base/admin/body.html @@ -1,4 +1,5 @@ [% INCLUDE 'admin/header.html' title=tprintf(loc('Council contacts for %s'), body.name) -%] +[% PROCESS 'admin/report_blocks.html' %] [% IF updated %] <p> @@ -6,6 +7,8 @@ </p> [% END %] +[% IF NOT errors %] + <p> [% IF example_pc %] <a href="[% c.uri_for_email( '/around', { pc => example_pc } ) %]" class="admin-offsite-link">[% tprintf( loc('Example postcode %s'), example_pc ) | html %]</a> | @@ -51,28 +54,31 @@ <table cellspacing="0" cellpadding="2" border="1"> <tr> <th>[% loc('Category') %]</th> - <th>[% loc('Email') %]</th> - <th>[% loc('Confirmed') %]</th> - <th>[% loc('Deleted') %]</th> - <th>[% loc('Devolved') %]</th> + <th colspan=2>[% loc('State') %]</th> <th>[% loc('Last editor') %]</th> <th>[% loc('Note') %]</th> - <th>[% loc('Public') %]</th> - <th>[% loc('When edited') %]</th> <th>[% loc('Confirm') %]</th> </tr> - [% WHILE ( contact = contacts.next ) %] - <tr [% IF contact.deleted %]class="is-deleted"[% END %]> - <td class="contact-category"><a href="[% c.uri_for( 'body_edit', body_id, contact.category ) %]">[% contact.category %]</a></td> - <td>[% contact.email | html %]</td> - <td>[% IF contact.confirmed %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td> - <td>[% IF contact.deleted %]<strong>[% loc('Yes') %]</strong>[% ELSE %][% loc('No') %][% END %]</td> - <td>[% IF body.can_be_devolved && contact.send_method %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</td> - <td>[% contact.editor %]</td> - <td>[% contact.note | html %]</td> - <td>[% contact.non_public ? loc('Non Public') : loc('Public') %]</td> - <td>[% contact.whenedited.ymd _ ' ' _ contact.whenedited.hms %]</td> - <td><input type="checkbox" name="confirmed" value="[% contact.category %]"></td> + [% WHILE ( cat = contacts.next ) %] + <tr [% IF cat.deleted %]class="is-deleted"[% END %]> + <td class="contact-category"><a href="[% c.uri_for( 'body_edit', body_id, cat.category ) %]">[% cat.category %]</a> + <br>[% cat.email | html %]</td> + <td> + [% loc('Confirmed') %]: + [%- IF cat.confirmed %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %] + <br>[% loc('Deleted') %]: + [%- IF cat.deleted %]<strong>[% loc('Yes') %]</strong>[% ELSE %][% loc('No') %][% END %] + </td> + <td> + [% loc('Private') %]: + [%- cat.non_public ? loc('Yes') : loc('No') %] + <br>[% loc('Devolved') %]: + [%- IF body.can_be_devolved AND cat.send_method %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %] + </td> + <td>[% cat.editor %] + <br><small>[% PROCESS format_time time=cat.whenedited %]</small></td> + <td>[% cat.note | html %]</td> + <td><input type="checkbox" name="confirmed" value="[% cat.category %]"></td> </tr> [% END %] </table> @@ -84,14 +90,25 @@ </p> </form> -<div class="admin-box"> - <h2>[% loc('Add new category') %]</h2> - <p class="fms-admin-info"> +<p class="fms-admin-info"> [% loc("Each contact for the body has a category, which is displayed to the public. Different categories <strong>can have the same contact</strong> (email address). This means you can add many categories even if you only have one contact for the body. ") %] - </p> +</p> + +[% END %][%# Only show all the above if no errors with below form %] + +<div class="admin-box"> + [% IF NOT contact %] + <h2>[% loc('Add new category') %]</h2> + [% END %] + +[% IF errors %] +<div class="fms-admin-warning"> + [% errors.values.join('<br>') %] +</div> +[% END %] <form method="post" action="[% c.uri_for('body', body_id ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> @@ -106,7 +123,7 @@ </p> </div> <p> - <strong>[% loc('Category:') %] </strong><input type="text" name="category" size="30"> + <strong>[% loc('Category:') %] </strong><input type="text" name="category" size="30" value="[% contact.category | html %]"> </p> [% END %] @@ -123,7 +140,7 @@ </div> <p> - <strong>[% loc('Email address:') %] </strong><input type="text" name="email" size="30"> + <strong>[% loc('Email address:') %] </strong><input type="text" name="email" size="30" value="[% contact.email | html %]"> </p> <div class="admin-hint"> @@ -133,7 +150,7 @@ </p> </div> <p> - <input type="checkbox" name="confirmed" value="1" id="confirmed"> + <input type="checkbox" name="confirmed" value="1" id="confirmed"[% ' checked' IF contact.confirmed %]> <label for="confirmed" class="inline">[% loc('Confirmed') %]</label> </p> @@ -144,7 +161,7 @@ </p> </div> <p> - <input type="checkbox" name="deleted" value="1" id="deleted"> + <input type="checkbox" name="deleted" value="1" id="deleted"[% ' checked' IF contact.deleted %]> <label for="deleted" class="inline">[% loc('Deleted') %]</label> </p> @@ -169,14 +186,14 @@ </p> </div> <p> - <input type="checkbox" name="non_public" value="1" id="non_public"> + <input type="checkbox" name="non_public" value="1" id="non_public" [% ' checked' IF contact.non_public %]> <label for="non_public" class="inline">[% loc('Private') %]</label> </p> <p> <input type="hidden" name="posted" value="new" > <input type="hidden" name="token" value="[% token %]" > - <input type="submit" name="Create category" value="[% loc('Create category') %]" > + <input type="submit" name="Create category" value="[% errors ? loc('Save changes') : loc('Create category') %]" > </p> <div> @@ -185,8 +202,12 @@ </div> </form> </div> + +[% IF NOT errors %] <div class="admin-box"> <h2>[% loc('Edit body details') %]</h2> [% INCLUDE 'admin/body-form.html' %] </div> +[% END %][%# Only show all the above if no errors with category form %] + [% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/admin/body_edit.html b/templates/web/base/admin/body_edit.html index f2bae0c0b..ef7a0a11c 100644 --- a/templates/web/base/admin/body_edit.html +++ b/templates/web/base/admin/body_edit.html @@ -41,7 +41,7 @@ [% END %] </p> - <p><strong>[% loc('Note:') %] </strong><textarea name="note" rows="3" cols="40">[% contact.note | html %]</textarea> + <p><strong>[% loc('Note:') %] </strong><textarea name="note" rows="3" cols="40"></textarea> [% IF body.can_be_devolved %] <h2>[% loc('Configure Endpoint') %]</h2> |