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

Add decision connection in serializer #93

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions backoffice/backoffice/workflows/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ def get_ticket_url(self, obj):
)


class WorkflowSerializer(serializers.ModelSerializer):
tickets = WorkflowTicketSerializer(many=True, read_only=True)
class DecisionSerializer(serializers.ModelSerializer):
workflow = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all())

class Meta:
model = Workflow
model = Decision
fields = "__all__"


class DecisionSerializer(serializers.ModelSerializer):
workflow = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all())
class WorkflowSerializer(serializers.ModelSerializer):
tickets = WorkflowTicketSerializer(many=True, read_only=True)
decisions = DecisionSerializer(many=True, read_only=True)

class Meta:
model = Decision
model = Workflow
fields = "__all__"


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.6 on 2024-08-23 13:02

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("workflows", "0009_decision"),
]

operations = [
migrations.AlterField(
model_name="decision",
name="workflow",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="decisions",
to="workflows.workflow",
),
),
migrations.AlterField(
model_name="workflowticket",
name="workflow_id",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tickets",
to="workflows.workflow",
),
),
]
9 changes: 7 additions & 2 deletions backoffice/backoffice/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ class WorkflowTicket(models.Model):

class Decision(models.Model):
user = models.ForeignKey(
User, to_field="email", db_column="email", on_delete=models.CASCADE
User,
to_field="email",
db_column="email",
on_delete=models.CASCADE,
)
workflow = models.ForeignKey(
Workflow, related_name="decisions", on_delete=models.CASCADE
)
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)
Expand Down
10 changes: 10 additions & 0 deletions backoffice/backoffice/workflows/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from backoffice.workflows.constants import (
WORKFLOW_DAGS,
AuthorCreateDags,
ResolutionDags,
StatusChoices,
WorkflowType,
)
Expand Down Expand Up @@ -100,6 +101,15 @@ def test_tickets(self):
assert "ticket_id" in workflow_data["tickets"][0]
assert "ticket_type" in workflow_data["tickets"][0]

def test_decisions(self):
Decision.objects.create(
workflow=self.workflow, user=self.user, action=ResolutionDags.accept
)
workflow_data = WorkflowSerializer(self.workflow).data
assert "decisions" in workflow_data
assert "action" in workflow_data["decisions"][0]
assert "user" in workflow_data["decisions"][0]

@pytest.mark.vcr()
def test_delete(self):
self.api_client.force_authenticate(user=self.curator)
Expand Down
Loading