summaryrefslogtreecommitdiffstats
path: root/dashboard/src/workflow/views.py
blob: e5ef5c600eb9e8a43d3496d5e1f7b9127c72c48d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Na
##############################################################################
# Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################


from django.http import HttpResponse, HttpResponseGone
from django.shortcuts import render

import uuid

from workflow.workflow_manager import ManagerTracker, SessionManager

import logging
logger = logging.getLogger(__name__)


def attempt_auth(request):
    try:
        manager = ManagerTracker.managers[request.session['manager_session']]

        return manager

    except KeyError:
        return None


def delete_session(request):
    try:
        del ManagerTracker.managers[request.session['manager_session']]
        return HttpResponse('')
    except Exception:
        return None


def step_view(request):
    manager = attempt_auth(request)
    if not manager:
        # no manager found, redirect to "lost" page
        return no_workflow(request)
    if request.GET.get('step') is not None:
        manager.goto(int(request.GET.get('step')))
    return manager.render(request)


def manager_view(request):
    manager = attempt_auth(request)

    if not manager:
        return HttpResponseGone("No session found that relates to current request")

    if request.method == 'GET':
        # no need for this statement if only intercepting post requests

        # return general context for viewport page
        return manager.status(request)

    if request.method == 'POST':
        if request.POST.get('add') is not None:
            logger.debug("add found")
            target_id = None
            if 'target' in request.POST:
                target_id = int(request.POST.get('target'))
            manager.add_workflow(workflow_type=int(request.POST.get('add')), target_id=target_id)
        elif request.POST.get('edit') is not None and request.POST.get('edit_id') is not None:
            logger.debug("edit found")
            manager.add_workflow(workflow_type=request.POST.get('edit'), edit_object=int(request.POST.get('edit_id')))
        elif request.POST.get('cancel') is not None:
            del ManagerTracker.managers[request.session['manager_session']]

    return manager.status(request)


def viewport_view(request):
    if not request.user.is_authenticated:
        return login(request)

    manager = attempt_auth(request)
    if manager is None:
        return no_workflow(request)

    if request.method == 'GET':
        return render(request, 'workflow/viewport-base.html')
    else:
        pass


def create_session(wf_type, request):
    wf = int(wf_type)
    smgr = SessionManager(request=request)
    smgr.add_workflow(workflow_type=wf, target_id=request.POST.get("target"))
    manager_uuid = uuid.uuid4().hex
    ManagerTracker.getInstance().managers[manager_uuid] = smgr

    return manager_uuid


def no_workflow(request):

    logger.debug("There is no active workflow")

    return render(request, 'workflow/no_workflow.html', {'title': "Not Found"})


def login(request):
    return render(request, "dashboard/login.html", {'title': 'Authentication Required'})