Changeset 1286 for trunk/LATMOS-Accounts
- Timestamp:
- 03/20/15 12:31:05 (9 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r1235 r1286 110 110 my $prefix = 'Base(' . $self->type . '/' . $self->label . ')'; 111 111 LATMOS::Accounts::Log::la_log($level, "$prefix $msg", @args); 112 } 113 114 =head2 logChanges($otype, $name, $ref, $changetype, $message, @args) 115 116 Functions to report back 117 118 =cut 119 120 sub ReportChange { 121 my ($self, $otype, $name, $ref, $changetype, $message, @args) = @_; 122 112 123 } 113 124 … … 437 448 } 438 449 #keys %data or return 0; # TODO: return an error ? 439 $self->create_object($otype, $id, %data); 450 my $obj = $self->create_object($otype, $id, %data); 451 $obj->ReportChange('Create', 'Object created'); 452 $obj 440 453 } 441 454 … … 614 627 return; 615 628 }; 616 $self->_delete_object($otype, $id); 629 my $ref = $obj->Iid; 630 if (my $res = $self->_delete_object($otype, $id)) { 631 $self->ReportChange($otype, $id, $ref, 'Delete', 'Object deleted'); 632 return $res; 633 } 634 return; 617 635 } 618 636 … … 650 668 }; 651 669 652 $self->_rename_object($otype, $id, $newid); 670 my $oldref = $obj->Iid; 671 672 if (my $res = $self->_rename_object($otype, $id, $newid)) { 673 my $newobj = $self->get_object($otype, $newid) or do { 674 $self->log(LA_WARN, 'Cannot get object %s/%s: rename failed ?', 675 $otype, $id); 676 return; 677 }; 678 679 $self->ReportChange($otype, $id, $oldref, 'Rename', 'Object rename to %s', $newid); 680 $newobj->ReportChange('Rename', 'Object renamed from %s', $id); 681 return $res; 682 } 683 return; 653 684 } 654 685 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm
r1278 r1286 128 128 my ($self) = @_; 129 129 $self->{_id} 130 } 131 132 133 =head2 Iid 134 135 Return internal id if different from Id 136 137 =cut 138 139 sub Iid { 140 my ($self) = @_; 141 $self->id 130 142 } 131 143 … … 368 380 return 0; 369 381 }; 370 $res += ($attribute->set($cdata{$cfield}) || 0); 371 372 } 373 $res 382 } 383 384 my %updated = (); 385 foreach my $cfield (keys %cdata) { 386 my $attribute = $self->attribute($cfield) or do { 387 $self->base->log(LA_ERR, 388 "Cannot set unsupported attribute %s to %s (%s)", 389 $cfield, $self->id, $self->type 390 ); 391 return; 392 }; 393 if ($attribute->set($cdata{$cfield})) { 394 $updated{$cfield} = $attribute->{notify}; 395 } 396 } 397 398 if (keys %updated) { 399 $self->ReportChange('Update', 'Attributes %s where updated', join(', ', sort keys %updated)); 400 foreach (sort keys %updated) { 401 $self->ReportChange('Attributes', '%s set to %s', $_, 402 (ref $cdata{$_} 403 ? join(', ', @{ $cdata{$_} }) 404 : $cdata{$_}) || '(none)') 405 if ($updated{$_}); 406 } 407 } 408 return scalar(keys %updated); 374 409 } 375 410 … … 390 425 my ($self, $clear_pass) = @_; 391 426 if ($self->base->check_acl($self, 'userPassword', 'w')) { 392 return $self->_set_password($clear_pass); 427 if ($self->_set_password($clear_pass)) { 428 $self->ReportChange('Password', 'user password has changed'); 429 return 1; 430 } else { 431 return; 432 } 393 433 } else { 394 434 $self->base->log(LA_ERROR, "Permission denied for %s to change its password", … … 623 663 } 624 664 665 =head2 ReportChange($changetype, $message, @args) 666 667 Possible per database way to log changes 668 669 =cut 670 671 sub ReportChange { 672 my ($self, $changetype, $message, @args) = @_; 673 674 $self->base->ReportChange( 675 $self->type, 676 $self->id, 677 $self->Iid, 678 $changetype, $message, @args 679 ) 680 } 681 625 682 1; 626 683 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r1285 r1286 637 637 } 638 638 639 sub ReportChange { 640 my ($self, $otype, $name, $ref, $changetype, $message, @args) = @_; 641 642 my $sth = $self->db->prepare(q{ 643 INSERT into objectslogs (ikey, otype, name, changetype, username, message) 644 VALUES (?,?,?,?,?,?) 645 }); 646 647 $sth->execute( 648 $ref, 649 $otype, 650 $name, 651 $changetype, 652 $self->user || '@Console', 653 sprintf($message, @args), 654 ); 655 } 656 639 657 =head2 getobjectlogs($otype, $name) 640 658 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Address.pm
r1144 r1286 143 143 my ($self, %data) = @_; 144 144 my %fdata; 145 my $res = 0; 145 146 foreach my $attr (keys %data) { 146 147 $attr =~ /^site$/ and do { … … 161 162 } 162 163 if (keys %fdata) { 163 $ self->SUPER::set_fields(%fdata);164 $res += $self->SUPER::set_fields(%fdata); 164 165 } 166 167 $res; 165 168 } 166 169 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm
r1280 r1286 169 169 next; 170 170 } 171 $ self->_set_group_members($data{$attr});171 $res += $self->_set_group_members($data{$attr}); 172 172 next; 173 173 }; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r1280 r1286 129 129 } 130 130 131 sub Iid { $_[0]->_get_ikey } 132 131 133 sub _get_ikey { 132 134 my ($class, $base, $id) = @_; … … 179 181 180 182 my $obj = $class->new($base, $id); 181 $obj->objectlog('Create', 'Object created');182 foreach (keys %first) {183 my $attr = $obj->attribute($_);184 $obj->objectlog('Attribute', '%s set to %s', $_, (185 defined($data{$_})186 ? (ref $data{$_}187 ? join(', ', @{ $data{$_} })188 : $data{$_})189 : '(none)'))190 if ($attr->{notify});191 }192 183 $obj->set_fields(%second); 193 184 … … 200 191 my $obj = $base->get_object($class->type, $id) 201 192 or return; 202 $obj->objectlog('Delete', 'Object deleted');203 193 204 194 my $sthd = $base->db->prepare_cached( … … 215 205 my ($class, $base, $id, $newid) = @_; 216 206 217 {218 my $obj = $base->get_object($class->type, $id)219 or return;220 $obj->objectlog('Rename', 'Object rename to %s', $newid);221 }222 223 207 my $sthr = $base->db->prepare_cached( 224 208 sprintf( … … 238 222 } 239 223 240 {241 my $obj = $base->get_object($class->type, $newid)242 or return;243 $obj->objectlog('Rename', 'Object renamed from %s', $id);244 }245 224 1; 246 225 } … … 471 450 472 451 delete($self->base->{__cache}{"_" . $self->type}{$self->id}); 473 $self->objectlog('Update', 'Attributes %s where updated', join(', ', @updated_attributes))474 if(@updated_attributes);475 foreach (@updated_attributes) {476 my $attr = $self->attribute($_);477 $self->objectlog('Attribute', '%s set to %s', $_, (478 defined($data{$_})479 ? (ref $data{$_}480 ? join(', ', @{ $data{$_} })481 : $data{$_})482 : '(none)'))483 if ($attr->{notify});484 }485 452 scalar(@updated_attributes); 486 453 } … … 546 513 $self->id 547 514 ); 548 $self-> objectlog('Password', 'user password has changed%s', ($asymencrypted ? ' and stored using internal key' : ''));515 $self->ReportChange('Password', 'Password stored using internal key'); 549 516 return 1; 550 517 } … … 749 716 } 750 717 751 =head2 objectlog752 753 =cut754 755 sub objectlog {756 my ($self, $changetype, $message, @args) = @_;757 758 my $sth = $self->base->db->prepare(q{759 INSERT into objectslogs (ikey, otype, name, changetype, username, message)760 VALUES (?,?,?,?,?,?)761 });762 763 $sth->execute(764 $self->_get_ikey,765 $self->type,766 $self->id,767 $changetype,768 $self->base->user || '@Console',769 sprintf($message, @args),770 );771 }772 773 718 1; 774 719
Note: See TracChangeset
for help on using the changeset viewer.