diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rwxr-xr-x | bin/expire-sessions | 79 | ||||
-rw-r--r-- | conf/crontab-example | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bristol.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 2 | ||||
-rw-r--r-- | t/utils.t | 4 | ||||
-rw-r--r-- | templates/web/bristol/maps/noscript_map.html | 32 |
7 files changed, 87 insertions, 35 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 628bac41b..0a86a2067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Change text on /reports to match lower down (fix translation). - Ensure all reports graph can't dip downward. #1956 - Fix error sending `requires_inspection` reports. #1961 + - Fix timezone related test failure. #1984 - Restore display of extra fields on inspector form. #1994 - Admin improvements: - Admin can anonymize/hide all a user's reports. #1942 #1943 @@ -28,6 +29,7 @@ - Admin can remove a user's account details. #1944 - Superusers can have optional two-factor authentication. #1973 - Development improvements: + - Add script to remove expired sessions. #1987 - 'components' parameter can be passed to Google geocoder. #1994 - UK: - Lazy load images in the footer. diff --git a/bin/expire-sessions b/bin/expire-sessions new file mode 100755 index 000000000..8cfdd57e3 --- /dev/null +++ b/bin/expire-sessions @@ -0,0 +1,79 @@ +#!/usr/bin/env perl + +# expire-sessions: Run regularly to remove old sessions (plus +# can set up data for 'log user out' admin functionality). + +use strict; +use warnings; +require 5.8.0; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../setenv.pl"; +} + +use FixMyStreet::DB; +use Getopt::Long; +use List::Util qw(uniq); +use MIME::Base64; +use Storable; + +GetOptions( + 'init' => \my $init, +); + +my $rs = FixMyStreet::DB->resultset("Session"); + +# Delete expired sessions (including from in User object) +while (my $session = $rs->search({ expires => { '<', time() } })->next) { + if (my $user = get_user($session)) { + my $id = get_id($session); + my $sessions = $user->get_extra_metadata('sessions'); + my @new_sessions = grep { $_ ne $id } @$sessions; + update_user_sessions($user, \@new_sessions) if @new_sessions != @$sessions; + } + $session->delete; +} + +if ($init) { + # Update sessions to make sure all present in User objects + print "Setting up sessions in user objects\n"; + while (my $session = $rs->next) { + my $user = get_user($session) or next; + my $id = get_id($session); + my $sessions = $user->get_extra_metadata('sessions'); + my @new_sessions = uniq @$sessions, $id; + update_user_sessions($user, \@new_sessions) if @new_sessions != @$sessions; + } +} + +# --- + +sub get_user { + my $session = shift; + return unless $session->session_data; + my $data = Storable::thaw(MIME::Base64::decode($session->session_data)); + return unless $data->{__user}; + my $user = FixMyStreet::DB->resultset("User")->find($data->{__user}{id}); + return $user; +} + +sub get_id { + my $session = shift; + my $id = $session->id; + $id =~ s/^session://; + $id =~ s/\s+$//; + return $id; +} + +sub update_user_sessions { + my ($user, $sessions) = @_; + if (@$sessions) { + $user->set_extra_metadata('sessions', $sessions); + } else { + $user->unset_extra_metadata('sessions'); + } + $user->update; +} diff --git a/conf/crontab-example b/conf/crontab-example index 037dd147e..f06144699 100644 --- a/conf/crontab-example +++ b/conf/crontab-example @@ -31,6 +31,7 @@ PATH=/usr/local/bin:/usr/bin:/bin 13 * * * * "$FMS/bin/update-all-reports" # Once a day on all servers +0 0 * * * "$FMS/bin/expire-sessions" 39 2 * * * "$FMS/bin/problems-filed-graph" 43 2 * * * "$FMS/bin/problem-creation-graph" 00 8 * * * "$FMS/bin/check-for-zombies" $UNIX_USER diff --git a/perllib/FixMyStreet/Cobrand/Bristol.pm b/perllib/FixMyStreet/Cobrand/Bristol.pm index b11a52643..4648802bd 100644 --- a/perllib/FixMyStreet/Cobrand/Bristol.pm +++ b/perllib/FixMyStreet/Cobrand/Bristol.pm @@ -20,7 +20,7 @@ sub example_places { } sub map_type { - 'Bristol'; + 'OSM'; } sub default_link_zoom { 6 } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 0aacc14a1..583aaaa08 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -86,7 +86,7 @@ sub send { $params->{From} = $self->send_from( $row ); } else { $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL'); - my $name = sprintf(_("On behalf of %s"), $params->{From}[1]); + my $name = sprintf(_("On behalf of %s"), @{ $self->send_from($row) }[1]); $params->{From} = [ $sender, $name ]; } @@ -67,7 +67,9 @@ is Utils::cleanup_text( "This has new\n\n\nlines in it", { allow_multiline => 1 is Utils::prettify_dt(), "[unknown time]"; -my $dt = DateTime->now; +# Make sure we create the date using the FMS timezone that prettify_dt uses +# otherwise this can fail if the local timezone is not the same as the FMS one +my $dt = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ); is Utils::prettify_dt($dt), $dt->strftime("%H:%M today"); # Same week test diff --git a/templates/web/bristol/maps/noscript_map.html b/templates/web/bristol/maps/noscript_map.html deleted file mode 100644 index 987aa76a6..000000000 --- a/templates/web/bristol/maps/noscript_map.html +++ /dev/null @@ -1,32 +0,0 @@ -<div class="noscript square-map__outer"> - <div class="square-map__inner"> - <div id="[% nsm_prefix %]drag"> - [%- FOR row IN map.tiles -%] - [%- FOR tile IN row -%] - [%- top_px = tile.row_offset * map.tile_size -%] - [%- left_px = tile.col_offset * map.tile_size %] - <[% map.img_type %] - class="square-map__tile" - alt="[% tile.alt %]" - id="[% nsm_prefix %]t[% tile.dotted_id %]" - name="tile_[% tile.dotted_id %]" - src="[% tile.src %]" - style="width: [% 100 / map.cols %]%; height: auto; float: left;"> - [%- END -%] - [% END %] - </div> - <div id="[% nsm_prefix %]pins">[% FOR pin IN map.pins %][% INCLUDE pin %][% END %]</div> - [% INCLUDE 'maps/_compass.html' %] - </div> -</div> - -[% BLOCK pin %] -[% - SET pin_top = pin.py / ( map.tile_size * map.rows ) * 100; - SET pin_left = pin.px / ( map.tile_size * map.cols ) * 100; - # -24px half of 48px wide image, -64px all of 64px tall image - INCLUDE 'maps/pin.html' - pin_style = 'top:' _ pin_top _ '%; left:' _ pin_left _ '%; position:absolute; margin-left:-24px; margin-top:-64px;' -%] -[% END %] - |