Multiple changes:

- Shift ProfileField API so that new returns undef on invalid fields.
    This makes it possible for Shortcut::www_saveUserPrefs to execute.
    The class methods in ProfileField are now also actually class methods.

    + Also fix up other modules that created dummy ProfileFields so that
      they don't need to do that anymore, because it's now invalid.

  - Merge contradictory-looking code from Shortcut's view and www_view
    into a reasonable compromise in view, and then have www_view call
    $self->view in a manner similar to that of the default Asset::view.

    + The profile field overrides still don't work, because there's no
      obvious mechanism for "transclude asset in context".  This may
      require some fiddling to get right...
This commit is contained in:
Drake 2006-08-31 00:14:56 +00:00
parent 84e8d8f689
commit 565119fa1a
5 changed files with 57 additions and 36 deletions

View file

@ -28,6 +28,10 @@
- fix: dashlet user preference setting causing nested dashboard to appear - fix: dashlet user preference setting causing nested dashboard to appear
- fix: saving edits to dashlet shortcuts kicks you out of your version tag - fix: saving edits to dashlet shortcuts kicks you out of your version tag
- fix: Discussion tmpl variables in Article asset - 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 7.0.6
- fix: Error in DateTime.pm - fix: Error in DateTime.pm

View file

@ -312,7 +312,7 @@ sub getFieldsList {
my $output = '<a href="'.$self->getUrl('op=editProfileSettings').'" class="formLink">'.$i18n->get('Manage Profile Fields').'</a><br /><br />'; my $output = '<a href="'.$self->getUrl('op=editProfileSettings').'" class="formLink">'.$i18n->get('Manage Profile Fields').'</a><br /><br />';
my %fieldNames; my %fieldNames;
tie %fieldNames, 'Tie::IxHash'; 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; my $fieldId = $field->getId;
next if $fieldId =~ /contentPositions/; next if $fieldId =~ /contentPositions/;
$fieldNames{$fieldId} = $field->getLabel.' ['.$fieldId.']'; $fieldNames{$fieldId} = $field->getLabel.' ['.$fieldId.']';
@ -616,11 +616,7 @@ sub prepareView {
$template->prepare; $template->prepare;
$self->{_viewTemplate} = $template; $self->{_viewTemplate} = $template;
my $shortcut = $self->getShortcut; my $shortcut = $self->getShortcut;
if (defined $shortcut) { $shortcut->prepareView if defined $shortcut;
$shortcut->prepareView;
} else {
$self->notLinked;
}
} }
@ -645,18 +641,21 @@ sub view {
my $content; my $content;
my $i18n = WebGUI::International->new($self->session,"Asset_Shortcut"); my $i18n = WebGUI::International->new($self->session,"Asset_Shortcut");
my $shortcut = $self->getShortcut; my $shortcut = $self->getShortcut;
if (defined $shortcut) {
# continue unless (defined $shortcut) {
} elsif ($self->canEdit) { if ($self->canEdit) {
return '<a href="'.$self->getUrl("func=delete").'">'.$self->notLinked.'</a>'; return $self->session->style->userStyle('<a href="'.$self->getUrl("func=delete").'">'.$self->notLinked.'</a>');
} else { } else {
return undef; return $self->notLinked;
}
} }
if ($self->get("shortcutToAssetId") eq $self->get("parentId")) { if ($self->get("shortcutToAssetId") eq $self->get("parentId")) {
$content = $i18n->get("Displaying this shortcut would cause a feedback loop"); $content = $i18n->get("Displaying this shortcut would cause a feedback loop");
} else { } else {
$content = $shortcut->view; $content = $shortcut->view;
} }
my %var = ( my %var = (
isShortcut => 1, isShortcut => 1,
'shortcut.content' => $content, 'shortcut.content' => $content,
@ -866,16 +865,12 @@ sub www_saveOverride {
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub www_view { sub www_view {
# Hrrrm. Why doesn't the default www_view work here?
my $self = shift; my $self = shift;
my $shortcut = $self->getShortcut; my $check = $self->checkView;
return $check if defined $check;
if (defined $shortcut) { $self->prepareView;
return $shortcut->www_view; return $self->view;
} elsif ($self->canEdit) {
return $self->session->style->userStyle('<a href="'.$self->getUrl("func=delete").'">'.$self->notLinked.'</a>');
} else {
return $self->notLinked;
}
} }
1; 1;

View file

@ -55,7 +55,7 @@ The current WebGUI session object.
sub getRequiredProfileFields { sub getRequiredProfileFields {
my $session = shift; my $session = shift;
my @array; my @array;
foreach my $field (@{WebGUI::ProfileField->new($session,'dummy')->getRequiredFields}) { foreach my $field (@{WebGUI::ProfileField->getRequiredFields($session)}) {
push(@array, { push(@array, {
'profile.formElement' => $field->formField, 'profile.formElement' => $field->formField,
'profile.formElement.label' => $field->getLabel 'profile.formElement.label' => $field->getLabel
@ -146,7 +146,7 @@ sub validateProfileData {
my $error = ""; my $error = "";
my $warning = ""; my $warning = "";
my $i18n = WebGUI::International->new($session); 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; my $fieldValue = $field->formProcess;
if (ref $fieldValue eq "ARRAY") { if (ref $fieldValue eq "ARRAY") {
$data{$field->getId} = $$fieldValue[0]; $data{$field->getId} = $$fieldValue[0];

View file

@ -442,7 +442,7 @@ sub www_editUserSave {
} }
# Loop through all profile fields, and update them with new values. # 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/; next if $field->getId =~ /contentPositions/;
$u->profileField($field->getId,$field->formProcess); $u->profileField($field->getId,$field->formProcess);
} }

View file

@ -21,6 +21,7 @@ use WebGUI::Form::DynamicField;
use WebGUI::Operation::Shared; use WebGUI::Operation::Shared;
use WebGUI::HTML; use WebGUI::HTML;
use WebGUI::User; use WebGUI::User;
use WebGUI::Utility;
=head1 NAME =head1 NAME
@ -54,6 +55,19 @@ sub _reorderFields {
$sth->finish; $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] ) =head2 create ( session, fieldName [, properties, categoryId] )
@ -86,6 +100,8 @@ sub create {
my $categoryId = shift || "1"; my $categoryId = shift || "1";
my ($fieldNameExists) = $session->db->quickArray("select count(*) from userProfileField where fieldName=".$session->db->quote($fieldName)); my ($fieldNameExists) = $session->db->quickArray("select count(*) from userProfileField where fieldName=".$session->db->quote($fieldName));
return undef if ($fieldNameExists); return undef if ($fieldNameExists);
return undef if $class->isReservedFieldName($fieldName);
my $id = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName); my $id = $session->db->setRow("userProfileField","fieldName",{fieldName=>"new"},$fieldName);
my $self = $class->new($session,$id); my $self = $class->new($session,$id);
$self->setCategory($categoryId); $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. Returns an array reference of WebGUI::ProfileField objects that are marked "editable" or "required". This is a class method.
=cut =cut
sub getEditableFields { sub getEditableFields {
my $self = shift; my $class = shift;
my $session = shift;
my @fields = (); my @fields = ();
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) { foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField where required=1 or editable=1 order by sequenceNumber")) {
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName)); push(@fields,WebGUI::ProfileField->new($session,$fieldName));
} }
return \@fields; return \@fields;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getFields ( ) =head2 getFields ( session )
Returns an array reference of WebGUI::ProfileField objects. This is a class method. Returns an array reference of WebGUI::ProfileField objects. This is a class method.
=cut =cut
sub getFields { sub getFields {
my $self = shift; my $class = shift;
my $session = shift;
my @fields = (); my @fields = ();
foreach my $fieldName ($self->session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) { foreach my $fieldName ($session->db->buildArray("select fieldName from userProfileField order by profileCategoryId, sequenceNumber")) {
push(@fields,WebGUI::ProfileField->new($self->session,$fieldName)); push(@fields,WebGUI::ProfileField->new($session,$fieldName));
} }
return \@fields; 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. Returns an array reference of WebGUI::ProfileField objects that are marked "required". This is a class method.
=cut =cut
sub getRequiredFields { sub getRequiredFields {
my $self = shift; my $class = shift;
my $session = shift;
my @fields = (); 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")) { 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($self->session,$fieldName)); push(@fields,WebGUI::ProfileField->new($session,$fieldName));
} }
return \@fields; return \@fields;
} }
@ -417,7 +436,10 @@ sub new {
my $session = shift; my $session = shift;
my $id = shift; my $id = shift;
return undef unless ($id); return undef unless ($id);
return undef if $class->isReservedFieldName($id);
my $properties = $session->db->getRow("userProfileField","fieldName",$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; bless {_session=>$session, _properties=>$properties}, $class;
} }