当前位置: 首页>>代码示例>>Python>>正文


Python rubeus.build_addon_root函数代码示例

本文整理汇总了Python中website.util.rubeus.build_addon_root函数的典型用法代码示例。如果您正苦于以下问题:Python build_addon_root函数的具体用法?Python build_addon_root怎么用?Python build_addon_root使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了build_addon_root函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_build_addon_root_has_correct_upload_limits

    def test_build_addon_root_has_correct_upload_limits(self):
        self.node_settings.config.max_file_size = 10
        self.node_settings.config.high_max_file_size = 20

        node = self.project
        user = self.project.creator
        auth = Auth(user)
        permissions = {
            'view': node.can_view(auth),
            'edit': node.can_edit(auth) and not node.is_registration,
        }

        result = rubeus.build_addon_root(
            self.node_settings,
            self.node_settings.bucket,
            permissions=permissions,
            user=user
        )

        assert_equal(result['accept']['maxSize'], self.node_settings.config.max_file_size)

        # user now has elevated upload limit
        user.system_tags.append('high_upload_limit')
        user.save()

        result = rubeus.build_addon_root(
            self.node_settings,
            self.node_settings.bucket,
            permissions=permissions,
            user=user
        )
        assert_equal(
            result['accept']['maxSize'],
            self.node_settings.config.high_max_file_size
        )
开发者ID:cldershem,项目名称:osf.io,代码行数:35,代码来源:test_rubeus.py

示例2: dataverse_hgrid_root

def dataverse_hgrid_root(node_addon, auth, **kwargs):
    node = node_addon.owner
    user_settings = node_addon.user_settings

    default_version = 'latest-published'
    version = 'latest-published' if not node.can_edit(auth) else default_version

    # Quit if no dataset linked
    if not node_addon.complete:
        return []

    can_edit = node.can_edit(auth)

    permissions = {
        'edit': can_edit and not node.is_registration,
        'view': node.can_view(auth)
    }

    try:
        connection = connect_from_settings(user_settings)
        dataverse = get_dataverse(connection, node_addon.dataverse_alias)
        dataset = get_dataset(dataverse, node_addon.dataset_doi)
    except SSLError:
        return [rubeus.build_addon_root(
            node_addon,
            node_addon.dataset,
            permissions=permissions
        )]

    # Quit if doi does not produce a dataset
    if dataset is None:
        return []

    published_files = get_files(dataset, published=True)

    # Produce draft version or quit if no published version is available
    if not published_files:
        if can_edit:
            version = 'latest'
        else:
            return []

    urls = {
        'publish': node.api_url_for('dataverse_publish_dataset'),
        'publishBoth': node.api_url_for('dataverse_publish_both')
    }

    return [rubeus.build_addon_root(
        node_addon,
        node_addon.dataset,
        urls=urls,
        permissions=permissions,
        dataset=node_addon.dataset,
        doi=dataset.doi,
        dataverse=dataverse.title,
        hasPublishedFiles=bool(published_files),
        dataverseIsPublished=dataverse.is_published,
        version=version,
    )]
开发者ID:GageGaskins,项目名称:osf.io,代码行数:59,代码来源:hgrid.py

示例3: bitbucket_hgrid_data

