(self, function, *args, **kwargs)
return _wrapped_view
Decorator used to tested if a user has rights to access an instance
Decorator used to tested if a user has rights to access an instance
Decorator used to tested if a user has rights to access an instance
def __call__(self, function, *args, **kwargs):
        """
        Decorator used to tested if a user has rights to access an instance
        """

        # Pass function attributes to the wrapper
        @wraps(function)
        def _wrapped_view(request, *args, **kwargs):
            # Each wrapped view must take an alphanumeric uid as parameter.
            uid = kwargs.get('uid')
            user = request.user

            # Fetches the object that will be checked for permissions.
            instance = self.type.objects.filter(uid=uid).first()
            if not instance:
                messages.error(request, f"Object id {uid} does not exist.")
                return redirect(reverse("project_list"))

            # Build redirect url
            if self.fallback_view:
                target = reverse(self.fallback_view, kwargs=dict(uid=uid))
            else:
                target = request.GET.get("next") or instance.url()

            # The project that corresponds to the instance.
            project = instance.project

            # Check write to an object.
            access = auth.is_writable(user=user, project=project)

            # Project owners may write their project.
            if access:
                return function(request, *args, **kwargs)

            msg = auth.access_denied_message(user=user, needed_access=models.Access.WRITE_ACCESS)
            messages.error(request, msg)
            return redirect(target)

        return _wrapped_view
def __call__ ( self , function , * args , * * kwargs ) : # Pass function attributes to the wrapper @ wraps ( function ) def _wrapped_view ( request , * args , * * kwargs ) : # Each wrapped view must take an alphanumeric uid as parameter. uid = kwargs . get ( 'uid' ) user = request . user # Fetches the object that will be checked for permissions. instance = self . type . objects . filter ( uid = uid ) . first ( ) if not instance : messages . error ( request , f"Object id {uid} does not exist." ) return redirect ( reverse ( "project_list" ) ) # Build redirect url if self . fallback_view : target = reverse ( self . fallback_view , kwargs = dict ( uid = uid ) ) else : target = request . GET . get ( "next" ) or instance . url ( ) # The project that corresponds to the instance. project = instance . project # Check write to an object. access = auth . is_writable ( user = user , project = project ) # Project owners may write their project. if access : return function ( request , * args , * * kwargs ) msg = auth . access_denied_message ( user = user , needed_access = models . Access . WRITE_ACCESS ) messages . error ( request , msg ) return redirect ( target ) return _wrapped_view