Changeset 1135


Ignore:
Timestamp:
09/15/12 08:52:16 (12 years ago)
Author:
nanardon
Message:

Merge branch 'dyngroup'

Location:
trunk
Files:
20 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/MANIFEST

    r1132 r1135  
    1515lib/LATMOS/Accounts/Web/Controller/Admin/Requests.pm 
    1616lib/LATMOS/Accounts/Web/Controller/Ajax.pm 
     17lib/LATMOS/Accounts/Web/Controller/Ajax/Services/Mailing.pm 
    1718lib/LATMOS/Accounts/Web/Controller/Aliases.pm 
    1819lib/LATMOS/Accounts/Web/Controller/Create.pm 
     
    2526lib/LATMOS/Accounts/Web/Controller/Rpc.pm 
    2627lib/LATMOS/Accounts/Web/Controller/Search.pm 
     28lib/LATMOS/Accounts/Web/Controller/Services/Mailing.pm 
    2729lib/LATMOS/Accounts/Web/Controller/Sites.pm 
    2830lib/LATMOS/Accounts/Web/Controller/Summary/Departments.pm 
     
    5456root/html/ajax/select_freeip_select.tt 
    5557root/html/ajax/select_objects_list.tt 
     58root/html/ajax/services/mailing/dest_list.tt 
     59root/html/ajax/services/mailing/users_list.tt 
    5660root/html/ajax/set_attrs.tt 
    5761root/html/ajax/user_to_group_form.tt 
     
    9599root/html/request/recorded.tt 
    96100root/html/search/index.tt 
     101root/html/services/mailing/filter.tt 
     102root/html/services/mailing/index.tt 
     103root/html/services/mailing/send.tt 
     104root/html/services/mailing/to.tt 
    97105root/html/sites/default.tt 
    98106root/html/sites/index.tt 
     
    122130root/static/icons/document-save-as.png 
    123131root/static/icons/document-save.png 
     132root/static/icons/editclear.png 
    124133root/static/icons/emblem-favorite.png 
    125134root/static/icons/emblem-urgent.png 
    126135root/static/icons/expired.png 
     136root/static/icons/find.png 
    127137root/static/icons/gnome-session-logout.png 
    128138root/static/icons/gnome-stock-mail-snd.png 
     
    139149root/static/icons/gtk-home.png 
    140150root/static/icons/gtk-jump-to-rtl.png 
     151root/static/icons/gtk-refresh.png 
    141152root/static/icons/help-contents.png 
    142153root/static/icons/icon_edit.png 
     
    198209t/04config_load.t 
    199210t/controller_About.t 
     211t/controller_Ajax-Services-Mailing.t 
    200212t/controller_Ajax.t 
    201213t/controller_Aliases.t 
     
    206218t/controller_Request.t 
    207219t/controller_Search.t 
     220t/controller_Services-Mailing.t 
    208221t/controller_Sites.t 
    209222t/controller_Summary-Department.t 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm

    r1107 r1135  
    4646 
    4747sub displayattr : Local { 
    48     my ($self, $c, $otype) = @_; 
    49     my $attribute = $c->model('Accounts')->db->attribute($otype, 
    50         $c->req->param('attr')) or return; 
     48    my ($self, $c, $otype, $attr) = @_; 
     49    $attr ||= $c->req->param('attr'); 
     50    my $attribute = $c->model('Accounts')->db->attribute($otype, $attr) or return; 
    5151    $c->stash->{value} = $attribute->display($c->req->param('id')); 
    5252} 
     
    5656 
    5757    my $base = $c->model('Accounts')->db; 
    58     my $val = $c->req->param('val'); 
    59     $c->stash->{'complete'} = $c->prototype->auto_complete_result([ 
     58    my $val = $c->req->param('val') || ''; 
     59    $c->stash->{values} = [ 
     60        sort 
    6061        grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr) 
    61     ]); 
     62    ]; 
    6263 
    6364} 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm

    r1131 r1135  
    4141 
    4242    my @objlist = (); 
    43     if ($c->req->params->{'q'}) { 
    44         my %objs; 
    45         foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'cn' ]}) { 
    46             foreach ($base->search_objects( 
    47                     $otype, "$attr~" . $c->req->params->{'q'})) { 
    48                 $objs{$_} = 1; 
     43    if ($c->req->params->{'q'} || exists($c->req->params->{'attr'}) ) { 
     44        my %objs = (); 
     45        if ($c->req->params->{'q'}) { 
     46            foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'cn' ]}) { 
     47                foreach ($base->search_objects( 
     48                        $otype, "$attr~" . $c->req->params->{'q'})) { 
     49                    $objs{$_} = 1; 
     50                } 
     51                @objlist = sort keys %objs; 
    4952            } 
    50             @objlist = sort keys %objs; 
    5153        } 
    52     } elsif (exists($c->req->params->{'attr'})) { 
    53         $self->{filter}{'attr'} = [ $c->req->param('attr') ]; 
    54         $self->{filter}{'attrval'} = [ $c->req->param('attrval') ]; 
    55         my @filter = $self->filter; 
    56         @objlist = $base->search_objects($otype, @filter); 
     54 
     55        if (exists($c->req->params->{'attr'})) { 
     56            $self->{filter}{'attr'} = [ $c->req->param('attr') ]; 
     57            $self->{filter}{'attrval'} = [ $c->req->param('attrval') ]; 
     58            my @filter = $self->filter; 
     59            @objlist = $base->search_objects($otype, @filter); 
     60            if ($c->req->params->{'q'}) { 
     61                @objlist = grep { $objs{$_} } @objlist; 
     62            } 
     63        } 
    5764    } else { 
    5865        @objlist = $base->list_objects($otype); 
  • trunk/LATMOS-Accounts-Web/root/html/ajax/attrvalues.tt

    r971 r1135  
    1 [% complete %] 
     1[% IF c.req.param('type') == 'select' %] 
     2<select name="toto"> 
     3<option value="">--</option> 
     4[% FOREACH v = values %] 
     5<option value="[% v | html %]">[% v | html %]</option> 
     6[% END %] 
     7</select> 
     8[% ELSE %] 
     9[% c.prototype.auto_complete_result(values) %] 
     10[% END %] 
  • trunk/LATMOS-Accounts-Web/root/html/includes/select_objects_list.tt

    r1131 r1135  
    99[% IF objectslist.size < 20 %] 
    1010[% object = c.model('Accounts').db.get_object(ofilter.otype, name) %] 
    11 <option value="[% name | html %]">[% name | html %] ([% 
    12 object.get_attributes('displayName') | html %])</option> 
     11<option value="[% name | html %]">[% name | html %] 
     12[% disp = object.get_attributes('displayName') %] 
     13[% IF disp %] 
     14([%disp | html %]) 
     15[% END %] 
     16</option> 
    1317[% ELSE %] 
    1418<option value="[% name | html %]">[% name | html %]</option> 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r1100 r1135  
    120120} 
    121121 
     122sub _sync_dyn_group { 
     123    my ($self) = @_; 
     124 
     125    my @groups = $self->search_objects('group', 'autoMemberFilter=*'); 
     126 
     127    foreach (@groups) { 
     128        my $g = $self->get_object('group', $_) or next; 
     129        $g->populate_dyn_group; 
     130    } 
     131} 
     132 
    122133sub _commit { 
    123134    my ($self) = @_; 
     135 
     136    $self->_sync_dyn_group; 
     137 
    124138    if ($ENV{LA_NO_COMMIT}) { 
    125139        $self->log(LA_DEBUG, 'DB::COMMIT (ignore due to LA_NO_COMMIT)'); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm

    r1023 r1135  
    4141                ro => sub { 
    4242                    $_[0] &&  
    43                     ($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
     43                    (($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
     44                     || $_[0]->_get_c_field('autoMemberFilter')) 
    4445                    ? 1 : 0  
    4546                }, 
     
    5253                ro => sub { 
    5354                    $_[0] &&  
    54                     ($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
     55                    (($_[0]->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ 
     56                     || $_[0]->_get_c_field('autoMemberFilter')) 
    5557                    ? 1 : 0  
    5658                }, 
     
    7072                reference => 'sutype', 
    7173            }, 
     74            autoMemberFilter => { 
     75                multiple => 1, 
     76            } 
    7277        } 
    7378    ) 
     
    96101} 
    97102 
     103sub _set_group_members { 
     104    my ($self, $members) = @_; 
     105    my %member; 
     106    my $res = 0; 
     107    foreach (@{ $self->get_field('memberUID') }) { 
     108        $member{$_}{c} = 1; 
     109    } 
     110    foreach (ref $members ? @{ $members || []} : $members) { 
     111        $_ or next; # avoid undef 
     112        $member{$_}{n} = 1; 
     113    } 
     114 
     115    foreach (keys %member) { 
     116        $member{$_}{c} && $member{$_}{n} and next; # no change ! 
     117        my $user = $self->base->get_object('user', $_) or next; 
     118        if ($member{$_}{n}) { 
     119            my $sth = $self->db->prepare_cached( 
     120                q{insert into group_attributes_users (value, attr, okey) values (?,?,?)} 
     121            ); 
     122            $sth->execute($_, 'memberUID', $self->_get_ikey); 
     123            $res++; 
     124        } elsif ($member{$_}{c}) { 
     125            if (($user->get_c_field('department') || '') eq $self->id) { 
     126                $self->base->log(LA_WARN, 
     127                    "Don't removing user %s from group %s: is it's department", 
     128                    $user->id, $self->id); 
     129                next; 
     130            } 
     131            my $sth = $self->db->prepare_cached( 
     132                q{delete from group_attributes_users where value = ? and attr = ? and okey = ?} 
     133            ); 
     134            $sth->execute($_, 'memberUID', $self->_get_ikey); 
     135            $res++; 
     136        } # else {} # can't happend 
     137    } 
     138    return $res; 
     139} 
     140 
    98141sub set_fields { 
    99142    my ($self, %data) = @_; 
     
    102145    foreach my $attr (keys %data) { 
    103146        $attr =~ /^memberUID|member$/ and do { 
    104             if (($self->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/) { 
     147            if (($self->_get_c_field('sutype') ||'') =~ /^(jobtype|contrattype)$/ || 
     148                 $self->get_field('autoMemberFilter')) { 
    105149                $self->base->log(LA_WARN, 
    106150                    "Group %s is managed, ignoring member set request", 
     
    108152                next; 
    109153            } 
    110             my %member; 
    111             foreach (@{ $self->get_field('memberUID') }) { 
    112                 $member{$_}{c} = 1; 
    113             } 
    114             foreach (ref $data{$attr} ? @{ $data{$attr} || []} : $data{$attr}) { 
    115                 $_ or next; # avoid undef 
    116                 $member{$_}{n} = 1; 
    117             } 
    118  
    119             foreach (keys %member) { 
    120                 $member{$_}{c} && $member{$_}{n} and next; # no change ! 
    121                 my $user = $self->base->get_object('user', $_) or next; 
    122                 if ($member{$_}{n}) { 
    123                     my $sth = $self->db->prepare_cached( 
    124                         q{insert into group_attributes_users (value, attr, okey) values (?,?,?)} 
    125                     ); 
    126                     $sth->execute($_, 'memberUID', $self->_get_ikey); 
    127                     $res++; 
    128                 } elsif ($member{$_}{c}) { 
    129                     if (($user->get_c_field('department') || '') eq $self->id) { 
    130                         $self->base->log(LA_WARN, 
    131                             "Don't removing user %s from group %s: is it's department", 
    132                             $user->id, $self->id); 
    133                         next; 
    134                     } 
    135                     my $sth = $self->db->prepare_cached( 
    136                         q{delete from group_attributes_users where value = ? and attr = ? and okey = ?} 
    137                     ); 
    138                     $sth->execute($_, 'memberUID', $self->_get_ikey); 
    139                     $res++; 
    140                 } # else {} # can't happend 
    141             } 
     154            $self->_set_group_members($data{$attr}); 
    142155            next; 
    143156        }; 
    144157        $fdata{$attr} = $data{$attr}; 
    145158    } 
     159 
    146160    if (keys %fdata) { 
    147161            my $setres = $self->SUPER::set_fields(%fdata); 
     162        if (exists($fdata{autoMemberFilter})) { 
     163            $res += $self->populate_dyn_group; 
     164        } 
    148165            if (defined($setres)) { return $res + $setres; } 
    149166            else { return; }  
     
    153170} 
    154171 
     172sub populate_dyn_group { 
     173    my ($self) = @_; 
     174 
     175    if (!$self->get_field('autoMemberFilter')) { 
     176        return; 
     177    } 
     178    $self->base->log(LA_DEBUG, 
     179        "Populating group %s from autoMemberFilter attribute", 
     180        $self->id 
     181    ); 
     182    my $filter = $self->get_field('autoMemberFilter'); 
     183    $self->_set_group_members( 
     184        [ $self->base->search_objects( 
     185            'user', 
     186            ref $filter ? @{ $filter } : $filter 
     187        ) ] 
     188    ) 
     189} 
     190 
    1551911; 
    156192 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/SyncManager.pm

    r1083 r1135  
    3636        return; 
    3737    }; 
     38 
     39    if ( !grep { 
     40        lc($ini->val($_, 'type', '')) eq 'basessynchro' 
     41        } $ini->Sections ) { 
     42        $ini->newval('_basesync', 'type', 'basessynchro'); 
     43    } 
     44    if ( !grep { 
     45        lc($ini->val($_, 'type', '')) eq 'refreshexpired' 
     46        } $ini->Sections ) { 
     47        $ini->newval('_refreshexpired', 'type', 'refreshexpired'); 
     48    } 
     49 
     50    $ini->newval('_automatedrequest', 'type', 'automatedrequest'); 
    3851 
    3952    bless { 
  • trunk/LATMOS-Accounts/man/man8/latmos-accounts-base-sql.pod

    r1073 r1135  
    1010containing the server, the database name, user and password, etc... 
    1111 
     12=head1 FEATURES 
     13 
     14=head2 Group AutoMemberFilter 
     15 
     16Group objects contains users members by setting either C<members> or 
     17C<memberUID> attributes. 
     18 
     19Sometimes it can be usefull to have group automatically populated by arbitrary 
     20rules. 
     21 
     22This is possible by setting a filter in the C<autoMemberFilter> attribute, 
     23The filter format is the same the one used by L<la-search>, the attribute is 
     24multivaluable. 
     25 
     26So for example one can create an account automatically a group containing people 
     27having "Olivier" as first name: 
     28 
     29    autoMemberFilter: givenBame=Olivier 
     30 
     31A probably more usefull example is a group containing people from two others 
     32groups: 
     33 
     34    autoMemberFilter: memberOf=group1 
     35    autoMemberFilter: memberOf=group2 
     36 
     37The  C<members> or C<memberUID> attribute becomes read-only attribute once 
     38C<autoMemberFilter> attribute is set. 
  • trunk/LATMOS-Accounts/sqldata/attributes.csv

    r1099 r1135  
    2828"group","gidNumber","" 
    2929"group","expire","" 
     30"group","autoMemberFilter" 
    3031"nethost","description","" 
    3132"nethost","owner","" 
Note: See TracChangeset for help on using the changeset viewer.