コード例 #1
0
ファイル: models.py プロジェクト: rdm-dev12/RDM-osf.io
    def before_page_load(self, node, user):
        """
        :param Node node:
        :param User user:
        :return str: Alert message
        """
        if not self.configured:
            return []
        figshare = node.get_addon('figshare')
        # Quit if no user authorization

        node_permissions = 'public' if node.is_public else 'private'

        if figshare.folder_path == 'project':
            if node_permissions == 'private':
                message = messages.BEFORE_PAGE_LOAD_PRIVATE_NODE_MIXED_FS.format(
                    category=node.project_or_component,
                    project_id=figshare.folder_id)
                return [message]
            else:
                message = messages.BEFORE_PAGE_LOAD_PUBLIC_NODE_MIXED_FS.format(
                    category=node.project_or_component,
                    project_id=figshare.folder_id)

        connect = FigshareClient(self.external_account.oauth_key)
        try:
            project_is_public = connect.container_is_public(
                self.folder_id, self.folder_path)
        except HTTPError as e:
            if e.code == 403:
                return [messages.OAUTH_INVALID]
            elif e.code == 500:
                return [messages.FIGSHARE_INTERNAL_SERVER_ERROR]
            else:
                return [
                    messages.FIGSHARE_UNSPECIFIED_ERROR.format(
                        error_message=e.message)
                ]

        article_permissions = 'public' if project_is_public else 'private'

        if article_permissions != node_permissions:
            message = messages.BEFORE_PAGE_LOAD_PERM_MISMATCH.format(
                category=node.project_or_component,
                node_perm=node_permissions,
                figshare_perm=article_permissions,
                figshare_id=self.folder_id,
                folder_type=self.folder_path,
            )
            if article_permissions == 'private' and node_permissions == 'public':
                message += messages.BEFORE_PAGE_LOAD_PUBLIC_NODE_PRIVATE_FS.format(
                    folder_type=self.folder_path)
            # No HTML snippets, so escape message all at once
            return [markupsafe.escape(message)]
コード例 #2
0
ファイル: models.py プロジェクト: CenterForOpenScience/osf.io
    def handle_callback(self, response):
        """View called when the Oauth flow is completed. Adds a new BoxUserSettings
        record to the user and saves the user's access token and account info.
        """
        client = FigshareClient(response['access_token'])
        about = client.userinfo()

        return {
            'provider_id': about['id'],
            'display_name': u'{} {}'.format(about['first_name'], about.get('last_name')),
        }
コード例 #3
0
    def handle_callback(self, response):
        """View called when the Oauth flow is completed. Adds a new BoxUserSettings
        record to the user and saves the user's access token and account info.
        """
        client = FigshareClient(response['access_token'])
        about = client.userinfo()

        return {
            'provider_id': about['id'],
            'display_name': '{} {}'.format(about['first_name'], about.get('last_name')),
        }
コード例 #4
0
    def archive_errors(self):
        items = []
        if self.folder_path in ('article', 'fileset'):
            article = FigshareClient(self.external_account.oauth_key).article(self.folder_id)
            items = [article]
        else:
            project = FigshareClient(self.external_account.oauth_key).project(self.folder_id)
            items = project['articles'] if project else []
        private = any(
            [item for item in items if item['status'].lower() != 'public']
        )

        if private:
            return 'The figshare {folder_path} <strong>{folder_name}</strong> contains private content that we cannot copy to the registration. If this content is made public on figshare we should then be able to copy those files. You can view those files <a href="{url}" target="_blank">here.</a>'.format(
                folder_path=markupsafe.escape(self.folder_path),
                folder_name=markupsafe.escape(self.folder_name),
                url=self.owner.web_url_for('collect_file_trees'))
コード例 #5
0
ファイル: models.py プロジェクト: CenterForOpenScience/osf.io
    def before_page_load(self, node, user):
        """
        :param Node node:
        :param User user:
        :return str: Alert message
        """
        if not self.configured:
            return []
        figshare = node.get_addon('figshare')
        # Quit if no user authorization

        node_permissions = 'public' if node.is_public else 'private'

        if figshare.folder_path == 'project':
            if node_permissions == 'private':
                message = messages.BEFORE_PAGE_LOAD_PRIVATE_NODE_MIXED_FS.format(category=node.project_or_component, project_id=figshare.folder_id)
                return [message]
            else:
                message = messages.BEFORE_PAGE_LOAD_PUBLIC_NODE_MIXED_FS.format(category=node.project_or_component, project_id=figshare.folder_id)

        connect = FigshareClient(self.external_account.oauth_key)
        try:
            project_is_public = connect.container_is_public(self.folder_id, self.folder_path)
        except HTTPError as e:
            if e.code == 403:
                return [messages.OAUTH_INVALID]
            elif e.code == 500:
                return [messages.FIGSHARE_INTERNAL_SERVER_ERROR]
            else:
                return [messages.FIGSHARE_UNSPECIFIED_ERROR.format(error_message=e.message)]

        article_permissions = 'public' if project_is_public else 'private'

        if article_permissions != node_permissions:
            message = messages.BEFORE_PAGE_LOAD_PERM_MISMATCH.format(
                category=node.project_or_component,
                node_perm=node_permissions,
                figshare_perm=article_permissions,
                figshare_id=self.folder_id,
                folder_type=self.folder_path,
            )
            if article_permissions == 'private' and node_permissions == 'public':
                message += messages.BEFORE_PAGE_LOAD_PUBLIC_NODE_PRIVATE_FS.format(folder_type=self.folder_path)
            # No HTML snippets, so escape message all at once
            return [markupsafe.escape(message)]
コード例 #6
0
 def credentials_are_valid(self, user_settings, client):
     if user_settings:
         client = client or FigshareClient.from_account(user_settings.external_accounts[0])
         try:
             client.userinfo()
         except Exception:
             return False
         else:
             return True
     return False
コード例 #7
0
 def credentials_are_valid(self, user_settings, client):
     if user_settings:
         client = client or FigshareClient.from_account(
             user_settings.external_accounts[0])
         try:
             client.userinfo()
         except Exception:
             return False
         else:
             return True
     return False
コード例 #8
0
    def set_folder(self, folder_id, auth):
        try:
            info = FigshareClient(self.external_account.oauth_key).get_linked_folder_info(folder_id)
        except HTTPError as e:
            raise exceptions.InvalidFolderError(e.message)

        self.folder_id = info['id']
        self.folder_name = info['name']
        self.folder_path = info['path']
        self.save()

        self.nodelogger.log(action='folder_selected', save=True)
コード例 #9
0
ファイル: models.py プロジェクト: rdm-dev12/RDM-osf.io
 def get_folders(self, **kwargs):
     return FigshareClient(self.external_account.oauth_key).get_folders()