def bitbucket_hgrid_data(node_settings, auth, **kwargs):

    # Quit if no repo linked
    if not node_settings.complete:
        return

    connection = BitbucketClient(access_token=node_settings.external_account.oauth_key)

    node = node_settings.owner
    if node.is_public and not node.is_contributor(auth.user):

        repo = connection.repo(node_settings.user, node_settings.repo)
        if not repo:
            # TODO: Add warning message
            logger.error('Could not access Bitbucket repo')
            return None
    try:
        branch, sha, branches = get_refs(
            node_settings,
            branch=kwargs.get('branch'),
            sha=kwargs.get('sha'),
            connection=connection,
        )
    except (NotFoundError, Exception):
        # TODO: Show an alert or change Bitbucket configuration?
        logger.error('Bitbucket repo not found')
        return

    ref = None if branch is None else ref_to_params(branch, sha)

    name_tpl = '{user}/{repo}'.format(
        user=node_settings.user, repo=node_settings.repo
    )

    permissions = {
        'edit': False,
        'view': True,
        'private': node_settings.is_private
    }
    urls = {
        'upload': None,
        'fetch': node_settings.owner.api_url + 'bitbucket/hgrid/' + (ref or ''),
        'branch': node_settings.owner.api_url + 'bitbucket/hgrid/root/',
        'zip': node_settings.owner.api_url + 'bitbucket/zipball/' + (ref or ''),
        'repo': 'https://bitbucket.com/{0}/{1}/branch/'.format(node_settings.user, node_settings.repo)
    }

    branch_names = [each['name'] for each in branches]
    if not branch_names:
        branch_names = [branch]  # if repo un-init-ed then still add default branch to list of branches

    return [rubeus.build_addon_root(
        node_settings,
        name_tpl,
        urls=urls,
        permissions=permissions,
        branches=branch_names,
        defaultBranch=branch,
        private_key=kwargs.get('view_only', None),
    )]
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:60,代码来源:apps.py

示例4: test_hgrid_dummy_fail

 def test_hgrid_dummy_fail(self):
     node_settings = self.node_settings
     node = self.project
     user = Auth(self.project.creator)
     rv = {
         'isPointer': False,
         'addon': 's3',
         'addonFullname': node_settings.config.full_name,
         'iconUrl': node_settings.config.icon_url,
         'name': 'Amazon Simple Storage Service: {0}'.format(
             node_settings.bucket
         ),
         'kind': 'folder',
         'permissions': {
             'view': node.can_view(user),
             'edit': node.can_edit(user) and not node.is_registration,
         },
         'urls': {
             'fetch': node.api_url + 's3/hgrid/',
             'upload': node.api_url + 's3/upload/'
         },
         'accept': {
             'maxSize': node_settings.config.max_file_size,
             'acceptedFiles': node_settings.config.accept_extensions
         },
         'isAddonRoot': True,
     }
     permissions = {
         'view': node.can_view(user),
         'edit': node.can_edit(user) and not node.is_registration,
     }
     assert_not_equals(rubeus.build_addon_root(
         node_settings, node_settings.bucket, permissions=permissions), rv)
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:33,代码来源:test_rubeus.py

示例5: test_hgrid_dummy

    def test_hgrid_dummy(self):
        node_settings = self.node_settings
        node = self.project
        user = Auth(self.project.creator)
        # FIXME: These tests are very brittle.
        expected = {
            "isPointer": False,
            "provider": "s3",
            "addonFullname": node_settings.config.full_name,
            "iconUrl": node_settings.config.icon_url,
            "name": "Amazon S3: {0}".format(node_settings.bucket),
            "kind": "folder",
            "accept": {
                "maxSize": node_settings.config.max_file_size,
                "acceptedFiles": node_settings.config.accept_extensions,
            },
            "isAddonRoot": True,
            "extra": None,
            "buttons": None,
            "nodeId": node._id,
            "nodeUrl": node.url,
            "nodeApiUrl": node.api_url,
        }
        permissions = {"view": node.can_view(user), "edit": node.can_edit(user) and not node.is_registration}

        expected["permissions"] = permissions

        actual = rubeus.build_addon_root(node_settings, node_settings.bucket, permissions=permissions)

        assert actual["urls"]["fetch"]
        assert actual["urls"]["upload"]

        del actual["urls"]

        assert_equals(actual, expected)
开发者ID:Alpani,项目名称:osf.io,代码行数:35,代码来源:test_rubeus.py

