Skip to content

Commit

Permalink
Backport code select validation consistency from master.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Mar 23, 2010
1 parent bd98163 commit 337ed87
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
12 changes: 7 additions & 5 deletions lib/Bric/App/Callback/Profile/FieldType.pm
Expand Up @@ -7,7 +7,7 @@ use constant CLASS_KEY => 'field_type';
use strict;
use Bric::App::Event qw(log_event);
use Bric::App::Authz qw(:all);
use Bric::App::Util qw(:msg :history);
use Bric::App::Util qw(:msg :history :elem);

my $type = CLASS_KEY;
my $disp_name = 'Field';
Expand Down Expand Up @@ -67,6 +67,10 @@ sub save : Callback {
$set_meta_string->($ed, $f, $param);
}

for my $f (qw(multiple required quantifier)) {
$set_meta_boolean->($ed, $f, $param);
}

# The default value for checkboxes is boolean.
if ($ed->get_widget_type eq 'checkbox') {
$set_meta_boolean->($ed, 'default_val', $param);
Expand All @@ -75,10 +79,8 @@ sub save : Callback {
# All other default vals are strings.
else {
$set_meta_string->($ed, 'default_val', $param);
}

for my $f (qw(multiple required quantifier)) {
$set_meta_boolean->($ed, $f, $param);
# Return if it's a code select with broken code.
return if $ed->get_widget_type eq 'codeselect' && ! eval_codeselect $param->{vals};
}

add_msg("$disp_name profile \"[_1]\" saved.", $name);
Expand Down
5 changes: 1 addition & 4 deletions lib/Bric/App/Callback/Profile/FormBuilder.pm
Expand Up @@ -536,10 +536,7 @@ $add_new_attrs = sub {
$$no_save = 1;
} else {
if ($param->{fb_type} eq 'codeselect') {
# XXX: change if comp/widgets/profile/displayAttrs.mc changes..
my $code = $param->{fb_vals};
my $items = eval_codeselect($code);
unless (ref $items eq 'HASH' or ref $items eq 'ARRAY') {
unless ( eval_codeselect $param->{fb_vals} ) {
$$no_save = 1;
return;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/Bric/Changes.pod
Expand Up @@ -88,6 +88,17 @@ The C<best_uri()> method of L<Bric::Util::Burner> now avoids expired stories
when searching for aliased stories. Thanks to Zdravko Balorda for the catch
(Bug #144). [David]

=item *

The field type profile now properly validates code select code and lets the
user know if it's not valid. [David]

=item *

The validation of code select field code is now consistent between the element
type profile, the field type profile, and the SOAP element type interface.
Thanks to Krzysztof Rudnik for the report (Bug #140). [David]

=back

=head1 VERSION 1.10.9 (2010-01-28)
Expand Down
9 changes: 2 additions & 7 deletions lib/Bric/SOAP/ElementType.pm
Expand Up @@ -8,6 +8,7 @@ use Bric::Biz::ElementType;
use Bric::Biz::ATType;
use Bric::Biz::Site;
use Bric::App::Session qw(get_user_id);
use Bric::App::Util qw(:elem :msg);
use Bric::App::Authz qw(chk_authz READ);
use Bric::App::Event qw(log_event);
use Bric::Util::Fault qw(throw_ap throw_dp);
Expand Down Expand Up @@ -639,14 +640,8 @@ sub load_asset {
unless defined $field->{key_name};

# Verify the code if it's a codeselect
# XXX: triplicated now... (cf. comp/widgets/profile/displayAttrs.mc
# and lib/Bric/App/Callback/Profile/FormBuilder.pm)
if ($field->{widget_type} eq 'codeselect') {
my $code = $field->{options};
my $items = eval "$code";
unless (ref $items eq 'ARRAY' and !(@$items % 2)) {
throw_dp "Invalid codeselect code (didn't return an array ref of even size)";
}
throw_dp get_msg unless eval_codeselect $field->{options};
}

# get a data object
Expand Down

0 comments on commit 337ed87

Please sign in to comment.