diff mbox

[Branch,~linaro-validation/lava-dashboard/trunk] Rev 252: add a put_ex xmlrpc method that returns the URL of the bundle rather than its sha1

Message ID 20110817211613.9637.43504.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Aug. 17, 2011, 9:16 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-dashboard/put-return-url/+merge/71806
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 252 [merge]
committer: Michael-Doyle Hudson <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Thu 2011-08-18 09:14:27 +1200
message:
  add a put_ex xmlrpc method that returns the URL of the bundle rather than its sha1
modified:
  dashboard_app/xmlrpc.py


--
lp:lava-dashboard
https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk

You are subscribed to branch lp:lava-dashboard.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'dashboard_app/xmlrpc.py'
--- dashboard_app/xmlrpc.py	2011-07-22 01:04:53 +0000
+++ dashboard_app/xmlrpc.py	2011-08-17 10:33:41 +0000
@@ -25,6 +25,7 @@ 
 import xmlrpclib
 
 from django.contrib.auth.models import User, Group
+from django.core.urlresolvers import reverse
 from django.db import IntegrityError, DatabaseError
 from linaro_django_xmlrpc.models import (
     ExposedAPI,
@@ -91,59 +92,7 @@ 
         """
         return ".".join(map(str, __version__))
 
-    @xml_rpc_signature('str', 'str', 'str', 'str')
-    def put(self, content, content_filename, pathname):
-        """
-        Name
-        ----
-        `put` (`content`, `content_filename`, `pathname`)
-
-        Description
-        -----------
-        Upload a bundle to the server.
-
-        Arguments
-        ---------
-        `content`: string
-            Full text of the bundle. This *SHOULD* be a valid JSON
-            document and it *SHOULD* match the "Dashboard Bundle Format
-            1.0" schema. The SHA1 of the content *MUST* be unique or a
-            ``Fault(409, "...")`` is raised. This is used to protect
-            from simple duplicate submissions.
-        `content_filename`: string
-            Name of the file that contained the text of the bundle. The
-            `content_filename` can be an arbitrary string and will be
-            stored along with the content for reference.
-        `pathname`: string
-            Pathname of the bundle stream where a new bundle should
-            be created and stored. This argument *MUST* designate a
-            pre-existing bundle stream or a ``Fault(404, "...")`` exception
-            is raised. In addition the user *MUST* have access
-            permission to upload bundles there or a ``Fault(403, "...")``
-            exception is raised. See below for access rules.
-
-        Return value
-        ------------
-        If all goes well this function returns the SHA1 of the content.
-
-        Exceptions raised
-        -----------------
-        404
-            Either:
-
-                - Bundle stream not found
-                - Uploading to specified stream is not permitted
-        409
-            Duplicate bundle content
-
-        Rules for bundle stream access
-        ------------------------------
-        The following rules govern bundle stream upload access rights:
-            - all anonymous streams are accessible
-            - personal streams are accessible to owners
-            - team streams are accessible to team members
-
-        """
+    def _put(self, content, content_filename, pathname):
         try:
             logging.debug("Getting bundle stream")
             bundle_stream = BundleStream.objects.accessible_by_principal(self.user).get(pathname=pathname)
@@ -163,8 +112,125 @@ 
         else:   
             logging.debug("Deserializing bundle")
             bundle.deserialize()
-            logging.debug("Returning content_sha1")
-            return bundle.content_sha1
+            return bundle
+
+    @xml_rpc_signature('str', 'str', 'str', 'str')
+    def put(self, content, content_filename, pathname):
+        """
+        Name
+        ----
+        `put` (`content`, `content_filename`, `pathname`)
+
+        Description
+        -----------
+        Upload a bundle to the server.
+
+        Arguments
+        ---------
+        `content`: string
+            Full text of the bundle. This *SHOULD* be a valid JSON
+            document and it *SHOULD* match the "Dashboard Bundle Format
+            1.0" schema. The SHA1 of the content *MUST* be unique or a
+            ``Fault(409, "...")`` is raised. This is used to protect
+            from simple duplicate submissions.
+        `content_filename`: string
+            Name of the file that contained the text of the bundle. The
+            `content_filename` can be an arbitrary string and will be
+            stored along with the content for reference.
+        `pathname`: string
+            Pathname of the bundle stream where a new bundle should
+            be created and stored. This argument *MUST* designate a
+            pre-existing bundle stream or a ``Fault(404, "...")`` exception
+            is raised. In addition the user *MUST* have access
+            permission to upload bundles there or a ``Fault(403, "...")``
+            exception is raised. See below for access rules.
+
+        Return value
+        ------------
+        If all goes well this function returns the SHA1 of the content.
+
+        Exceptions raised
+        -----------------
+        404
+            Either:
+
+                - Bundle stream not found
+                - Uploading to specified stream is not permitted
+        409
+            Duplicate bundle content
+
+        Rules for bundle stream access
+        ------------------------------
+        The following rules govern bundle stream upload access rights:
+            - all anonymous streams are accessible
+            - personal streams are accessible to owners
+            - team streams are accessible to team members
+
+        """
+        bundle = self._put(content, content_filename, pathname)
+        logging.debug("Returning bundle SHA1")
+        return bundle.content_sha1
+
+    @xml_rpc_signature('str', 'str', 'str', 'str')
+    def put_ex(self, content, content_filename, pathname):
+        """
+        Name
+        ----
+        `put` (`content`, `content_filename`, `pathname`)
+
+        Description
+        -----------
+        Upload a bundle to the server.  A variant on put_ex that returns the
+        URL of the bundle instead of its SHA1.
+
+        Arguments
+        ---------
+        `content`: string
+            Full text of the bundle. This *SHOULD* be a valid JSON
+            document and it *SHOULD* match the "Dashboard Bundle Format
+            1.0" schema. The SHA1 of the content *MUST* be unique or a
+            ``Fault(409, "...")`` is raised. This is used to protect
+            from simple duplicate submissions.
+        `content_filename`: string
+            Name of the file that contained the text of the bundle. The
+            `content_filename` can be an arbitrary string and will be
+            stored along with the content for reference.
+        `pathname`: string
+            Pathname of the bundle stream where a new bundle should
+            be created and stored. This argument *MUST* designate a
+            pre-existing bundle stream or a ``Fault(404, "...")`` exception
+            is raised. In addition the user *MUST* have access
+            permission to upload bundles there or a ``Fault(403, "...")``
+            exception is raised. See below for access rules.
+
+        Return value
+        ------------
+        If all goes well this function returns the full URL of the bundle.
+
+        Exceptions raised
+        -----------------
+        404
+            Either:
+
+                - Bundle stream not found
+                - Uploading to specified stream is not permitted
+        409
+            Duplicate bundle content
+
+        Rules for bundle stream access
+        ------------------------------
+        The following rules govern bundle stream upload access rights:
+            - all anonymous streams are accessible
+            - personal streams are accessible to owners
+            - team streams are accessible to team members
+
+        """
+        bundle = self._put(content, content_filename, pathname)
+        logging.debug("Returning permalink to bundle")
+        return self._context.request.build_absolute_uri(
+            reverse(
+                'dashboard_app.views.redirect_to_bundle',
+                kwargs={'content_sha1':bundle.content_sha1}))
 
     def get(self, content_sha1):
         """