summaryrefslogtreecommitdiff
path: root/rt/lib/RT
diff options
context:
space:
mode:
Diffstat (limited to 'rt/lib/RT')
-rw-r--r--rt/lib/RT/CustomField.pm45
-rw-r--r--rt/lib/RT/Generated.pm2
-rw-r--r--rt/lib/RT/Handle.pm1
-rw-r--r--rt/lib/RT/ObjectCustomFieldValue.pm46
-rw-r--r--rt/lib/RT/ObjectCustomFieldValues.pm34
-rwxr-xr-xrt/lib/RT/Record.pm40
-rw-r--r--rt/lib/RT/Shredder/Plugin/Users.pm1
-rw-r--r--rt/lib/RT/Test.pm5
-rwxr-xr-xrt/lib/RT/Ticket.pm2
-rwxr-xr-xrt/lib/RT/Tickets.pm9
10 files changed, 97 insertions, 88 deletions
diff --git a/rt/lib/RT/CustomField.pm b/rt/lib/RT/CustomField.pm
index e71bbf78a..ff1eec9b3 100644
--- a/rt/lib/RT/CustomField.pm
+++ b/rt/lib/RT/CustomField.pm
@@ -1547,12 +1547,6 @@ sub AddValueForObject {
}
}
- if (my $canonicalizer = $self->can('_CanonicalizeValue'.$self->Type)) {
- $canonicalizer->($self, \%args);
- }
-
-
-
my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
my ($val, $msg) = $newval->Create(
ObjectType => ref($obj),
@@ -1574,6 +1568,17 @@ sub AddValueForObject {
}
+sub _CanonicalizeValue {
+ my $self = shift;
+ my $args = shift;
+
+ my $type = $self->_Value('Type');
+ return 1 unless $type;
+
+ my $method = '_CanonicalizeValue'. $type;
+ return 1 unless $self->can($method);
+ $self->$method($args);
+}
sub _CanonicalizeValueDateTime {
my $self = shift;
@@ -1582,6 +1587,7 @@ sub _CanonicalizeValueDateTime {
$DateObj->Set( Format => 'unknown',
Value => $args->{'Content'} );
$args->{'Content'} = $DateObj->ISO;
+ return 1;
}
# For date, we need to store Content as ISO date
@@ -1596,6 +1602,33 @@ sub _CanonicalizeValueDate {
Value => $args->{'Content'},
);
$args->{'Content'} = $DateObj->Date( Timezone => 'user' );
+ return 1;
+}
+
+sub _CanonicalizeValueIPAddress {
+ my $self = shift;
+ my $args = shift;
+
+ $args->{Content} = RT::ObjectCustomFieldValue->ParseIP( $args->{Content} );
+ return (0, $self->loc("Content is not a valid IP address"))
+ unless $args->{Content};
+ return 1;
+}
+
+sub _CanonicalizeValueIPAddressRange {
+ my $self = shift;
+ my $args = shift;
+
+ my $content = $args->{Content};
+ $content .= "-".$args->{LargeContent} if $args->{LargeContent};
+
+ ($args->{Content}, $args->{LargeContent})
+ = RT::ObjectCustomFieldValue->ParseIPRange( $content );
+
+ $args->{ContentType} = 'text/plain';
+ return (0, $self->loc("Content is not a valid IP address range"))
+ unless $args->{Content};
+ return 1;
}
=head2 MatchPattern STRING
diff --git a/rt/lib/RT/Generated.pm b/rt/lib/RT/Generated.pm
index eee892dd9..f4fb88d8f 100644
--- a/rt/lib/RT/Generated.pm
+++ b/rt/lib/RT/Generated.pm
@@ -50,7 +50,7 @@ package RT;
use warnings;
use strict;
-our $VERSION = '4.0.20';
+our $VERSION = '4.0.21';
diff --git a/rt/lib/RT/Handle.pm b/rt/lib/RT/Handle.pm
index e6ecdda77..0fce6465f 100644
--- a/rt/lib/RT/Handle.pm
+++ b/rt/lib/RT/Handle.pm
@@ -128,6 +128,7 @@ sub Connect {
if ( $db_type eq 'Pg' ) {
my $version = $self->DatabaseVersion;
($version) = $version =~ /^(\d+\.\d+)/;
+ $self->dbh->{pg_server_prepare} = 0 if $version > 9.1; #and we're using a deb-7 version DBD::Pg?
$self->dbh->do("SET bytea_output = 'escape'") if $version >= 9.0;
}
diff --git a/rt/lib/RT/ObjectCustomFieldValue.pm b/rt/lib/RT/ObjectCustomFieldValue.pm
index de4bc748d..0e63ced1b 100644
--- a/rt/lib/RT/ObjectCustomFieldValue.pm
+++ b/rt/lib/RT/ObjectCustomFieldValue.pm
@@ -84,36 +84,11 @@ 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'});
-
- if($cf_as_sys->Type eq 'IPAddress') {
- if ( $args{'Content'} ) {
- $args{'Content'} = $self->ParseIP( $args{'Content'} );
- }
-
- unless ( defined $args{'Content'} ) {
- return
- wantarray
- ? ( 0, $self->loc("Content is an invalid IP address") )
- : 0;
- }
- }
-
- if($cf_as_sys->Type eq 'IPAddressRange') {
- if ($args{'Content'}) {
- ($args{'Content'}, $args{'LargeContent'}) = $self->ParseIPRange( $args{'Content'} );
- }
- $args{'ContentType'} = 'text/plain';
-
- unless ( defined $args{'Content'} ) {
- return
- wantarray
- ? ( 0, $self->loc("Content is an invalid IP address range") )
- : 0;
- }
- }
+ my ($val, $msg) = $cf->_CanonicalizeValue(\%args);
+ return ($val, $msg) unless $val;
if ( defined $args{'Content'} && length( Encode::encode_utf8($args{'Content'}) ) > 255 ) {
if ( defined $args{'LargeContent'} && length $args{'LargeContent'} ) {
@@ -164,16 +139,9 @@ sub LoadByCols {
if ( $args{CustomField} ) {
$cf = RT::CustomField->new( $self->CurrentUser );
$cf->Load( $args{CustomField} );
- if ( $cf->Type && $cf->Type eq 'IPAddressRange' ) {
-
- my ( $sIP, $eIP ) = $cf->ParseIPRange( $args{'Content'} );
- if ( $sIP && $eIP ) {
- $self->SUPER::LoadByCols( %args,
- Content => $sIP,
- LargeContent => $eIP
- );
- }
- }
+
+ my ($ok, $msg) = $cf->_CanonicalizeValue(\%args);
+ return ($ok, $msg) unless $ok;
}
return $self->SUPER::LoadByCols(%args);
}
diff --git a/rt/lib/RT/ObjectCustomFieldValues.pm b/rt/lib/RT/ObjectCustomFieldValues.pm
index 486265e26..a2ec317e8 100644
--- a/rt/lib/RT/ObjectCustomFieldValues.pm
+++ b/rt/lib/RT/ObjectCustomFieldValues.pm
@@ -115,10 +115,10 @@ sub LimitToObject {
}
-=head2 HasEntry VALUE
+=head2 HasEntry CONTENT LARGE_CONTENT
-If this collection has an entry with content that eq VALUE then
-returns the entry, otherwise returns undef.
+If this collection has an entry with content that eq CONTENT and large content
+that eq LARGE_CONTENT then returns the entry, otherwise returns undef.
=cut
@@ -126,11 +126,37 @@ returns the entry, otherwise returns undef.
sub HasEntry {
my $self = shift;
my $value = shift;
+ my $large_content = shift;
return undef unless defined $value && length $value;
+ my %canon_value;
#TODO: this could cache and optimize a fair bit.
foreach my $item ( @{$self->ItemsArrayRef} ) {
- return $item if lc $item->Content eq lc $value;
+ my $cf = $item->CustomFieldObj;
+ my $args = $canon_value{ $cf->Type };
+ if ( !$args ) {
+ $args = { Content => $value, LargeContent => $large_content };
+ my ($ok, $msg) = $cf->_CanonicalizeValue( $args );
+ next unless $ok;
+ $canon_value{ $cf->Type } = $args;
+ }
+
+ if ( $cf->Type eq 'Select' ) {
+ # select is case insensitive
+ return $item if lc $item->Content eq lc $args->{Content};
+ }
+ else {
+ if ( $item->_Value('Content') eq $args->{Content} ) {
+ if ( defined $item->LargeContent ) {
+ return $item
+ if defined $args->{LargeContent}
+ && $item->LargeContent eq $args->{LargeContent};
+ }
+ else {
+ return $item unless defined $args->{LargeContent};
+ }
+ }
+ }
}
return undef;
}
diff --git a/rt/lib/RT/Record.pm b/rt/lib/RT/Record.pm
index 59867aae8..7adfc2678 100755
--- a/rt/lib/RT/Record.pm
+++ b/rt/lib/RT/Record.pm
@@ -1796,8 +1796,8 @@ sub _AddCustomFieldValue {
$i++;
if ( $i < $cf_values ) {
my ( $val, $msg ) = $cf->DeleteValueForObject(
- Object => $self,
- Content => $value->Content
+ Object => $self,
+ Id => $value->id,
);
unless ($val) {
return ( 0, $msg );
@@ -1813,31 +1813,14 @@ sub _AddCustomFieldValue {
$values->RedoSearch if $i; # redo search if have deleted at least one value
}
- my ( $old_value, $old_content );
- if ( $old_value = $values->First ) {
- $old_content = $old_value->Content;
- $old_content = undef if defined $old_content && !length $old_content;
-
- my $is_the_same = 1;
- if ( defined $args{'Value'} ) {
- $is_the_same = 0 unless defined $old_content
- && $old_content eq $args{'Value'};
- } else {
- $is_the_same = 0 if defined $old_content;
- }
- if ( $is_the_same ) {
- my $old_content = $old_value->LargeContent;
- if ( defined $args{'LargeContent'} ) {
- $is_the_same = 0 unless defined $old_content
- && $old_content eq $args{'LargeContent'};
- } else {
- $is_the_same = 0 if defined $old_content;
- }
- }
-
- return $old_value->id if $is_the_same;
+ if ( my $entry = $values->HasEntry($args{'Value'}, $args{'LargeContent'}) ) {
+ return $entry->id;
}
+ my $old_value = $values->First;
+ my $old_content;
+ $old_content = $old_value->Content if $old_value;
+
my ( $new_value_id, $value_msg ) = $cf->AddValueForObject(
Object => $self,
Content => $args{'Value'},
@@ -1904,6 +1887,13 @@ sub _AddCustomFieldValue {
# otherwise, just add a new value and record "new value added"
else {
+ if ( !$cf->Repeated ) {
+ my $values = $cf->ValuesForObject($self);
+ if ( my $entry = $values->HasEntry($args{'Value'}, $args{'LargeContent'}) ) {
+ return $entry->id;
+ }
+ }
+
my ($new_value_id, $msg) = $cf->AddValueForObject(
Object => $self,
Content => $args{'Value'},
diff --git a/rt/lib/RT/Shredder/Plugin/Users.pm b/rt/lib/RT/Shredder/Plugin/Users.pm
index 5b7ccae8f..f763246c2 100644
--- a/rt/lib/RT/Shredder/Plugin/Users.pm
+++ b/rt/lib/RT/Shredder/Plugin/Users.pm
@@ -241,6 +241,7 @@ sub FilterWithoutTickets {
sub _WithoutTickets {
my ($self, $user) = @_;
+ return unless $user and $user->Id;
my $tickets = RT::Tickets->new( RT->SystemUser );
$tickets->{'allow_deleted_search'} = 1;
$tickets->FromSQL( 'Watcher.id = '. $user->id );
diff --git a/rt/lib/RT/Test.pm b/rt/lib/RT/Test.pm
index b15c03d23..19dc26378 100644
--- a/rt/lib/RT/Test.pm
+++ b/rt/lib/RT/Test.pm
@@ -1462,7 +1462,8 @@ sub test_app {
}
require Plack::Middleware::Test::StashWarnings;
- my $stashwarnings = Plack::Middleware::Test::StashWarnings->new;
+ my $stashwarnings = Plack::Middleware::Test::StashWarnings->new(
+ $ENV{'RT_TEST_WEB_HANDLER'} && $ENV{'RT_TEST_WEB_HANDLER'} eq 'inline' ? ( verbose => 0 ) : () );
$app = $stashwarnings->wrap($app);
if ($server_opt{basic_auth}) {
@@ -1596,8 +1597,6 @@ sub file_content {
$path = File::Spec->catfile( @$path ) if ref $path eq 'ARRAY';
- Test::More::diag "reading content of '$path'" if $ENV{'TEST_VERBOSE'};
-
open( my $fh, "<:raw", $path )
or do {
warn "couldn't open file '$path': $!" unless $args{noexist};
diff --git a/rt/lib/RT/Ticket.pm b/rt/lib/RT/Ticket.pm
index 6a8b40cfb..c3d4c2773 100755
--- a/rt/lib/RT/Ticket.pm
+++ b/rt/lib/RT/Ticket.pm
@@ -203,7 +203,7 @@ Arguments: ARGS is a hash of named parameters. Valid parameters are:
Priority -- an integer from 0 to 99
InitialPriority -- an integer from 0 to 99
FinalPriority -- an integer from 0 to 99
- Status -- any valid status (Defined in RT::Queue)
+ Status -- any valid status for Queue's Lifecycle, otherwises uses on_create from Lifecycle default
TimeEstimated -- an integer. estimated time for this task in minutes
TimeWorked -- an integer. time worked so far in minutes
TimeLeft -- an integer. time remaining in minutes
diff --git a/rt/lib/RT/Tickets.pm b/rt/lib/RT/Tickets.pm
index 2220a077f..cd5649dd9 100755
--- a/rt/lib/RT/Tickets.pm
+++ b/rt/lib/RT/Tickets.pm
@@ -1578,15 +1578,6 @@ sub _CustomFieldLimit {
}
if ( $cf && $cf->Type eq 'IPAddressRange' ) {
-
- if ( $value =~ /^\s*$RE{net}{CIDR}{IPv4}{-keep}\s*$/o ) {
-
- # convert incomplete 192.168/24 to 192.168.0.0/24 format
- $value =
- join( '.', map $_ || 0, ( split /\./, $1 )[ 0 .. 3 ] ) . "/$2"
- || $value;
- }
-
my ( $start_ip, $end_ip ) =
RT::ObjectCustomFieldValue->ParseIPRange($value);
if ( $start_ip && $end_ip ) {