def _folder_data(self, folder_id):
        # Split out from set_folder for ease of testing, due to
        # outgoing requests. Should only be called by set_folder
        try:
            Provider(self.external_account).refresh_oauth_key(force=True)
        except InvalidGrantError:
            raise exceptions.InvalidAuthError()
        try:
            oauth = OAuth2(client_id=settings.BOX_KEY,
                           client_secret=settings.BOX_SECRET,
                           access_token=ensure_str(
                               self.external_account.oauth_key))
            client = Client(oauth)
            folder_data = client.folder(self.folder_id).get()
        except BoxAPIException:
            raise exceptions.InvalidFolderError()

        folder_name = folder_data['name'].replace('All Files',
                                                  '') or '/ (Full Box)'
        folder_path = '/'.join([
            x['name']
            for x in folder_data['path_collection']['entries'] if x['name']
        ] + [folder_data['name']]).replace('All Files', '') or '/'

        return folder_name, folder_path
示例#2
0
    def get_folders(self, path=None, folder_id=None, **kwargs):
        """
        Returns Zotero folders at any level.
        Top level are group/personal libraries.  Secondary levels are folders within those libraries.
        If path (also known as library id) is specified, then folders are returned from that specific library.

        If no path(library) specified, then all libraries are returned.
        """
        if self.has_auth:
            if path:
                return self.get_sub_folders(path, folder_id)
            else:
                return self.get_top_level_folders(**kwargs)
        else:
            raise exceptions.InvalidAuthError()
示例#3
0
    def get_folders(self, **kwargs):
        try:
            containers = get_container_names(self)
        except:
            raise exceptions.InvalidAuthError()

        return [{
            'addon': 'swift',
            'kind': 'folder',
            'id': container,
            'name': container,
            'path': container,
            'urls': {
                'folders': ''
            }
        } for container in containers]
示例#4
0
    def get_folders(self, **kwargs):
        # This really gets only containers, not subfolders,
        # as that's all we want to be linkable on a node.
        try:
            containers = get_container_names(self)
        except:
            raise exceptions.InvalidAuthError()

        return [{
            'addon': 'azureblobstorage',
            'kind': 'folder',
            'id': container,
            'name': container,
            'path': container,
            'urls': {
                'folders': ''
            }
        } for container in containers]
示例#5
0
    def get_folders(self, **kwargs):
        # This really gets only buckets, not subfolders,
        # as that's all we want to be linkable on a node.
        try:
            buckets = get_bucket_names(self)
        except:
            raise exceptions.InvalidAuthError()

        return [{
            'addon': 's3',
            'kind': 'folder',
            'id': bucket,
            'name': bucket,
            'path': bucket,
            'urls': {
                'folders': ''
            }
        } for bucket in buckets]
 def get_folders(self, **kwargs):
     if not self.has_auth:
         raise exceptions.InvalidAuthError()
     else:
         connection = GitHubClient(external_account=self.external_account)
         # Since /user/repos excludes organization repos to which the
         # current user has push access, we have to make extra requests to
         # find them
         try:
             repo_data = [{
                 'addon': 'github',
                 'kind': 'repo',
                 'id': repo.id,
                 'name': repo.name,
                 'path': os.path.join(repo.owner.login, repo.name)
             } for repo in connection.repos()]
         except GitHubError:
             repo_data = []
         return repo_data
示例#7
0
    def _folder_data(self, folder_id):
        # Split out from set_folder for ease of testing, due to
        # outgoing requests. Should only be called by set_folder
        try:
            Provider(self.external_account).refresh_oauth_key(force=True)
        except InvalidGrantError:
            raise exceptions.InvalidAuthError()
        try:
            client = BoxClient(self.external_account.oauth_key)
            folder_data = client.get_folder(self.folder_id)
        except BoxClientException:
            raise exceptions.InvalidFolderError()

        folder_name = folder_data['name'].replace('All Files', '') or '/ (Full Box)'
        folder_path = '/'.join(
            [x['name'] for x in folder_data['path_collection']['entries'] if x['name']] +
            [folder_data['name']]
        ).replace('All Files', '') or '/'

        return folder_name, folder_path
示例#8
0
 def get_folders(self, show_root=False, **kwargs):
     if self.has_auth:
         try:
             folders = self.api._get_folders()
             serialized_root_folder = {
                 'name': 'All Documents',
                 'provider_list_id': None,
                 'id': 'ROOT',
                 'parent_list_id': '__',
                 'kind': 'folder',
                 'addon': 'mendeley'
             }
             serialized_folders = [{
                 'addon':
                 'mendeley',
                 'kind':
                 'folder',
                 'id':
                 folder.json['id'],
                 'name':
                 folder.json['name'],
                 'path':
                 folder.json.get('parent_id', '/'),
                 'parent_list_id':
                 folder.json.get('parent_id', None),
                 'provider_list_id':
                 folder.json['id']
             } for folder in folders]
             if show_root:
                 serialized_folders.insert(0, serialized_root_folder)
             return serialized_folders
         except MendeleyApiException as error:
             sentry.log_exception()
             sentry.log_message(
                 'Unexpected Mendeley Error when fetching folders.')
             raise HTTPError(error.status)
     else:
         raise exceptions.InvalidAuthError()