diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9819efb45..81512da67 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed #11950: Username set to 0 when edit user - fixed #11946: Double time zone correction when addding an event - fixed #11952: Navigation template help error + - fixed #11951: Privacy setting of new profile field 7.10.4 - Added WebGUI::Fork api diff --git a/lib/WebGUI/User.pm b/lib/WebGUI/User.pm index dbd6ef587..867fed90f 100644 --- a/lib/WebGUI/User.pm +++ b/lib/WebGUI/User.pm @@ -779,7 +779,7 @@ Field to get privacy setting for. sub getProfileFieldPrivacySetting { my $self = shift; my $session = $self->session; - my $field = shift; + my $fieldId = shift; unless ($self->{_privacySettings}) { #Look it up manually because we want to cache this separately. @@ -791,12 +791,16 @@ sub getProfileFieldPrivacySetting { $self->{_privacySettings} = JSON->new->decode($privacySettings); } - return $self->{_privacySettings} unless ($field); + return $self->{_privacySettings} unless ($fieldId); #No privacy settings returned the privacy setting field - return "none" if($field eq "wg_privacySettings"); + return "none" if($fieldId eq "wg_privacySettings"); - return $self->{_privacySettings}->{$field}; + if (exists $self->{_privacySettings}->{$fieldId}) { + return $self->{_privacySettings}->{$fieldId}; + } + my $field = WebGUI::ProfileField->new($session, $fieldId); + return $field && $field->get('defaultPrivacySetting'); } diff --git a/t/User.t b/t/User.t index b43c2a3c7..0d96abe0f 100644 --- a/t/User.t +++ b/t/User.t @@ -22,7 +22,7 @@ use WebGUI::User; use WebGUI::ProfileField; use WebGUI::Shop::AddressBook; -use Test::More tests => 225; # increment this value for each test you create +use Test::More tests => 226; # increment this value for each test you create use Test::Deep; use Data::Dumper; @@ -942,6 +942,15 @@ is($neighbor->getProfileFieldPrivacySetting('email'), 'none', '...set will not s is($admin->getProfileFieldPrivacySetting('publicEmail'), 'all', '...get on a user with existing settings'); is($neighbor->getProfileFieldPrivacySetting('wg_privacySettings'), 'none', '...the privacy field always returns "none"'); +my $recentProfileField = WebGUI::ProfileField->create($session, 'recentField', { + fieldName => 'recentField', + defaultPrivacySetting => 'all', + visible => 1, + label => 'recentField', +}); +WebGUI::Test->addToCleanup($recentProfileField); +is($neighbor->getProfileFieldPrivacySetting('recentField'), 'all', '...if a field is added and the user does not have privacy data for it, check the original field'); + ################################################################ # # updateProfileFields diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 8dbbcc2a0..07d440e18 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -137,6 +137,7 @@ sub _initSession { 'Payment Drivers' => 'paymentGateway', 'Database Links' => 'databaseLink', 'LDAP Links' => 'ldapLink', + 'Profile Fields' => 'userProfileField', ); my %initCounts; for ( my $i = 0; $i < @checkCount; $i += 2) { @@ -750,6 +751,7 @@ were passed in. Currently able to destroy: WebGUI::DatabaseLink WebGUI::LDAPLink WebGUI::Inbox::Message + WebGUI::ProfileField Example call: @@ -853,6 +855,7 @@ Example call: 'WebGUI::Inbox::Message' => 'purge', 'WebGUI::AdSpace' => 'delete', 'WebGUI::FilePump::Bundle' => 'delete', + 'WebGUI::ProfileField' => 'delete', 'WebGUI::Shop::Cart' => sub { my $cart = shift; my $addressBook = eval { $cart->getAddressBook(); };