[Rt-commit] r9155 - in rt/branches/3.6-EXPERIMENTAL-CLI: bin
html/REST/1.0/Forms/ticket
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Sep 26 05:47:28 EDT 2007
Author: sunnavy
Date: Wed Sep 26 05:47:18 2007
New Revision: 9155
Modified:
rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in
rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default
rt/branches/3.6-EXPERIMENTAL-CLI/lib/t/regression/26command_line.t
Log:
cf multiple value field now do the right way in cli
Modified: rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in (original)
+++ rt/branches/3.6-EXPERIMENTAL-CLI/bin/rt.in Wed Sep 26 05:47:18 2007
@@ -1327,11 +1327,41 @@
my ($word, @words);
my @values = ref $val eq 'ARRAY' ? @$val : $val;
- foreach my $line (map {split /\n/} @values) {
+ foreach my $line ( map { split /\n/ } @values ) {
+
# XXX: This should become a real parser, à la Text::ParseWords.
$line =~ s/^\s+//;
$line =~ s/\s+$//;
- push @words, split /\s*,\s*/, $line;
+ my ( $a, $b ) = split /,/, $line, 2;
+
+ while ($a) {
+ no warnings 'uninitialized';
+ if ( $a =~ /^'/ ) {
+ my $s = $a;
+ while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
+ && $a =~ /(\\)+'$/ )) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ push @words, $s;
+ }
+ elsif ( $a =~ /^q{/ ) {
+ my $s = $a;
+ while ( $a !~ /}$/ ) {
+ ( $a, $b ) =
+ split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^q{/'/;
+ $s =~ s/}/'/;
+ push @words, $s;
+ }
+ else {
+ push @words, $a;
+ }
+ ( $a, $b ) = split /,/, $b, 2;
+ }
+
}
return \@words;
Modified: rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default (original)
+++ rt/branches/3.6-EXPERIMENTAL-CLI/html/REST/1.0/Forms/ticket/default Wed Sep 26 05:47:18 2007
@@ -217,8 +217,21 @@
next unless (!%$fields || (exists $fields->{"cf-".lc $cf->Name}));
my $vals = $ticket->CustomFieldValues($cf->Id());
my @out = ();
- while (my $v = $vals->Next()) {
- push @out, $v->Content;
+ if ( $cf->SingleValue ) {
+ my $v = $vals->Next;
+ push @out, $v->Content if $v;
+ }
+ else {
+ while (my $v = $vals->Next()) {
+ my $content = $v->Content;
+ $content =~ s/'/\\'/g;
+ if ( $v->Content =~ /,/ ) {
+ push @out, q{'} . $content . q{'};
+ }
+ else {
+ push @out, $content;
+ }
+ }
}
push @data, [ 'CF-' . $cf->Name => join ',', @out ];
}
@@ -313,9 +326,77 @@
$s = "Unknown custom field.";
}
else {
- ($n, $s) = $ticket->AddCustomFieldValue(
+ my $vals = $ticket->CustomFieldValues($cf->id);
+
+ if ( $cf->SingleValue ) {
+ my $old = $vals->Next;
+ if ( $old ) {
+ if ( $val ne $old->Content ) {
+ $old->Delete;
+ ($n, $s) = $ticket->AddCustomFieldValue(
+ Field => $cf, Value => $val );
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ else {
+ ($n, $s) = $ticket->AddCustomFieldValue(
Field => $cf, Value => $val );
- $s =~ s/^# // if defined $s;
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ else {
+ my @new;
+ my ( $a, $b ) = split /,/, $val, 2;
+ while ($a) {
+ no warnings 'uninitialized';
+ if ( $a =~ /^'/ ) {
+ my $s = $a;
+ while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
+ && $a =~ /(\\)+'$/ ) ) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^'//;
+ $s =~ s/'$//;
+ $s =~ s/\\'/'/g;
+ push @new, $s;
+ }
+ elsif ( $a =~ /^q{/ ) {
+ my $s = $a;
+ while ( $a !~ /}$/ ) {
+ ( $a, $b ) = split /,/, $b, 2;
+ $s .= ',' . $a;
+ }
+ $s =~ s/^q{//;
+ $s =~ s/}//;
+ push @new, $s;
+ }
+ else {
+ push @new, $a;
+ }
+ ( $a, $b ) = split /,/, $b, 2;
+ }
+
+ my %new;
+ $new{$_}++ for @new;
+
+ while (my $v = $vals->Next()) {
+ my $c = $v->Content;
+ if ( $new{$c} ) {
+ $new{$c}--;
+ }
+ else {
+ $v->Delete();
+ }
+ }
+ for ( @new ) {
+ while ( $new{$_} && $new{$_}-- ) {
+ ($n, $s) = $ticket->AddCustomFieldValue(
+ Field => $cf, Value => $_ );
+ $s =~ s/^# // if defined $s;
+ }
+ }
+ }
}
}
elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
Modified: rt/branches/3.6-EXPERIMENTAL-CLI/lib/t/regression/26command_line.t
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-CLI/lib/t/regression/26command_line.t (original)
+++ rt/branches/3.6-EXPERIMENTAL-CLI/lib/t/regression/26command_line.t Wed Sep 26 05:47:18 2007
@@ -3,7 +3,7 @@
use strict;
use Test::Expect;
#use Test::More qw/no_plan/;
-use Test::More tests => 216;
+use Test::More tests => 269;
use RT;
RT::LoadConfig();
@@ -100,6 +100,10 @@
($val,$msg) = $othercf->Create(Name => 'My CF'.$$, Type => 'FreeformSingle', Queue => $queue_id);
ok($val,$msg);
+my $multiple_cf = RT::CustomField->new($RT::SystemUser);
+($val,$msg) = $multiple_cf->Create(Name => 'MultipleCF'.$$, Type =>
+ 'FreeformMultiple', Queue => $queue_id);
+ok($val,$msg);
# add a comment to ticket
@@ -163,6 +167,65 @@
expect_send("show ticket/$ticket_id -f 'CF-my CF$$'", 'Checking new value');
expect_like(qr/my CF$$: VALUE/i, 'Verified change');
+# Test reading and setting single value custom field with commas or quotes
+expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking initial value');
+expect_like(qr/myCF$$:/i, 'Verified change');
+expect_send("edit ticket/$ticket_id set CF-myCF$$=1,2,3", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed cf');
+expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value');
+expect_like(qr/myCF$$: 1,2,3/i, 'Verified change');
+expect_send("edit ticket/$ticket_id set CF-myCF$$=\"1's,2,3\"", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed cf');
+expect_send("show ticket/$ticket_id -f CF-myCF$$", 'Checking new value');
+expect_like(qr/myCF$$: 1's,2,3/i, 'Verified change');
+
+# Test reading and setting custom fields with multiple values
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking initial value');
+expect_like(qr/CF-MultipleCF$$:/i, 'Verified multiple cf change');
+expect_send("edit ticket/$ticket_id set CF-MultipleCF$$=1,2,3 ", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: 1,\s*2,\s*3/i, 'Verified multiple cf change');
+expect_send("edit ticket/$ticket_id set CF-MultipleCF$$=a,b,c ", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: a,\s*b,\s*c/i, 'Verified change');
+expect_send("edit ticket/$ticket_id del CF-MultipleCF$$=a", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'del multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: b,\s*c/i, 'Verified multiple cf change');
+expect_send("edit ticket/$ticket_id add CF-MultipleCF$$=o", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: b,\s*c,\s*o/i, 'Verified multiple cf change');
+
+expect_send("edit ticket/$ticket_id set CF-MultipleCF$$=\"'a,b,c'\" ", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: 'a,b,c'/i, 'Verified change');
+expect_send("edit ticket/$ticket_id del CF-MultipleCF$$=a", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: 'a,b,c'/i, 'Verified change');
+
+expect_send("edit ticket/$ticket_id set CF-MultipleCF$$=q{a,b,c}", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: 'a,b,c'/i, 'Verified change');
+expect_send("edit ticket/$ticket_id del CF-MultipleCF$$=a", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: 'a,b,c'/i, 'Verified change');
+expect_send("edit ticket/$ticket_id del CF-MultipleCF$$=\"'a,b,c'\"", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: \s*$/i, 'Verified change');
+
+expect_send("edit ticket/$ticket_id set CF-MultipleCF$$=\"q{1,2's,3}\"", 'Changing CF...');
+expect_like(qr/Ticket $ticket_id updated/, 'Changed multiple cf');
+expect_send("show ticket/$ticket_id -f CF-MultipleCF$$", 'Checking new value');
+expect_like(qr/CF-MultipleCF$$: '1,2\\'s,3'/i, 'Verified change');
+
# ...
# change a ticket's ...[other properties]...
# ...
@@ -440,4 +503,6 @@
expect_is($attachment_content,"Attachment contains original text");
}
+
+
1;
More information about the Rt-commit
mailing list