[Rt-commit] rt branch, 4.2/rest-search-refactor, repushed
? sunnavy
sunnavy at bestpractical.com
Thu Nov 14 10:51:48 EST 2013
The branch 4.2/rest-search-refactor was deleted and repushed:
was eec3a130dad800a2c5a42bf5f862f5450d3b84ce
now 1fa9c23dfb9386dab689c8443de621b1e6de778d
1: 9786818 < --: ------- refactor the orderby code: old code uses eval and is weird
2: 5e4f141 = 1: 7404f3a prepare to support restful searches for queues, users and groups
3: b45e7e8 ! 2: af00e71 restful search support for queues/users/groups
@@ -247,7 +247,8 @@
+ $objects->Limit(
+ FIELD => $field,
+ OPERATOR => uc $op,
-+ VALUE => $value
++ VALUE => $value,
++ CASESENSITIVE => 0,
+ );
+ }
+ else {
4: 70014ea ! 3: 1d15587 merge restful ticket search to dhandler to avoid replicated code
@@ -41,7 +41,8 @@
- $objects->Limit(
- FIELD => $field,
- OPERATOR => uc $op,
-- VALUE => $value
+- VALUE => $value,
+- CASESENSITIVE => 0,
- );
+ if ( $type eq 'ticket' ) {
+ my ( $n, $s );
@@ -70,7 +71,8 @@
+ $objects->Limit(
+ FIELD => $field,
+ OPERATOR => uc $op,
-+ VALUE => $value
++ VALUE => $value,
++ CASESENSITIVE => 0,
+ );
+ }
+ else {
@@ -109,7 +111,7 @@
else {
diff --git a/share/html/REST/1.0/search/ticket b/share/html/REST/1.0/search/ticket
-deleted file mode 100755
+deleted file mode 100644
--- a/share/html/REST/1.0/search/ticket
+++ /dev/null
@@
@@ -117,7 +119,7 @@
-%#
-%# COPYRIGHT:
-%#
--%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+-%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
-%# <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
@@ -203,6 +205,29 @@
-eval {
- ($n, $s) = $tickets->FromSQL($query);
-};
+-
+-if ($orderby) {
+- my %args;
+-
+- my $order = substr($orderby, 0, 1);
+- if ($order eq '+' || $order eq '-') {
+- # remove the +/- sorting sigil
+- substr($orderby, 0, 1, '');
+-
+- if ($order eq '+') {
+- $args{ORDER} = 'ASC';
+- }
+- elsif ($order eq '-') {
+- $args{ORDER} = 'DESC';
+- }
+- }
+-
+- $tickets->OrderBy(
+- FIELD => $orderby,
+- %args,
+- );
+-}
+-
-if ($@ || $n == 0) {
- $s ||= $@;
- $status = "400 Bad request";
@@ -210,43 +235,37 @@
- goto OUTPUT;
-}
-
--if ($orderby) {
-- my ($order, $field) = $orderby =~ /^([\+\-])?(.+)/;
-- $order = $order && $order eq '-' ? 'DESC' : 'ASC';
-- $tickets->OrderBy( FIELD => $field, ORDER => $order );
--}
--
-$n = 0;
-my @output;
-while (my $ticket = $tickets->Next) {
- $n++;
-
-- my $id = $ticket->Id;
+- my $id = $ticket->Id;
- if ($format eq "i") {
- $output .= "ticket/" . $id . "\n";
- }
- elsif ($format eq "s") {
-- if ($fields) {
-- my $result = $m->comp("/REST/1.0/Forms/ticket/default", id => $id, format => $format, fields => \%fields);
-- my ($notes, $order, $key_values, $errors) = @$result;
-- # If it's the first time through, add our header
-- if ($n == 1) {
-- $output .= join("\t",@$order)."\n";
-- }
-- # Cut off the annoying ticket/ before the id;
-- $key_values->{'id'} = $id;
-- $output .= join("\t", map { ref $key_values->{$_} eq 'ARRAY' ?
--join( ', ', @{$key_values->{$_}} ) : $key_values->{$_} } @$order)."\n";
--
--
-- } else {
-- $output .= $ticket->Id . ": ". $ticket->Subject . "\n";
-- }
+- if ($fields) {
+- my $result = $m->comp("/REST/1.0/Forms/ticket/default", id => $id, format => $format, fields => \%fields);
+- my ($notes, $order, $key_values, $errors) = @$result;
+- # If it's the first time through, add our header
+- if ($n == 1) {
+- $output .= join("\t",@$order)."\n";
+- }
+- # Cut off the annoying ticket/ before the id;
+- $key_values->{'id'} = $id;
+- $output .= join("\t", map {
+- ref $key_values->{$_} eq 'ARRAY'
+- ? join( ', ', @{$key_values->{$_}} )
+- : $key_values->{$_} } @$order)."\n";
+- } else {
+- $output .= $ticket->Id . ": ". $ticket->Subject . "\n";
+- }
- }
- else {
- my $d = $m->comp("/REST/1.0/Forms/ticket/default", id => $id, format => $format, fields => \%fields);
- my ($c, $o, $k, $e) = @$d;
-- push @output, [ $c, $o, $k ];
+- push @output, [ $c, $o, $k ];
- }
-}
-if ($n == 0 && $format ne "i") {
5: ab289b2 = 4: 3489bde clean some replicated code
6: c91aeea = 5: a3310a6 shouldn't allow user to search password field
7: a68af35 = 6: debbccd allow restful user search only if current user has AdminUsers right
8: 9f76037 = 7: c06ae90 search user defined groups only
9: 862b6b8 = 8: ed96938 whitelist of restful search fields
10: ea91ca2 = 9: 96c6f12 allow < and > ops too
12: 749f765 = 10: ed5a660 REST: show Disabled column for queues/groups
13: eec3a13 ! 11: f80a254 REST: handle Disabled column search for queues/groups/users
@@ -9,16 +9,17 @@
if ( $field && $op && defined $value ) {
+-
+- $objects->Limit(
+- FIELD => $field,
+- OPERATOR => uc $op,
+- VALUE => $value,
+- CASESENSITIVE => 0,
+- );
+ if ( $field eq 'Disabled' ) {
+ if ($value) {
+ $objects->FindAllRows;
+ if ( $type eq 'queue' ) {
-
-- $objects->Limit(
-- FIELD => $field,
-- OPERATOR => uc $op,
-- VALUE => $value
-- );
+ # special case for queue that
+ # Disabled could be 2(___Approvals)
+ $objects->Limit(
@@ -33,7 +34,8 @@
+ $objects->Limit(
+ FIELD => $field,
+ OPERATOR => uc $op,
-+ VALUE => $value
++ VALUE => $value,
++ CASESENSITIVE => 0,
+ );
+ }
}
@@ -53,3 +55,4 @@
map { lc $_ => 1 }
grep { $RT::Record::_TABLE_ATTR->{'RT::Group'}{$_}{read} }
keys %{ $RT::Record::_TABLE_ATTR->{'RT::Group'} }
+
11: 600c037 ! 12: 1fa9c23 tests for restful search of queue/group/user
@@ -7,10 +7,9 @@
--- /dev/null
+++ b/t/web/rest-search-group.t
@@
-+#!/usr/bin/env perl
+use strict;
+use warnings;
-+use RT::Test tests => 18;
++use RT::Test tests => undef;
+
+my $group_foo = RT::Group->new($RT::SystemUser);
+$group_foo->CreateUserDefinedGroup( Name => 'foo' );
@@ -92,16 +91,17 @@
+
+}
+
++undef $m;
++done_testing();
diff --git a/t/web/rest-search-queue.t b/t/web/rest-search-queue.t
new file mode 100644
--- /dev/null
+++ b/t/web/rest-search-queue.t
@@
-+#!/usr/bin/env perl
+use strict;
+use warnings;
-+use RT::Test tests => 20;
++use RT::Test tests => undef;
+
+my $queue_foo = RT::Test->load_or_create_queue( Name => 'foo' );
+my $queue_bar = RT::Test->load_or_create_queue( Name => 'bar' );
@@ -147,19 +147,19 @@
+
+search_queues_ok(
+ { query => '', orderby => 'name' },
-+ [ '1: General', $queue_bar->id . ': bar', $queue_foo->id . ': foo' ],
++ [ $queue_bar->id . ': bar', $queue_foo->id . ': foo', '1: General', ],
+ 'order by name'
+);
+
+search_queues_ok(
+ { query => '', orderby => '+name' },
-+ [ '1: General', $queue_bar->id . ': bar', $queue_foo->id . ': foo' ],
++ [ $queue_bar->id . ': bar', $queue_foo->id . ': foo', '1: General', ],
+ 'order by +name'
+);
+
+search_queues_ok(
+ { query => '', orderby => '-name' },
-+ [ $queue_foo->id . ': foo', $queue_bar->id . ': bar', '1: General', ],
++ [ '1: General', $queue_foo->id . ': foo', $queue_bar->id . ': bar', ],
+ 'order by -name'
+);
+
@@ -181,16 +181,17 @@
+
+}
+
++undef $m;
++done_testing();
diff --git a/t/web/rest-search-user.t b/t/web/rest-search-user.t
new file mode 100644
--- /dev/null
+++ b/t/web/rest-search-user.t
@@
-+#!/usr/bin/env perl
+use strict;
+use warnings;
-+use RT::Test tests => 23;
++use RT::Test tests => undef;
+
+my $root = RT::Test->load_or_create_user( Name => 'root', );
+my $user_foo = RT::Test->load_or_create_user(
@@ -287,4 +288,5 @@
+
+}
+
-
++undef $m;
++done_testing();
More information about the rt-commit
mailing list