# (c) cavaliba.com  - data/api - version.py



from django.views.decorators.csrf import csrf_exempt


from app_home.log import log, DEBUG
from django.conf import settings

from app_user.aaa_api import start_api

from .helper import send_denied
from .helper import send_response
from .helper import get_cavctl_version



# permission: p_info

#  ----------------------------------------------------------------------------
# /api/version/
#  ----------------------------------------------------------------------------
@csrf_exempt
def version(request):

    aaa_api = start_api(request, permission="p_info")
    if not aaa_api["is_allowed"]:
        return send_denied()

    log(DEBUG, aaa=aaa_api, app="api", view="version", action="GET", status="OK", data="")

    reply = {
        "version": settings.CAVALIBA_VERSION,
        "cavctl_supported_version": get_cavctl_version(),
    }
    return send_response(request, reply, 200)

