From 720429ee6bde3c451fe041b31710dfa9d454e554 Mon Sep 17 00:00:00 2001
From: DonHaul <ramiro.animus@gmail.com>
Date: Mon, 12 Aug 2024 11:13:16 +0200
Subject: [PATCH] author submissions: add author accept curate action

* ref: cern-sis/issues-inspire/issues/522
---
 backoffice/backoffice/workflows/api/views.py | 29 ++++++++++++++++++--
 backoffice/backoffice/workflows/constants.py |  1 +
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/backoffice/backoffice/workflows/api/views.py b/backoffice/backoffice/workflows/api/views.py
index ca78ae8e..0d8a16d8 100644
--- a/backoffice/backoffice/workflows/api/views.py
+++ b/backoffice/backoffice/workflows/api/views.py
@@ -104,8 +104,8 @@ class AuthorWorkflowViewSet(viewsets.ViewSet):
     serializer_class = WorkflowAuthorSerializer
 
     @extend_schema(
-        summary="Create a New Author",
-        description="Creates a new author, launches the required airflow dags.",
+        summary="Create/Update an Author",
+        description="Creates/Updates an author, launches the required airflow dags.",
         request=serializer_class,
     )
     def create(self, request):
@@ -127,6 +127,31 @@ def create(self, request):
             workflow.data,
         )
 
+    @extend_schema(
+        summary="Updates an Author",
+        description="Updates an author, launches the required airflow dag.",
+        request=serializer_class,
+    )
+    def update(self, request, pk=None):
+        logger.info("Creating workflow with data: %s", request.data)
+        serializer = self.serializer_class(data=request.data)
+        if serializer.is_valid(raise_exception=True):
+            workflow = Workflow.objects.create(
+                data=serializer.validated_data["data"],
+                workflow_type=WorkflowType.AUTHOR_UPDATE,
+            )
+
+        logger.info(
+            "Trigger Airflow DAG: %s for %s",
+            WORKFLOW_DAGS[workflow.workflow_type].initialize,
+            workflow.id,
+        )
+        return airflow_utils.trigger_airflow_dag(
+            WORKFLOW_DAGS[workflow.workflow_type].initialize,
+            str(workflow.id),
+            workflow.data,
+        )
+
     @extend_schema(
         summary="Partially Updates Author",
         description="Updates specific fields of the author.",
diff --git a/backoffice/backoffice/workflows/constants.py b/backoffice/backoffice/workflows/constants.py
index 273faeac..371ae726 100644
--- a/backoffice/backoffice/workflows/constants.py
+++ b/backoffice/backoffice/workflows/constants.py
@@ -32,6 +32,7 @@ class WorkflowType(models.TextChoices):
 
 class ResolutionDags(models.TextChoices):
     accept = "accept", "author_create_approved_dag"
+    accept_curate = "accept_curate", "author_create_approved_dag"
     reject = "reject", "author_create_rejected_dag"