コード例 #1
0
ファイル: config.py プロジェクト: KerryKDiehl/osf.io
def box_list_folders(node_addon, **kwargs):
    """Returns a list of folders in Box"""
    if not node_addon.has_auth:
        raise HTTPError(http.FORBIDDEN)

    node = node_addon.owner
    folder_id = request.args.get('folderId')

    if folder_id is None:
        return [{
            'id': '0',
            'path': 'All Files',
            'addon': 'box',
            'kind': 'folder',
            'name': '/ (Full Box)',
            'urls': {
                'folders': node.api_url_for('box_list_folders', folderId=0),
            }
        }]

    try:
        client = get_node_client(node)
    except BoxClientException:
        raise HTTPError(http.FORBIDDEN)

    try:
        metadata = client.get_folder(folder_id)
    except BoxClientException:
        raise HTTPError(http.NOT_FOUND)
    except MaxRetryError:
        raise HTTPError(http.BAD_REQUEST)

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

    folder_path = '/'.join(
        [
            x['name']
            for x in metadata['path_collection']['entries']
        ] + [metadata['name']]
    )

    return [
        {
            'addon': 'box',
            'kind': 'folder',
            'id': item['id'],
            'name': item['name'],
            'path': os.path.join(folder_path, item['name']),
            'urls': {
                'folders': node.api_url_for('box_list_folders', folderId=item['id']),
            }
        }
        for item in metadata['item_collection']['entries']
        if item['type'] == 'folder'
    ]
コード例 #2
0
ファイル: config.py プロジェクト: pazthor/osf.io
def box_list_folders(node_addon, **kwargs):
    """Returns a list of folders in Box"""
    if not node_addon.has_auth:
        raise HTTPError(http.FORBIDDEN)

    node = node_addon.owner
    folder_id = request.args.get('folderId')

    if folder_id is None:
        return [{
            'id': '0',
            'path': 'All Files',
            'addon': 'box',
            'kind': 'folder',
            'name': '/ (Full Box)',
            'urls': {
                'folders': node.api_url_for('box_list_folders', folderId=0),
            }
        }]

    try:
        client = get_node_client(node)
    except BoxClientException:
        raise HTTPError(http.FORBIDDEN)

    try:
        metadata = client.get_folder(folder_id)
    except BoxClientException:
        raise HTTPError(http.NOT_FOUND)
    except MaxRetryError:
        raise HTTPError(http.BAD_REQUEST)

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

    folder_path = '/'.join(
        [x['name']
         for x in metadata['path_collection']['entries']] + [metadata['name']])

    return [{
        'addon': 'box',
        'kind': 'folder',
        'id': item['id'],
        'name': item['name'],
        'path': os.path.join(folder_path, item['name']),
        'urls': {
            'folders': node.api_url_for('box_list_folders',
                                        folderId=item['id']),
        }
    } for item in metadata['item_collection']['entries']
            if item['type'] == 'folder']
コード例 #3
0
ファイル: config.py プロジェクト: njantrania/osf.io
def box_list_folders(node_addon, **kwargs):
    """Returns a list of folders in Box"""
    if not node_addon.has_auth:
        raise HTTPError(http.FORBIDDEN)

    node = node_addon.owner
    folder_id = request.args.get("folderId")

    if folder_id is None:
        return [
            {
                "id": "0",
                "path": "All Files",
                "addon": "box",
                "kind": "folder",
                "name": "/ (Full Box)",
                "urls": {"folders": node.api_url_for("box_list_folders", folderId=0)},
            }
        ]

    try:
        client = get_node_client(node)
    except BoxClientException:
        raise HTTPError(http.FORBIDDEN)

    try:
        metadata = client.get_folder(folder_id)
    except BoxClientException:
        raise HTTPError(http.NOT_FOUND)
    except MaxRetryError:
        raise HTTPError(http.BAD_REQUEST)

    # Raise error if folder was deleted
    if metadata.get("is_deleted"):
        raise HTTPError(http.NOT_FOUND)

    folder_path = "/".join([x["name"] for x in metadata["path_collection"]["entries"]] + [metadata["name"]])

    return [
        {
            "addon": "box",
            "kind": "folder",
            "id": item["id"],
            "name": item["name"],
            "path": os.path.join(folder_path, item["name"]),
            "urls": {"folders": node.api_url_for("box_list_folders", folderId=item["id"])},
        }
        for item in metadata["item_collection"]["entries"]
        if item["type"] == "folder"
    ]
コード例 #4
0
ファイル: test_client.py プロジェクト: XTech2K/osf.io
 def test_get_node_client(self):
     client = get_node_client(self.node)
     assert_true(isinstance(client, BoxClient))
コード例 #5
0
ファイル: test_client.py プロジェクト: dplorimer/osf
 def test_get_node_client(self):
     client = get_node_client(self.node)
     assert_true(isinstance(client, BoxClient))