Beispiel #1
0
        def wrapper(context, *args, **kwargs):
            is_owner_perm = is_colleague_perm = False
            obj = None
            if len(args) > 0:
                cls = args[0]
                new_args = args[1:]
                if 'input' in kwargs and hasattr(cls, 'get_form_kwargs'):
                    form = cls.get_form_kwargs(*new_args, **kwargs['input'])
                    if 'instance' in form:
                        obj = form['instance']
                elif hasattr(cls._meta, 'model'):
                    obj = cls._meta.model._default_manager.get(pk=args[2])
                else:
                    obj = kwargs['input'].model._default_manager.get(
                        pk=from_global_id(kwargs['input'].id)[1])

                if obj is not None:
                    is_owner_perm = is_owner(context.user, obj)
                    is_colleague_perm = is_colleague(context.user, obj)
                else:
                    is_owner_perm = True

            if check_perms(context) and (is_owner_perm or is_colleague_perm
                                         ) or context.user.is_superuser:
                return func(*args, **kwargs)
            raise exceptions.PermissionDenied()
Beispiel #2
0
 def wrapper(context, *args, **kwargs):
     if test_func(context):
         return f(*args, **kwargs)
     raise exceptions.PermissionDenied()