[Rt-commit] [svn] r790 - in rt: . branches/rt-3.3/html/REST/2.0 branches/rt-3.3/html/REST/2.0/Auth branches/rt-3.3/html/REST/2.0/Create branches/rt-3.3/html/REST/2.0/Delete branches/rt-3.3/html/REST/2.0/Error branches/rt-3.3/html/REST/2.0/Get branches/rt-3.3/html/REST/2.0/Search branches/rt-3.3/html/REST/2.0/Update

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Sat May 1 09:22:21 EDT 2004


Author: autrijus
Date: Sat May  1 09:22:21 2004
New Revision: 790

Added:
   rt/branches/rt-3.3/html/REST/2.0/Auth/
   rt/branches/rt-3.3/html/REST/2.0/Create/
   rt/branches/rt-3.3/html/REST/2.0/Delete/
   rt/branches/rt-3.3/html/REST/2.0/Error/
   rt/branches/rt-3.3/html/REST/2.0/Error/index
   rt/branches/rt-3.3/html/REST/2.0/Get/
   rt/branches/rt-3.3/html/REST/2.0/Search/
   rt/branches/rt-3.3/html/REST/2.0/Search/index
   rt/branches/rt-3.3/html/REST/2.0/Update/
   rt/branches/rt-3.3/html/REST/2.0/index
Modified:
   rt/   (props changed)
   rt/branches/rt-3.3/html/REST/2.0/dhandler
Log:
 ----------------------------------------------------------------------
 r4335 at not:  autrijus | 2004-05-01T13:20:56.570615Z
 
 * Establish directory layout.
 * Error handling.
 * Refactor out the 'Search' verb.
 
 ----------------------------------------------------------------------


Added: rt/branches/rt-3.3/html/REST/2.0/Error/index
==============================================================================
--- (empty file)
+++ rt/branches/rt-3.3/html/REST/2.0/Error/index	Sat May  1 09:22:21 2004
@@ -0,0 +1,8 @@
+<%INIT>
+$r->content_type('text/html');
+$r->status($Status);
+$m->abort($Status);
+</%INIT>
+<%ARGS>
+$Status => 500
+</%ARGS>

Added: rt/branches/rt-3.3/html/REST/2.0/Search/index
==============================================================================
--- (empty file)
+++ rt/branches/rt-3.3/html/REST/2.0/Search/index	Sat May  1 09:22:21 2004
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/css" href="<% $RT::WebPath %>/REST/2.0/NoAuth/feed.css"?>
+<feed version="0.3" xmlns="http://purl.org/atom/ns#">
+  <title>Search result on <% $Type %></title>
+  <author>
+    <name><% $RT::Organization %></name>
+    <url><% $RT::WebURL %></url>
+  </author>
+  <link rel="alternate" type="text/html" href="<% $RT::WebURL %>"/>
+  <tagline mode="escaped"><% $count %> results found.</tagline>
+  <id>rt-fsck.com://<% $Path %></id>
+  <modified><% $modified %></modified>
+  <generator url="http://www.bestpractical.com/rt/" version="<% $RT::VERSION %>">RT</generator>
+% foreach my $entry (@entries) {
+  <entry>
+    <title mode="escaped"><% $entry->{Name} %></title>
+    <link rel="alternate" type="text/html" href="$RT::WebPath/$Type/Display.html?id=<% $entry->{Id} %>"/>
+    <modified><% $entry->{LastUpdated} %></modified>
+    <issued><% $entry->{Created} %></issued>
+    <created><% $entry->{Created} %></created>
+    <id>rt-fsck.com:$RT::rtname/<% $entry->{Id} %></id>
+    <summary mode="escaped"><% $entry->{Description} %></summary>
+    <content type="text/plain" mode="escaped"><% $entry->{Content} %></content>
+  </entry>
+% }
+</feed>
+<%INIT>
+my $Collection = $CollectionClass->new($session{CurrentUser});
+$Collection->UnLimit;
+my $count = $Collection->Count;
+
+$r->content_type('text/xml');
+
+my $entries = '';
+
+my $now = RT::Date->new;
+$now->SetToNow;
+my $modified = $now->W3CDTF;
+
+my @entries;
+
+while (my $entry = $Collection->Next) {
+    my %entry = map { $_ => eval { $entry->$_ } || '' }
+	qw(Id Name Description Content);
+    $entry{Created} = $entry->CreatedObj->W3CDTF;
+    $entry{Created} =~ s/ /T/;
+    $entry{LastUpdated} = $entry->LastUpdatedObj->W3CDTF;
+    $entry{LastUpdated} =~ s/ /T/;
+    push @entries, \%entry;
+}
+
+</%INIT>
+<%ARGS>
+$Path
+$Type
+$CollectionClass
+</%ARGS>

