Changeset 1865


Ignore:
Timestamp:
12/21/16 15:07:28 (7 years ago)
Author:
nanardon
Message:

Merge branch

Location:
trunk
Files:
7 added
26 edited

Legend:

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

    r1853 r1865  
    3434lib/LATMOS/Accounts/Web/Controller/NetHosts.pm 
    3535lib/LATMOS/Accounts/Web/Controller/NetZones.pm 
     36lib/LATMOS/Accounts/Web/Controller/OAliases.pm 
    3637lib/LATMOS/Accounts/Web/Controller/Remote.pm 
    3738lib/LATMOS/Accounts/Web/Controller/Remote/AskPwReset.pm 
     
    116117root/html/netzones/object_header.tt 
    117118root/html/no_object.tt 
     119root/html/oaliases/Create.tt 
     120root/html/oaliases/Edit.tt 
     121root/html/oaliases/index.tt 
    118122root/html/request/default.tt 
    119123root/html/request/index.tt 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/I18N/fr.po

    r1694 r1865  
    3434msgstr "%1 ans" 
    3535 
    36 #: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:51 
    37 #: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:79 
    38 #: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:84 
    39 #: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:97 
     36#: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:126 
     37#: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:131 
     38#: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:145 
     39#: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:77 
    4040#: lib/LATMOS/Accounts/Web/Controller/Json/Expire.pm:44 
    4141msgid "(none)" 
     
    4949msgid "About" 
    5050msgstr "À propos" 
     51 
     52#: root/html/summary/accage/index.tt:5 
     53msgid "Active/Non active" 
     54msgstr "" 
    5155 
    5256#: lib/LATMOS/Accounts/Web/Controller/Json/Timeline.pm:127 
     
    6468msgstr "Arrivée" 
    6569 
    66 #: root/html/includes/sidebar.tt:16 
     70#: root/html/includes/sidebar.tt:15 
    6771msgid "Change my password" 
    6872msgstr "Changer mon mot de passe" 
    6973 
    70 #: root/html/includes/sidebar.tt:9 
     74#: root/html/includes/sidebar.tt:8 
    7175msgid "Connected as" 
    7276msgstr "Connecté en tant que" 
    7377 
    74 #: root/html/includes/sidebar.tt:38 
     78#: root/html/includes/sidebar.tt:37 
    7579msgid "Create" 
    7680msgstr "Créer" 
     
    8589msgstr "Statut actuel" 
    8690 
    87 #: root/html/summary/employment/index.tt:6 
     91#: root/html/summary/accage/index.tt:7 root/html/summary/employment/index.tt:6 
    8892msgid "Department" 
    8993msgstr "Départment" 
     
    101105msgstr "Expiration" 
    102106 
     107#: root/html/summary/employment/index.tt:12 
     108msgid "Filter" 
     109msgstr "" 
     110 
    103111#: root/html/users/employment.tt:91 
    104112msgid "From" 
    105113msgstr "Du" 
    106114 
    107 #: root/html/includes/wrapper.tt:56 
     115#: root/html/includes/wrapper.tt:57 
    108116msgid "IT management" 
    109117msgstr "Gestion informatique" 
     
    113121msgstr "Départ" 
    114122 
    115 #: root/html/includes/sidebar.tt:21 
     123#: root/html/includes/sidebar.tt:20 
    116124msgid "Logout" 
    117125msgstr "Se déconnecter" 
     
    121129msgstr "Nouveau statut" 
    122130 
     131#: root/html/summary/accage/index.tt:13 
     132msgid "Show inactive accounts" 
     133msgstr "" 
     134 
    123135#: root/html/users/employment.tt:94 
    124136msgid "Since" 
    125137msgstr "A partir du" 
     138 
     139#: root/html/summary/employment/index.tt:10 
     140msgid "Site" 
     141msgstr "" 
    126142 
    127143#: root/html/summary/employment/index.tt:3 
     
    129145msgstr "Trié par" 
    130146 
    131 #: root/html/summary/employment/index.tt:11 
     147#: root/html/summary/employment/index.tt:19 
    132148msgid "Stacked" 
    133149msgstr "Cumulé" 
     
    137153msgstr "Statistiques" 
    138154 
    139 #: root/html/groups/dpmt.tt:91 root/html/summary/employment/index.tt:8 
     155#: root/html/groups/dpmt.tt:91 root/html/summary/accage/index.tt:9 
     156#: root/html/summary/employment/index.tt:8 
    140157msgid "Status" 
    141158msgstr "Statut" 
    142159 
    143 #: root/html/includes/sidebar.tt:58 
     160#: root/html/includes/sidebar.tt:57 
    144161msgid "Status evolution" 
    145162msgstr "Évolution des status" 
     
    153170msgstr "Aujourd'hui" 
    154171 
    155 #: root/html/includes/sidebar.tt:50 
     172#: root/html/includes/sidebar.tt:49 
    156173msgid "Tools" 
    157174msgstr "Outils" 
    158175 
    159 #: root/html/includes/sidebar.tt:28 
     176#: root/html/includes/sidebar.tt:27 
    160177msgid "View" 
    161178msgstr "Voir" 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/I18N/messages.pot

    r1694 r1865  
    3131msgstr "" 
    3232 
    33 #: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:51 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:79 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:84 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:97 lib/LATMOS/Accounts/Web/Controller/Json/Expire.pm:44 
     33#: lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:126 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:131 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:145 lib/LATMOS/Accounts/Web/Controller/Json/Employment.pm:77 lib/LATMOS/Accounts/Web/Controller/Json/Expire.pm:44 
    3434msgid "(none)" 
    3535msgstr "" 
     
    4141#: root/html/includes/sidebar.tt:76 
    4242msgid "About" 
     43msgstr "" 
     44 
     45#: root/html/summary/accage/index.tt:5 
     46msgid "Active/Non active" 
    4347msgstr "" 
    4448 
     
    5559msgstr "" 
    5660 
    57 #: root/html/includes/sidebar.tt:16 
     61#: root/html/includes/sidebar.tt:15 
    5862msgid "Change my password" 
    5963msgstr "" 
    6064 
    61 #: root/html/includes/sidebar.tt:9 
     65#: root/html/includes/sidebar.tt:8 
    6266msgid "Connected as" 
    6367msgstr "" 
    6468 
    65 #: root/html/includes/sidebar.tt:38 
     69#: root/html/includes/sidebar.tt:37 
    6670msgid "Create" 
    6771msgstr "" 
     
    7579msgstr "" 
    7680 
    77 #: root/html/summary/employment/index.tt:6 
     81#: root/html/summary/accage/index.tt:7 root/html/summary/employment/index.tt:6 
    7882msgid "Department" 
    7983msgstr "" 
     
    9195msgstr "" 
    9296 
     97#: root/html/summary/employment/index.tt:12 
     98msgid "Filter" 
     99msgstr "" 
     100 
    93101#: root/html/users/employment.tt:91 
    94102msgid "From" 
    95103msgstr "" 
    96104 
    97 #: root/html/includes/wrapper.tt:56 
     105#: root/html/includes/wrapper.tt:57 
    98106msgid "IT management" 
    99107msgstr "" 
     
    103111msgstr "" 
    104112 
    105 #: root/html/includes/sidebar.tt:21 
     113#: root/html/includes/sidebar.tt:20 
    106114msgid "Logout" 
    107115msgstr "" 
     
    111119msgstr "" 
    112120 
     121#: root/html/summary/accage/index.tt:13 
     122msgid "Show inactive accounts" 
     123msgstr "" 
     124 
    113125#: root/html/users/employment.tt:94 
    114126msgid "Since" 
     127msgstr "" 
     128 
     129#: root/html/summary/employment/index.tt:10 
     130msgid "Site" 
    115131msgstr "" 
    116132 
     
    119135msgstr "" 
    120136 
    121 #: root/html/summary/employment/index.tt:11 
     137#: root/html/summary/employment/index.tt:19 
    122138msgid "Stacked" 
    123139msgstr "" 
     
    127143msgstr "" 
    128144 
    129 #: root/html/groups/dpmt.tt:91 root/html/summary/employment/index.tt:8 
     145#: root/html/groups/dpmt.tt:91 root/html/summary/accage/index.tt:9 root/html/summary/employment/index.tt:8 
    130146msgid "Status" 
    131147msgstr "" 
    132148 
    133 #: root/html/includes/sidebar.tt:58 
     149#: root/html/includes/sidebar.tt:57 
    134150msgid "Status evolution" 
    135151msgstr "" 
     
    143159msgstr "" 
    144160 
    145 #: root/html/includes/sidebar.tt:50 
     161#: root/html/includes/sidebar.tt:49 
    146162msgid "Tools" 
    147163msgstr "" 
    148164 
    149 #: root/html/includes/sidebar.tt:28 
     165#: root/html/includes/sidebar.tt:27 
    150166msgid "View" 
    151167msgstr "" 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm

    r1343 r1865  
    4646            foreach my $attr (@{ $c->config->{objects}{$otype}{quick_search} || [ 'name' ]}) { 
    4747                foreach ($base->search_objects( 
    48                         $otype, "$attr~" . $c->req->params->{'q'})) { 
     48                        $otype, "$attr~" . $c->req->params->{'q'}, 
     49                                'oalias=NULL', 
     50                    )) { 
    4951                    $objs{$_} = 1; 
    5052                } 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r1860 r1865  
    102102        attrs => [ qw( 
    103103            isMainAddress 
     104            expire 
    104105            telephoneNumber 
    105106            streetAddress 
  • trunk/LATMOS-Accounts-Web/root/html/includes/sidebar.tt

    r1758 r1865  
    6464    <li class="ui-widget-header"><a href="[% c.uri_for('/stat') %]">[% l('Statistics') %]</a>: 
    6565    [% END %] 
    66     <li><a href="[% c.uri_for('/stat', stat) %]">[% ostat.get_attributes('description') || stat | html %]</a></li> 
     66    <li><a href="[% c.uri_for('/stat', stat) %]">[% ostat.get_attributes('description') || stat | html %]</a> 
     67    </li> 
     68 
    6769    [% IF loop.last %] 
    6870    </li> 
    6971    [% END %] 
    7072    [% END %] 
    71  
     73     
     74    [% IF c.model('Accounts').db.search_objects('stat', 'exported=true', 'display=*').sort %] 
     75    <li><a href="[% c.uri_for('/stat') %]">[% l('Others Statistics') %]</a> 
     76    </li> 
     77    [% END %] 
    7278    </ul> 
    7379</li> 
  • trunk/LATMOS-Accounts-Web/root/html/users/address_form.tt

    r1162 r1865  
    3838[% END %] 
    3939 
     40<tr> 
     41    <th> 
     42        [% form.attr_label('expire') %] 
     43 
     44        [% IF form.attr_hint('expire') %] 
     45        <span 
     46            title="[% form.attr_hint('expire') | html %]" 
     47            class="hint">?</span> 
     48        [% END %] 
     49    </th> 
     50    <td>[% form.attr_field('expire') %]</td> 
     51</tr> 
    4052[% IF NOT c.req.param('add_addr') %] 
    4153<tr> 
  • trunk/LATMOS-Accounts/MANIFEST

    r1855 r1865  
    2525bin/la-renewEmp 
    2626bin/la-search 
     27bin/la-sql-alias 
    2728bin/la-sql-crypt-passwd 
    2829bin/la-sql-edit-form 
     
    3435bin/la-sql-log 
    3536bin/la-sql-recompute 
     37bin/la-sql-properties 
    3638bin/la-sql-rename-host 
    3739bin/la-sql-reset-passwd 
  • trunk/LATMOS-Accounts/Makefile.PL

    r1855 r1865  
    7777        bin/la-sql-log 
    7878        bin/la-sql-runstat 
     79        bin/la-sql-properties 
     80        bin/la-sql-alias 
    7981        bin/la-sql-stat2csv 
    8082        bin/la2xls 
  • trunk/LATMOS-Accounts/bin/la-sql-upgrade.in

    r1843 r1865  
    4747my $LA = LATMOS::Accounts->new($config, noacl => 1); 
    4848my $labase = $LA->base($base); 
     49$labase->unexported(1); 
    4950 
    5051my $dbi = $labase->db; 
     
    10031004        ], 
    10041005    }, 
     1006    { 
     1007        ver => 21, 
     1008        sql => [ 
     1009            'ALTER TABLE objects ADD COLUMN oalias text', 
     1010            'ALTER TABLE objects 
     1011               ADD COLUMN nodelete boolean NOT NULL DEFAULT false', 
     1012            'ALTER TABLE objects 
     1013               ADD COLUMN internobject boolean NOT NULL DEFAULT false', 
     1014        ], 
     1015    }, 
     1016    { 
     1017        ver => 22, 
     1018        sql => [ 
     1019            'CREATE INDEX fki_employment 
     1020            ON employment_attributes 
     1021            USING btree (okey);' 
     1022        ], 
     1023    }, 
     1024    { 
     1025        ver => 23, 
     1026        sql => [ 
     1027            'ALTER TABLE address ADD COLUMN expire timestamp with time zone' 
     1028        ], 
     1029    }, 
     1030    { 
     1031        ver => 24, 
     1032        sql => [ 
     1033            q{ 
     1034            CREATE OR REPLACE FUNCTION user_sort_fields() 
     1035            RETURNS trigger AS 
     1036            $BODY$DECLARE 
     1037            rec RECORD; 
     1038            BEGIN 
     1039 
     1040            IF (TG_OP='UPDATE' or TG_OP='INSERT') THEN 
     1041 
     1042            IF (new.attr='locked') THEN 
     1043            IF (TG_OP = 'INSERT') THEN 
     1044            new.value = now()::text; 
     1045            ELSIF (TG_OP='UPDATE') THEN 
     1046            new.value = old.value; 
     1047            END IF; 
     1048            END IF; 
     1049 
     1050            IF (new.attr='nickname') THEN 
     1051            PERFORM 1 from "user" where "user".ikey = new.okey 
     1052                and new.value = "user".name; 
     1053            IF NOT FOUND THEN 
     1054            select aliases.name into rec from aliases join "user" 
     1055            on array["user".name] = aliases.forward 
     1056            where "user".ikey = new.okey and aliases.name = new.value; 
     1057            IF NOT FOUND THEN 
     1058            insert into aliases ("name", "forward", "description", exported) 
     1059            select new.value, array["user".name], 'Forward for ' || "user".name || ' nickname', "user".exported from "user" where "user".ikey = new.okey; 
     1060            END IF; 
     1061            END IF; 
     1062            END IF; 
     1063 
     1064            IF (new.attr='uidNumber') THEN 
     1065            update "user" set uidnumber = new.value::integer where ikey = new.okey; 
     1066            RETURN NULL; 
     1067            END IF; 
     1068 
     1069            IF (new.attr='gidNumber') THEN 
     1070            update "user" set gidnumber = new.value::integer where ikey = new.okey; 
     1071            RETURN null; 
     1072            END IF; 
     1073 
     1074            IF (new.attr='expire') THEN 
     1075            update "user" set expire = new.value::timestamp where ikey = new.okey; 
     1076            RETURN NULL; 
     1077            END IF; 
     1078 
     1079            IF (new.attr='exported') THEN 
     1080            update "user" set exported = true where ikey = new.okey; 
     1081            RETURN NULL; 
     1082            END IF; 
     1083 
     1084            END IF; 
     1085 
     1086            IF (TG_OP = 'DELETE') THEN 
     1087 
     1088            IF (old.attr='expire') THEN 
     1089            update "user" set expire = NULL where ikey = old.okey; 
     1090            RETURN NULL; 
     1091            END IF; 
     1092 
     1093            IF (old.attr='exported') THEN 
     1094            update "user" set exported = false where ikey = old.okey; 
     1095            RETURN NULL; 
     1096            END IF; 
     1097 
     1098            END IF; 
     1099 
     1100 
     1101            IF (TG_OP='INSERT') THEN 
     1102            IF (new.attr='manager') THEN 
     1103            insert into user_attributes_users VALUES (new.*); 
     1104            RETURN NULL; 
     1105            END IF; 
     1106 
     1107            IF (new.attr='site') THEN 
     1108            insert into user_attributes_site VALUES (new.*); 
     1109            RETURN NULL; 
     1110            END IF; 
     1111 
     1112            IF (new.attr='department') THEN 
     1113            insert into user_attributes_groups VALUES (new.*); 
     1114            RETURN NULL; 
     1115            END IF; 
     1116 
     1117            IF (new.attr='contratType') THEN 
     1118            insert into user_attributes_groups VALUES (new.*); 
     1119            RETURN NULL; 
     1120            END IF; 
     1121 
     1122            IF (new.attr='jobType') THEN 
     1123            insert into user_attributes_groups VALUES (new.*); 
     1124            RETURN NULL; 
     1125            END IF; 
     1126 
     1127            END IF; 
     1128 
     1129            IF (TG_OP='DELETE') then 
     1130            RETURN old; 
     1131            ELSE 
     1132            RETURN new; 
     1133            end if; 
     1134            END;$BODY$ 
     1135            LANGUAGE plpgsql VOLATILE 
     1136            COST 100; 
     1137            ALTER FUNCTION user_sort_fields() 
     1138            OWNER TO latmos; 
     1139 
     1140            }, 
     1141        ], 
     1142    }, 
    10051143); 
    10061144 
     
    10191157            description => 'Contract', 
    10201158        }, 
     1159    }, 
     1160    { 
     1161        name => '-useralias', 
     1162        otype => 'group', 
     1163        attrs => { 
     1164            description => 'Internal group for user alias object', 
     1165            gidnumber => -1, 
     1166            unexported => 1, 
     1167        }, 
     1168        intern => 1, 
    10211169    }, 
    10221170); 
     
    10571205} 
    10581206 
     1207my $setnodel  = $dbi->prepare('UPDATE objects SET nodelete     = true where name = ?'); 
     1208my $setintern = $dbi->prepare('UPDATE objects SET internobject = true where name = ?'); 
     1209 
    10591210foreach (@objects) { 
    1060     if (!$labase->get_object($_->{otype}, $_->{name})) { 
    1061         printf("Creatting object %s/%s\n", $_->{otype}, $_->{name}); 
     1211    if (!$labase->GetRawObject($_->{otype}, $_->{name})) { 
     1212        printf("Creating object %s/%s\n", $_->{otype}, $_->{name}); 
    10621213        $labase->create_object($_->{otype}, $_->{name}, %{$_->{attrs} || {}}) 
    10631214            or die sprintf("cannot create %s/%s\n", $_->{otype}, $_->{name}); 
    10641215 
    10651216    } 
     1217 
     1218    $setnodel->execute($_->{name}); 
     1219    $setintern->execute($_->{name}) if ($_->{intern}); 
    10661220} 
    10671221 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Acls/Acl.pm

    r1048 r1865  
    100100        # any user 
    101101        } elsif ($u->{user} eq '*' || $u->{user} eq $who) { 
     102            # TODO deference alias for SQL base 
     103            # $obj->base->get_objects(...) ? 
    102104            return $u->{$perm} if (defined($u->{$perm})); 
    103105        # any authenticated user 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r1839 r1865  
    278278} 
    279279 
    280 =head2 list_objects($otype) 
     280=head2 list_objects($otype, %options) 
    281281 
    282282Return the list of UID for object of $otype. 
     
    290290} 
    291291 
     292=head2 listRealObjects 
     293 
     294Return the list of UID for object of $otype, alias objects are not return 
     295 
     296Options depend of database support 
     297 
     298=cut 
     299 
     300sub listRealObjects { 
     301    my ($self, $otype) = @_; 
     302    $self->list_objects($otype); 
     303} 
     304 
    292305=head2 get_object($type, $id) 
    293306 
     
    300313    my ($self, $otype, $id) = @_; 
    301314 
    302     return LATMOS::Accounts::Bases::Objects->_new($self, $otype, $id); 
     315    # finding perl class: 
     316    my $pclass = $self->_load_obj_class($otype) or return; 
     317    my $newobj = "$pclass"->new($self, $id); 
     318 
     319    defined($newobj) or do { 
     320        $self->log(LA_DEBUG, "$pclass->new() returned undef for $otype / %s", $id || '(none)'); 
     321        return; 
     322    }; 
     323 
     324    $newobj->{_base} = $self; 
     325    $newobj->{_type} = lc($otype); 
     326    $newobj->{_id} ||= $id; 
     327 
     328    return $newobj; 
    303329} 
    304330 
     
    411437    } else { 
    412438        my $last = LATMOS::Accounts::Log::lastmessage(LA_ERR); 
    413         warn $last; 
    414439        la_log(LA_ERR, 
    415440            'Object creation %s (%s) in base %s (%s) failed%s', 
     
    906931            } 
    907932        } 
    908         $data{$_} = $srcobj->_get_c_field($_); 
     933        $data{$_} = $srcobj->GetAttributeValue($_); 
    909934    } 
    910935    if (my $dstobj = $self->get_object($srcobj->type, $srcobj->id)) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Attributes.pm

    r1839 r1865  
    261261    } 
    262262 
     263    if (ref $values eq 'ARRAY' && ! $self->multiple) { 
     264        $self->base->log(LA_WARN, 'Attribute %s is not multi valuesd', $self->name); 
     265        # TODO: really return an error 
     266        # return; 
     267    } 
     268 
     269    if ($self->{checkinput}) { 
     270        foreach my $val (ref $values ? @{ $values } : $values) { 
     271            if (!$self->{checkinput}->($val)) { 
     272                return; 
     273            } 
     274        } 
     275        return 1; 
     276    } 
     277 
    263278    if ($self->has_values_list && $values) { 
    264279        my @possible = $self->can_values; 
     
    281296    } 
    282297 
    283     if (ref $values eq 'ARRAY' && ! $self->multiple) { 
    284         $self->base->log(LA_WARN, 'Attribute %s is not multi valuesd', $self->name); 
    285         # TODO: really return an error 
    286         # return; 
    287     } 
    288  
    289     if ($self->{checkinput}) { 
    290         foreach my $val (ref $values ? @{ $values } : $values) { 
    291             if (!$self->{checkinput}->($val)) { 
    292                 return; 
    293             } 
    294         } 
    295     } 
    296298 
    297299    return 1; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap/Group.pm

    r1120 r1865  
    100100    while (my ($f, $val) = each(%data)) { 
    101101        $f eq 'memberUID' and do { 
     102            $val = [ $val ] unless(ref $val); 
    102103            my %users; 
    103104            $users{$_}{e} = 1 foreach (@{ $self->get_field('memberUID') || []}); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ldap/User.pm

    r1706 r1865  
    232232                ? $self->get_attributes('memberOf') 
    233233                : ()); 
     234            $val = [ $val ] unless(ref $val); 
    234235            $users{$_}{n} = 1 foreach (@{ $val || []}); 
    235236            foreach (keys %users) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r1840 r1865  
    4545 
    4646=cut 
     47 
     48=head2 listReal($base) 
     49 
     50List object supported by this module existing in base $base 
     51 
     52Can be override by base driver. The result must exclude specials object such alias. 
     53 
     54=cut 
     55 
     56sub listReal { 
     57    my ($class, $base) = @_; 
     58    $class->list($base); 
     59} 
    4760 
    4861=head2 list_from_rev($base, $rev) 
     
    6881} 
    6982 
    70 # _new($base, $type, $id, ...) 
    71  
    72 # Return a new object of type $type having unique identifier 
    73 # $id, all remaining arguments are passed to the subclass. 
    74  
    75 sub _new { 
    76     my ($class, $base, $otype, $id, @args) = @_; 
    77  
    78     # finding perl class: 
    79     my $pclass = $base->_load_obj_class($otype) or return; 
    80     my $newobj = "$pclass"->new($base, $id, @args); 
    81  
    82     defined($newobj) or do { 
    83         $base->log(LA_DEBUG, "$pclass->new() returned undef for $otype / %s", $id || '(none)'); 
    84         return; 
    85     }; 
    86  
    87     $newobj->{_base} = $base; 
    88     $newobj->{_type} = lc($otype); 
    89     $newobj->{_id} ||= $id; 
    90  
    91     return $newobj; 
    92 } 
    93  
    9483=head2 _create($class, $base, $id, %data) 
    9584 
     
    265254} 
    266255 
    267 =head2 get_state ($state) 
    268  
    269 Return an on fly computed value 
    270  
    271 =cut 
    272  
    273 sub get_state { 
    274     my ($self, $state) = @_; 
    275     # hum... 
    276     if (defined(my $res = $self->_get_state($state))) { 
    277         return $res; 
    278     } 
    279     for ($state) { 
    280     } 
    281     return; 
    282 } 
    283  
    284 sub _get_state { 
    285     my ($self, $state) = @_; 
    286     return; 
    287 } 
    288  
    289256sub _get_c_field { 
    290257    my ($self, $cfield) = @_; 
     
    299266    return $attribute->get;  
    300267} 
     268 
     269=head2 GetAttributeValue($cfield) 
     270 
     271Return the value to exposed to other base 
     272 
     273=cut 
     274 
     275sub GetAttributeValue { 
     276    my ($self, $cfield) = @_; 
     277 
     278    return $self->get_c_field($cfield); 
     279} 
     280 
    301281 
    302282=head2 queryformat ($fmt) 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r1843 r1865  
    147147} 
    148148 
     149=head2 ListInternalObjects($otype) 
     150 
     151List objects flags as internal for type C<$otype> 
     152 
     153=cut 
     154 
     155sub ListInternalObjects { 
     156    my ($self, $otype) = @_; 
     157 
     158    my $pclass = $self->_load_obj_class($otype) or return; 
     159 
     160    # Object Alias: checking if object is alias, then returning it: 
     161    my $sth = $self->db->prepare_cached( 
     162        sprintf(q{select %s as k from %s where and internobject = true}, 
     163            $self->db->quote_identifier($pclass->_key_field), 
     164            $self->db->quote_identifier($pclass->_object_table), 
     165        ), 
     166    ); 
     167    $sth->execute(); 
     168    my @list; 
     169    while (my $res = $sth->fetchrow_hashref) { 
     170       push(@list, $_->{k}); 
     171   } 
     172   return(@list); 
     173} 
     174 
     175=head2 GetRawObject($otype, $id) 
     176 
     177Return an object even it is internal, alias are not follow and even 
     178unexported object are returned 
     179 
     180This function must be used only for maintenance operation. 
     181 
     182=cut 
     183 
     184sub GetRawObject { 
     185    my ($self, $otype, $id) = @_; 
     186 
     187    my $pclass = $self->_load_obj_class($otype) or return; 
     188 
     189    return $self->SUPER::get_object($otype, $id); 
     190} 
     191 
     192sub _derefObject { 
     193    my ($self, $otype, $oalias) = @_; 
     194    if (my ($aliasotype, $aliasoname, $aliasattr) = $oalias =~ m/^([^\/]+)\.([^\.]+)\.(.*)$/) { 
     195        my $attribute = $self->attribute($aliasotype, $aliasattr) or do { 
     196            $self->log(LA_DEBUG, "Oalias %s (%s): can fetch attibute %s/%s", 
     197                $otype, $oalias, $aliasotype, $aliasattr); 
     198            return; 
     199        }; 
     200        my $refotype = $attribute->reference or do { 
     201            $self->log(LA_DEBUG, "Oalias %s (%s): Attribute does not reference an object", 
     202                $otype, $oalias); 
     203            return; 
     204        }; 
     205        my $robj = $self->get_object($aliasotype, $aliasoname) or do { 
     206            $self->log(LA_DEBUG, "Oalias %s (%s): can fetch object %s/%s", 
     207                $otype, $oalias, $aliasotype, $aliasoname); 
     208            return; 
     209        }; 
     210        my $rvalue = $robj->get_attributes($aliasattr) or do { 
     211            $self->log(LA_DEBUG, "Oalias %s (%s): attribute value is empty", 
     212                $otype, $oalias); 
     213            return; 
     214        }; 
     215        return $self->get_object($refotype, $rvalue); 
     216    } else { 
     217        return $self->get_object($otype, $oalias); 
     218    } 
     219} 
     220 
     221sub get_object { 
     222    my ($self, $otype, $id) = @_; 
     223 
     224    my $pclass = $self->_load_obj_class($otype) or return; 
     225 
     226    # Object Alias: checking if object is alias, then returning it: 
     227    my $sth = $self->db->prepare_cached( 
     228        sprintf(q{select oalias from %s where %s = ? and internobject = false %s}, 
     229            $self->db->quote_identifier($pclass->_object_table), 
     230            $self->db->quote_identifier($pclass->_key_field), 
     231            ($self->{wexported} ? '' : 'and exported = true'), 
     232        ), 
     233    ); 
     234    $sth->execute($id); 
     235    my $res = $sth->fetchrow_hashref; 
     236    $sth->finish; 
     237    if (my $oalias = $res->{oalias}) { 
     238        # Cross reference over object/attribute 
     239        $self->_derefObject($otype, $oalias); 
     240    } else { 
     241        return $self->SUPER::get_object($otype, $id); 
     242    } 
     243} 
     244 
    149245=head2 getObjectFromOKey ($okey) 
    150246 
     
    255351    my ($self, @otype) = @_; 
    256352    $self->SUPER::list_supported_objects(qw(site), @otype); 
     353} 
     354 
     355# For SQL listRealObjects != list_objects 
     356sub listRealObjects { 
     357    my ($self, $otype) = @_; 
     358    my $pclass = $self->_load_obj_class($otype) or return; 
     359    $pclass->listReal($self); 
    257360} 
    258361 
     
    287390 
    288391=head1 SPECIFICS FUNCTIONS 
     392 
     393=head2 GetAlias($base, $id) 
     394 
     395Return object having id C<$id> only if it is an object alias 
     396 
     397=cut 
     398 
     399sub GetAlias { 
     400    my ($self, $otype, $id) = @_; 
     401 
     402    my $pclass = $self->_load_obj_class($otype) or return; 
     403 
     404    # Object Alias: checking if object is alias, then returning it: 
     405    my $sth = $self->db->prepare_cached( 
     406        sprintf(q{select oalias from %s where %s = ? and oalias IS NOT NULL and internobject = false %s}, 
     407            $self->db->quote_identifier($pclass->_object_table), 
     408            $self->db->quote_identifier($pclass->_key_field), 
     409            ($self->{wexported} ? '' : 'and exported = true'), 
     410        ), 
     411    ); 
     412    $sth->execute($id); 
     413    my $res = $sth->fetchrow_hashref; 
     414    $sth->finish; 
     415    if ($res) { 
     416        return $self->SUPER::get_object($otype, $id); 
     417    } else { 
     418        return; 
     419    } 
     420} 
     421 
     422=head2 CreateAlias($otype, $name, $for) 
     423 
     424Create an object alias named C<$name> for ovbject C<$for> 
     425 
     426=cut 
     427 
     428sub CreateAlias { 
     429    my ($self, $otype, $name, $for) = @_; 
     430 
     431    my $pclass = $self->_load_obj_class($otype) or return; 
     432 
     433    $for or die "Cannot create alias without giving object to point"; 
     434 
     435    my $res = $pclass->CreateAlias($self, $name, $for); 
     436 
     437    if ($res) { 
     438        $self->ReportChange( 
     439            $otype, 
     440            $name, 
     441            $pclass->_get_ikey($self, $name), 
     442            'Create', "Alias %s %s => %s", $otype, $name, $for 
     443        ); 
     444        $self->log(LA_DEBUG, "Alias $otype $name => $for created"); 
     445        return 1; 
     446    } else { 
     447        $self->log(LA_ERR, "Error when creating alias $otype $name"); 
     448        return; 
     449    } 
     450} 
     451 
     452=head2 RemoveAlias($otype, $name, $for) 
     453 
     454Create an object alias named C<$name> for ovbject C<$for> 
     455 
     456=cut 
     457 
     458sub RemoveAlias { 
     459    my ($self, $otype, $name) = @_; 
     460 
     461    my $pclass = $self->_load_obj_class($otype) or return; 
     462 
     463    my $obj = $self->GetAlias($otype, $name) or do { 
     464        $self->log('Cannot get alias %s/%s for removal', $otype, $name); 
     465        return; 
     466    }; 
     467 
     468    if ($obj->_get_attributes('internobject')) { 
     469        # Cannot happend: internal are not fetchable 
     470        $self->log(LA_ERR,'Cannot delete %s/%s: is an internal object', $pclass->type, $name); 
     471        return; 
     472    } 
     473    if ($obj->_get_attributes('nodelete')) { 
     474        $self->log(LA_ERR,'Cannot delete %s/%s: is write protected', $pclass->type, $name); 
     475        return; 
     476    } 
     477 
     478    my $id = $obj->Iid; 
     479 
     480    my $sth = $self->db->prepare_cached(sprintf( 
     481        'DELETE FROM %s WHERE %s = ?', 
     482        $self->db->quote_identifier($pclass->_object_table), 
     483        $self->db->quote_identifier($pclass->_key_field), 
     484    )); 
     485 
     486    my $res = $sth->execute($name); 
     487 
     488    if ($res) { 
     489        $self->ReportChange( 
     490            $otype, 
     491            $name, 
     492            $id, 
     493            'Delete', "Alias %s %s deleted", $otype, $name 
     494        ); 
     495        $self->log(LA_DEBUG, "Alias $otype $name removed"); 
     496        return 1; 
     497    } else { 
     498        $self->log(LA_ERR, "Error when removing alias $otype $name"); 
     499        return; 
     500    } 
     501} 
    289502 
    290503=head2 get_global_value ($varname) 
     
    419632            and expire > now() 
    420633            and expire is not null 
     634            and internobject = false 
    421635            } . ($self->{wexported} ? '' : 'and exported = true') . q{ 
    422636            order by expire 
     
    444658            expire < now() - ?::interval 
    445659            and expire is not null 
     660            and internobject = false 
    446661        } . ($self->{wexported} ? '' : 'and exported = true') . q{ 
    447662            order by expire 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Address.pm

    r1613 r1865  
    324324                label => l('Description'), 
    325325            }, 
     326            expire    => { 
     327                inline => 1, 
     328                formtype => 'DATE', 
     329                label => l('Expire'), 
     330            }, 
    326331        } 
    327332    ); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r1863 r1865  
    508508                        select name from "group" join 
    509509                        group_attributes on group_attributes.okey = "group".ikey 
    510                         where value = ? and attr = ? 
     510                        where value = ? and attr = ? and internobject = false 
    511511                        } . ($self->base->{wexported} ? '' : ' and "group".exported = true') 
    512512                    ); 
     
    558558                    my ($self) = @_; 
    559559                    my $sth = $self->base->db->prepare(q{ 
    560                         select forward from aliases where name = ? 
     560                        select forward from aliases where name = ? and internobject = false 
    561561                        } . ($self->base->{wexported} ? '' : ' and exported = true')); 
    562562                    $sth->execute($self->object->id); 
     
    609609                    my ($self) = @_; 
    610610                    my $sth = $self->base->db->prepare(q{ 
    611                         select name from aliases where lower($1) = 
     611                        select name from aliases where internobject = false and lower($1) = 
    612612                        lower(array_to_string("forward", ',')) 
    613613                        } . ($self->base->{wexported} ? '' : 'and exported = true')); 
     
    13481348            /^never$/ and return 0; 
    13491349 
    1350             !$_[0] and return 0; 
     1350            $_[0] or return 0; 
    13511351 
    13521352            /^any$/i and return $_[0]->listEmployment ? 1 : 0; 
     
    13891389 
    13901390    $class->SUPER::_get_attr_schema($base, $attrs) 
     1391} 
     1392 
     1393sub CreateAlias { 
     1394    my ($class, $base, $name, $for) = @_; 
     1395 
     1396    my $stAddAlias = $base->db->prepare_cached( 
     1397        q{INSERT INTO "user" (name, uidnumber,            gidnumber, oalias) values 
     1398                             (?,    -nextval('ikey_seq'), ?,         ?)} 
     1399    ); 
     1400 
     1401    my $res = $stAddAlias->execute($name, -1, $for); 
     1402    return $res ? 1 : 0; 
    13911403} 
    13921404 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1823 r1865  
    2222sub _attributes_table { $_[0]->_object_table . '_attributes_list' } 
    2323 
    24 sub list { 
     24sub listReal { 
    2525    my ($class, $base) = @_; 
    2626 
    2727    my $sth = $base->db->prepare_cached( 
    2828        sprintf( 
    29             q{select %s as k from %s %s order by %s}, 
     29            q{select %s as k from %s where internobject = false 
     30                and oalias IS NULL %s order by %s}, 
    3031            $base->db->quote_identifier($class->_key_field), 
    3132            $base->db->quote_identifier($class->_object_table), 
    32             ($base->{wexported} ? '' : 'where exported = true'), 
     33            ($base->{wexported} ? '' : 'and exported = true'), 
    3334            $base->db->quote_identifier($class->_key_field), 
    3435        ) 
     
    4243} 
    4344 
     45sub list { 
     46    my ($class, $base) = @_; 
     47 
     48    my $sth = $base->db->prepare_cached( 
     49        sprintf( 
     50            q{select %s as k from %s where internobject = false %s order by %s}, 
     51            $base->db->quote_identifier($class->_key_field), 
     52            $base->db->quote_identifier($class->_object_table), 
     53            ($base->{wexported} ? '' : 'and exported = true'), 
     54            $base->db->quote_identifier($class->_key_field), 
     55        ) 
     56    ); 
     57    $sth->execute; 
     58    my @keys; 
     59    while(my $res = $sth->fetchrow_hashref) { 
     60        push(@keys, $res->{k}); 
     61    } 
     62    @keys 
     63} 
     64 
    4465sub list_from_rev { 
    4566    my ($class, $base, $rev) = @_; 
    4667    my $sth = $base->db->prepare_cached( 
    4768        sprintf( 
    48             q{select %s as k from %s where rev > ? %s order by %s}, 
     69            q{select %s as k from %s where rev > ? and internobject = false 
     70                and oalias IS NULL  %s order by %s}, 
    4971            $base->db->quote_identifier($class->_key_field), 
    5072            $base->db->quote_identifier($class->_object_table), 
     
    135157            label => l('Created by'), 
    136158        }, 
     159        oalias => { 
     160            inline  => 1, 
     161            reference => $class->type, 
     162            label => 'Alias for', 
     163            post => sub { 
     164                my ($self, $value) = @_; 
     165                $self->object->_update_aliases_ptr(); 
     166            }, 
     167            checkinput => sub { 
     168                my ($oalias) = @_; 
     169                my $otype = $class->type; 
     170 
     171                if (my ($aliasotype, $aliasoname, $aliasattr) = $oalias =~ m/^([^\/]+)\.([^\.]+)\.(.*)$/) { 
     172                    my $attribute = $base->attribute($aliasotype, $aliasattr) or do { 
     173                        $base->log(LA_DEBUG, "Oalias %s (%s): can fetch attibute %s/%s", 
     174                            $otype, $oalias, $aliasotype, $aliasattr); 
     175                        return; 
     176                    }; 
     177                    my $refotype = $attribute->reference or do { 
     178                        $base->log(LA_DEBUG, "Oalias %s (%s): Attribute does not reference an object", 
     179                            $otype, $oalias); 
     180                        return; 
     181                    }; 
     182 
     183                    if ($attribute->multiple) { 
     184                        $base->log(LA_DEBUG, "Oalias %s (%s): Attribute must not be multiple", 
     185                            $otype, $oalias); 
     186                        return; 
     187                    }; 
     188                } elsif(!$base->get_object($otype, $oalias)) { 
     189                    $base->log(LA_DEBUG, "Cannot get object $otype/$oalias"); 
     190                    return; 
     191                } 
     192                return 1; 
     193            }, 
     194        }, 
     195        internobject => { 
     196            inline  => 1, 
     197            label => 'True if object is for internal use', 
     198            hide => 1, 
     199        }, 
     200        nodelete => { 
     201            inline => 1, 
     202            label => 'True if the object is protected against deletion', 
     203            hide => 1, 
     204        }, 
    137205    ); 
    138206 
     
    161229        } 
    162230        foreach (@{$base->{__cache}{$class->_object_table}{extend}}) { 
    163             $base->log(LA_DEBUG, 'Attribute %s for %s not declared in code', $_, $class->type) if(!exists($info->{$_})); 
     231            #$base->log(LA_DEBUG, 'Attribute %s for %s not declared in code', $_, $class->type) if(!exists($info->{$_})); 
    164232            $info->{$_} ||= {}; 
    165233        } 
     
    185253 
    186254        my $sth = $base->db->prepare_cached( 
    187             sprintf(q{select 1 from %s where %s = ? %s}, 
     255            sprintf(q{ select 1 from %s where %s = ?}, 
    188256                $base->db->quote_identifier($class->_object_table), 
    189257                $base->db->quote_identifier($class->_key_field), 
    190                 ($base->{wexported} ? '' : 'and exported = true'), 
    191258            ), 
    192259        ); 
     
    288355} 
    289356 
     357=head2 refreshRev 
     358 
     359Increase revision of the object to force synchronisation 
     360 
     361=cut 
     362 
     363sub refreshRev { 
     364    my ($self) = @_; 
     365 
     366    my $sth = $self->db->prepare_cached( 
     367        sprintf(q{ 
     368                UPDATE %s SET rev = nextval('revisions_rev_seq'::regclass)  WHERE %s = ? 
     369            }, 
     370            $self->db->quote_identifier($self->_object_table), 
     371            $self->db->quote_identifier($self->_key_field), 
     372        ) 
     373    ); 
     374    $sth->execute($self->id); 
     375} 
     376 
     377=head2 CreateAlias($base, $name, $for) 
     378 
     379Create an alias named C<$name> with pointing to C<$for> 
     380 
     381=cut 
     382 
     383sub CreateAlias { 
     384    my ($class, $base, $name, $for) = @_; 
     385 
     386    $base->log(LA_ERR, '%s does not support alias object, alias %s not created', $class->type, $name); 
     387} 
     388 
    290389sub _delete { 
    291390    my ($class, $base, $id) = @_; 
     
    295394    my $obj = $base->get_object($class->type, $id) 
    296395        or return; 
     396 
     397    if ($obj->_get_attributes('internobject')) { 
     398        # Cannot happend: internal are not fetchable 
     399        $base->log(LA_ERR,'Cannot delete %s/%s: is an internal object', $class->type, $id); 
     400        return; 
     401    } 
     402    if ($obj->_get_attributes('nodelete')) { 
     403        $base->log(LA_ERR,'Cannot delete %s/%s: is write protected', $class->type, $id); 
     404        return; 
     405    } 
    297406 
    298407    my $sthd = $base->db->prepare_cached( 
     
    411520        my $val = $__cache->{$self->id}{$field}; 
    412521        return @{$val || []} > 1 ? $val : $val->[0]; 
     522    } 
     523} 
     524 
     525sub GetAttributeValue { 
     526    my ($self, $cfield) = @_; 
     527 
     528    my $res = $self->SUPER::GetAttributeValue($cfield) or return; 
     529 
     530    my $attribute = $self->attribute($cfield) or do { 
     531        $self->base->log(LA_WARN, "Unknow attribute $cfield"); 
     532        return; 
     533    }; 
     534 
     535    if (my $ref = $attribute->reference) { 
     536        my @deref; 
     537        foreach my $v (ref $res ? @{ $res } : $res) { 
     538            my $derefobj = $self->base->_derefObject($ref, $v); 
     539            push(@deref, $derefobj ? $derefobj->id : $v); 
     540        } 
     541        return scalar(@deref) > 1 ? \@deref : $deref[0]; 
     542    } else { 
     543        return $res; 
    413544    } 
    414545} 
     
    588719} 
    589720 
     721=head2 SetNoDelete($value) 
     722 
     723Set nodelete attribute to true or false 
     724 
     725=cut 
     726 
     727sub SetNoDelete { 
     728    my ($self, $value) = @_; 
     729 
     730    my $sthr = $self->db->prepare_cached( 
     731        sprintf( 
     732            q{update %s set nodelete = ? where %s = ?}, 
     733            $self->db->quote_identifier($self->_object_table), 
     734            $self->db->quote_identifier($self->_key_field), 
     735        ) 
     736    ); 
     737 
     738    if (($sthr->execute($value ? 'true' : 'false', $self->id) || 0) != 1) { 
     739        $self->log(LA_ERR, "Erreur seting nodelete for %s/%s to %s", 
     740            $self->type, 
     741            $self->id, 
     742            $value, 
     743        ); 
     744        return; 
     745    } 
     746 
     747    1; 
     748} 
     749 
    590750=head2 find_next_numeric_id($class, $base, $field, $min, $max) 
    591751 
     
    644804        $attr->{inline} 
    645805            ? sprintf( 
    646                 q{select %s as value from %s} . ($base->{wexported} ? '' : ' and "exported" = true'), 
     806                q{select %s as value from %s where internobject = false} . ($base->{wexported} ? '' : ' and "exported" = true'), 
    647807                $base->db->quote_identifier($attr->iname), 
    648808                $base->db->quote_identifier($class->_object_table), 
     
    650810            : sprintf( 
    651811                q{select value from %s join 
    652                 %s on %s.ikey = %s.okey where attr = ? group by value} . ($base->{wexported} ? '' : ' and "exported" = true'), 
     812                %s on %s.ikey = %s.okey where attr = ? and internobject = false group by value} .  
     813                    ($base->{wexported} ? '' : ' and "exported" = true'), 
    653814                $base->db->quote_identifier($class->_object_table), 
    654815                $base->db->quote_identifier($class->_object_table . 
     
    756917    # foo=1 bar=1 => foo =1 and bar = 2 
    757918    my $results = {}; 
     919    my $noalias = 0; 
    758920 
    759921    @filter = grep { defined($_) && $_ ne '' } @filter; 
     
    776938            return; 
    777939        }; 
     940        $attribute->name eq 'oalias' and $noalias = 1; 
    778941        defined($val) or $val =  ''; 
    779942 
     
    822985    } 
    823986 
     987    # We add to result aliases: 
     988    if(keys %mresults && !$noalias) { 
     989        my @alias = $class->_search_uniq_filter($base, 'oalias', '=', join('||', keys %mresults)); 
     990        foreach(@alias) { 
     991            $mresults{$_} = 1; 
     992        } 
     993    } 
     994 
    824995    return(sort keys %mresults); 
    825996} 
    826  
    827997 
    828998sub _search_uniq_filter { 
     
    8381008 
    8391009    my @values = split(/([\|\&]+)/, $value); 
     1010    return unless(@values); 
     1011 
     1012    $base->log(LA_DEBUG, "Uniq search for $attr $operator (%s)", join(' ', @values)); 
    8401013     
    8411014    # We detect if we can do a very quick search: 
     
    9401113    # building the query 
    9411114    if (!$base->{wexported}) { 
    942         push(@attrsql, 'intersect', sprintf( 
    943                 q{select ikey from %s where exported = true}, 
     1115        push(@attrsql, 'intersect') if (@attrsql); 
     1116        push(@attrsql, sprintf( 
     1117                q{select ikey from %s where exported = true and internobject = false}, 
    9441118                $base->db->quote_identifier($class->_object_table) 
    9451119            ) 
     
    9491123        sprintf(q{ 
    9501124            select name from %s 
     1125            where internobject = false 
    9511126            %s 
    9521127            order by name 
     
    9541129            $base->db->quote_identifier($class->_object_table), 
    9551130            @attrsql 
    956             ? "where ikey in (\n" . join(" ", @attrsql) . ")\n" 
     1131            ? "and ikey in (\n" . join(" ", @attrsql) . ")\n" 
    9571132            : '', 
    9581133        ) 
     
    10651240} 
    10661241 
     1242sub _update_aliases_ptr { 
     1243    my ($self) = @_; 
     1244 
     1245    my $atype = $self->type; 
     1246    my $name  = $self->id; 
     1247    my $base  = $self->base; 
     1248 
     1249    foreach my $otype ($base->list_supported_objects) { 
     1250        foreach my $attr ($base->list_canonical_fields($otype, 'r')) { 
     1251            $attr =~ /^(oalias|modifiedby|createdby)$/ and next; 
     1252            my $attribute = $base->attribute($otype, $attr); 
     1253            my $ref = $attribute->reference or next; 
     1254 
     1255            if ($ref eq $atype) { 
     1256                $base->log(LA_DEBUG, "Searching object referencing alias %s/%s in %s->%s", 
     1257                    $atype, $name, $otype, $attr); 
     1258                foreach my $target ($base->search_objects($otype, "$attr\=$name", 'oalias=NULL')) { 
     1259                    $base->log(LA_DEBUG, "Update ref for object %s/%s", $otype, $target); 
     1260                    my $otarget = $base->get_object($otype, $target) or next; 
     1261                    $otarget->refreshRev; 
     1262                } 
     1263            } 
     1264        } 
     1265    } 
     1266} 
     1267 
    106712681; 
    10681269 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm

    r1313 r1865  
    731731        ); 
    732732    } 
     733    if ($labase->can('CreateAlias')) { 
     734        $env->add_func( 
     735            'newalias', { 
     736                help => 'Create an alias object', 
     737                code => sub { 
     738                    my ($self, $otype, $name, $for) = @_; 
     739                    if ($self->base->CreateAlias($otype, $name, $for)) { 
     740                        print $OUT "Alias $otype/$name Created\n"; 
     741                        $self->commit; 
     742                    } 
     743                }, 
     744                completion => sub { 
     745                    if ($_[3]) { 
     746                        return $_[0]->base->list_objects($_[2]); 
     747                    } elsif (!$_[2]) { 
     748                        return $_[0]->base->list_supported_objects; 
     749                    } else { 
     750                        return; 
     751                    } 
     752                } 
     753            }, 
     754        ); 
     755        $env->add_func( 
     756            'rmalias', { 
     757                help => 'Remove an alias object', 
     758                code => sub { 
     759                    my ($self, $otype, $name) = @_; 
     760                    if ($self->base->RemoveAlias($otype, $name)) { 
     761                        print $OUT "Alias $otype/$name Removed\n"; 
     762                        $self->commit; 
     763                    } 
     764                }, 
     765                completion => sub { 
     766                    if (!$_[2]) { 
     767                        return $_[0]->base->list_supported_objects; 
     768                    } else { 
     769                        return $_[0]->base->search_objects($_[2], 'oalias=*'); 
     770                    } 
     771                } 
     772            }, 
     773        ); 
     774        $env->add_func( 
     775            'updalias', { 
     776                help => 'Update an alias object', 
     777                code => sub { 
     778                    my ($self, $otype, $name, $for) = @_; 
     779                    my $obj = $self->base->GetAlias($otype, $name) or do { 
     780                        print $OUT "No alias $otype/$name found"; 
     781                        return; 
     782                    }; 
     783                    if ($obj->set_c_fields(oalias => $for)) { 
     784                        print $OUT "Alias $otype/$name Updated\n"; 
     785                        $self->commit; 
     786                    } 
     787                }, 
     788                completion => sub { 
     789                    if ($_[3]) { 
     790                        return $_[0]->base->list_objects($_[2]); 
     791                    } elsif($_[2]) { 
     792                        return $_[0]->base->search_objects($_[2], 'oalias=*'); 
     793                    } else { 
     794                        return $_[0]->base->list_supported_objects; 
     795                    } 
     796                } 
     797            }, 
     798        ); 
     799    } 
    733800    $env->add_func('quit', { help => 'quit - exit the tool', 
    734801            code => sub { print "\n"; exit(0) }, }); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Log.pm

    r1698 r1865  
    173173    my ($level, $msg, @args) = @_; 
    174174    no warnings 'printf'; 
     175 
    175176    if (!$msg) { 
     177        # Wrong la_log usage 
    176178        my @call = caller(); 
    177179        la_log(LA_WARN, 'empty message at %s:%s', $call[1], $call[2]); 
    178180        return; 
    179181    } 
     182    if ($level =~ /\D/) { 
     183        # Wrong la_log usage 
     184        my @call = caller(); 
     185        la_log(LA_WARN, 'unrecognize message level %s at %s:%s', $level, $call[1], $call[2]); 
     186        return; 
     187    } 
     188 
    180189    $lastmessages{$level} = sprintf($msg, map { defined($_) ? $_ : '' } @args); 
    181190    if ($log_method{syslog}) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r1805 r1865  
    286286 
    287287            $existings{$otype} = { map { $_ => 1 } 
    288                 $self->from->list_objects($otype) }; 
     288                $self->from->listRealObjects($otype) }; 
    289289 
    290290            # Is there a filter to apply: 
     
    293293                la_log(LA_DEBUG, "Found %s param, using it: %s", $filtername, $filter); 
    294294                $filtering{$otype} = { map { $_ => 1 } 
    295                     $self->from->search_objects($otype, $filter) }; 
     295                    $self->from->search_objects($otype, $filter, 'oalias=NULL') }; 
    296296            } else { 
    297297                $filtering{$otype} = $existings{$otype}; 
     
    319319            my $deletefiltered = 'deletefiltered.' . $destbase->label . '.' . $otype; 
    320320 
    321             foreach ($destbase->list_objects($otype)) { 
     321            foreach ($destbase->listRealObjects($otype)) { 
    322322 
    323323                if ($filtering{$otype}{$_}) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Unexportexpired.pm

    r1801 r1865  
    4848    my $nowtext = $now->iso8601(); 
    4949 
    50     foreach my $otype (qw(Aliases Nethost)) { 
     50    foreach my $otype (qw(Aliases Nethost Address)) { 
    5151 
    5252        foreach my $name ( 
  • trunk/LATMOS-Accounts/live-test/10_sql.t

    r1836 r1865  
    1818    plan skip_all => 'No SQL base defined'; 
    1919} else { 
    20     plan tests => 75; # Number of test 
     20    plan tests => 90; # Number of test 
    2121} 
    2222 
     
    4747ok($base->delete_object('user', $oid), "Can delete user $oid"); 
    4848ok(!$base->get_object('user', $oid), "user $oid is actually deleted"); 
     49} 
     50 
     51$base->rollback; 
     52 
     53{ # test alias 
     54 
     55my $oid = genid(); 
     56 
     57ok($base->create_c_object('user', $oid, 
     58    sn => "snUser", 
     59    givenName => "givenNameUser", 
     60    expire => undef, 
     61    ), "Can create user $oid"); 
     62ok(my $realobj = $base->get_object('user', $oid), "user $oid is actually created"); 
     63 
     64my $aliasoid = genid(); 
     65 
     66ok($base->CreateAlias('user', $aliasoid, $oid), "Can create alias object"); 
     67 
     68ok(my $obj = $base->get_object('user', $aliasoid), "Can get object trought alias"); 
     69is($obj->get_attributes('sn'), 'snUser'); 
     70 
     71ok(my $aobj = $base->GetAlias('user', $aliasoid), "Can get alias object"); 
     72 
     73is($aobj->get_attributes('oalias'), $oid); 
     74 
     75my $oidsub = genid(); 
     76ok($base->create_c_object('user', $oidsub, 
     77    sn => "snUserSub", 
     78    givenName => "givenNameSub", 
     79    expire => undef, 
     80    ), "Can create user $oid"); 
     81ok(my $subobj = $base->get_object('user', $oidsub), "user $oidsub is actually created"); 
     82 
     83$subobj->set_c_fields( 
     84    managerContact => $aliasoid, 
     85); 
     86 
     87is($subobj->get_c_field('manager'), $aliasoid, "Can get ref manager"); 
     88is($subobj->GetAttributeValue('manager'), $oid, "Can get ref manager via GetAttributeValue"); 
     89 
     90ok(eq_set( 
     91        [ $base->search_objects('user', 'sn=snUser') ], 
     92        [ $oid, $aliasoid ] 
     93    ), 'Search retrieve alias'); 
     94 
     95ok(eq_set( 
     96        [ $base->search_objects('user', 'sn=snUser', 'oalias=NULL') ], 
     97        [ $oid ] 
     98    ), 'Search with oalias=NULL don\'t retrieve alias'); 
     99 
     100ok(eq_set( 
     101        [ $base->search_objects('user', 'sn=XXXXXXXXX') ], 
     102        [ ] 
     103    ), 'Search with no result don\'t retrieve alias'); 
     104 
     105ok($base->RemoveAlias('user', $aliasoid), "Removing Alias"); 
    49106} 
    50107 
  • trunk/LATMOS-Accounts/t/16_bases_heimdal.t

    r1040 r1865  
    11use strict; 
    22use warnings; 
    3 use Test::More tests => 4; 
     3use Test::More; 
     4 
     5eval "use Heimdal::Kadm5;"; 
     6if ($@) { 
     7    plan skip_all => "Heimdal::Kadm5 is not present"; 
     8} else { 
     9    plan tests => 4; 
     10} 
    411 
    512use_ok('LATMOS::Accounts::Bases'); 
Note: See TracChangeset for help on using the changeset viewer.