示例6: test_hgrid_dummy_overrides

 def test_hgrid_dummy_overrides(self):
     node_settings = self.node_settings
     node = self.project
     user = Auth(self.project.creator)
     expected = {
         "isPointer": False,
         "provider": "s3",
         "addonFullname": node_settings.config.full_name,
         "iconUrl": node_settings.config.icon_url,
         "name": "Amazon S3: {0}".format(node_settings.bucket),
         "kind": "folder",
         "permissions": {"view": node.can_view(user), "edit": node.can_edit(user) and not node.is_registration},
         "urls": {},
         "accept": {
             "maxSize": node_settings.config.max_file_size,
             "acceptedFiles": node_settings.config.accept_extensions,
         },
         "isAddonRoot": True,
         "extra": None,
         "buttons": None,
         "nodeId": node._id,
         "nodeUrl": node.url,
         "nodeApiUrl": node.api_url,
     }
     permissions = {"view": node.can_view(user), "edit": node.can_edit(user) and not node.is_registration}
     assert_equal(
         rubeus.build_addon_root(node_settings, node_settings.bucket, permissions=permissions, urls={}), expected
     )
开发者ID:Alpani,项目名称:osf.io,代码行数:28,代码来源:test_rubeus.py

示例7: gitlab_hgrid_data

def gitlab_hgrid_data(node_settings, auth, **kwargs):

    # Quit if no repo linked
    if not node_settings.complete:
        return

    connection = GitLabClient(external_account=node_settings.external_account)

    # Initialize repo here in the event that it is set in the privacy check
    # below. This potentially saves an API call in _check_permissions, below.
    repo = None

    # Quit if privacy mismatch and not contributor
    node = node_settings.owner
    if node.is_public or node.is_contributor(auth.user):
        try:
            repo = connection.repo(node_settings.repo_id)
        except NotFoundError:
            logger.error('Could not access GitLab repo')
            return None

    try:
        branch, sha, branches = get_refs(node_settings, branch=kwargs.get('branch'), sha=kwargs.get('sha'), connection=connection)
    except (NotFoundError, GitLabError):
        logger.error('GitLab repo not found')
        return

    if branch is not None:
        ref = ref_to_params(branch, sha)
        can_edit = check_permissions(node_settings, auth, connection, branch, sha, repo=repo)
    else:
        ref = ''
        can_edit = False

    permissions = {
        'edit': can_edit,
        'view': True,
        'private': node_settings.is_private
    }
    urls = {
        'upload': node_settings.owner.api_url + 'gitlab/file/' + ref,
        'fetch': node_settings.owner.api_url + 'gitlab/hgrid/' + ref,
        'branch': node_settings.owner.api_url + 'gitlab/hgrid/root/' + ref,
        'zip': 'https://{0}/{1}/repository/archive.zip?branch={2}'.format(node_settings.external_account.oauth_secret, repo.path_with_namespace, ref),
        'repo': 'https://{0}/{1}/tree/{2}'.format(node_settings.external_account.oauth_secret, repo.path_with_namespace, ref)
    }

    branch_names = [each.name for each in branches]
    if not branch_names:
        branch_names = [branch]  # if repo un-init-ed then still add default branch to list of branches

    return [rubeus.build_addon_root(
        node_settings,
        repo.path_with_namespace,
        urls=urls,
        permissions=permissions,
        branches=branch_names,
        private_key=kwargs.get('view_only', None),
        default_branch=repo.default_branch,
    )]
开发者ID:aaxelb,项目名称:osf.io,代码行数:60,代码来源:apps.py

示例8: s3_hgrid_data

def s3_hgrid_data(node_settings, auth, **kwargs):
    # Quit if no bucket
    if not node_settings.bucket or not node_settings.user_settings or not node_settings.user_settings.has_auth:
        return

    node = node_settings.owner
    return [
        rubeus.build_addon_root(
            node_settings, node_settings.bucket, permissions=auth,
            nodeUrl=node.url, nodeApiUrl=node.api_url,
        )
    ]
开发者ID:GageGaskins,项目名称:osf.io,代码行数:12,代码来源:hgrid.py

示例9: s3_hgrid_data

def s3_hgrid_data(node_settings, auth, **kwargs):
    # Dont display if not properly configured
    if not node_settings.complete:
        return

    node = node_settings.owner
    return [
        rubeus.build_addon_root(
            node_settings, node_settings.bucket, permissions=auth,
            nodeUrl=node.url, nodeApiUrl=node.api_url,
        )
    ]
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:12,代码来源:hgrid.py

