Changeset 1076
- Timestamp:
- 07/25/12 09:52:11 (12 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r1071 r1076 314 314 } 315 315 316 =head2 compute_default($otype, $id, %cdata) 317 318 Return a hash containing value to set for new object 319 320 =cut 321 322 sub compute_default { 323 my ($self, $otype, $id, %cdata) = @_; 324 325 my %default; 326 foreach my $def (keys %{ $self->{defattr} || {}}) { 327 if ($def =~ /^$otype\.(.*)$/) { 328 $default{$1} = $self->{defattr}{$def} if(!$cdata{$1}); 329 } 330 } 331 332 # computed default value (not a simple set) 333 if (lc($otype) eq 'user') { 334 if (!$cdata{homeDirectory}) { 335 $default{homeDirectory} = $self->{defattr}{'user.homebase'} 336 ? $self->{defattr}{'user.homebase'} . "/$id" 337 : ''; 338 } 339 340 if (!$cdata{uidNumber}) { 341 $default{uidNumber} ||= $self->find_next_numeric_id('user', 'uidNumber', 342 $self->{defattr}{'user.min_uid'}, $self->{defattr}{'user.max_uid'}); 343 } 344 345 my $mailid = $cdata{givenName} && $cdata{sn} 346 ? sprintf('%s.%s', 347 to_ascii(lc($cdata{givenName})), 348 to_ascii(lc($cdata{sn})),) 349 : undef; 350 $mailid =~ s/\s+/-/g if($mailid); 351 352 if ($mailid && 353 $self->is_supported_object('aliases') && 354 ! $self->get_object('aliases', $mailid)) { 355 if (my $attr = $self->attribute($otype, 'mail')) { 356 if ((!$attr->ro) && $self->{defattr}{'user.maildomain'}) { 357 $default{mail} ||= sprintf('%s@%s', 358 $mailid, 359 $self->{defattr}{'user.maildomain'}); 360 } 361 } 362 if (my $attr = $self->attribute($otype, 'aliases')) { 363 $default{aliases} ||= $mailid unless ($attr->ro); 364 } 365 if (my $attr = $self->attribute($otype, 'revaliases')) { 366 $default{revaliases} ||= $mailid unless ($attr->ro); 367 } 368 } 369 } elsif (lc($otype) eq 'group') { 370 if (!$cdata{gidNumber}) { 371 $default{gidNumber} ||= $self->find_next_numeric_id( 372 'group', 'gidNumber', 373 $self->{defattr}{'group.min_gid'}, 374 $self->{defattr}{'group.max_gid'} 375 ); 376 } 377 } 378 379 return %default; 380 } 381 316 382 sub _create_c_object { 317 383 my ($self, $otype, $id, %cdata) = @_; 318 384 319 385 $id ||= ''; # Avoid undef 320 386 321 387 if (my $chk = ( 322 388 lc($otype) eq 'user' || lc($otype) eq 'group') … … 334 400 335 401 # populating default value 336 foreach my $def (keys %{ $self->{defattr} || {}}) { 337 if ($def =~ /^$otype\.(.*)$/) { 338 $cdata{$1} = $self->{defattr}{$def} if(!$cdata{$1}); 339 } 340 } 341 if (lc($otype) eq 'user') { 342 $cdata{homeDirectory} ||= $self->{defattr}{'user.homebase'} ? 343 $self->{defattr}{'user.homebase'} . "/$id" : ''; 344 $cdata{uidNumber} ||= $self->find_next_numeric_id('user', 'uidNumber', 345 $self->{defattr}{'user.min_uid'}, $self->{defattr}{'user.max_uid'}); 346 my $mailid = $cdata{givenName} && $cdata{sn} 347 ? sprintf('%s.%s', 348 to_ascii(lc($cdata{givenName})), 349 to_ascii(lc($cdata{sn})),) 350 : undef; 351 $mailid =~ s/\s*//g if($mailid); 352 353 if ($mailid && 354 $self->is_supported_object('aliases') && 355 ! $self->get_object('aliases', $mailid)) { 356 if (my $attr = $self->attribute($otype, 'mail')) { 357 if ((!$attr->ro) && $self->{defattr}{'user.maildomain'}) { 358 $cdata{mail} ||= sprintf('%s@%s', 359 $mailid, 360 $self->{defattr}{'user.maildomain'}); 361 } 362 } 363 if (my $attr = $self->attribute($otype, 'aliases')) { 364 $cdata{aliases} ||= $mailid unless ($attr->ro); 365 } 366 if (my $attr = $self->attribute($otype, 'revaliases')) { 367 $cdata{revaliases} ||= $mailid unless ($attr->ro); 368 } 369 } 370 } elsif (lc($otype) eq 'group') { 371 $cdata{gidNumber} ||= $self->find_next_numeric_id('group', 'gidNumber', 372 $self->{defattr}{'group.min_gid'}, $self->{defattr}{'group.max_gid'}); 373 } 402 { 403 my %default = $self->compute_default($otype, $id, %cdata); 404 foreach my $k (keys %default) { 405 $cdata{$k} = $default{$k}; 406 } 407 } 408 374 409 my %data; 375 410 foreach my $cfield (keys %cdata) { … … 381 416 $self->create_object($otype, $id, %data); 382 417 } 383 384 418 385 419 sub _allowed_values { -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/OCHelper/User.pm
r1023 r1076 59 59 push(@{$info->{ask}}, 'uidNumber'); 60 60 push(@{$info->{ask}}, 'gidNumber'); 61 my $mailid = $info->{contents}{givenName} && $info->{contents}{sn} 62 ? sprintf('%s.%s', 63 to_ascii(lc($info->{contents}{givenName})), 64 to_ascii(lc($info->{contents}{sn})),) 65 : undef; 66 $mailid =~ s/ /-/g if ($mailid); # replace space by '-' in mail 67 push(@{$info->{ask}}, 'mail'); 68 $info->{contents}{mail} = $mailid && $self->base->{defattr}{'user.maildomain'} 69 ? sprintf('%s@%s', $mailid, 70 $self->base->{defattr}{'user.maildomain'}) 71 : undef; 61 62 my %default = $self->base->compute_default( 63 'user', $login || '', 64 %{ $info->{contents} || {} } 65 ); 66 67 if ($default{mail}) { 68 push(@{$info->{ask}}, 'mail'); 69 $info->{contents}{mail} = $default{mail}; 70 } 72 71 if (my $attr = $self->base->attribute('user', 'aliases')) { 73 72 if (!$attr->ro) { 74 73 push(@{$info->{ask}}, 'aliases'); 75 $info->{contents}{aliases} = $ mailid74 $info->{contents}{aliases} = $default{aliases}; 76 75 } 77 76 } … … 79 78 if (!$attr->ro) { 80 79 push(@{$info->{ask}}, 'revaliases'); 81 $info->{contents}{revaliases} = $ mailid80 $info->{contents}{revaliases} = $default{revaliases}; 82 81 } 83 82 }
Note: See TracChangeset
for help on using the changeset viewer.