docs: def check_permissions(self, request):
          """ Retrieves the controlled object and perform the permissions check. """
          obj = (
              hasattr(self, 'get_controlled_object') and self.get_controlled_object() or
              hasattr(self, 'get_object') and self.get_object() or getattr(self, 'object', None)
          )
          user = request.user
  
          # Get the permissions to check
          perms = self.get_required_permissions(self)
  
          # Check permissions
          has_permissions = self.perform_permissions_check(user, obj, perms)
  
          if not has_permissions and not user.is_authenticated:
              return HttpResponseRedirect('{}?{}={}'.format(
                  resolve_url(self.login_url),
                  self.redirect_field_name,
                  urlquote(request.get_full_path())
              ))
          elif not has_permissions:
              raise PermissionDenied