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 7831e81
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 39 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
12 changes: 10 additions & 2 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ def test_create_author(self):
@pytest.mark.vcr()
def test_accept_author(self):
self.api_client.force_authenticate(user=self.curator)
data = {"create_ticket": True, "value": "accept"}
action = "accept"
data = {"create_ticket": True, "value": action}

response = self.api_client.post(
reverse("api:workflows-authors-resolve", kwargs={"pk": self.workflow.id}),
Expand All @@ -333,6 +334,9 @@ def test_accept_author(self):
)

self.assertEqual(response.status_code, 200)
self.assertEqual(
Decision.objects.filter(workflow=self.workflow.id)[0].action, action
)

airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS[WorkflowType.AUTHOR_CREATE].approve, self.workflow.id
Expand All @@ -341,7 +345,8 @@ def test_accept_author(self):
@pytest.mark.vcr()
def test_reject_author(self):
self.api_client.force_authenticate(user=self.curator)
data = {"create_ticket": True, "value": "reject"}
action = "reject"
data = {"create_ticket": True, "value": action}

response = self.api_client.post(
reverse("api:workflows-authors-resolve", kwargs={"pk": self.workflow.id}),
Expand All @@ -350,6 +355,9 @@ def test_reject_author(self):
)

self.assertEqual(response.status_code, 200)
self.assertEqual(
Decision.objects.filter(workflow=self.workflow.id)[0].action, action
)

airflow_utils.delete_workflow_dag(
WORKFLOW_DAGS[WorkflowType.AUTHOR_CREATE].reject, self.workflow.id
Expand Down
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 7831e81

Please sign in to comment.