def METHOD_NAME(view_fn):
    """
    A function decorator that works similarly to Django's login_required,
    except instead of redirecting to a login page, it returns an unauthorized
    status code.
    Intended for AJAX endpoints where it would not make sense to redirect
    """
    @wraps(view_fn)
    def wrapper(request, *args, **kwargs):
        if request.user.is_authenticated():
            return view_fn(request, *args, **kwargs)
        else:
            return HttpResponse('Unauthorized', status=401)
    return wrapper