From c59b546364c391808afc5cea7a48142ef6db02f1 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Wed, 14 Aug 2024 12:46:23 +0200 Subject: [PATCH] switched to use email --- backoffice/backoffice/workflows/api/views.py | 14 +++++++------- .../dags/author/author_create/shared_tasks.py | 11 ++--------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/backoffice/backoffice/workflows/api/views.py b/backoffice/backoffice/workflows/api/views.py index 03ae0804..890693a8 100644 --- a/backoffice/backoffice/workflows/api/views.py +++ b/backoffice/backoffice/workflows/api/views.py @@ -21,6 +21,7 @@ from rest_framework.decorators import action from rest_framework.response import Response +from backoffice.users.models import User from backoffice.utils.pagination import OSStandardResultsSetPagination from backoffice.workflows import airflow_utils from backoffice.workflows.api.serializers import ( @@ -117,18 +118,18 @@ def retrieve(self, request, *args, **kwargs): def create(self, request, *args, **kwargs): workflow_id = request.data.get("workflow_id") action = request.data.get("action") - user_id = request.data.get("user_id") + email = request.data.get("email") - if not all([workflow_id, action, user_id]): + if not all([workflow_id, action, email]): return Response( - {"error": "Workflow_id, ticket_id and ticket_type are required."}, + {"error": "workflow_id, action and email are required."}, status=status.HTTP_400_BAD_REQUEST, ) try: workflow = Workflow.objects.get(id=workflow_id) decision = Decision.objects.create( - workflow_id=workflow, user_id=user_id, action=action + workflow_id=workflow, user=User.object.get(email=email), action=action ) serializer = DecisionSerializer(decision) return Response(serializer.data, status=status.HTTP_201_CREATED) @@ -198,9 +199,8 @@ def resolve(self, request, pk=None): logger.info("Resolving data: %s", request.data) serializer = AuthorResolutionSerializer(data=request.data) if serializer.is_valid(raise_exception=True): - extra_data = {"user_id": str(request.user.id)} - print("extra_data") - print(extra_data) + extra_data = serializer.validated_data + extra_data["email"] = str(request.user.email) logger.info( "Trigger Airflow DAG: %s for %s", ResolutionDags[serializer.validated_data["value"]], diff --git a/workflows/dags/author/author_create/shared_tasks.py b/workflows/dags/author/author_create/shared_tasks.py index 1c02e314..55bbda11 100644 --- a/workflows/dags/author/author_create/shared_tasks.py +++ b/workflows/dags/author/author_create/shared_tasks.py @@ -1,6 +1,5 @@ from airflow.decorators import task from hooks.backoffice.base import BackofficeHook -from hooks.backoffice.workflow_management_hook import WorkflowManagementHook @task() @@ -9,15 +8,9 @@ def create_decision_on_curation_choice(**context): print(context["params"]) data = { - "user_id": context["params"]["workflow_id"], - "action": context["params"]["workflow_id"], + "email": context["params"]["data"]["email"], + "action": context["params"]["data"]["value"], "workflow_id": context["params"]["workflow_id"], } - workflow_data = WorkflowManagementHook().get_workflow( - workflow_id=context["params"]["workflow_id"] - ) - - print(workflow_data) - BackofficeHook().request(method="POST", data=data, endpoint="api/decisions/")