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' ]
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']
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" ]
def test_get_node_client(self): client = get_node_client(self.node) assert_true(isinstance(client, BoxClient))