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

Commit

Permalink
switched to use email
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 14, 2024
1 parent 7d2828b commit c59b546
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
14 changes: 7 additions & 7 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"]],
Expand Down
11 changes: 2 additions & 9 deletions workflows/dags/author/author_create/shared_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from airflow.decorators import task
from hooks.backoffice.base import BackofficeHook
from hooks.backoffice.workflow_management_hook import WorkflowManagementHook


@task()
Expand All @@ -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/")

0 comments on commit c59b546

Please sign in to comment.