From 7eb5f967f2d85ea3a7846353fbaf666e3a0e2bc5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 4 Sep 2020 18:38:35 +0200 Subject: profile: limit history to four weeks by default --- lib/Travelynx/Controller/Account.pm | 9 +++++++++ lib/Travelynx/Controller/Traveling.pm | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'lib/Travelynx/Controller') diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index 10200a6..c68a22c 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -261,6 +261,13 @@ sub privacy { $public_level &= ~0x30; } + if ( $self->param('history_age') eq 'infinite' ) { + $public_level |= 0x40; + } + else { + $public_level &= ~0x40; + } + $self->users->set_privacy( uid => $user->{id}, level => $public_level @@ -281,6 +288,8 @@ sub privacy { : $public_level & 0x20 ? 'extern' : 'private' ); + $self->param( + history_age => $public_level & 0x40 ? 'infinite' : 'month' ); $self->render( 'privacy', name => $user->{name} ); } } diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 33b3118..24edaa3 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -160,12 +160,32 @@ sub public_profile { ) { my $status = $self->get_user_status( $user->{id} ); + my @journeys; + if ( $user->{public_level} & 0x40 ) { + @journeys = $self->journeys->get( + uid => $user->{id}, + limit => 10, + with_datetime => 1 + ); + } + else { + my $now = DateTime->now( time_zone => 'Europe/Berlin' ); + my $month_ago = $now->clone->subtract( weeks => 4 ); + @journeys = $self->journeys->get( + uid => $user->{id}, + limit => 10, + with_datetime => 1, + after => $month_ago, + before => $now + ); + } $self->render( 'profile', name => $name, uid => $user->{id}, public_level => $user->{public_level}, journey => $status, + journeys => [@journeys], version => $self->app->config->{version} // 'UNKNOWN', ); } @@ -207,12 +227,22 @@ sub public_journey_details { with_polyline => 1, ); + if ( not( $user->{public_level} & 0x40 ) ) { + my $month_ago = DateTime->now( time_zone => 'Europe/Berlin' ) + ->subtract( weeks => 4 )->epoch; + if ( $journey and $journey->{rt_dep_ts} < $month_ago ) { + $journey = undef; + } + } + if ($journey) { my $map_data = $self->journeys_to_map_data( journeys => [$journey], include_manual => 1, ); - if ( $journey->{user_data}{comment} ) { + if ( $journey->{user_data}{comment} + and not $user->{public_level} & 0x04 ) + { delete $journey->{user_data}{comment}; } $self->render( @@ -226,7 +256,7 @@ sub public_journey_details { ); } else { - $self->render( 'not_found', ); + $self->render('not_found'); } } else { -- cgit v1.2.3