Changeset 1735 for trunk


Ignore:
Timestamp:
03/21/16 14:51:29 (8 years ago)
Author:
nanardon
Message:

Fix days left wrongly display in expire mail

This patch also allow to make different mail according "endcircuit" attribute.

Location:
trunk/LATMOS-Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Maintenance.pm

    r1365 r1735  
    88use LATMOS::Accounts::Mail; 
    99use FindBin qw($Bin); 
     10use DateTime; 
     11use Date::Calc; 
     12use Date::Parse; 
    1013 
    1114=head1 NAME 
     
    3942    my $sth= $base->db->prepare(q{ 
    4043        select name, 
    41             justify_hours(coalesce(endcircuit, expire) - now()) as delay, 
    42             endcircuit 
     44            coalesce(endcircuit, expire) as appliedexpire, 
     45            endcircuit, 
     46            expire 
    4347            from "user" 
    4448            where 
    4549            coalesce(endcircuit, expire) < now() + ?::interval 
    46             and expire > now() 
     50            and coalesce(endcircuit, expire) > now() 
    4751            and coalesce(endcircuit, expire) is not null 
    4852            and exported = True 
     
    5357    my @users; 
    5458    while (my $res = $sth->fetchrow_hashref) { 
    55         $res->{delay} =~ s/ day.? .*//; 
     59        my $now = DateTime->now; 
     60        my @expire = strptime($res->{appliedexpire}); 
     61 
     62        my ($days) = Date::Calc::Delta_Days( 
     63            $now->year, $now->month, $now->day, 
     64            1900 + $expire[5], $expire[4] +1, $expire[3], 
     65        ); 
     66 
     67        $res->{days} = $days; 
     68 
    5669        $res->{obj} = $base->get_object('user', $res->{name}); 
    5770        $res->{obj}->get_attributes('locked') and next; 
     
    97110        my %mail = ( 
    98111            From => $self->val('_default_', 'mailFrom', 'nomail@localhost'), 
    99             Subject => sprintf('Account %s Expire in %s days', $user->{name}, $user->{delay}), 
     112            Subject => sprintf('Account %s Expire in %s days', $user->{name}, $user->{days}), 
    100113            'X-LATMOS-Reason' => 'Account expiration', 
    101114        ); 
     
    124137        my $mailcc = join(', ', @cc) || ''; 
    125138        push(@summary, sprintf("%s : %s : %s\n", 
    126                 $user->{obj}->queryformat('%{sn} %{givenName} : %{name} : %{department} : %{manager} : %{expireText}'), 
     139                $user->{obj}->queryformat('%{sn} %{givenName} : %{name} : %{department} : %{manager} : %{expireText} : %{endcircuit}'), 
    127140                $to || 'Not sent, no destination', 
    128141                ($mailcc ? $mailcc : ''), 
     
    133146            la_log(LA_NOTICE, "Expiration mail for %s (%s) sent to %s; cc %s", 
    134147                $user->{obj}->id, 
    135                 $user->{delay}, 
     148                $user->{days}, 
    136149                $mail{to}, ($mail{cc} || '')); 
    137150            if ($options{to}) { 
  • trunk/LATMOS-Accounts/templates/mail/account_expire.mail

    r1426 r1735  
    44 
    55sauf erreur ou ommission de notre part votre compte [% obj.id %] expire 
    6 dans [% delay %] jours ([% obj.get_c_field('expire') %]). 
     6dans [% IF days %][% days %] jours[% ELSE %]aujourd'hui[% END %] ([% obj.get_c_field('expire') %]). 
    77En aucun cas vos fichiers ne seront détruits.  
    88 
     9[% IF endcircuit %] 
     10Il semble que vous n'avez pas fini votre circuit de sortie 
     11 
     12Merci de terminer celui-ci pour voir votre compte prolongé. 
     13[% ELSE %] 
    914Si ce dernier devait être prolongé, merci de dire à votre responsable 
    1015de contacter svp@latmos.ipsl.fr afin de nous donner la nouvelle date. 
    11  
    12  
    13 Cas d'un nouvel arrivant: 
    14  
    15 Si vous êtes un nouvel arrivant, veuillez réaliser votre circuit d'entrée et 
    16 remettre la fiche à Brigitte Fromager (Guyancourt - bureau 2421) ou Irina 
    17 Tchoumakova (Jussieu - bureau 409). 
    18 Si vous rencontrez des difficultés, n'hésitez pas à vous adresser à votre 
    19 responsable, ou à Brigitte et Irina. 
     16[% END %] 
    2017 
    2118 
     
    3633 
    3734Except error or omission on our part, your account login expires 
    38 in [% delay %] days ([% obj.get_c_field('expire') %]). 
     35in [% IF days %][% days %] days[% ELSE %]today[% END %] ([% obj.get_c_field('expire') %]). 
    3936In no case your files will be destroyed. 
    4037 
     38[% IF endcircuit %] 
     39It seems you haven't finish your entrance circuit 
     40 
     41Thanks to finish it to have your account prolongated. 
     42[% ELSE %] 
    4143If your account had to be extended, please ask your manager to contact 
    4244svp@latmos.ipsl.fr to give us a new expiration date. 
    43  
    44  
    45 If you are new in laboratory: 
    46  
    47 If you are a newcomer, please make your entrance circuit and pass on the sheet 
    48 to Brigitte Fromager (Guyancourt - office 2421) or Irina Tchoumakova (Jussieu - 
    49 office 409).                      
    50 If you meet difficulties, don't hesitate to deal with your manager, or with 
    51 Brigitte and Irina. 
     45[% END %] 
    5246 
    5347 
Note: See TracChangeset for help on using the changeset viewer.