diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 54dffe3b2..7994a3662 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -37,6 +37,8 @@ - fixed: Hover Help outdated: automatically request commit - fixed: Thingy: Subtext disappears when editing a field - fixed: WebGUI Search errors - boolean search using filtering does not work + - Updated User->profileField method to return all default values as a scalar, + rather than just the first option in the list. - fixed: Layout can now uncheck all Assets that are hidden. This also resolves any CheckList issue so that all buttons can be left blank. 7.5.18 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 0effcda28..330fb0f7e 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -13,6 +13,11 @@ save you many hours of grief. using an earlier version you will need to upgrade this perl module before you upgrade. + * If a user profile field allowed multiple selects, and it also had + more than one default value, the User method profileField would + return the first. It will now return all default values as a string, + joined by commas. + 7.5.17 -------------------------------------------------------------------- * If users are allowed to self register and emails are not required, this diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index 9c4a6c1c1..57aa92cfa 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -218,23 +218,24 @@ Friend's group. sub delete { my $self = shift; + my $userId = $self->userId; $self->uncache; my $db = $self->session->db; - foreach my $groupId (@{$self->getGroups($self->userId)}) { - WebGUI::Group->new($self->session,$groupId)->deleteUsers([$self->userId]); + foreach my $groupId (@{$self->getGroups($userId)}) { + WebGUI::Group->new($self->session,$groupId)->deleteUsers([$userId]); } $self->friends->delete if ($self->{_user}{"friendsGroup"} ne ""); - $db->write("delete from inbox where userId=? and (groupId is null or groupId='')",[$self->{_userId}]); + $db->write("delete from inbox where userId=? and (groupId is null or groupId='')",[$userId]); require WebGUI::Operation::Auth; - my $authMethod = WebGUI::Operation::Auth::getInstance($self->session,$self->authMethod,$self->{_userId}); - $authMethod->deleteParams($self->{_userId}); - my $rs = $db->read("select sessionId from userSession where userId=?",[$self->{_userId}]); + my $authMethod = WebGUI::Operation::Auth::getInstance($self->session,$self->authMethod,$userId); + $authMethod->deleteParams($userId); + my $rs = $db->read("select sessionId from userSession where userId=?",[$userId]); while (my ($id) = $rs->array) { $db->write("delete from userSessionScratch where sessionId=?",[$id]); } - $db->write("delete from userSession where userId=?",[$self->{_userId}]); - $db->write("delete from userProfileData where userId=?",[$self->{_userId}]); - $db->write("delete from users where userId=?",[$self->{_userId}]); + $db->write("delete from userSession where userId=?",[$userId]); + $db->write("delete from userProfileData where userId=?",[$userId]); + $db->write("delete from users where userId=?",[$userId]); } #------------------------------------------------------------------- @@ -575,7 +576,9 @@ sub new { } } - $profile{alias} = $user{username} if ($profile{alias} =~ /^\W+$/ || $profile{alias} eq ""); + if (($profile{alias} =~ /^\W+$/ || $profile{alias} eq "") and $user{username}) { + $profile{alias} = $user{username}; + } $self->{_userId} = $userId; $self->{_user} = \%user, $self->{_profile} = \%profile, @@ -683,6 +686,10 @@ sub profileField { my $default = $self->session->db->quickScalar("SELECT dataDefault FROM userProfileField WHERE fieldName=?", [$fieldName]); $self->{_profile}{$fieldName} = WebGUI::Operation::Shared::secureEval($self->session, $default); $self->cache; + } + if (ref $self->{_profile}{$fieldName} eq 'ARRAY') { + ##Return a scalar, that is a string with all the defaults + return join ',', @{ $self->{_profile}{$fieldName} }; } return $self->{_profile}{$fieldName}; } @@ -788,16 +795,16 @@ If specified, the username is set to this value. =cut sub username { - my $self = shift; - my $value = shift; - if (defined $value) { - $self->uncache; - $self->{_user}{"username"} = $value; - $self->{_user}{"lastUpdated"} = $self->session->datetime->time(); - $self->session->db->write("update users set username=?, lastUpdated=? where userId=?", - [$value, $self->session->datetime->time(), $self->userId]); - } - return $self->{_user}{"username"}; + my $self = shift; + my $value = shift; + if (defined $value) { + $self->uncache; + $self->{_user}{"username"} = $value; + $self->{_user}{"lastUpdated"} = $self->session->datetime->time(); + $self->session->db->write("update users set username=?, lastUpdated=? where userId=?", + [$value, $self->session->datetime->time(), $self->userId]); + } + return $self->{_user}{"username"}; } #------------------------------------------------------------------- diff --git a/t/User.t b/t/User.t index 709c5670e..637481591 100644 --- a/t/User.t +++ b/t/User.t @@ -20,7 +20,7 @@ use WebGUI::Cache; use WebGUI::User; use WebGUI::ProfileField; -use Test::More tests => 132; # increment this value for each test you create +use Test::More tests => 133; # increment this value for each test you create use Test::Deep; my $session = WebGUI::Test->session; @@ -39,7 +39,7 @@ my $userCreationTime = time(); ok(defined ($user = WebGUI::User->new($session,"new")), 'new("new") -- object reference is defined'); #New does not return undef if something breaks, so we'll see if the _profile hash was set. -ok(scalar %{$user->{_profile}} > 0, 'new("new") -- profile property contains at least one key'); +ok(exists $user->{_profile}, 'new("new") -- profile subhash exists'); #Let's assign a username $user->username("bill_lumberg"); @@ -84,7 +84,7 @@ is($user->profileField('notAProfileField'), undef, 'getting non-existant profile ##Check for valid profileField access, even if it is not cached in the user object. my $newProfileField = WebGUI::ProfileField->create($session, 'testField', {dataDefault => 'this is a test'}); -is($user->profileField('testField'), undef, 'getting profile fields not cached in the user object returns undef'); +is($user->profileField('testField'), 'this is a test', 'getting profile fields not cached in the user object returns the profile field default'); ################################################################ # @@ -401,8 +401,6 @@ is( $busterCopy->profileField('timeZone'), 'America/Hillsboro', 'busterCopy rece $profileField->set(\%originalFieldData); -$buster->username('mythBuster'); - my $aliasProfile = WebGUI::ProfileField->new($session, 'alias'); my %originalAliasProfile = %{ $aliasProfile->get() }; my %copiedAliasProfile = %originalAliasProfile; @@ -416,6 +414,8 @@ $copiedAliasProfile{'dataDefault'} = "'....^^^^....'"; ##Non word characters; $aliasProfile->set(\%copiedAliasProfile); $buster->uncache(); +$buster->username('mythBuster'); + $buster3 = WebGUI::User->new($session, $buster->userId); is($buster3->profileField('alias'), 'mythBuster', 'alias set to username since the default alias has only non-word characters'); @@ -428,7 +428,7 @@ my $listProfileField = WebGUI::ProfileField->create($session, 'listProfile', \%l $buster->uncache; $buster3 = WebGUI::User->new($session, $buster->userId); -is($buster3->profileField('listProfile'), 'alpha', 'profile field with default data value that is a list gives the user the first value'); +is($buster3->profileField('listProfile'), 'alpha,delta,tango', 'profile field with default data value that is a list returns a string with all values as CSV'); ################################################################ #