Example #1
0
def dropbox_hgrid_data_contents(node_addon, auth, **kwargs):
    """Return the Rubeus/HGrid-formatted response for a folder's contents.

    Takes optional query parameters `foldersOnly` (only return folders) and
    `includeRoot` (include the root folder).
    """
    # No folder, just return an empty list of data
    node = node_addon.owner
    path = kwargs.get('path', '')

    if 'root' in request.args:
        return [{
            'kind': rubeus.FOLDER,
            'path': '/',
            'name': '/ (Full Dropbox)',
            'urls': {
                'folders': node.api_url_for('dropbox_hgrid_data_contents'),
            }
        }]

    # Verify that path is a subdirectory of the node's shared folder
    if not is_authorizer(auth, node_addon):
        abort_if_not_subdir(path, node_addon.folder)

    permissions = {
        'edit': node.can_edit(auth) and not node.is_registration,
        'view': node.can_view(auth)
    }
    client = get_node_client(node)
    file_not_found = HTTPError(http.NOT_FOUND,
                               data=dict(message_short='File not found',
                                         message_long='The Dropbox file '
                                         'you requested could not be found.'))

    max_retry_error = HTTPError(
        http.REQUEST_TIMEOUT,
        data=dict(message_short='Request Timeout',
                  message_long='Dropbox could not be reached '
                  'at this time.'))

    try:
        metadata = client.metadata(path)
    except ErrorResponse:
        raise file_not_found
    except MaxRetryError:
        raise max_retry_error

    # Raise error if folder was deleted
    if metadata.get('is_deleted'):
        raise file_not_found

    return [
        metadata_to_hgrid(file_dict, node, permissions)
        for file_dict in metadata['contents'] if file_dict['is_dir']
    ]
Example #2
0
def dropbox_hgrid_data_contents(node_addon, auth, **kwargs):
    """Return the Rubeus/HGrid-formatted response for a folder's contents.

    Takes optional query parameters `foldersOnly` (only return folders) and
    `includeRoot` (include the root folder).
    """
    # No folder, just return an empty list of data
    node = node_addon.owner
    path = kwargs.get('path', '')

    if 'root' in request.args:
        return [{
            'kind': rubeus.FOLDER,
            'path': '/',
            'name': '/ (Full Dropbox)',
            'urls': {
                'folders': node.api_url_for('dropbox_hgrid_data_contents'),
            }
        }]

    # Verify that path is a subdirectory of the node's shared folder
    if not is_authorizer(auth, node_addon):
        abort_if_not_subdir(path, node_addon.folder)

    permissions = {
        'edit': node.can_edit(auth) and not node.is_registration,
        'view': node.can_view(auth)
    }
    client = get_node_client(node)
    file_not_found = HTTPError(http.NOT_FOUND, data=dict(message_short='File not found',
                                                  message_long='The Dropbox file '
                                                  'you requested could not be found.'))

    max_retry_error = HTTPError(http.REQUEST_TIMEOUT, data=dict(message_short='Request Timeout',
                                                   message_long='Dropbox could not be reached '
                                                   'at this time.'))

    try:
        metadata = client.metadata(path)
    except ErrorResponse:
        raise file_not_found
    except MaxRetryError:
        raise max_retry_error

    # Raise error if folder was deleted
    if metadata.get('is_deleted'):
        raise file_not_found

    return [
        metadata_to_hgrid(file_dict, node, permissions) for
        file_dict in metadata['contents'] if file_dict['is_dir']
    ]
Example #3
0
 def test_get_node_client(self):
     client = get_node_client(self.node)
     assert_true(isinstance(client, DropboxClient))