From b9400f341d1c521735009b02457f1e6f6ad3997e Mon Sep 17 00:00:00 2001 From: "ian%hixie.ch" Date: Sat, 10 Nov 2001 21:00:37 +0000 Subject: [PATCH] The User object was not saving anything if its userID started off as undef (i.e., new user) and the code never changed any properties (which is normal for a new user). Changed the code to automatically assume it is dirty if it starts with an undefined userID. Changed writeProperties to use the return value from the data source to save any changes to userID, so that when it is defined (by inserting a new record, probably) then we can remember it. Finally, changed propertySet so that when userID is changed from an undefined value to a defined value, the change is propagated to the fields and the groups are marked dirty, which will force them to be written out too. --- webtools/PLIF/PLIF/Service/User.pm | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/webtools/PLIF/PLIF/Service/User.pm b/webtools/PLIF/PLIF/Service/User.pm index 3b898ab2cd9e..412283ce1c53 100644 --- a/webtools/PLIF/PLIF/Service/User.pm +++ b/webtools/PLIF/PLIF/Service/User.pm @@ -128,7 +128,7 @@ sub objectInit { $self->originalGroups({%$groups}); # a backup used to make a comparison when saving the groups my %rights = map {$_ => 1} @$rights; $self->rights(\%rights); # map a list of strings into a hash for easy access - $self->{'_DIRTY'}->{'properties'} = 0; + $self->{'_DIRTY'}->{'properties'} = not(defined($userID)); } sub hasRight { @@ -301,7 +301,20 @@ sub invalidateRights { sub propertySet { my $self = shift; + my($name, $value) = @_; + # check that we're not doing silly things like changing the user's ID + my $hadUndefinedID = (($name eq 'userID') and + ($self->propertyExists($name)) and + (not defined($self->propertyGet($name)))); my $result = $self->SUPER::propertySet(@_); + if (($name eq 'userID') and (defined($value)) and ($hadUndefinedID)) { + # we've just aquired an ID, so propagate the change to all fields + foreach my $field (values(%{$self->fieldsByID})) { + $field->userID($value); + } + # and mark the groups as dirty too + $self->{'_DIRTY'}->{'groups'} = 1; + } $self->{'_DIRTY'}->{'properties'} = 1; return $result; } @@ -335,9 +348,9 @@ sub DESTROY { sub writeProperties { my $self = shift; - $self->app->getService('dataSource.user')->setUser($self->app, $self->userID, $self->mode, - $self->password, $self->adminMessage, - $self->newFieldID, $self->newFieldValue, $self->newFieldKey); + $self->userID($self->app->getService('dataSource.user')->setUser($self->app, $self->userID, $self->mode, + $self->password, $self->adminMessage, + $self->newFieldID, $self->newFieldValue, $self->newFieldKey)); } sub writeGroups {