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

Commit

Permalink
improve readibility of the approve dag
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 15, 2024
1 parent 0cb110a commit c9ad198
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 75 deletions.
6 changes: 1 addition & 5 deletions backoffice/backoffice/workflows/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ class DecisionAdmin(admin.ModelAdmin):

ordering = ("-_updated_at",)
search_fields = ["id", "data"]
list_display = (
"id",
"action",
"user",
)
list_display = ("id", "action", "user", "workflow_id")
list_filter = [
"action",
"user",
Expand Down
25 changes: 10 additions & 15 deletions backoffice/backoffice/workflows/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,15 @@ def create(self, request, *args, **kwargs):
)


class DecisionViewSet(viewsets.ViewSet):
def retrieve(self, request, *args, **kwargs):
workflow_id = kwargs.get("pk")
try:
decision = Decision.objects.get(workflow_id=workflow_id)
serializer = DecisionSerializer(decision)
return Response(serializer.data)
except Decision.DoesNotExist:
return Response(
{"error": "Workflow ticket not found."},
status=status.HTTP_404_NOT_FOUND,
)
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):
workflow_id = request.data.get("workflow_id")
Expand All @@ -125,10 +122,8 @@ def create(self, request, *args, **kwargs):
)

try:
workflow = Workflow.objects.get(id=workflow_id)

decision = Decision.objects.create(
workflow_id=workflow, user=request.user, action=action
workflow_id=workflow_id, user=request.user, action=action
)
serializer = DecisionSerializer(decision)
return Response(serializer.data, status=status.HTTP_201_CREATED)
Expand Down
3 changes: 3 additions & 0 deletions backoffice/backoffice/workflows/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ResolutionDags(models.TextChoices):
accept_curate = "accept_curate", "author_create_approved_dag"


DECISION_CHOICES = ResolutionDags.choices + []


class AuthorCreateDags(models.TextChoices):
initialize = "author_create_initialization_dag", "initialize"
approve = "author_create_approved_dag", "approve"
Expand Down
8 changes: 5 additions & 3 deletions backoffice/backoffice/workflows/migrations/0009_decision.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.6 on 2024-08-13 08:38
# Generated by Django 4.2.6 on 2024-08-15 12:25

import django.db.models.deletion
from django.conf import settings
Expand Down Expand Up @@ -38,14 +38,16 @@ class Migration(migrations.Migration):
("_created_at", models.DateTimeField(auto_now_add=True)),
("_updated_at", models.DateTimeField(auto_now=True)),
(
"user_id",
"user",
models.ForeignKey(
db_column="email",
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
to_field="email",
),
),
(
"workflow_id",
"workflow",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="workflows.workflow",
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions backoffice/backoffice/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from backoffice.users.models import User
from backoffice.workflows.constants import (
DECISION_CHOICES,
DEFAULT_STATUS_CHOICE,
DEFAULT_TICKET_TYPE,
DEFAULT_WORKFLOW_TYPE,
TICKET_TYPES,
ResolutionDags,
StatusChoices,
WorkflowType,
)
Expand Down Expand Up @@ -49,8 +49,8 @@ class Decision(models.Model):
user = models.ForeignKey(
User, to_field="email", db_column="email", on_delete=models.CASCADE
)
workflow_id = models.ForeignKey(Workflow, on_delete=models.CASCADE)
action = models.CharField(max_length=30, choices=ResolutionDags.choices)
workflow = models.ForeignKey(Workflow, on_delete=models.CASCADE)
action = models.CharField(max_length=30, choices=DECISION_CHOICES)

_created_at = models.DateTimeField(auto_now_add=True)
_updated_at = models.DateTimeField(auto_now=True)
16 changes: 0 additions & 16 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.test import TransactionTestCase
from django.urls import reverse
from django_opensearch_dsl.registries import registry
from opensearch_dsl import Index
from rest_framework import status
from rest_framework.test import APIClient

Expand Down Expand Up @@ -497,18 +496,3 @@ def test_create_decision(self):
url = reverse("api:decisions-list")
response = self.api_client.post(url, format="json", data=data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)

def test_get_decisoin(self):
self.api_client.force_authenticate(user=self.curator)

decision = Decision.objects.create(
workflow_id=self.workflow, action="accept", user=self.curator
)

url = reverse("api:decisions-detail", kwargs={"pk": decision.id})

print("wawa")
print(url)
response = self.api_client.get(f"{url}/{decision.id}")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(decision.id, response.data[id])
6 changes: 4 additions & 2 deletions workflows/dags/author/author_create/author_create_approved.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
params={
"workflow_id": Param(type="string", default=""),
"data": Param(type="object", default={}),
"create_ticket": Param(type="boolean", default=False),
},
start_date=datetime.datetime(2024, 5, 5),
schedule_interval=None,
Expand Down Expand Up @@ -67,8 +66,11 @@ def author_check_approval_branch(**context: dict) -> None:
dag goes either to create_ticket_on_author_approval task or
directly to create_author_on_inspire
"""
if context["params"]["create_ticket"]:
print("iam blue")
print(context["params"])
if context["params"]["data"]["create_ticket"]:
return "create_author_create_curation_ticket"
return "close_author_create_user_ticket"

@task
def create_author_create_curation_ticket(**context: dict) -> None:
Expand Down

0 comments on commit c9ad198

Please sign in to comment.