[Rt-commit] [svn] r878 - in RTx-Atom: . html/Atom/0.3 html/Atom/0.3/Add html/Atom/0.3/Get html/Atom/0.3/Search lib/RTx

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Wed May 12 09:05:43 EDT 2004


Author: autrijus
Date: Wed May 12 09:05:43 2004
New Revision: 878

Modified:
   RTx-Atom/   (props changed)
   RTx-Atom/html/Atom/0.3/Add/index
   RTx-Atom/html/Atom/0.3/Get/Property
   RTx-Atom/html/Atom/0.3/Search/index
   RTx-Atom/html/Atom/0.3/dhandler
   RTx-Atom/lib/RTx/Atom.pm
Log:
 ----------------------------------------------------------------------
 r4790 at not:  autrijus | 2004-05-12T13:04:52.264083Z
 
 * much better path walking.
 ----------------------------------------------------------------------
 r4791 at not:  autrijus | 2004-05-12T13:05:27.198874Z
 
 * use upper case "UTF-8".
 ----------------------------------------------------------------------


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	Wed May 12 09:05:43 2004
@@ -8,7 +8,12 @@
 my $obj = eval {$CollectionClass->new($session{CurrentUser})->NewItem}
     or return $m->comp($ShowError, Status => 404);
 
-my ($status, $msg) = ($obj->Create( $m->request_args ))[0, -1];
+my %args = $m->request_args;
+# XXX - factor away the creation defaults
+$args{Requestor} ||= $session{CurrentUser}->Id
+    if $CollectionClass->isa('RT::Tickets');
+
+my ($status, $msg) = ($obj->Create( %args ))[0, -1];
 if (my $id = $obj->Id) {
     $r->header_out(Location => "$FeedURI/$id");
     return $m->comp($ShowError, Status => 303);

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	Wed May 12 09:05:43 2004
@@ -1,18 +1,33 @@
 %# [GET EditURI]
 %# Retrieve a representation of an property.
 <%INIT>
-
-# Can't allow cache to happen at all
-eval { $Object->_expire( $Object->_gen_primary_cache_key()) };
+my $is_obj = ($Property =~ s/Obj$//);
 
 $Object->_ClassAccessible->{$Property}{read}
-    or return $m->comp($ShowError, Status => 404);
+    or $Property eq 'Id'
+    or return $m->comp($ShowError, Status => 404)
+    if $Object->can('_ClassAccessible');
+
+if ($is_obj) {
+    my $code = $Object->can($Property.'Obj')
+	or return $m->comp($ShowError, Status => 404);
+
+    my $obj = $code->($Object);
+    return $m->comp($ShowError, Status => 404)
+	unless ($obj and $obj->Id);
+
+    my $path = $obj->Table;
+    $r->header_out(Location => "$BaseURI/$path/".$obj->Id);
+    return $m->comp($ShowError, Status => 303);
+}
 
 $r->content_type('text/plain');
 print $Object->$Property;
 </%INIT>
 <%ARGS>
+$BaseURI
+$ShowError
+
 $Object
 $Property
-$ShowError
 </%ARGS>

Modified: RTx-Atom/html/Atom/0.3/Search/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Search/index	(original)
+++ RTx-Atom/html/Atom/0.3/Search/index	Wed May 12 09:05:43 2004
@@ -39,14 +39,12 @@
 </feed>
 <%INIT>
 
-my $List = $CollectionClass->new($session{CurrentUser});
+my $List = $Collection;
 
 if (defined($rows) and $List->isa('RT::Tickets')) {
     $List->FromSQL( $query || "Type = 'ticket'" );
 }
-else {
-    $List->UnLimit;
-}
+
 $List->RowsPerPage($rows) if $rows > 0;
 $List->GotoPage($page - 1) if $page > 0;
 
@@ -78,10 +76,10 @@
 $ShowEntry
 
 $Type
-$CollectionClass
+$Collection
 $FeedURI
 
-$rows => undef
+$rows => 10
 $page => 1
 $query => undef
 </%ARGS>

Modified: RTx-Atom/html/Atom/0.3/dhandler
==============================================================================
--- RTx-Atom/html/Atom/0.3/dhandler	(original)
+++ RTx-Atom/html/Atom/0.3/dhandler	Wed May 12 09:05:43 2004
@@ -190,6 +190,8 @@
 
 my ($type, @parts) = grep length, split('/', $path);
 $type =~ s{-}{::}g;
+my $property;
+$property = $1 if $type =~ s/\.(\w+)$//;
 
 my $verb = $Methods{$method} or return $m->comp(
     'Elements/Error',
@@ -218,7 +220,8 @@
 	# Redirect "safe" methods.
 	$path = join('/', $type, @parts);
 	my $query = $m->comp('/Elements/QueryString', $m->request_args);
-	$r->header_out(Location => "$BaseURI/$path?$query");
+	$query = "?$query" if length $query;
+	$r->header_out(Location => "$BaseURI/$path$query");
 	return $m->comp('Elements/Error', Status => 301);
     }
 }
@@ -250,10 +253,51 @@
     return $m->comp('Elements/Error', Status => 404);
 }
 
