Changeset 1912 for trunk


Ignore:
Timestamp:
01/04/17 19:57:18 (7 years ago)
Author:
nanardon
Message:

Populate manager attribute from employment

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql
Files:
3 edited

Legend:

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

    r1860 r1912  
    372372        my $cval = $self->get_attributes($attr) || ''; 
    373373 
     374        for ($attr) { 
     375            if ($attr eq 'managerContact') { 
     376                if (!$cval) { 
     377                    my $dpmt  = $self->get_attributes('department') or last; 
     378                    my $odmpt = $self->base->get_object('group', $dpmt) or last; 
     379                    $cval = $odmpt->get_attributes('managedBy'); 
     380                } 
     381            } 
     382        } 
     383 
    374384        if ($uval ne $cval) { 
    375385            my $oattr = $self->base->attribute('user', $attr); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm

    r1904 r1912  
    4040                uniq => 1, 
    4141                iname => 'gidnumber', 
    42                 mandatory => 1,  
     42                mandatory => 1, 
    4343                label => l('GID'), 
    4444            }, 
     
    5252                delayed => 1, 
    5353                ro => sub { 
    54                     $_[0] &&  
     54                    $_[0] && 
    5555                    (($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
    5656                     || $_[0]->_get_c_field('autoMemberFilter') 
    5757                     || $_[0]->_get_c_field('autoFromSutype')) 
    58                     ? 1 : 0  
     58                    ? 1 : 0 
    5959                }, 
    6060                get => sub { 
    61                     my ($self) = @_;  
     61                    my ($self) = @_; 
    6262                    my $sth = $self->base->db->prepare_cached( 
    6363                        q{ 
     
    8585                monitored => 1, 
    8686                reference => 'user', 
    87                 multiple => 1,  
     87                multiple => 1, 
    8888                delayed => 1, 
    8989                iname => 'memberUID', 
    9090                can_values => sub { $base->list_objects('user') }, 
    9191                ro => sub { 
    92                     $_[0] &&  
     92                    $_[0] && 
    9393                    (($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
    9494                     || $_[0]->_get_c_field('autoMemberFilter') 
    9595                     || $_[0]->_get_c_field('autoFromSutype')) 
    96                     ? 1 : 0  
     96                    ? 1 : 0 
    9797                }, 
    9898                get => sub { 
     
    113113                can_values => sub { 
    114114                    my %uniq = map { $_ => 1 } grep { $_ } 
    115                     ($_[1] ? $_[1]->get_attributes('manager') : ()), 
    116                     $base->search_objects('user', 'active=*'); 
     115                    (($_[1] ? $_[1]->get_attributes('managedBy') : ()), 
     116                    $base->search_objects('user', 'active=*')); 
    117117                    sort keys %uniq; 
    118118                }, 
    119119                label => l('Manager'), 
     120                post => sub { 
     121                    my ($self, $value) = @_; 
     122                    $self->object->_update_employment_manager; 
     123                }, 
    120124            }, 
    121125            managedAlsoBy  => { 
     
    126130                can_values => sub { 
    127131                    my %uniq = map { $_ => 1 } grep { $_ } 
    128                     ($_[1] ? $_[1]->get_attributes('manager') : ()), 
     132                    ($_[1] ? $_[1]->get_attributes('managedBy') : ()), 
    129133                    $base->search_objects('user', 'active=*'); 
    130134                    sort keys %uniq; 
     
    250254    } 
    251255 
    252      
    253256    if (my $filter = $self->get_field('autoMemberFilter')) { 
    254257        foreach ($self->base->search_objects( 
     
    265268} 
    266269 
     270sub _update_employment_manager { 
     271    my ($self) = @_; 
     272 
     273    my $listEmp = $self->base->db->prepare(q{ 
     274        select name from employment join employment_attributes 
     275            on employment.ikey = employment_attributes.okey 
     276        where firstday < now() and (lastday > now() or lastday is NULL) 
     277            and employment_attributes.attr = 'department' and employment_attributes.value = ? 
     278        }); 
     279    $listEmp->execute($self->id); 
     280    while (my $res = $listEmp->fetchrow_hashref()) { 
     281        my $employment = $self->base->get_object('employment', $res->{name}) or next; 
     282        $employment->get_attributes('managerContact') and next; 
     283        my $dpmt  = $employment->_get_attributes('department') or next; 
     284        my $odmpt = $employment->base->get_object('group', $dpmt) or next; 
     285        my $manager = $odmpt->get_attributes('managedBy') or next; 
     286        my $user = $employment->get_attributes('user'); 
     287        my $ouser = $employment->base->get_object('user', $user) or next; 
     288        $self->base->log(LA_DEBUG, "Updating manager for $user due to dpmt update"); 
     289        $ouser->ReportChange( 
     290            'Update', 'Attr manager updated to match Dpmt manager %s (%s)', 
     291            $manager, 
     292            $dpmt, 
     293        ); 
     294        $ouser->set_fields('managerContact', $manager); 
     295    } 
     296 
     297    return 1; 
     298} 
     299 
    2673001; 
    268301 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1910 r1912  
    10851085                can_values => sub { 
    10861086                    my %uniq = map { $_ => 1 } grep { $_ } 
    1087                     ($_[1] ? $_[1]->get_attributes('managerContact') : ()), 
    1088                     $base->search_objects('user', 'active=1'); 
     1087                    (($_[1] ? $_[1]->get_attributes('managerContact') : ()), 
     1088                    $base->search_objects('user', 'active=1')); 
    10891089                    sort keys %uniq; 
    10901090                }, 
Note: See TracChangeset for help on using the changeset viewer.