diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt
index 4f33c0e91..b4d31e27b 100644
--- a/docs/changelog/7.x.x.txt
+++ b/docs/changelog/7.x.x.txt
@@ -28,6 +28,10 @@
- fix: dashlet user preference setting causing nested dashboard to appear
- fix: saving edits to dashlet shortcuts kicks you out of your version tag
- fix: Discussion tmpl variables in Article asset
+ - fix: dashlet www_saveUserPrefs refusing to execute
+ - API change: ProfileField::new now returns undef for invalid fields
+ - API change: in ProfileField, the get*Fields family of methods are now class methods
+ - API change: 'func' and 'op' are now reserved and not usable as profile fields
7.0.6
- fix: Error in DateTime.pm
diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm
index deaf1f460..90fdd71b3 100644
--- a/lib/WebGUI/Asset/Shortcut.pm
+++ b/lib/WebGUI/Asset/Shortcut.pm
@@ -312,7 +312,7 @@ sub getFieldsList {
my $output = ''.$i18n->get('Manage Profile Fields').'
';
my %fieldNames;
tie %fieldNames, 'Tie::IxHash';
- foreach my $field (@{WebGUI::ProfileField->new($self->session,'dummy')->getFields}) {
+ foreach my $field (@{WebGUI::ProfileField->getFields($self->session)}) {
my $fieldId = $field->getId;
next if $fieldId =~ /contentPositions/;
$fieldNames{$fieldId} = $field->getLabel.' ['.$fieldId.']';
@@ -616,11 +616,7 @@ sub prepareView {
$template->prepare;
$self->{_viewTemplate} = $template;
my $shortcut = $self->getShortcut;
- if (defined $shortcut) {
- $shortcut->prepareView;
- } else {
- $self->notLinked;
- }
+ $shortcut->prepareView if defined $shortcut;
}
@@ -645,18 +641,21 @@ sub view {
my $content;
my $i18n = WebGUI::International->new($self->session,"Asset_Shortcut");
my $shortcut = $self->getShortcut;
- if (defined $shortcut) {
- # continue
- } elsif ($self->canEdit) {
- return ''.$self->notLinked.'';
- } else {
- return undef;
+
+ unless (defined $shortcut) {
+ if ($self->canEdit) {
+ return $self->session->style->userStyle(''.$self->notLinked.'');
+ } else {
+ return $self->notLinked;
+ }
}
+
if ($self->get("shortcutToAssetId") eq $self->get("parentId")) {
$content = $i18n->get("Displaying this shortcut would cause a feedback loop");
} else {
$content = $shortcut->view;
}
+
my %var = (
isShortcut => 1,
'shortcut.content' => $content,
@@ -866,16 +865,12 @@ sub www_saveOverride {
#-------------------------------------------------------------------
sub www_view {
+ # Hrrrm. Why doesn't the default www_view work here?
my $self = shift;
- my $shortcut = $self->getShortcut;
-
- if (defined $shortcut) {
- return $shortcut->www_view;
- } elsif ($self->canEdit) {
- return $self->session->style->userStyle(''.$self->notLinked.'');
- } else {
- return $self->notLinked;
- }
+ my $check = $self->checkView;
+ return $check if defined $check;
+ $self->prepareView;
+ return $self->view;
}
1;
diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm
index 724122472..e158ad126 100644
--- a/lib/WebGUI/Operation/Profile.pm
+++ b/lib/WebGUI/Operation/Profile.pm
@@ -55,7 +55,7 @@ The current WebGUI session object.
sub getRequiredProfileFields {
my $session = shift;
my @array;
- foreach my $field (@{WebGUI::ProfileField->new($session,'dummy')->getRequiredFields}) {
+ foreach my $field (@{WebGUI::ProfileField->getRequiredFields($session)}) {
push(@array, {
'profile.formElement' => $field->formField,
'profile.formElement.label' => $field->getLabel
@@ -146,7 +146,7 @@ sub validateProfileData {
my $error = "";
my $warning = "";
my $i18n = WebGUI::International->new($session);
- foreach my $field (@{WebGUI::ProfileField->new($session,'dummy')->getEditableFields}) {
+ foreach my $field (@{WebGUI::ProfileField->getEditableFields($session)}) {
my $fieldValue = $field->formProcess;
if (ref $fieldValue eq "ARRAY") {
$data{$field->getId} = $$fieldValue[0];
diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm
index af870bbd9..39feda1a6 100644
--- a/lib/WebGUI/Operation/User.pm
+++ b/lib/WebGUI/Operation/User.pm
@@ -442,7 +442,7 @@ sub www_editUserSave {
}
# Loop through all profile fields, and update them with new values.
- foreach my $field (@{WebGUI::ProfileField->new($session,'dummy')->getFields}) {
+ foreach my $field (@{WebGUI::ProfileField->getFields($session)}) {
next if $field->getId =~ /contentPositions/;
$u->profileField($field->getId,$field->formProcess);
}
diff --git a/lib/WebGUI/ProfileField.pm b/lib/WebGUI/ProfileField.pm
index 5701e9f57..56b1625e8 100644
--- a/lib/WebGUI/ProfileField.pm
+++ b/lib/WebGUI/ProfileField.pm
@@ -21,6 +21,7 @@ use WebGUI::Form::DynamicField;
use WebGUI::Operation::Shared;
use WebGUI::HTML;
use WebGUI::User;
+use WebGUI::Utility;
=head1 NAME
@@ -54,6 +55,19 @@ sub _reorderFields {
$sth->finish;
}
+#-------------------------------------------------------------------
+=head2 isReservedFieldName ( fieldName )
+
+Return true iff fieldName is reserved and therefore not usable as a profile field name.
+
+=cut
+
+sub isReservedFieldName {
+ my $class = shift;
+ my $fieldName = shift;
+ return isIn($fieldName, ('func', 'op'));
+}
+
#-------------------------------------------------------------------
=head2 create ( session, fieldName [, properties, categoryId] )
@@ -86,6 +100,8 @@ sub create {
my $categoryId = shift || "1";
my ($fieldNameExists) = $session->db->quickArray("select count(*) from userProfileField where fieldName=".$session->db->quote($fieldName));
return undef if ($fieldNameExists);
+ return undef if $class->isReservedFieldName($fieldName);
+
my $id = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName);
my $self = $class->new($session,$id);
$self->setCategory($categoryId);
@@ -225,34 +241,36 @@ sub getCategory {
#-------------------------------------------------------------------
-=head2 getEditableFields ( )
+=head2 getEditableFields ( session )
Returns an array reference of WebGUI::ProfileField objects that are marked "editable" or "required". This is a class method.
=cut
sub getEditableFields {
- my $self = shift;
+ my $class = shift;
+ my $session = shift;
my @fields = ();
- foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) {
- push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
+ foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) {
+ push(@fields,WebGUI::ProfileField->new($session,$fieldName));
}
return \@fields;
}
#-------------------------------------------------------------------
-=head2 getFields ( )
+=head2 getFields ( session )
Returns an array reference of WebGUI::ProfileField objects. This is a class method.
=cut
sub getFields {
- my $self = shift;
+ my $class = shift;
+ my $session = shift;
my @fields = ();
- foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
- push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
+ foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
+ push(@fields,WebGUI::ProfileField->new($session,$fieldName));
}
return \@fields;
}
@@ -287,17 +305,18 @@ sub getLabel {
#-------------------------------------------------------------------
-=head2 getRequiredFields ( )
+=head2 getRequiredFields ( session )
Returns an array reference of WebGUI::ProfileField objects that are marked "required". This is a class method.
=cut
sub getRequiredFields {
- my $self = shift;
+ my $class = shift;
+ my $session = shift;
my @fields = ();
- foreach my $fieldName ($self->session->db->buildArray("select userProfileField.fieldName from userProfileField LEFT JOIN userProfileCategory ON userProfileField.profileCategoryId = userProfileCategory.profileCategoryId where userProfileField.required=1 order by userProfileCategory.sequenceNumber, userProfileField.sequenceNumber")) {
- push(@fields,WebGUI::ProfileField->new($self->session,$fieldName));
+ foreach my $fieldName ($session->db->buildArray("select userProfileField.fieldName from userProfileField LEFT JOIN userProfileCategory ON userProfileField.profileCategoryId = userProfileCategory.profileCategoryId where userProfileField.required=1 order by userProfileCategory.sequenceNumber, userProfileField.sequenceNumber")) {
+ push(@fields,WebGUI::ProfileField->new($session,$fieldName));
}
return \@fields;
}
@@ -417,7 +436,10 @@ sub new {
my $session = shift;
my $id = shift;
return undef unless ($id);
+ return undef if $class->isReservedFieldName($id);
my $properties = $session->db->getRow("userProfileField","fieldName",$id);
+ # Reject properties that don't exist.
+ return undef unless scalar keys %$properties;
bless {_session=>$session, _properties=>$properties}, $class;
}