=== modified file 'dashboard_app/xmlrpc.py'
@@ -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):
"""