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


Python DatasetManager.is_accessible方法代码示例

本文整理汇总了Python中galaxy.managers.datasets.DatasetManager.is_accessible方法的典型用法代码示例。如果您正苦于以下问题:Python DatasetManager.is_accessible方法的具体用法?Python DatasetManager.is_accessible怎么用?Python DatasetManager.is_accessible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在galaxy.managers.datasets.DatasetManager的用法示例。


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

示例1: DatasetManagerTestCase

# 需要导入模块: from galaxy.managers.datasets import DatasetManager [as 别名]
# 或者: from galaxy.managers.datasets.DatasetManager import is_accessible [as 别名]
class DatasetManagerTestCase( BaseTestCase ):

    def set_up_managers( self ):
        super( DatasetManagerTestCase, self ).set_up_managers()
        self.dataset_mgr = DatasetManager( self.app )

    def test_create( self ):
        self.log( "should be able to create a new Dataset" )
        dataset1 = self.dataset_mgr.create( self.trans )
        self.assertIsInstance( dataset1, model.Dataset )
        self.assertEqual( dataset1, self.trans.sa_session.query( model.Dataset ).get( dataset1.id ) )

    def test_base( self ):
        dataset1 = self.dataset_mgr.create( self.trans )
        dataset2 = self.dataset_mgr.create( self.trans )

        self.log( "should be able to query" )
        datasets = self.trans.sa_session.query( model.Dataset ).all()
        self.assertEqual( self.dataset_mgr.list( self.trans ), datasets )
        self.assertEqual( self.dataset_mgr.one( self.trans, filters=( model.Dataset.id == dataset1.id ) ), dataset1 )
        self.assertEqual( self.dataset_mgr.by_id( self.trans, dataset1.id ), dataset1 )
        self.assertEqual( self.dataset_mgr.by_ids( self.trans, [ dataset2.id, dataset1.id ] ), [ dataset2, dataset1 ] )

        self.log( "should be able to limit and offset" )
        self.assertEqual( self.dataset_mgr.list( self.trans, limit=1 ), datasets[0:1] )
        self.assertEqual( self.dataset_mgr.list( self.trans, offset=1 ), datasets[1:] )
        self.assertEqual( self.dataset_mgr.list( self.trans, limit=1, offset=1 ), datasets[1:2] )

        self.assertEqual( self.dataset_mgr.list( self.trans, limit=0 ), [] )
        self.assertEqual( self.dataset_mgr.list( self.trans, offset=3 ), [] )

        self.log( "should be able to order" )
        self.assertEqual( self.dataset_mgr.list( self.trans, order_by=sqlalchemy.desc( model.Dataset.create_time ) ),
            [ dataset2, dataset1 ] )

    def test_delete( self ):
        item1 = self.dataset_mgr.create( self.trans )

        self.log( "should be able to delete and undelete an hda" )
        self.assertFalse( item1.deleted )
        self.assertEqual( self.dataset_mgr.delete( self.trans, item1 ), item1 )
        self.assertTrue( item1.deleted )
        self.assertEqual( self.dataset_mgr.undelete( self.trans, item1 ), item1 )
        self.assertFalse( item1.deleted )

    def test_purge_allowed( self ):
        self.trans.app.config.allow_user_dataset_purge = True
        item1 = self.dataset_mgr.create( self.trans )

        self.log( "should purge an hda if config does allow" )
        self.assertFalse( item1.purged )
        self.assertEqual( self.dataset_mgr.purge( self.trans, item1 ), item1 )
        self.assertTrue( item1.purged )

    def test_purge_not_allowed( self ):
        self.trans.app.config.allow_user_dataset_purge = False
        item1 = self.dataset_mgr.create( self.trans )

        self.log( "should raise an error when purging an hda if config does not allow" )
        self.assertFalse( item1.purged )
        self.assertRaises( exceptions.ConfigDoesNotAllowException, self.dataset_mgr.purge, self.trans, item1 )
        self.assertFalse( item1.purged )

    ##TODO: I'm unclear as to how these work, so I'm kicking this down the road a bit....
    #def test_access_permission( self ):
    #    owner = self.user_mgr.create( self.trans, **user2_data )
    #    dataset = self.dataset_mgr.create( self.trans )
    #    # giving one user access permission makes it non-public, removing access for anyone else
    #    self.dataset_mgr.give_access_permission( self.trans, dataset, owner )
    #
    #    user3 = self.user_mgr.create( self.trans, **user3_data )
    #    user4 = self.user_mgr.create( self.trans,
    #        email='[email protected]', username='user4', password=default_password )
    #
    #    self.assertTrue( self.dataset_mgr.has_access_permission( self.trans, dataset, owner ) )
    #    self.assertFalse( self.dataset_mgr.has_access_permission( self.trans, dataset, user3 ) )
    #    self.assertFalse( self.dataset_mgr.has_access_permission( self.trans, dataset, user4 ) )
    #
    #    # should be able to progressively add more roles without removing the previous
    #    self.dataset_mgr.give_access_permission( self.trans, dataset, user3 )
    #    self.assertTrue( self.dataset_mgr.has_access_permission( self.trans, dataset, user3 ) )
    #    self.assertTrue( self.dataset_mgr.has_access_permission( self.trans, dataset, owner ) )
    #    self.assertFalse( self.dataset_mgr.has_access_permission( self.trans, dataset, user4 ) )
    #
    #    #self.assertTrue( self.dataset_mgr.is_accessible( self.trans, dataset, owner ) )
    #    #self.assertFalse( self.dataset_mgr.is_accessible( self.trans, dataset, non_owner ) )

    def test_accessible( self ):
        owner = self.user_mgr.create( self.trans, **user2_data )
        non_owner = self.user_mgr.create( self.trans, **user3_data )

        dataset = self.dataset_mgr.create( self.trans )

        self.log( "(by default, dataset permissions are lax) should be accessible to all" )
        for user in self.user_mgr.list( self.trans ):
            self.assertTrue( self.dataset_mgr.is_accessible( self.trans, dataset, user ) )
