Changeset 1577 for trunk


Ignore:
Timestamp:
12/31/15 14:31:46 (9 years ago)
Author:
nanardon
Message:

Make expiration synchronisation with employment configurable

Location:
trunk/LATMOS-Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Employment.pm

    r1576 r1577  
    285285 
    286286    my %changes; 
    287     foreach (qw( endEmployment endStrictEmployment endCurrentEmployment endLastEmployment )) { 
     287    my @employmentDate = qw( endEmployment endStrictEmployment endCurrentEmployment endLastEmployment ); 
     288    foreach (@employmentDate) { 
    288289        my $old = $user->_get_attributes($_) || ''; 
    289290        my $new = $user->_get_attributes("_$_") || ''; 
     
    295296    # If there is no current employment we try to find any to not let expire 
    296297    # unset 
    297     my $endemploy = $currentemployment 
    298         ? $user->_get_attributes('_endEmployment') 
    299         : $user->_get_attributes('_endLastEmployment'); 
    300     my $nextexpire = str2time($endemploy || '1970-01-01T00:00:00'); 
    301  
    302     if ($expire != $nextexpire) { 
    303         $changes{expire} = $endemploy; 
     298 
     299    my $expireOn = $self->base->config('expireOn') || ''; 
     300    if (!grep { $_ eq $expireOn } (@employmentDate, '', 'never')) { 
     301        $self->base->log(LA_ERR, "expireOn set to invalid parameter %s, using endEmployment instead", $expireOn);  
     302        $expireOn = 'endEmployment'; 
     303    } 
     304 
     305    if ($expireOn ne 'never') { 
     306        my $endemploy = $currentemployment 
     307            ? $user->_get_attributes("_$expireOn") 
     308            : $user->_get_attributes('_endLastEmployment'); 
     309        my $nextexpire = str2time($endemploy || '1970-01-01T00:00:00'); 
     310 
     311        if ($expire != $nextexpire) { 
     312            $changes{expire} = $endemploy; 
     313        } 
    304314    } 
    305315 
    306316    if (keys %changes) { 
    307317        $user->ReportChange('Update', 'Update %s to match employment', join(', ', sort keys %changes)); 
    308         $user->ReportChange('Update', 'Expire update to %s to match employment', ($endemploy || '(none)')) 
     318        $user->ReportChange('Update', 'Expire update to %s to match employment', ($changes{expire} || '(none)')) 
    309319            if (exists($changes{expire})); 
    310320        $user->set_fields(%changes); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1570 r1577  
    11041104    }; 
    11051105 
    1106     foreach (qw(expire contratType managerContact company endcircuit department)) { 
    1107         $attrs->{$_}{ro} = sub { 
    1108  
    1109             my $setting = $base->config('employment_lock_user') || 'any'; 
    1110  
    1111             for ($setting) { 
    1112                 /^always$/ and return 1; 
    1113                 /^never$/ and return 0; 
    1114  
    1115                 !$_[0] and return 1; 
    1116  
    1117                 /^any$/i and return $_[0]->listEmployment ? 1 : 0; 
    1118                 /^active/i and do { 
    1119                     return $_[0]->_get_c_field('currentEmployment') 
    1120                         ? 1 
    1121                         : $_[0]->_get_c_field('nextEmployment') ? 1 : 0; 
    1122                 }; 
    1123                 /(\S+)=(\S+)/ and do { 
    1124                     my $attr = $_[0]->_get_c_field($1); 
    1125                     if (defined($attr)) { 
    1126                         if ($2 eq '*') { 
    1127                             return 1; 
    1128                         } elsif($2 eq $attr) { 
    1129                             return 1; 
    1130                         } else { 
    1131                             return 0; 
    1132                         } 
     1106    my $employmentro = sub { 
     1107        my $setting = $base->config('employment_lock_user') || 'any'; 
     1108 
     1109        for ($setting) { 
     1110            /^always$/ and return 1; 
     1111            /^never$/ and return 0; 
     1112 
     1113            !$_[0] and return 1; 
     1114 
     1115            /^any$/i and return $_[0]->listEmployment ? 1 : 0; 
     1116            /^active/i and do { 
     1117                return $_[0]->_get_c_field('currentEmployment') 
     1118                ? 1 
     1119                : $_[0]->_get_c_field('nextEmployment') ? 1 : 0; 
     1120            }; 
     1121            /(\S+)=(\S+)/ and do { 
     1122                my $attr = $_[0]->_get_c_field($1); 
     1123                if (defined($attr)) { 
     1124                    if ($2 eq '*') { 
     1125                        return 1; 
     1126                    } elsif($2 eq $attr) { 
     1127                        return 1; 
    11331128                    } else { 
    11341129                        return 0; 
    11351130                    } 
    1136                 }; 
    1137             } 
    1138             return $_[0]->listEmployment ? 1 : 0; # default is any! 
    1139         }; 
     1131                } else { 
     1132                    return 0; 
     1133                } 
     1134            }; 
     1135        } 
     1136        return $_[0]->listEmployment ? 1 : 0; # default is any! 
     1137    }; 
     1138 
     1139    foreach (qw(contratType managerContact company endcircuit department)) { 
     1140        $attrs->{$_}{ro} = $employmentro; 
    11401141    } 
     1142 
     1143    $attrs->{expire}{ro} = sub { 
     1144        my $expireOn = $base->config('expireOn') || ''; 
     1145        if ($expireOn eq 'never') { 
     1146            return 0; 
     1147        } 
     1148 
     1149        $employmentro->($_[0]); 
     1150    }; 
    11411151 
    11421152    $class->SUPER::_get_attr_schema($base, $attrs) 
  • trunk/LATMOS-Accounts/man/man8/latmos-accounts-base-sql.pod

    r1576 r1577  
    150150The end of the employment matching current date. 
    151151 
     152=head3 Account Expiration 
     153 
     154When using employment, account expiration are set to match employment. By 
     155default the expiration is set to C<endEmployment> value. 
     156 
     157This behaviour can be changed by setting C<expireOn> parameter into base 
     158definition: 
     159 
     160=over 4 
     161 
     162=item any of endCurrentEmployment, endEmployment, endStrictEmployment, endLastEmployment 
     163 
     164=item never 
     165 
     166The expire date is left unchanged and must managed manually. 
     167 
     168=back 
     169 
    152170=head2 Group AutoMemberFilter 
    153171 
Note: See TracChangeset for help on using the changeset viewer.