[Rt-commit] rt branch, 5.0/rest2-add-asset-and-transaction-sql-endpoints, repushed
Craig Kaiser
craig at bestpractical.com
Thu Mar 4 17:34:20 EST 2021
The branch 5.0/rest2-add-asset-and-transaction-sql-endpoints was deleted and repushed:
was 07c9f268dc3d3ac9f83b574b62f6d760d2abf9e0
now 90cf24e37742d5c7c56bd6a3865e8ac656a28b75
1: 8e9addf313 ! 1: fddc958fec Add RT::REST2::Collection::QueryBySQL role
@@ -21,9 +21,25 @@
--- a/lib/RT/REST2/Resource/Collection.pm
+++ b/lib/RT/REST2/Resource/Collection.pm
@@
+ use Module::Runtime qw( require_module );
+ use RT::REST2::Util qw( serialize_record expand_uid format_datetime );
+ use POSIX qw( ceil );
++use RT::REST2::Util qw( error_as_json );
+
+ has 'collection_class' => (
+ is => 'ro',
+@@
$collection->{'find_disabled_rows'} = 1
if $self->request->param('find_disabled_rows');
++ if ( $self->can('limit_collection_from_json') ) {
++ $self->limit_collection_from_json();
++ }
++ if ( $self->can('limit_collection_from_sql') ) {
++ my ($ret, $msg) = $self->limit_collection_from_sql();
++ return error_as_json( $self->response, $ret, $msg ) unless $ret;
++ }
++
+ my @orderby_cols;
+ my @orders = $self->request->param('order');
+ foreach my $orderby ($self->request->param('orderby')) {
@@ -34,13 +50,6 @@
+ }
+ $self->collection->OrderByCols(@orderby_cols)
+ if @orderby_cols;
-+
-+ if ( $self->can('query_json') && scalar @{$self->query_json} ) {
-+ return $self->limit_collection_from_json();
-+ }
-+ elsif ( $self->can('query_sql') && $self->query_sql ) {
-+ return $self->limit_collection_from_sql();
-+ }
+
return 1;
}
@@ -85,9 +94,18 @@
my $collection = $self->collection;
- my $query = $self->query;
+ my $query = $self->query_json;
++
++ return unless ref $query eq 'ARRAY' && scalar @{$query};
++
my @fields = $self->searchable_fields;
my %searchable = map {; $_ => 1 } @fields;
+- $collection->{'find_disabled_rows'} = 1
+- if $self->request->param('find_disabled_rows');
+-
+ for my $limit (@$query) {
+ next unless $limit->{field}
+ and $searchable{$limit->{field}}
@@
);
}
@@ -168,13 +186,12 @@
+use namespace::autoclean;
+
+use Encode qw( decode_utf8 );
-+use RT::REST2::Util qw( error_as_json );
+
+requires 'collection';
+
+has 'query_sql' => (
+ is => 'ro',
-+ isa => 'Str|ArrayRef[HashRef]',
++ isa => 'Str',
+ required => 1,
+ lazy_build => 1,
+);
@@ -186,41 +203,16 @@
+ if ( $self->request->method eq 'GET' && $self->request->param('query') ) {
+ $query_sql = decode_utf8($self->request->param('query') || "");
+ }
-+ elsif ( $self->request->method eq 'GET' ) {
-+ my $content = $self->request->param('query');
-+ return "" unless $content;
-+
-+ eval { $query_sql = JSON::decode_json($content); };
-+ return "" if $@;
-+ }
-+ elsif ( $self->request->method eq 'POST' ) {
-+ my $content = $self->request->content;
-+ return "" unless $content;
-+
-+ eval { $query_sql = JSON::decode_json($content); };
-+ return "" if $@;
-+ }
+
+ return $query_sql;
+}
+
+sub limit_collection_from_sql {
+ my $self = shift;
++ return 1 unless $self->query_sql;
+
+ my ($ok, $msg) = $self->collection->FromSQL( $self->query_sql );
-+ return error_as_json( $self->response, 0, $msg ) unless $ok;
-+
-+ my @orderby_cols;
-+ my @orders = $self->request->param('order');
-+ foreach my $orderby ($self->request->param('orderby')) {
-+ $orderby = decode_utf8($orderby);
-+ my $order = shift @orders || 'ASC';
-+ $order = uc(decode_utf8($order));
-+ $order = 'ASC' unless $order eq 'DESC';
-+ push @orderby_cols, {FIELD => $orderby, ORDER => $order};
-+ }
-+ $self->collection->OrderByCols(@orderby_cols)
-+ if @orderby_cols;
++ return ( 0, $msg ) unless $ok;
+
+ return 1;
+};
2: 258baf1819 = 2: 3eb0917e37 Preserve first_row and show_rows across the CleanSlate
3: 8064bb200a = 3: bc3c1e62e1 Add test for REST2 assetSQL search
4: 07c9f268dc = 4: 90cf24e377 Add test for REST2 transactionSQL search
More information about the rt-commit
mailing list