Mailing List Archive

rt branch, 5.0/rest2-efficiently-get-ticket-attachment-list, repushed
The branch 5.0/rest2-efficiently-get-ticket-attachment-list was deleted and repushed:
was ac085f9cd432e062dc328b7be5ca675aeaf12382
now cc82acb8044d3733d6211fca301701f427c17a8f

1: ac085f9cd4 ! 1: cc82acb804 Add the REST2 endpoint: GET /ticket/:id/attachments?field=F1,F2,...,Fn
@@ -5,9 +5,6 @@
This endpoint returns a list of attachments associated with a ticket; the
"fields" query parameter lets you select which fields to return for each
attachment.
-
- This endpoint only returns non-empty attachments; as such, it won't return
- multipart wrappers.

diff --git a/lib/RT/REST2.pm b/lib/RT/REST2.pm
--- a/lib/RT/REST2.pm
@@ -21,6 +18,20 @@
+
GET /attachment/:id
retrieve an attachment
+
+
+diff --git a/lib/RT/REST2/Resource.pm b/lib/RT/REST2/Resource.pm
+--- a/lib/RT/REST2/Resource.pm
++++ b/lib/RT/REST2/Resource.pm
+@@
+
+ push @{ $result }, values %values if %values;
+ }
+-
++ } elsif ($field eq 'ContentLength' && $item->can('ContentLength')) {
++ $result = $item->ContentLength;
+ } elsif ($item->can('_Accessible') && $item->_Accessible($field => 'read')) {
+ # RT::Record derived object, so we can check access permissions.


diff --git a/lib/RT/REST2/Resource/Attachments.pm b/lib/RT/REST2/Resource/Attachments.pm
@@ -41,9 +52,10 @@
+ ),
+}
+
-+# Get a collection of non-empty attachments associated with a ticket
-+# This code was put into a subroutine as it was a little long to
-+# put inline above and maintain readability.
++# Get a collection of attachments associated with a ticket This code
++# was put into a subroutine as it was a little long to put inline
++# above and maintain readability.
++
+sub _get_ticket_attachments
+{
+ my ($match, $req) = @_;
@@ -61,7 +73,6 @@
+ return { collection => $attachments } unless $ticket->CurrentUserHasRight('ShowTicket');
+
+ $attachments->LimitByTicket($id);
-+ $attachments->LimitNotEmpty();
+ return { collection => $attachments };
}

@@ -76,39 +87,56 @@

+# Check the GET /ticket/:id/attachments endpoint
+{
-+ my $res = $mech->get("$rest_base_path/ticket/$ticket_id/attachments?fields=Subject,Filename,ContentType",
-+ 'Authorization' => $auth);
-+ is ($res->code, 200);
++ my $res = $mech->get(
++ "$rest_base_path/ticket/$ticket_id/attachments?fields=Subject,Filename,ContentType,ContentLength",
++ 'Authorization' => $auth
++ );
++ is( $res->code, 200 );
+
-+ # We get three attachments instead of 4 because the
-+ # /ticket/:id/attachments endpoint suppresses empty attachments;
-+ # we won't see the multipart/mixed wrapper.
-+ cmp_deeply($mech->json_response,
-+ { per_page => 20,
-+ pages => 1,
-+ total => 3,
-+ page => 1,
-+ count => 3,
-+ items => [.
-+ {type => 'attachment',
-+ Subject => '',
-+ _url => re( qr/^https?:/ ),
-+ ContentType => 'text/html',
-+ Filename => '',
-+ id => re(qr/^\d+$/)},
-+ {type => 'attachment',
-+ Subject => '',
-+ _url => re( qr/^https?:/ ),
-+ ContentType => 'image/png',
-+ Filename => 'image.png',
-+ id => re(qr/^\d+$/)},
-+ {type => 'attachment',
-+ Subject => '',
-+ _url => re( qr/^https?:/ ),
-+ ContentType => 'text/plain',
-+ Filename => 'password',
-+ id => re(qr/^\d+$/)},
-+ ]}, 'Got expected attachment list');
++ cmp_deeply(
++ $mech->json_response,
++ { per_page => 20,
++ pages => 1,
++ total => 4,
++ page => 1,
++ count => 4,
++ items => [.
++ { type => 'attachment',
++ Subject => 'HTML comment with PNG image and text file',
++ _url => re(qr/^https?:/),
++ ContentType => 'multipart/mixed',
++ ContentLength => 0,
++ Filename => '',
++ id => re(qr/^\d+$/)
++ },
++ { type => 'attachment',
++ Subject => '',
++ _url => re(qr/^https?:/),
++ ContentType => 'text/html',
++ ContentLength => 31,
++ Filename => '',
++ id => re(qr/^\d+$/)
++ },
++ { type => 'attachment',
++ Subject => '',
++ _url => re(qr/^https?:/),
++ ContentType => 'image/png',
++ ContentLength => 3929,
++ Filename => 'image.png',
++ id => re(qr/^\d+$/)
++ },
++ { type => 'attachment',
++ Subject => '',
++ _url => re(qr/^https?:/),
++ ContentType => 'text/plain',
++ ContentLength => 19,
++ Filename => 'password',
++ id => re(qr/^\d+$/)
++ },
++ ]
++ },
++ 'Got expected attachment list'
++ );
+}
+
# Comment ticket with image attachment and no content through JSON Base64

_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit