Commit d3928d7b authored by Alex Vandiver's avatar Alex Vandiver
Browse files

Move canonicalization into RT::ObjectCustomFieldValue->Create

Previously, value canonicalization happened for dates and datetimes in
RT::CustomField->AddValueForObject, and for IP addresses and ranges in
RT::ObjectCustomFieldValue->Create.  Standardize on the latter, as it is
lower down and thus harder to skip accidentally.

This requires creating the CustomField object as the current user, not
as the system user, as Date and DateTime canonicalization cares about
the time zone of the current user.  This, in turn, requires switching to
_Value('Type') instead of Type, as the constructed $cf object is not
guaranteed to have the right context objects for it to be readable by
the user.
parent 66cf1d42
......@@ -1675,8 +1675,6 @@ sub AddValueForObject {
}
}
$self->_CanonicalizeValue(\%args);
my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
my ($val, $msg) = $newval->Create(
ObjectType => ref($obj),
......@@ -1702,9 +1700,10 @@ sub _CanonicalizeValue {
my $self = shift;
my $args = shift;
return unless $self->Type;
my $type = $self->_Value('Type');
return unless $type;
my $method = '_CanonicalizeValue'.$self->Type;
my $method = '_CanonicalizeValue'. $type;
return unless $self->can($method);
$self->$method($args);
}
......
......@@ -82,11 +82,12 @@ sub Create {
@_,
);
my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $args{CustomField} );
my $cf_as_sys = RT::CustomField->new(RT->SystemUser);
$cf_as_sys->Load($args{'CustomField'});
$cf->_CanonicalizeValue(\%args);
if($cf_as_sys->Type eq 'IPAddress') {
if($cf->_Value('Type') eq 'IPAddress') {
if ( $args{'Content'} ) {
$args{'Content'} = $self->ParseIP( $args{'Content'} );
}
......@@ -99,7 +100,7 @@ sub Create {
}
}
if($cf_as_sys->Type eq 'IPAddressRange') {
if($cf->_Value('Type') eq 'IPAddressRange') {
if ($args{'Content'}) {
($args{'Content'}, $args{'LargeContent'}) = $self->ParseIPRange( $args{'Content'} );
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment