[Rt-commit] rt branch, 4.0/ip-address-canonicalization, repushed
Alex Vandiver
alexmv at bestpractical.com
Thu Jun 5 16:25:07 EDT 2014
The branch 4.0/ip-address-canonicalization was deleted and repushed:
was 938e91a6f8472893f6aa2040f12c7957953db53f
now 4cd0b9c7c258b985159d96f6aa75d871f0300777
1: da51698 = 1: da51698 ->Content is as formatted for the user, not the DB value
2: eb939ac = 2: eb939ac Add a generic ->_CanonicalizeValue
--: ------- > 3: 9ec3b7d Move canonicalization into RT::ObjectCustomFieldValue->Create
3: d6430de ! 4: 45b6324 Add common IP address and range canonicalizers
@@ -1,29 +1,16 @@
Author: Alex Vandiver <alexmv at bestpractical.com>
- Refactor IP canonicalizers in Create into standard methods
+ Add common IP address and range canonicalizers
- The IP address and range code in ObjectCustomFieldValue's Create is
- moved into the more general canonicalization functions. This also
- allows HasEntry can split IP ranges correctly to check their existance,
- and ensures that the standard form (padded to three digits per octet) is
- compared against the database.
-
- This additionally ensures that invalid Date and DateTime CF values
- cannot be created directly via ObjectCustomFieldValue->Create; they were
- previously cleaned up only at the ->AddValueForObject level.
+ The IP address and range canonicalization in ObjectCustomFieldValue's
+ Create is moved into the more general canonicalization functions. This
+ also allows HasEntry can split IP ranges correctly to check their
+ existance, and ensures that the standard form (padded to three digits
+ per octet) is compared against the database.
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
-@@
- }
- }
-
-- $self->_CanonicalizeValue(\%args);
--
- my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
- my ($val, $msg) = $newval->Create(
- ObjectType => ref($obj),
@@
$args->{'Content'} = $DateObj->Date( Timezone => 'user' );
}
@@ -56,17 +43,10 @@
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@
- @_,
- );
-+ my $cf = RT::CustomField->new( $self->CurrentUser );
-+ $cf->Load( $args{CustomField} );
-+ return (0, $self->loc("Invalid custom field")) unless $cf->id;
+ $cf->_CanonicalizeValue(\%args);
-- my $cf_as_sys = RT::CustomField->new(RT->SystemUser);
-- $cf_as_sys->Load($args{'CustomField'});
--
-- if($cf_as_sys->Type eq 'IPAddress') {
+- if($cf->_Value('Type') eq 'IPAddress') {
- if ( $args{'Content'} ) {
- $args{'Content'} = $self->ParseIP( $args{'Content'} );
- }
@@ -79,7 +59,7 @@
- }
- }
-
-- if($cf_as_sys->Type eq 'IPAddressRange') {
+- if($cf->_Value('Type') eq 'IPAddressRange') {
- if ($args{'Content'}) {
- ($args{'Content'}, $args{'LargeContent'}) = $self->ParseIPRange( $args{'Content'} );
- }
@@ -92,8 +72,8 @@
- : 0;
- }
- }
-+ $cf->_CanonicalizeValue(\%args);
-
+-
if ( defined $args{'Content'} && length( Encode::encode_utf8($args{'Content'}) ) > 255 ) {
if ( defined $args{'LargeContent'} && length $args{'LargeContent'} ) {
+ $RT::Logger->error("Content is longer than 255 bytes and LargeContent specified");
4: 8b9a9a7 ! 5: 6382145 Let canonicalization return a failure message
@@ -10,13 +10,13 @@
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@
- my $self = shift;
my $args = shift;
-- return unless $self->Type;
-+ return 1 unless $self->Type;
+ my $type = $self->_Value('Type');
+- return unless $type;
++ return 1 unless $type;
- my $method = '_CanonicalizeValue'.$self->Type;
+ my $method = '_CanonicalizeValue'. $type;
- return unless $self->can($method);
+ return 1 unless $self->can($method);
$self->$method($args);
@@ -63,8 +63,8 @@
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@
+ my $cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $args{CustomField} );
- return (0, $self->loc("Invalid custom field")) unless $cf->id;
- $cf->_CanonicalizeValue(\%args);
+ my ($val, $msg) = $cf->_CanonicalizeValue(\%args);
5: 70df354 = 6: e688a79 Provide a better error message for loading OCFVs on an invalid CF
6: df06197 = 7: b32a818 Canonicalize all OCFVs on load, not just IP address ranges
7: 5e76118 = 8: e93f585 Remove too-many-value OCFVs by id, not Content
8: cb25f53 = 9: 61c4118 Reuse existing validation in OCVF canonicalization
9: 938e91a = 10: 4cd0b9c Remove a needless block; ParseIPRange does the exact same as its first step
More information about the rt-commit
mailing list