Mailing List Archive

[svn] r893 - in RTx-Atom: . html/Atom/0.3 html/Atom/0.3/Add html/Atom/0.3/Describe html/Atom/0.3/Get html/Atom/0.3/Remove lib/RTx
Author: autrijus
Date: Fri May 14 12:36:00 2004
New Revision: 893

Modified:
RTx-Atom/ (props changed)
RTx-Atom/html/Atom/0.3/Add/index
RTx-Atom/html/Atom/0.3/Describe/Container
RTx-Atom/html/Atom/0.3/Get/Object
RTx-Atom/html/Atom/0.3/Get/Property
RTx-Atom/html/Atom/0.3/Remove/index
RTx-Atom/html/Atom/0.3/dhandler
RTx-Atom/lib/RTx/Atom.pod
Log:
----------------------------------------------------------------------
r4878@not: autrijus | 2004-05-14T16:35:59.439667Z

* Add 204 response for Add/Remove.
* Recognize specialized API, eg. AddCustomField and AddCustomFieldValue.
* Correctly return 404 for out-of-bound items.
----------------------------------------------------------------------


Modified: RTx-Atom/html/Atom/0.3/Add/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Add/index (original)
+++ RTx-Atom/html/Atom/0.3/Add/index Fri May 14 12:36:00 2004
@@ -1,7 +1,8 @@
+%# 204: Created, but the new object has no EditURI.
-%# (for subsequent Get/Update). Body is success message in text/plain.
+%# (for subsequent Get/Update).
<%INIT>
@@ -9,18 +10,30 @@
or return $m->comp($ShowError, Status => 404);

my %args = $m->request_args;
+$args{$1} = $2 while $Path =~ m{\G.*?(\w+)s/(\d+)/(?=\w)}g;
+
# XXX - factor away the creation defaults
$args{Requestor} ||= $session{CurrentUser}->Id
if $CollectionClass->isa('RT::Tickets');

-my ($status, $msg) = ($obj->Create( %args ))[0, -1];
+my @rv;
+if ($Path =~ /.*\b(\w+)s/ and $Object and my $code = $Object->can("Add$1")) {
+ @rv = $code->($Object, %args);
+ return $m->comp($ShowError, Status => 204) if $rv[0];
+}
+else {
+ @rv = $obj->Create( %args );
+}
+
if (my $id = $obj->Id) {
- $r->header_out(Location => "$FeedURI/$id");
+ $r->header_out(Location => "$BaseURI/$Path/$id");
return $m->comp($ShowError, Status => 303);
}
+
$r->content_type('text/plain');
$r->status(400);
-print $msg;
+
+print $rv[-1];
</%INIT>
<%ARGS>
$Path
@@ -32,6 +45,7 @@
$X

$Type
+$Object
$CollectionClass
$FeedURI
</%ARGS>

Modified: RTx-Atom/html/Atom/0.3/Describe/Container
==============================================================================
--- RTx-Atom/html/Atom/0.3/Describe/Container (original)
+++ RTx-Atom/html/Atom/0.3/Describe/Container Fri May 14 12:36:00 2004
@@ -3,8 +3,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
- <& $ShowLink, Relation => "service.post", URI => $FeedURI, Id => '!add', Title => $Type &>
- <& $ShowLink, Relation => "service.feed", URI => $FeedURI, Id => '!search', Title => $Type &>
+ <& $ShowLink, Relation => "service.post", URI => "$BaseURI/$Path", Id => '!add', Title => $Type &>
+ <& $ShowLink, Relation => "service.feed", URI => "$BaseURI/$Path", Id => '!search', Title => $Type &>
<entry>
<content type="text/xml" mode="xml">
% $Map->{action} = 'add';

Modified: RTx-Atom/html/Atom/0.3/Get/Object
==============================================================================
--- RTx-Atom/html/Atom/0.3/Get/Object (original)
+++ RTx-Atom/html/Atom/0.3/Get/Object Fri May 14 12:36:00 2004
@@ -26,7 +26,12 @@

