Changeset 1307 for trunk/LATMOS-Accounts
- Timestamp:
- 04/01/15 18:41:34 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r1298 r1307 59 59 } 60 60 61 =head2 load 62 63 Make account base loading data into memory if need. 64 Should always be called, if database fetch data on the fly 65 (SQL, LDAP), the function just return True. 66 67 =cut 68 69 # override by the database driver if need 70 sub load { 1 } 71 72 =head2 label 73 74 Return the database label 75 76 =cut 77 78 sub label { 79 $_[0]->{_label} || 'NoLabel'; 80 } 81 82 =head2 type 83 84 Return the type of the base 85 86 =cut 87 88 sub type { 89 $_[0]->{_type}; 90 } 91 92 =head2 la 93 94 return LATMOS::Accounts object parent to the base 95 96 =cut 97 98 sub la { $_[0]->{_la} }; 99 100 =head2 config ($opt) 101 102 Return options from config 103 104 =cut 105 106 sub config { 107 my ($self, $opt) = @_; 108 return $self->{_options}{$opt}; 109 } 110 61 111 =head2 wexported 62 112 … … 118 168 =cut 119 169 120 sub ReportChange { 121 my ($self, $otype, $name, $ref, $changetype, $message, @args) = @_; 122 123 } 124 125 =head2 label 126 127 Return the database label 128 129 =cut 130 131 sub label { 132 $_[0]->{_label} || 'NoLabel'; 133 } 134 135 =head2 type 136 137 Return the type of the base 138 139 =cut 140 141 sub type { 142 $_[0]->{_type}; 143 } 144 145 =head2 la 146 147 return LATMOS::Accounts object parent to the base 148 149 =cut 150 151 sub la { $_[0]->{_la} }; 152 153 =head2 config ($opt) 154 155 Return options from config 156 157 =cut 158 159 sub config { 160 my ($self, $opt) = @_; 161 return $self->{_options}{$opt}; 162 } 170 sub ReportChange {} 163 171 164 172 =head2 list_supported_objects(@otype) … … 294 302 } 295 303 304 =head2 create_c_object($type, $id, %data) 305 306 Create and return an object of type $type with unique id 307 $id having %data using canonical fields 308 309 =cut 310 311 sub create_c_object { 312 my ($self, $otype, $id, %cdata) = @_; 313 $self->check_acl($otype, '@CREATE', 'w') or do { 314 $self->log(LA_WARN, 'permission denied to create object type %s', 315 $otype); 316 return; 317 }; 318 319 $self->_create_c_object($otype, $id, %cdata); 320 } 321 322 sub _create_c_object { 323 my ($self, $otype, $id, %cdata) = @_; 324 325 $id ||= ''; # Avoid undef 326 327 if (my $chk = ( 328 lc($otype) eq 'user' || lc($otype) eq 'group') 329 ? LATMOS::Accounts::Utils::check_ug_validity($id) 330 : LATMOS::Accounts::Utils::check_oid_validity($id)) { 331 $self->log(LA_ERR, "Cannot create $otype with ID $id `%s:'", $chk); 332 return; 333 } 334 foreach my $cfield (keys %cdata) { 335 $self->check_allowed_values($otype, $cfield, $cdata{$cfield}) or do { 336 $self->log(LA_ERR, "Cannot create $otype, wrong value"); 337 return; 338 }; 339 } 340 341 # populating default value 342 { 343 my %default = $self->compute_default($otype, $id, %cdata); 344 foreach my $k (keys %default) { 345 $cdata{$k} = $default{$k}; 346 } 347 } 348 349 my %data; 350 foreach my $cfield (keys %cdata) { 351 my $attribute = $self->attribute($otype, $cfield) or next; 352 $attribute->ro and next; 353 $data{$attribute->iname} = $cdata{$cfield}; 354 } 355 $self->create_object($otype, $id, %data) or return; 356 my $obj = $self->get_object($otype, $id) or return; 357 $obj->ReportChange('Create', 'Object created with %s', join(', ', sort keys %cdata)); 358 359 foreach my $attrname (keys %data) { 360 my $attribute = $self->attribute($obj->type, $attrname) or next; 361 $attribute->monitored or next; 362 363 $obj->ReportChange('Attributes', '%s set to %s', $attrname, 364 (ref $data{$attrname} 365 ? join(', ', @{ $data{$attrname} }) 366 : $data{$attrname}) || '(none)'); 367 } 368 369 $obj 370 } 371 296 372 =head2 create_object($type, $id, %data) 297 373 … … 330 406 } 331 407 332 =head2 create_c_object($type, $id, %data)333 334 Create and return an object of type $type with unique id335 $id having %data using canonical fields336 337 =cut338 339 sub create_c_object {340 my ($self, $otype, $id, %cdata) = @_;341 $self->check_acl($otype, '@CREATE', 'w') or do {342 $self->log(LA_WARN, 'permission denied to create object type %s',343 $otype);344 return;345 };346 347 $self->_create_c_object($otype, $id, %cdata);348 }349 408 350 409 =head2 compute_default($otype, $id, %cdata) … … 414 473 } 415 474 416 sub _create_c_object {417 my ($self, $otype, $id, %cdata) = @_;418 419 $id ||= ''; # Avoid undef420 421 if (my $chk = (422 lc($otype) eq 'user' || lc($otype) eq 'group')423 ? LATMOS::Accounts::Utils::check_ug_validity($id)424 : LATMOS::Accounts::Utils::check_oid_validity($id)) {425 $self->log(LA_ERR, "Cannot create $otype with ID $id `%s:'", $chk);426 return;427 }428 foreach my $cfield (keys %cdata) {429 $self->check_allowed_values($otype, $cfield, $cdata{$cfield}) or do {430 $self->log(LA_ERR, "Cannot create $otype, wrong value");431 return;432 };433 }434 435 # populating default value436 {437 my %default = $self->compute_default($otype, $id, %cdata);438 foreach my $k (keys %default) {439 $cdata{$k} = $default{$k};440 }441 }442 443 my %data;444 foreach my $cfield (keys %cdata) {445 my $attribute = $self->attribute($otype, $cfield) or next;446 $attribute->ro and next;447 $data{$attribute->iname} = $cdata{$cfield};448 }449 $self->create_object($otype, $id, %data) or return;450 my $obj = $self->get_object($otype, $id) or return;451 $obj->ReportChange('Create', 'Object created with %s', join(', ', sort keys %cdata));452 453 foreach my $attrname (keys %data) {454 my $attribute = $self->attribute($obj->type, $attrname) or next;455 $attribute->monitored or next;456 457 $obj->ReportChange('Attributes', '%s set to %s', $attrname,458 (ref $data{$attrname}459 ? join(', ', @{ $data{$attrname} })460 : $data{$attrname}) || '(none)');461 }462 463 $obj464 }465 466 475 sub _allowed_values { 467 476 $_[0]->{_allowed_values} … … 704 713 $pclass->_rename($self, $id, $newid); 705 714 } 706 707 =head2 load708 709 Make account base loading data into memory if need.710 Should always be called, if database fetch data on the fly711 (SQL, LDAP), the function just return True.712 713 =cut714 715 sub load { 1 }716 715 717 716 =head2 is_transactionnal
Note: See TracChangeset
for help on using the changeset viewer.