Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
decisions: added to endpoint to resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 20, 2024
1 parent e083725 commit ef5e678
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 37 deletions.
31 changes: 14 additions & 17 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
logger = logging.getLogger(__name__)


def add_decision(workflow_id, user, action):
serializer_class = DecisionSerializer
data = {"workflow": workflow_id, "user": user, "action": action}

serializer = serializer_class(data=data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)


class WorkflowViewSet(viewsets.ModelViewSet):
queryset = Workflow.objects.all()
serializer_class = WorkflowSerializer
Expand Down Expand Up @@ -103,25 +113,11 @@ def create(self, request, *args, **kwargs):

class DecisionViewSet(viewsets.ModelViewSet):
queryset = Decision.objects.all()
serializer_class = DecisionSerializer

def get_queryset(self):
status = self.request.query_params.get("status")
if status:
return self.queryset.filter(status__status=status)
return self.queryset

def create(self, request, *args, **kwargs):
data = {
"workflow": request.data["workflow_id"],
"user": request.user,
"action": request.data["action"],
}

serializer = self.serializer_class(data=data)
if serializer.is_valid(raise_exception=True):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return add_decision(
request.data["workflow_id"], request.user, request.data["action"]
)


class AuthorWorkflowViewSet(viewsets.ViewSet):
Expand Down Expand Up @@ -190,6 +186,7 @@ def resolve(self, request, pk=None):
ResolutionDags[serializer.validated_data["value"]],
pk,
)
add_decision(pk, request.user, serializer.validated_data["value"])

return airflow_utils.trigger_airflow_dag(
ResolutionDags[serializer.validated_data["value"]].label, pk, extra_data
Expand Down
38 changes: 38 additions & 0 deletions workflows/plugins/hooks/backoffice/decision_management_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from hooks.backoffice.base import BackofficeHook
from requests import Response


class WorkflowTicketManagementHook(BackofficeHook):
"""
A hook to update the status of a workflow in the backoffice system.
:param method: The HTTP method to use for the request (default: "GET").
:type method: str
:param http_conn_id: The ID of the HTTP connection to use (
default: "backoffice_conn").
:type http_conn_id: str
"""

def __init__(
self,
method: str = "GET",
http_conn_id: str = "backoffice_conn",
headers: dict = None,
) -> None:
super().__init__(method, http_conn_id, headers)
self.endpoint = "api/decision/"

def create_decision_entry(
self, workflow_id: str, user_id: str, action: str
) -> Response:
data = {
"user_id": user_id,
"action": action,
"workflow_id": workflow_id,
}
return self.run_with_advanced_retry(
_retry_args=self.tenacity_retry_kwargs,
method="POST",
data=data,
endpoint=self.endpoint,
)
Empty file removed workflows/tests/__init__.py
Empty file.
20 changes: 0 additions & 20 deletions workflows/tests/test_author_create_tasks.py

This file was deleted.

0 comments on commit ef5e678

Please sign in to comment.