开发者ID:BinglanLi,项目名称:galaxy,代码行数:98,代码来源:test_DatasetManager.py

示例2: JobController

# 需要导入模块: from galaxy.managers.datasets import DatasetManager [as 别名]
# 或者: from galaxy.managers.datasets.DatasetManager import is_accessible [as 别名]

#.........这里部分代码省略.........
            raise exceptions.ConfigDoesNotAllowException("Tool '%s' cannot be rerun." % (job.tool_id))
        return tool.to_json(trans, {}, job=job)

    def __dictify_associations(self, trans, *association_lists):
        rval = []
        for association_list in association_lists:
            rval.extend(self.__dictify_association(trans, a) for a in association_list)
        return rval

    def __dictify_association(self, trans, job_dataset_association):
        dataset_dict = None
        dataset = job_dataset_association.dataset
        if dataset:
            if isinstance(dataset, model.HistoryDatasetAssociation):
                dataset_dict = dict(src="hda", id=trans.security.encode_id(dataset.id))
            else:
                dataset_dict = dict(src="ldda", id=trans.security.encode_id(dataset.id))
        return dict(name=job_dataset_association.name, dataset=dataset_dict)

    def __get_job(self, trans, id):
        try:
            decoded_job_id = self.decode_id(id)
        except Exception:
            raise exceptions.MalformedId()
        job = trans.sa_session.query(trans.app.model.Job).filter(trans.app.model.Job.id == decoded_job_id).first()
        if job is None:
            raise exceptions.ObjectNotFound()
        belongs_to_user = (job.user == trans.user) if job.user else (job.session_id == trans.get_galaxy_session().id)
        if not trans.user_is_admin() and not belongs_to_user:
            # Check access granted via output datasets.
            if not job.output_datasets:
                raise exceptions.ItemAccessibilityException("Job has no output datasets.")
            for data_assoc in job.output_datasets:
                if not self.dataset_manager.is_accessible(data_assoc.dataset.dataset, trans.user):
                    raise exceptions.ItemAccessibilityException("You are not allowed to rerun this job.")
        return job

    @expose_api
    def create(self, trans, payload, **kwd):
        """ See the create method in tools.py in order to submit a job. """
        raise exceptions.NotImplemented('Please POST to /api/tools instead.')

    @expose_api
    def search(self, trans, payload, **kwd):
        """
        search( trans, payload )
        * POST /api/jobs/search:
            return jobs for current user

        :type   payload: dict
        :param  payload: Dictionary containing description of requested job. This is in the same format as
            a request to POST /apt/tools would take to initiate a job

        :rtype:     list
        :returns:   list of dictionaries containing summary job information of the jobs that match the requested job run

        This method is designed to scan the list of previously run jobs and find records of jobs that had
        the exact some input parameters and datasets. This can be used to minimize the amount of repeated work, and simply
        recycle the old results.
        """
        tool_id = payload.get('tool_id')
        if tool_id is None:
            raise exceptions.ObjectAttributeMissingException("No tool id")
        tool = trans.app.toolbox.get_tool(tool_id)
        if tool is None:
            raise exceptions.ObjectNotFound("Requested tool not found")
开发者ID:ImmPortDB,项目名称:immport-galaxy,代码行数:70,代码来源:jobs.py

示例3: DatasetDeserializerTestCase

