Author: sevein
Date: Sun Oct  9 23:20:25 2011
New Revision: 9999

Log:
Save user object as a request property to make it available under SWORD plugin 
actions, add a generateResponse function to avoid code repetition

Modified:
   trunk/plugins/qtSwordPlugin/lib/qtSwordPluginHttpAuthFilter.class.php
   
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
   
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/templates/depositSuccess.xml.php

Modified: trunk/plugins/qtSwordPlugin/lib/qtSwordPluginHttpAuthFilter.class.php
==============================================================================
--- trunk/plugins/qtSwordPlugin/lib/qtSwordPluginHttpAuthFilter.class.php       
Sun Oct  9 21:56:05 2011        (r9998)
+++ trunk/plugins/qtSwordPlugin/lib/qtSwordPluginHttpAuthFilter.class.php       
Sun Oct  9 23:20:25 2011        (r9999)
@@ -40,9 +40,7 @@
       }
 
       // We'll need username/email details later
-      $request = sfContext::getInstance()->request;
-      $request->setAttribute('username', $user->username);
-      $request->setAttribute('email', $user->email);
+      sfContext::getInstance()->request->setAttribute('user', $user);
     }
 
     $filterChain->execute();

Modified: 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
==============================================================================
--- 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
   Sun Oct  9 21:56:05 2011        (r9998)
+++ 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/actions/depositAction.class.php
   Sun Oct  9 23:20:25 2011        (r9999)
@@ -17,6 +17,17 @@
  * along with Qubit Toolkit.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+// TODO
+// Check user authorization
+// Check upload limit
+// Check 'Content-Type'
+// Check 'Content-Length' ?
+// Check attatchment size, zero?
+// Save the file temporary // Open the package (METS support?), get metadata 
and digital objects
+// Create persistent objects in the database
+// Generate routes and response with links, depositSuccess, etc...
+// Complete XML error documents (see templates/error/*)
+
 class qtSwordPluginDepositAction extends sfAction
 {
   public function execute($request)
@@ -25,22 +36,23 @@
     // QubitResourceroute throws 404 exception before this is executed
     $this->resource = $this->getRoute()->resource;
 
+    $this->user = $request->getAttribute('user');
+
     if ($request->isMethod('post'))
     {
+      /* TODO: it is not working properly, see QubitAcl error
+      if (QubitAcl::check(QubitInformationObject::getRoot(), 'create', 
array('user' => $this->user)))
+      {
+        return $this->generateResponse(403);
+      }
+      */
+
       $this->packaging = $request->getHttpHeader('X-Packaging');
 
       // Check if the packaging format is supported
       if (!in_array($this->packaging, qtSwordPluginConfiguration::$packaging))
       {
-        // HTTP status code 415: Unsupported Media Type
-        $this->response->setStatusCode('415');
-
-        $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
-
-        $request->setRequestFormat('xml');
-        $this->setTemplate('error/ErrorContent');
-
-        return;
+        return $this->generateResponse(415, 'error/ErrorContent');
       }
 
       // TODO: Mediation (see [2])
@@ -53,14 +65,7 @@
       // Clarify that we don't support this extension yet
       if ('true' == $request->getHttpHeader('X-No-Op'))
       {
-        $this->response->setStatusCode('400');
-
-        $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
-
-        $request->setRequestFormat('xml');
-        $this->setTemplate('error/ErrorBadRequest');
-
-        return;
+        return $this->generateResponse(400, 'error/ErrorBadRequest');
       }
 
       // Package content
@@ -77,20 +82,10 @@
         $package_name = 'foobar';
       }
 
-      // 'Content-Type'
-      // 'Content-Length'
-
       // Calculated MD5 check does not match the value provided by the client
       if (md5($package_content) != $request->getHttpHeader('Content-MD5'))
       {
-        $this->response->setStatusCode('412');
-
-        $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
-
-        $request->setRequestFormat('xml');
-        $this->setTemplate('error/ErrorChecksumMismatchSuccess');
-
-        return;
+        return $this->generateResponse(412, 
'error/ErrorChecksumMismatchSuccess');
       }
 
       // Create tmp dir, if it doesn't exist already
@@ -101,15 +96,6 @@
         chmod($tmpDir, 0775);
       }
 
-      // TODO
-      // Check user authorization
-      // Check upload limit
-      // Save the file temporary
-      // Open the package (METS support?), get metadata and digital objects
-      // Create persistent objects in the database
-      // Generate routes and response with links, depositSuccess, etc...
-      // Complete XML error documents (see templates/error/*)
-
       // HTTP status code 201: Created
       $this->response->setStatusCode('201');
 
@@ -119,14 +105,27 @@
     else if ($request->isMethod('put') || $request->isMethod('delete'))
     {
       // TODO: Editing and deleting resources, not implemented
-      // HTTP status code 501, Not Implemented
-      $this->response->setStatusCode('501');
-
-      return;
+      return $this->generateResponse(501);
     }
+    else
+    {
+      return $this->generateResponse(400, 'error/ErrorBadRequest');
+    }
+  }
 
-    $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
+  protected function generateResponse($code, $template = null, array $headers 
= array())
+  {
+    $this->response->setStatusCode($code);
+
+    if ($template !== null)
+    {
+      $this->request->setRequestFormat('xml');
+
+      $this->response->setHttpHeader('Content-Type', 'application/atom+xml; 
charset="utf-8"');
+
+      $this->setTemplate($template);
+    }
 
-    $request->setRequestFormat('xml');
+    return null;
   }
 }

Modified: 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/templates/depositSuccess.xml.php
==============================================================================
--- 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/templates/depositSuccess.xml.php
  Sun Oct  9 21:56:05 2011        (r9998)
+++ 
trunk/plugins/qtSwordPlugin/modules/qtSwordPlugin/templates/depositSuccess.xml.php
  Sun Oct  9 23:20:25 2011        (r9999)
@@ -8,7 +8,7 @@
 
   <updated>2008-08-18T14:27:08Z</updated>
 
-  <author><name><?php echo $sf_request->getAttribute('username') 
?></name></author>
+  <author><name><?php echo $user->username ?></name></author>
 
   <?php
     /*

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to