-my $obj = $class->new($session{CurrentUser})->NewItem;
-my ($id, $property) = ($1, $2) if $path =~ m{/(\d+)(?:\.(\w+))?$};
-$obj->Load($id) or return $m->comp('Elements/Error', Status => 404) if $id;
-my $resource = ($id ? $property ? 'Property' : 'Object' : 'Container');
+my $list = $class->new($session{CurrentUser});
+$list->UnLimit;
+
+my $obj;
+$obj = $list if $property;
+
+foreach my $part (@parts) {
+    if ($part =~ /^(\*)?(\d+)(?:\.(\w+))?$/) {
+        my $id = $2;
+	$property = $3;
+
+	if ($1) {
+	    $list->GotoItem($1);
+	    $obj = $list->Next;
+	}
+	else {
+	    $obj = $list->NewItem;
+	    $obj->Load($id);
+	}
+
+	return $m->comp('Elements/Error', Status => 404) unless $obj and $obj->Id;
+    }
+    elsif ($part =~ /^([A-Z]\w*)(?:\.(\w+))?$/) {
+	$list = $obj->$1;
+	if (ref($list) eq 'RT::Group') {
+	    $list = $list->UserMembersObj;
+	}
+	else {
+	    $list->UnLimit;
+	}
+	if ( ($property = $2) ) {
+	    $obj = $list;
+	}
+	else {
+	    $property = $obj = undef;
+	}
+    }
+    # Can't allow cache to happen at all
+    eval { $obj->_expire( $obj->_gen_primary_cache_key()) };
+}
+my $resource = ($obj ? $property ? 'Property' : 'Object' : 'Container');
+$obj ||= $list->NewItem;
+
+# Can't allow cache to happen at all
+eval { $obj->_expire( $obj->_gen_primary_cache_key()) };
 
 if ($resource eq 'Container') {
     # FeedURI on collection
@@ -269,8 +313,9 @@
     Type => $type,
     Resource => $resource,
     Object => $obj,
+    Collection => $list,
     Property => $property,
-    CollectionClass => $class,
+    CollectionClass => ref($list),
     FeedURI => "$BaseURI/$type",
     X => XML::Simple->new(RootName => 'body', NoIndent => 0),
 );

Modified: RTx-Atom/lib/RTx/Atom.pm
==============================================================================
--- RTx-Atom/lib/RTx/Atom.pm	(original)
+++ RTx-Atom/lib/RTx/Atom.pm	Wed May 12 09:05:43 2004
@@ -239,7 +239,7 @@
 =item Accept-Charset
 
 The character encoding expected by the client.  If unspecified, defaults
-to C<utf-8>.  If the requested encoding cannot represent certain codepoints
+to C<UTF-8>.  If the requested encoding cannot represent certain codepoints
 in the response, the server must use XML character references (C<&#xABCD;>)
 instead.
 


More information about the Rt-commit mailing list