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


Python ObjectACL.get_effective_query方法代码示例

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


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

示例1: has_perm

# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import get_effective_query [as 别名]
    def has_perm(self, user_obj, perm, obj=None):
        '''
        main method, calls other methods based on permission type queried
        '''
        if not user_obj.is_authenticated():
            allowed_tokens = getattr(user_obj, 'allowed_tokens', [])
            user_obj = AnonymousUser()
            user_obj.allowed_tokens = allowed_tokens

        if obj is None:
            return False

        try:
            perm_label, perm_type = perm.split('.')
            perm_action, perm_ct = perm_type.split('_')
        except:
            return False

        if perm_label != self.app_label:
            return False

        ct = ContentType.objects.get_for_model(obj)
        if ct.name != perm_ct:
            return False

        method_name = '_has_%s_perm' % perm_action

        # run any custom perms per model, continue if not None
        # allows complete overriding of standard authorisation, eg for public
        # experiments
        model_spec_perm = getattr(obj, method_name,
                                  lambda *args, **kwargs: None)(user_obj)
        if type(model_spec_perm) == bool:
            return model_spec_perm

        #get_acls
        obj_acls = ObjectACL.objects.filter(
            content_type=ct, object_id=obj.id).filter(
                self.get_perm_bool(perm_action)).filter(
                    ObjectACL.get_effective_query())

        query = Q(pluginId='django_user',
                  entityId=str(user_obj.id))

        if user_obj.is_authenticated():
            for name, group in user_obj.get_profile().ext_groups:
                query |= Q(pluginId=name, entityId=str(group))
        else:
            # the only authorisation available for anonymous users is tokenauth
            tgp = TokenGroupProvider()
            for name, group in tgp.getGroups(user_obj):
                query |= Q(pluginId=name, entityId=str(group))

        return obj_acls.filter(query).count() > 0
开发者ID:crawley,项目名称:mytardis,代码行数:56,代码来源:authorisation.py

示例2: has_perm

# 需要导入模块: from tardis.tardis_portal.models import ObjectACL [as 别名]
# 或者: from tardis.tardis_portal.models.ObjectACL import get_effective_query [as 别名]
    def has_perm(self, user_obj, perm, obj=None):
        '''
        main method, calls other methods based on permission type queried
        '''
        if not user_obj.is_authenticated():
            allowed_tokens = getattr(user_obj, 'allowed_tokens', [])
            user_obj = AnonymousUser()
            user_obj.allowed_tokens = allowed_tokens

        if obj is None:
            return False

        try:
            perm_label, perm_type = perm.split('.')
            # the following is necessary because of the ridiculous naming
            # of 'Dataset_File'......
            type_list = perm_type.split('_')
            perm_action = type_list[0]
            perm_ct = '_'.join(type_list[1:])
        except:
            return False

        if perm_label != self.app_label:
            return False

        ct = ContentType.objects.get_for_model(obj)
        if ct.model != perm_ct:
            return False

        method_name = '_has_%s_perm' % perm_action

        # run any custom perms per model, continue if not None
        # allows complete overriding of standard authorisation, eg for public
        # experiments
        model_spec_perm = getattr(obj, method_name,
                                  lambda *args, **kwargs: None)(user_obj)
        if type(model_spec_perm) == bool:
            return model_spec_perm
        elif model_spec_perm is not None:
            # pass auth to a different object, if False try this ACL
            # works when returned object is parent.
            # makes it impossible to 'hide' child objects
            if type(model_spec_perm) not in (list, set, QuerySet):
                model_spec_perm = [model_spec_perm]
            for msp in model_spec_perm:
                new_ct = ContentType.objects.get_for_model(msp)
                new_perm = '%s.%s_%s' % (perm_label, perm_action, new_ct)
                if user_obj.has_perm(new_perm, msp):
                    return True

        #get_acls
        obj_acls = ObjectACL.objects\
            .filter(content_type=ct, object_id=obj.id)\
            .filter(self.get_perm_bool(perm_action))\
            .filter(ObjectACL.get_effective_query())

        query = Q(pluginId='django_user',
                  entityId=str(user_obj.id))

        if user_obj.is_authenticated():
            for name, group in user_obj.get_profile().ext_groups:
                query |= Q(pluginId=name, entityId=str(group))
        else:
            # the only authorisation available for anonymous users is tokenauth
            tgp = TokenGroupProvider()
            for group in tgp.getGroups(user_obj):
                query |= Q(pluginId=tgp.name, entityId=str(group))

        return obj_acls.filter(query).count() > 0
开发者ID:TheGoodRob,项目名称:mytardis,代码行数:71,代码来源:authorisation.py


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