Beispiel #1
0
def dropbox_view_file(path, node_addon, auth, **kwargs):
    """Web view for the file detail page."""
    if not path:
        raise HTTPError(http.NOT_FOUND)
    # check that current user has access to the path
    if not is_authorizer(auth, node_addon):
        abort_if_not_subdir(path, node_addon.folder)
    node = node_addon.owner
    client = get_node_addon_client(node_addon)
    # Lazily create a file GUID record
    file_obj, created = DropboxFile.get_or_create(node=node, path=path)

    redirect_url = check_file_guid(file_obj)
    if redirect_url:
        return redirect(redirect_url)
    rev = request.args.get('rev') or ''
    rendered = render_dropbox_file(file_obj, client=client, rev=rev)
    cleaned_path = clean_path(path)
    response = {
        'revisions_url': node.api_url_for('dropbox_get_revisions',
            path=cleaned_path, rev=rev),  # Append current revision as a query param
        'file_name': get_file_name(path),
        'render_url': node.api_url_for('dropbox_render_file', path=cleaned_path),
        'download_url': file_obj.download_url(guid=True, rev=rev),
        'rendered': rendered,
    }
    response.update(serialize_node(node, auth, primary=True))
    return response, http.OK
Beispiel #2
0
    def get_waterbutler_render_url(self, path, rev=None, **kwargs):
        cleaned_path = clean_path(os.path.join(self.folder, path))
        url = furl.furl(
            self.owner.web_url_for('dropbox_view_file', path=cleaned_path))

        if rev:
            url.args['rev'] = rev

        return url.url
Beispiel #3
0
 def test_build_dropbox_urls_file(self):
     node = ProjectFactory()
     fake_metadata = mock_responses['metadata_single']
     result = utils.build_dropbox_urls(fake_metadata, node)
     path = utils.clean_path(fake_metadata['path'])
     assert_equal(result['download'],
                  node.web_url_for('dropbox_download', path=path))
     assert_equal(result['view'],
                  node.web_url_for('dropbox_view_file', path=path))
     assert_equal(result['delete'],
                  node.api_url_for('dropbox_delete_file', path=path))
Beispiel #4
0
 def get_or_create(cls, node, path):
     """Get or create a new file record. Return a tuple of the form (obj, created)
     """
     cleaned_path = clean_path(path)
     try:
         new = cls.find_one(
             Q('node', 'eq', node) & Q('path', 'eq', cleaned_path))
         created = False
     except ModularOdmException:
         # Create new
         new = cls(node=node, path=cleaned_path)
         new.save()
         created = True
     return new, created
Beispiel #5
0
 def create_waterbutler_log(self, auth, action, metadata):
     cleaned_path = clean_path(os.path.join(self.folder, metadata["path"]))
     url = self.owner.web_url_for("addon_view_or_download_file", path=cleaned_path, provider="dropbox")
     self.owner.add_log(
         "dropbox_{0}".format(action),
         auth=auth,
         params={
             "project": self.owner.parent_id,
             "node": self.owner._id,
             "path": metadata["path"],
             "folder": self.folder,
             "urls": {"view": url, "download": url + "?action=download"},
         },
     )
Beispiel #6
0
 def get_or_create(cls, node, path):
     """Get or create a new file record. Return a tuple of the form (obj, created)
     """
     cleaned_path = clean_path(path)
     try:
         new = cls.find_one(
             Q('node', 'eq', node) &
             Q('path', 'eq', cleaned_path)
         )
         created = False
     except ModularOdmException:
         # Create new
         new = cls(node=node, path=cleaned_path)
         new.save()
         created = True
     return new, created
Beispiel #7
0
 def create_waterbutler_log(self, auth, action, metadata):
     cleaned_path = clean_path(os.path.join(self.folder, metadata['path']))
     url = self.owner.web_url_for('addon_view_or_download_file', path=cleaned_path, provider='dropbox')
     self.owner.add_log(
         'dropbox_{0}'.format(action),
         auth=auth,
         params={
             'project': self.owner.parent_id,
             'node': self.owner._id,
             'path': metadata['path'],
             'folder': self.folder,
             'urls': {
                 'view': url,
                 'download': url + '?action=download'
             },
         },
     )
Beispiel #8
0
 def test_build_dropbox_urls_file(self):
     node = ProjectFactory()
     fake_metadata = mock_responses['metadata_single']
     result = utils.build_dropbox_urls(fake_metadata, node)
     path = utils.clean_path(fake_metadata['path'])
     assert_equal(
         result['download'],
         node.web_url_for('dropbox_download', path=path)
     )
     assert_equal(
         result['view'],
         node.web_url_for('dropbox_view_file', path=path)
     )
     assert_equal(
         result['delete'],
         node.api_url_for('dropbox_delete_file', path=path)
     )
Beispiel #9
0
 def create_waterbutler_log(self, auth, action, metadata):
     cleaned_path = clean_path(os.path.join(self.folder, metadata['path']))
     url = self.owner.web_url_for('addon_view_or_download_file',
                                  path=cleaned_path,
                                  provider='dropbox')
     self.owner.add_log(
         'dropbox_{0}'.format(action),
         auth=auth,
         params={
             'project': self.owner.parent_id,
             'node': self.owner._id,
             'path': cleaned_path,
             'folder': self.folder,
             'urls': {
                 'view': url,
                 'download': url + '?action=download'
             },
         },
     )
Beispiel #10
0
def dropbox_addon_folder(node_settings, auth, **kwargs):
    """Return the Rubeus/HGrid-formatted response for the root folder only."""
    # Quit if node settings does not have authentication
    if not node_settings.has_auth or not node_settings.folder:
        return None
    node = node_settings.owner
    path = clean_path(node_settings.folder)
    root = rubeus.build_addon_root(
        node_settings=node_settings,
        name=node_settings.folder,
        permissions=auth,
        nodeUrl=node.url,
        nodeApiUrl=node.api_url,
        urls={
            'upload': node.api_url_for('dropbox_upload',
                path=path),
            'fetch': node.api_url_for('dropbox_hgrid_data_contents',
                path=path)
        }
    )
    return [root]
Beispiel #11
0
 def find_or_create_file_guid(self, path):
     return DropboxFile.get_or_create(
         node=self.owner,
         path=clean_path(os.path.join(self.folder, path.lstrip('/'))),
     )
Beispiel #12
0
 def find_or_create_file_guid(self, path):
     return DropboxFile.get_or_create(
         self.owner, clean_path(os.path.join(self.folder,
                                             path.lstrip('/'))))
Beispiel #13
0
def test_clean_path():
    assert_equal(utils.clean_path('/'), '')
    assert_equal(utils.clean_path('/foo/bar/baz/'), 'foo/bar/baz')
    assert_equal(utils.clean_path(None), '')
Beispiel #14
0
def test_clean_path():
    assert_equal(utils.clean_path('/'), '')
    assert_equal(utils.clean_path('/foo/bar/baz/'), 'foo/bar/baz')
    assert_equal(utils.clean_path(None), '')