示例10: osf_storage_root

def osf_storage_root(addon_config, node_settings, auth, **kwargs):
    """Build HGrid JSON for root node. Note: include node URLs for client-side
    URL creation for uploaded files.
    """
    node = node_settings.owner
    root = rubeus.build_addon_root(
        node_settings=node_settings,
        name='',
        permissions=auth,
        user=auth.user,
        nodeUrl=node.url,
        nodeApiUrl=node.api_url,
    )
    return [root]
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:14,代码来源:apps.py

示例11: test_osf_storage_root

 def test_osf_storage_root(self):
     auth = Auth(self.project.creator)
     result = views.osf_storage_root(self.node_settings, auth=auth)
     node = self.project
     expected = rubeus.build_addon_root(
         node_settings=self.node_settings,
         name='',
         permissions=auth,
         user=auth.user,
         nodeUrl=node.url,
         nodeApiUrl=node.api_url,
     )
     root = result[0]
     assert_equal(root, expected)
开发者ID:erinmayhood,项目名称:osf.io,代码行数:14,代码来源:test_views.py

示例12: googledrive_addon_folder

def googledrive_addon_folder(node_settings, auth, **kwargs):
    """Return the Rubeus/HGrid-formatted response for the root folder only."""
    # Quit if node settings does not have authentication
    if not node_settings.has_auth or not node_settings.folder_id:
        return None
    node = node_settings.owner
    root = rubeus.build_addon_root(
        node_settings=node_settings,
        name=node_settings.folder_name,
        permissions=auth,
        nodeUrl=node.url,
        nodeApiUrl=node.api_url,
    )
    return [root]
开发者ID:GageGaskins,项目名称:osf.io,代码行数:14,代码来源:hgrid.py

示例13: test_build_addon_root_for_anonymous_vols_hides_path

    def test_build_addon_root_for_anonymous_vols_hides_path(self):
        private_anonymous_link = PrivateLinkFactory(anonymous=True)
        private_anonymous_link.nodes.add(self.project)
        private_anonymous_link.save()
        project_viewer = UserFactory()

        result = rubeus.build_addon_root(
            self.node_settings,
            self.node_settings.bucket,
            user=project_viewer,
            private_key=private_anonymous_link.key
        )

        assert result['name'] == 'Amazon S3'
开发者ID:adlius,项目名称:osf.io,代码行数:14,代码来源:test_rubeus.py

示例14: _root_folder

 def _root_folder(node_settings, auth, **kwargs):
     """Return the Rubeus/HGrid-formatted response for the root folder only."""
     # Quit if node settings does not have authentication
     if not node_settings.has_auth or not node_settings.folder_id:
         return None
     node = node_settings.owner
     root = rubeus.build_addon_root(
         node_settings=node_settings,
         name=node_settings.fetch_folder_name(),
         permissions=auth,
         nodeUrl=node.url,
         nodeApiUrl=node.api_url,
         private_key=kwargs.get('view_only', None),
     )
     return [root]
开发者ID:adlius,项目名称:osf.io,代码行数:15,代码来源:apps.py

示例15: osf_storage_root

def osf_storage_root(node_settings, auth, **kwargs):
    """Build HGrid JSON for root node. Note: include node URLs for client-side
    URL creation for uploaded files.
    """
    node = node_settings.owner
    root = rubeus.build_addon_root(
        node_settings=node_settings,
        name='',
        permissions=auth,
        urls={
            'upload': node.api_url_for('osf_storage_request_upload_url'),
            'fetch': node.api_url_for('osf_storage_hgrid_contents'),
        },
        nodeUrl=node.url,
        nodeApiUrl=node.api_url,
    )
    return [root]
开发者ID:csheldonhess,项目名称:osf.io,代码行数:17,代码来源:views.py


注:本文中的website.util.rubeus.build_addon_root函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。