# 需要导入模块: from galaxy.managers.datasets import DatasetManager [as 别名]
# 或者: from galaxy.managers.datasets.DatasetManager import is_accessible [as 别名]
class DatasetDeserializerTestCase( BaseTestCase ):

    def set_up_managers( self ):
        super( DatasetDeserializerTestCase, self ).set_up_managers()
        self.dataset_manager = DatasetManager( self.app )
        self.dataset_serializer = DatasetSerializer( self.app )
        self.dataset_deserializer = DatasetDeserializer( self.app )
        self.role_manager = RoleManager( self.app )

    def test_deserialize_delete( self ):
        dataset = self.dataset_manager.create()

        self.log( 'should raise when deserializing deleted from non-bool' )
        self.assertFalse( dataset.deleted )
        self.assertRaises( exceptions.RequestParameterInvalidException,
            self.dataset_deserializer.deserialize, dataset, data={ 'deleted': None } )
        self.assertFalse( dataset.deleted )
        self.log( 'should be able to deserialize deleted from True' )
        self.dataset_deserializer.deserialize( dataset, data={ 'deleted': True } )
        self.assertTrue( dataset.deleted )
        self.log( 'should be able to reverse by deserializing deleted from False' )
        self.dataset_deserializer.deserialize( dataset, data={ 'deleted': False } )
        self.assertFalse( dataset.deleted )

    def test_deserialize_purge( self ):
        dataset = self.dataset_manager.create()

        self.log( 'should raise when deserializing purged from non-bool' )
        self.assertRaises( exceptions.RequestParameterInvalidException,
            self.dataset_deserializer.deserialize, dataset, data={ 'purged': None } )
        self.assertFalse( dataset.purged )
        self.log( 'should be able to deserialize purged from True' )
        self.dataset_deserializer.deserialize( dataset, data={ 'purged': True } )
        self.assertTrue( dataset.purged )
        # TODO: should this raise an error?
        self.log( 'should NOT be able to deserialize purged from False (will remain True)' )
        self.dataset_deserializer.deserialize( dataset, data={ 'purged': False } )
        self.assertTrue( dataset.purged )

    def test_deserialize_permissions( self ):
        dataset = self.dataset_manager.create()
        who_manages = self.user_manager.create( **user2_data )
        self.dataset_manager.permissions.manage.grant( dataset, who_manages )
        existing_permissions = self.dataset_serializer.serialize_permissions( dataset, 'permissions', user=who_manages )
        existing_manage_permissions = existing_permissions[ 'manage' ]

        user3 = self.user_manager.create( **user3_data )

        self.log( 'deserializing permissions from a non-dictionary should error' )
        not_a_dict = []
        self.assertRaises( exceptions.RequestParameterInvalidException, self.dataset_deserializer.deserialize,
            dataset, user=who_manages, data={ 'permissions': not_a_dict })

        self.log( 'deserializing permissions from a malformed dictionary should error' )
        self.assertRaises( exceptions.RequestParameterInvalidException, self.dataset_deserializer.deserialize,
            dataset, user=who_manages, data={ 'permissions': dict( nope=[], access=[] ) })

        self.log( 'deserializing permissions with no manage roles should error' )
        self.assertRaises( exceptions.RequestParameterInvalidException, self.dataset_deserializer.deserialize,
            dataset, user=who_manages, data={ 'permissions': dict( manage=[], access=[] ) })

        self.log( 'deserializing permissions using a non-managing user should error' )
        self.assertRaises( rbac_secured.DatasetManagePermissionFailedException, self.dataset_deserializer.deserialize,
            dataset, user=user3, data={ 'permissions': existing_permissions })

        self.log( 'deserializing permissions with a single access should make the dataset private' )
        private_role = self.user_manager.private_role( who_manages )
        private_role = private_role.to_dict( value_mapper={ 'id' : self.app.security.encode_id } )
        permissions = dict( manage=existing_manage_permissions, access=[ private_role[ 'id' ] ] )
        self.dataset_deserializer.deserialize( dataset, user=who_manages, data={
            'permissions': permissions
        })
        self.assertFalse( self.dataset_manager.is_accessible( dataset, user=user3 ) )

        self.log( 'deserializing permissions manage should make the permissions available' )
        self.assertRaises( SkipAttribute, self.dataset_serializer.serialize_permissions,
            dataset, 'perms', user=user3 )
        # now, have who_manages give a manage permission to user3
        private_role = self.user_manager.private_role( user3 )
        new_manage_permissions = existing_manage_permissions + [ self.app.security.encode_id( private_role.id ) ]
        permissions = dict( manage=new_manage_permissions, access=[] )
        self.dataset_deserializer.deserialize( dataset, user=who_manages, data={
            'permissions': permissions
        })

        # deserializing for user3 shouldn't throw a skip bc they can manage
        permissions = self.dataset_serializer.serialize_permissions( dataset, 'perms', user=who_manages )
        self.assertEqual( new_manage_permissions, permissions[ 'manage' ] )
开发者ID:AbhishekKumarSingh,项目名称:galaxy,代码行数:90,代码来源:test_DatasetManager.py


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