Modified: rt/branches/rt-3.3/html/REST/2.0/dhandler
==============================================================================
--- rt/branches/rt-3.3/html/REST/2.0/dhandler	(original)
+++ rt/branches/rt-3.3/html/REST/2.0/dhandler	Sat May  1 09:22:21 2004
@@ -117,9 +117,6 @@
     #	last; # system clock differ by more than one day, oops!
     # }
 
-    delete $INC{'RT/CurrentUser.pm'};
-    require RT::CurrentUser;
-
     require MIME::Base64;
     $auth_nonce = MIME::Base64::decode_base64($auth_nonce);
 
@@ -131,71 +128,41 @@
     $nonce_cache->set( $auth_nonce, 1 );
 }
 
-if ($CurrentUser and $CurrentUser->Id) {
-    # XXX - do proper delegation goes here
+if (!$CurrentUser or !$CurrentUser->Id) {
+    $m->comp('Error/index', Status => 401);
+}
+
+$session{CurrentUser} = $CurrentUser;
 
-    my $path = $m->dhandler_arg;
-    my $type = ucfirst(lc($path));
-    $type =~ s{/.*}{};
-    $type =~ s{s$}{};
-
-    require "RT/${type}s.pm";
-    my $collection = "RT::${type}s"->new($CurrentUser);
-    $collection->UnLimit;
-    my $count = $collection->Count;
-
-    $r->content_type('text/xml; charset=utf-8');
-    my $entries = '';
-
-    my $now = RT::Date->new;
-    $now->SetToNow;
-    my $modified = $now->W3CDTF;
-
-    while (my $entry = $collection->Next) {
-	my %entry = map { $_ => eval { $entry->$_ } || '' }
-	    qw(Id Name Description Content);
-        $entry{Created} = $entry->CreatedObj->W3CDTF;
-        $entry{Created} =~ s/ /T/;
-        $entry{LastUpdated} = $entry->LastUpdatedObj->W3CDTF;
-        $entry{LastUpdated} =~ s/ /T/;
-    
-	$entries .= <<".";
-  <entry>
-    <title mode="escaped">$entry{Name}</title>
-    <link rel="alternate" type="text/html" href="$RT::WebPath/$type/Display.html?id=$entry{Id}"/>
-    <modified>$entry{LastUpdated}</modified>
-    <issued>$entry{Created}</issued>
-    <created>$entry{Created}</created>
-    <id>rt-fsck.com:$RT::rtname/$entry{Id}</id>
-    <summary mode="escaped">$entry{Description}</summary>
-    <content type="text/plain" mode="escaped" xml:base="http://diveintomark.org/archives/2004/04/19/feed-parser-beta-22">
-      <![CDATA[$entry{Content}]]>
-    </content>
-  </entry>
-.
-    }
-    print << ".";
-<?xml version="1.0" encoding="utf-8"?>
-<?xml-stylesheet type="text/css" href="$RT::WebPath/REST/2.0/NoAuth/feed.css"?>
-<feed version="0.3" xmlns="http://purl.org/atom/ns#">
-  <title>\u$type search results</title>
-  <author>
-    <name>$RT::Organization</name>
-    <url>$RT::WebURL</url>
-  </author>
-  <link rel="alternate" type="text/html" href="$RT::WebURL"/>
-  <tagline mode="escaped">$count results found.</tagline>
-  <id>rt-fsck.com://$path</id>
-  <modified>$modified</modified>
-  <generator url="http://www.bestpractical.com/rt/" version="$RT::VERSION">RT</generator>
-  $entries
-</feed>
-.
+# TODO: Redirect /template to /templates
+
+my $path = $m->dhandler_arg;
+my $type = lc($path);
+$type =~ s{/.*}{};
+$type =~ s{-}{/};
+
+my $class;
+foreach my $key (keys %INC) {
+    $key =~ m{^RTx?(?:/.+)?/($type).pm}i or next;
+    $type = $1;
+    $class = $key;
+    $class =~ s{.pm$}{}i;
+    $class =~ s{/}{::}g;
+    $class->can('UnLimit') or (undef $class, next);
+    last;
 }
-else {
-    $r->status(401);
+
+if (!$class) {
+    return $m->comp('index') if $path =~ /index|^\W*$/i;
+    return $m->comp('Error/index', Status => 404);
 }
 
+$m->comp(
+    'Search/index', %ARGS,
+    Path => $path,
+    Type => $type,
+    CollectionClass => $class,
+);
 </%INIT>
 <%FLAGS>
 inherit	=> undef

Added: rt/branches/rt-3.3/html/REST/2.0/index
==============================================================================
--- (empty file)
+++ rt/branches/rt-3.3/html/REST/2.0/index	Sat May  1 09:22:21 2004
@@ -0,0 +1 @@
+%# XXX - Put service links to all actions and objects here


More information about the Rt-commit mailing list