$session{CurrentUser}->LanguageHandle('en-us');
my $handler = "/REST/1.0/Forms/$type/default";
-my $struct = $m->comp($handler, id => $Object->Id, fields => {})->[2];
+my $struct = eval { $m->comp($handler, id => $Object->Id, fields => {})->[2] };
+$struct ||= {
+ map +($_ => $Object->$_),
+ grep $Object->_ClassAccessible->{$_}{read},
+ keys %{$Object->_ClassAccessible}
+};
delete $session{CurrentUser}{LangHandle};

my $xml = $X->XMLout($struct);

Modified: RTx-Atom/html/Atom/0.3/Get/Property
==============================================================================
--- RTx-Atom/html/Atom/0.3/Get/Property (original)
+++ RTx-Atom/html/Atom/0.3/Get/Property Fri May 14 12:36:00 2004
@@ -21,6 +21,9 @@
return $m->comp($ShowError, Status => 303);
}

+$m->comp($ShowError, Status => 404)
+ unless $Object and $Object->can($Property);
+
$r->content_type('text/plain');
print $Object->$Property;
</%INIT>

Modified: RTx-Atom/html/Atom/0.3/Remove/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Remove/index (original)
+++ RTx-Atom/html/Atom/0.3/Remove/index Fri May 14 12:36:00 2004
@@ -1,5 +1,6 @@
-%# 200: Successfully deleted. Body is success message in text/plain.
-%# 400: Request failed. Body is error message in text/plain.
+%# 204: Successfully deleted.
+%# 400: Request failed. Body is error message.
+% return $m->comp($ShowError, Status => 400);

Modified: RTx-Atom/html/Atom/0.3/dhandler
==============================================================================
--- RTx-Atom/html/Atom/0.3/dhandler (original)
+++ RTx-Atom/html/Atom/0.3/dhandler Fri May 14 12:36:00 2004
@@ -274,7 +274,7 @@
my $list = $class->new($session{CurrentUser});
$list->UnLimit;

-my $obj;
+my ($obj, $prev_obj);

foreach my $part (@parts) {
if ($part =~ /^(\*(-)?)?(\d+)(?:\.(\w+))?$/) {
@@ -289,6 +289,7 @@
$list->GotoItem($id);
$obj = $list->Next;
}
+ return $m->comp('Elements/Error', Status => 404) if !$obj;
}
else {
$obj = $list->NewItem;
@@ -301,6 +302,8 @@
$obj->Load($1);
}
elsif ($part =~ /^([A-Z]\w*)(?:\.(\w+))?$/) {
+ $obj->can($1) or return $m->comp('Elements/Error', Status => 404);
+
$list = $obj->$1;

if ( ($property = $2) or !$list->can('UnLimit') ) {
@@ -308,6 +311,7 @@
undef $list;
}
else {
+ $prev_obj = $obj;
$property = $obj = undef;
}
}
@@ -325,6 +329,7 @@

# Can't allow cache to happen at all
eval {
+ $prev_obj = $obj if $obj;
$obj ||= $list->NewItem;
$obj->_expire( $obj->_gen_primary_cache_key());
$list->UnLimit unless $list->_isLimited;
@@ -353,7 +358,7 @@
"$verb/index", %ARGS,
Type => $type,
Resource => $resource,
- Object => $obj,
+ Object => $prev_obj || $obj,
Collection => $list,
Property => $property,
CollectionClass => ref($list),

Modified: RTx-Atom/lib/RTx/Atom.pod
==============================================================================
--- RTx-Atom/lib/RTx/Atom.pod (original)
+++ RTx-Atom/lib/RTx/Atom.pod Fri May 14 12:36:00 2004
@@ -315,7 +315,7 @@

Remove the specified object.

- 200: Successfully deleted. Body is success message.
+ 204: Successfully deleted.
400: Request failed. Body is the error message.
404: There is no object matching the specified URI.

@@ -344,8 +344,9 @@

Create a new object from the AtomEntry in the request's body.

+ 204: Created, but the new object has no EditURI.
303: Created. The 'Location' header is set to the new object's
- EditURI (for subsequent Get/Update). Body is success message.
+ EditURI (for subsequent Get/Update).
400: Request failed. Body is the error message.
404: There is no container matching the specified URI.

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