diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rwxr-xr-x | bin/oxfordshire/send-rdi-emails | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 42 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 2 | ||||
-rw-r--r-- | t/app/controller/admin.t | 49 | ||||
-rw-r--r-- | t/cobrand/councils.t | 36 | ||||
-rw-r--r-- | templates/email/oxfordshire/rdi.txt | 7 | ||||
-rw-r--r-- | templates/web/base/admin/report_blocks.html | 2 | ||||
-rw-r--r-- | templates/web/base/admin/user-form.html | 6 | ||||
-rw-r--r-- | templates/web/base/admin/users.html | 2 | ||||
-rw-r--r-- | templates/web/base/auth/general.html | 4 | ||||
-rw-r--r-- | templates/web/base/report/new/form_user_loggedout.html | 4 | ||||
-rw-r--r-- | templates/web/base/report/update/form_user_loggedout.html | 4 | ||||
-rw-r--r-- | web/cobrands/sass/_base.scss | 10 | ||||
-rw-r--r-- | web/cobrands/sass/_layout.scss | 14 |
16 files changed, 166 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index aca47a305..a5224b3fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Add functionality to have per-body /reports page. - Front end improvements: - Remove unneeded 2x PNG fallback images. + - Individual cobrands can disable social login #1890 - Bugfixes - Shortlist menu item always remains a link #1855 - Fix encoded entities in RSS output. #1859 @@ -23,6 +24,8 @@ - Always allow reports to be removed from shortlist #1882 - Remove shortlist form from inspect duplicate list. - Fix pin size when JavaScript unavailable. + - Fix display of text only body contacts #1895 + - Prevent text overflow bug on homepage stats #1722 - Admin improvements: - Character length limit can be placed on report detailed information #1848 - Inspector panel shows nearest address if available #1850 @@ -32,6 +35,7 @@ - Marking an item as a duplicate enforces providing duplicate id or a public update #1873 - Report field pre-filling for inspectors configurable #1854 + - Admins can now unban users #1881 - UK: - Use SVG logo, inlined on front page. #1887 - Inline critical CSS on front page. diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails index 801c1a889..9cc3e5502 100755 --- a/bin/oxfordshire/send-rdi-emails +++ b/bin/oxfordshire/send-rdi-emails @@ -40,6 +40,12 @@ foreach my $inspector (@inspectors) { user => $inspector, mark_as_processed => 1, }; + my $email_params = { + start_date => $start_date, + end_date => $end_date, + user => $inspector, + staging_site => FixMyStreet->config('STAGING_SITE'), + }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); try { my $hdrs = { @@ -58,7 +64,7 @@ foreach my $inspector (@inspectors) { my $result = FixMyStreet::Email::send_cron( FixMyStreet::DB->schema, - "rdi.txt", $params, $hdrs, + "rdi.txt", $email_params, $hdrs, undef, 0, $cobrand, ); if ($result) { diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 82041a6b1..27aeb9e5b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -608,9 +608,12 @@ sub edit_body : Chained('body') : PathPart('') : Args(0) { $c->set_param('posted', ''); $c->forward('fetch_translations'); - $c->forward('fetch_contacts'); + # don't set this last as fetch_contacts might over-ride it + # to display email addresses as text $c->stash->{template} = 'admin/body.html'; + $c->forward('fetch_contacts'); + return 1; } @@ -1412,6 +1415,7 @@ sub user_edit : Path('user_edit') : Args(1) { } $c->stash->{user} = $user; + $c->forward( 'check_username_for_abuse', [ $user ] ); if ( $user->from_body && $c->user->has_permission_to('user_manage_permissions', $user->from_body->id) ) { $c->stash->{available_permissions} = $c->cobrand->available_permissions; @@ -1425,11 +1429,15 @@ sub user_edit : Path('user_edit') : Args(1) { '<p><em>' . $c->flash->{status_message} . '</em></p>'; } - if ( $c->get_param('submit') ) { + if ( $c->get_param('submit') and $c->get_param('unban') ) { + $c->forward('/auth/check_csrf_token'); + $c->forward('unban_user', [ $user ]); + } elsif ( $c->get_param('submit') ) { $c->forward('/auth/check_csrf_token'); my $edited = 0; + my $name = $c->get_param('name'); my $email = lc $c->get_param('email'); my $phone = $c->get_param('phone'); my $email_v = $c->get_param('email_verified') || 0; @@ -1452,7 +1460,7 @@ sub user_edit : Path('user_edit') : Args(1) { $phone = $parsed_phone if $parsed_phone; } - unless ($user->name) { + unless ($name) { $c->stash->{field_errors}->{name} = _('Please enter a name'); } @@ -1471,7 +1479,7 @@ sub user_edit : Path('user_edit') : Args(1) { return if %{$c->stash->{field_errors}}; if ( ($user->email || "") ne $email || - $user->name ne $c->get_param('name') || + $user->name ne $name || ($user->phone || "") ne $phone || ($user->from_body && $c->get_param('body') && $user->from_body->id ne $c->get_param('body')) || (!$user->from_body && $c->get_param('body')) @@ -1489,7 +1497,7 @@ sub user_edit : Path('user_edit') : Args(1) { $user->phone($phone) if !$existing_phone; $user->email_verified( $email_v ); $user->phone_verified( $phone_v ); - $user->name( $c->get_param('name') ); + $user->name( $name ); $user->flagged( $c->get_param('flagged') || 0 ); # Only superusers can grant superuser status @@ -1870,6 +1878,28 @@ sub ban_user : Private { return 1; } +sub unban_user : Private { + my ( $self, $c, $user ) = @_; + + my @username; + if ($user->email_verified && $user->email) { + push @username, $user->email; + } + if ($user->phone_verified && $user->phone) { + push @username, $user->phone; + } + if (@username) { + my $abuse = $c->model('DB::Abuse')->search({ email => \@username }); + if ( $abuse ) { + $abuse->delete; + $c->stash->{status_message} = _('user removed from abuse list'); + } else { + $c->stash->{status_message} = _('user not in abuse list'); + } + $c->stash->{username_in_abuse} = 0; + } +} + =head2 flag_user Sets the flag on a user @@ -1941,8 +1971,6 @@ sub check_username_for_abuse : Private { my $is_abuse = $c->model('DB::Abuse')->find({ email => [ $user->phone, $user->email ] }); $c->stash->{username_in_abuse} = 1 if $is_abuse; - - return 1; } =head2 rotate_photo diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 2ee259b62..68d11f227 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1244,6 +1244,10 @@ admin. sub allow_report_extra_fields { 0 } - +sub social_auth_enabled { + my $self = shift; + my $key_present = FixMyStreet->config('FACEBOOK_APP_ID') or FixMyStreet->config('TWITTER_KEY'); + return $key_present && !$self->call_hook("social_auth_disabled"); +} 1; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 661d4a79b..f958b525a 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -222,4 +222,6 @@ sub available_permissions { sub prefill_report_fields_for_inspector { 1 } +sub social_auth_disabled { 1 } + 1; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index e6a8a34cf..3f69829f7 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -289,6 +289,7 @@ subtest 'check text output' => sub { $mech->get_ok('/admin/body/' . $body->id . '?text=1'); is $mech->content_type, 'text/plain'; $mech->content_contains('test category'); + $mech->content_lacks('<body'); }; @@ -740,13 +741,45 @@ subtest 'adding email to abuse list from report page' => sub { $mech->click_ok('banuser'); $mech->content_contains('User added to abuse list'); - $mech->content_contains('<small>(User in abuse table)</small>'); + $mech->content_contains('<small>User in abuse table</small>'); $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } ); ok $abuse, 'entry created in abuse table'; $mech->get_ok( '/admin/report_edit/' . $report->id ); - $mech->content_contains('<small>(User in abuse table)</small>'); + $mech->content_contains('<small>User in abuse table</small>'); +}; + +subtest 'remove user from abuse list from edit user page' => sub { + my $abuse = FixMyStreet::App->model('DB::Abuse')->find_or_create( { email => $user->email } ); + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->content_contains('User in abuse table'); + + $mech->click_ok('unban'); + + $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $user->email } ); + ok !$abuse, 'record removed from abuse table'; +}; + +subtest 'remove user with phone account from abuse list from edit user page' => sub { + my $abuse_user = $mech->create_user_ok('01234 456789'); + my $abuse = FixMyStreet::App->model('DB::Abuse')->find_or_create( { email => $abuse_user->phone } ); + $mech->get_ok( '/admin/user_edit/' . $abuse_user->id ); + $mech->content_contains('User in abuse table'); + my $abuse_found = FixMyStreet::App->model('DB::Abuse')->find( { email => $abuse_user->phone } ); + ok $abuse_found, 'user in abuse table'; + + $mech->click_ok('unban'); + + $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $user->phone } ); + ok !$abuse, 'record removed from abuse table'; +}; + +subtest 'no option to remove user already in abuse list' => sub { + my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $user->email } ); + $abuse->delete if $abuse; + $mech->get_ok( '/admin/user_edit/' . $user->id ); + $mech->content_lacks('User in abuse table'); }; subtest 'flagging user from report page' => sub { @@ -1048,13 +1081,13 @@ subtest 'adding email to abuse list from update page' => sub { $mech->click_ok('banuser'); $mech->content_contains('User added to abuse list'); - $mech->content_contains('<small>(User in abuse table)</small>'); + $mech->content_contains('<small>User in abuse table</small>'); $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } ); ok $abuse, 'entry created in abuse table'; $mech->get_ok( '/admin/update_edit/' . $update->id ); - $mech->content_contains('<small>(User in abuse table)</small>'); + $mech->content_contains('<small>User in abuse table</small>'); }; subtest 'flagging user from update page' => sub { @@ -1164,7 +1197,7 @@ subtest 'report search' => sub { subtest 'search abuse' => sub { $mech->get_ok( '/admin/users?search=example' ); - $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(User in abuse table}s); + $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>User in abuse table}s); }; subtest 'show flagged entries' => sub { @@ -1325,6 +1358,10 @@ my %default_perms = ( trusted_bodies => undef, ); +# Start this section with user having no name +# Regression test for mysociety/fixmystreetforcouncils#250 +$user->update({ name => '' }); + FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', }, sub { @@ -1332,7 +1369,7 @@ FixMyStreet::override_config { { desc => 'edit user name', fields => { - name => 'Test User', + name => '', email => 'test@example.com', body => $haringey->id, phone => '', diff --git a/t/cobrand/councils.t b/t/cobrand/councils.t index 4de8bbf2e..c44605bd9 100644 --- a/t/cobrand/councils.t +++ b/t/cobrand/councils.t @@ -1,6 +1,15 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council' ); +my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' ); + +my ($report) = $mech->create_problems_for_body(1, $oxon->id, 'Test', { + category => 'Cows', cobrand => 'fixmystreet', +}); +my $report_id = $report->id; + + foreach my $council (qw/oxfordshire bromley/) { FixMyStreet::override_config { ALLOWED_COBRANDS => [ $council ], @@ -11,4 +20,31 @@ foreach my $council (qw/oxfordshire bromley/) { }; } + +foreach my $test ( + { cobrand => 'fixmystreet', social => 1 }, + { cobrand => 'bromley', social => 0 }, +) { + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ $test->{cobrand} ], + FACEBOOK_APP_ID => 'facebook-app-id', + TWITTER_KEY => 'twitter-key', + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->get_ok('/auth'); + $mech->contains_or_lacks($test->{social}, "Log in with Facebook"); + $mech->contains_or_lacks($test->{social}, "Log in with Twitter"); + + $mech->get_ok("/report/new?lat=51.754926&lon=-1.256179"); + $mech->contains_or_lacks($test->{social}, "Log in with Facebook"); + $mech->contains_or_lacks($test->{social}, "Log in with Twitter"); + + $mech->get_ok("/report/$report_id"); + $mech->contains_or_lacks($test->{social}, "Log in with Facebook"); + $mech->contains_or_lacks($test->{social}, "Log in with Twitter"); + }; +}; + + done_testing(); diff --git a/templates/email/oxfordshire/rdi.txt b/templates/email/oxfordshire/rdi.txt index f12467d68..9dcf24186 100644 --- a/templates/email/oxfordshire/rdi.txt +++ b/templates/email/oxfordshire/rdi.txt @@ -1,8 +1,11 @@ -Subject: RDI report for [% user.name %] +Subject:[% IF staging_site %] [STAGING][% END %] RDI report for [% user.name %] Please find attached RDI file for [% start_date %] to [% end_date %]. - +[% IF staging_site %] +NB: This RDI file was generated on a staging site and is for testing +purposes only. +[% END %] ---- The mySociety team and Oxfordshire County Council diff --git a/templates/web/base/admin/report_blocks.html b/templates/web/base/admin/report_blocks.html index 8e8b56393..4c52b14bb 100644 --- a/templates/web/base/admin/report_blocks.html +++ b/templates/web/base/admin/report_blocks.html @@ -15,7 +15,7 @@ SET state_groups = c.cobrand.state_groups_admin; [% BLOCK abuse_button -%] [% IF allowed_pages.abuse_edit -%] -[% IF username_in_abuse %]<small>[% loc('(User in abuse table)') %]</small>[% ELSE %]<input type="submit" class="btn" name="banuser" value="[% loc('Ban user') %]" />[% END %] +[% IF username_in_abuse %]<small>[% loc('User in abuse table') %]</small>[% ELSE %]<input type="submit" class="btn" name="banuser" value="[% loc('Ban user') %]" />[% END %] [%- END %] [%- END %] diff --git a/templates/web/base/admin/user-form.html b/templates/web/base/admin/user-form.html index 5637252e2..7b27f7497 100644 --- a/templates/web/base/admin/user-form.html +++ b/templates/web/base/admin/user-form.html @@ -33,6 +33,12 @@ <input type="hidden" name="phone_verified" value="0"> [% END %] + [% IF username_in_abuse %] + <li> + <p class="error">[% loc('User in abuse table') %] <input name="unban" type="submit" value="[% loc('Unban') %]"></p> + </li> + [% END %] + [% IF c.user.is_superuser || c.cobrand.moniker == 'zurich' %] <li> <div class="admin-hint"> diff --git a/templates/web/base/admin/users.html b/templates/web/base/admin/users.html index d367c18d8..6dfcf4204 100644 --- a/templates/web/base/admin/users.html +++ b/templates/web/base/admin/users.html @@ -29,7 +29,7 @@ [% IF user.is_superuser %] * [% END %] </td> [% IF c.cobrand.moniker != 'zurich' %] - <td>[% user.flagged == 2 ? loc('(User in abuse table)') : user.flagged ? loc('Yes') : ' ' %]</td> + <td>[% user.flagged == 2 ? loc('User in abuse table') : user.flagged ? loc('Yes') : ' ' %]</td> [% END %] <td>[% IF user.id %]<a href="[% c.uri_for( 'user_edit', user.id ) %]">[% loc('Edit') %]</a>[% END %]</td> </tr> diff --git a/templates/web/base/auth/general.html b/templates/web/base/auth/general.html index d630dd415..76426f5d8 100644 --- a/templates/web/base/auth/general.html +++ b/templates/web/base/auth/general.html @@ -16,7 +16,7 @@ <input type="hidden" name="r" value="[% c.req.params.r | html %]"> -[% IF NOT oauth_need_email AND (c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY) %] +[% IF NOT oauth_need_email AND c.cobrand.social_auth_enabled %] [% IF c.config.FACEBOOK_APP_ID %] <div class="form-box"> <button name="facebook_sign_in" id="facebook_sign_in" value="facebook_sign_in" class="btn btn--block btn--social btn--facebook"> @@ -64,7 +64,7 @@ [% END %] </div> -[% IF NOT oauth_need_email AND (c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY) %] +[% IF NOT oauth_need_email AND c.cobrand.social_auth_enabled %] </div> [% END %] diff --git a/templates/web/base/report/new/form_user_loggedout.html b/templates/web/base/report/new/form_user_loggedout.html index 4142f4582..d7bbbf588 100644 --- a/templates/web/base/report/new/form_user_loggedout.html +++ b/templates/web/base/report/new/form_user_loggedout.html @@ -1,4 +1,4 @@ -[% IF c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY %] +[% IF c.cobrand.social_auth_enabled %] [% IF c.config.FACEBOOK_APP_ID %] <div class="form-box"> <button name="facebook_sign_in" id="facebook_sign_in" value="facebook_sign_in" class="btn btn--block btn--social btn--facebook"> @@ -27,6 +27,6 @@ [% PROCESS 'report/new/form_user_loggedout_by_email.html' %] </div> -[% IF c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY %] +[% IF c.cobrand.social_auth_enabled %] </div> [% END %] diff --git a/templates/web/base/report/update/form_user_loggedout.html b/templates/web/base/report/update/form_user_loggedout.html index d9f67e06e..19295b94c 100644 --- a/templates/web/base/report/update/form_user_loggedout.html +++ b/templates/web/base/report/update/form_user_loggedout.html @@ -1,4 +1,4 @@ -[% IF c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY %] +[% IF c.cobrand.social_auth_enabled %] <h3>[% loc("Now to submit your update…") %]</h3> [% IF c.config.FACEBOOK_APP_ID %] <div class="form-box"> @@ -29,6 +29,6 @@ [% INCLUDE 'report/update/form_user_loggedout_by_email.html' %] </div> -[% IF c.config.FACEBOOK_APP_ID OR c.config.TWITTER_KEY %] +[% IF c.cobrand.social_auth_enabled %] </div> [% END %] diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index dbae6e6a6..016967457 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -1978,11 +1978,11 @@ label .muted { size:0.8125em; weight:bold; } - big { - display:block; - margin-bottom:0.5em; - font-size:1.5385em; - } + } + big { + display:block; + margin-bottom:0.5em; + font-size:1.5385em; } } } diff --git a/web/cobrands/sass/_layout.scss b/web/cobrands/sass/_layout.scss index 5a78ff4d5..fce99c3de 100644 --- a/web/cobrands/sass/_layout.scss +++ b/web/cobrands/sass/_layout.scss @@ -931,10 +931,16 @@ textarea.form-error { color: #222; border-top:0.25em solid $primary; padding-top:1em; - div { - big { - color: $layout_front_stats_color; - font-size: 3.2308em; + big { + color: $layout_front_stats_color; + font-size: 2em; + @media (min-width: 54em) { + // 54em roughly halfway between 48em and 62em + font-size: 2.5em; + } + @media (min-width: 62em) { + // container max-width 60em + 2em side padding + font-size: 3em; } } } |