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

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul committed Aug 23, 2024
1 parent 21c3ff1 commit 3167432
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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
8 changes: 6 additions & 2 deletions backoffice/backoffice/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Workflow(models.Model):


class WorkflowTicket(models.Model):
workflow_id = models.ForeignKey(
workflow = models.ForeignKey(
Workflow, related_name="tickets", on_delete=models.CASCADE
)
ticket_id = models.CharField(
Expand All @@ -49,7 +49,11 @@ 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",
related_name="decisions",
db_column="email",
on_delete=models.CASCADE,
)
workflow = models.ForeignKey(Workflow, on_delete=models.CASCADE)
action = models.CharField(max_length=30, choices=DECISION_CHOICES)
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 "email" in workflow_data["decisions"][0]

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

0 comments on commit 3167432

Please sign in to comment.