This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from DonHaul/decision-action-log
author decisions: decision logic added
- Loading branch information
Showing
10 changed files
with
240 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from backoffice.workflows.api.serializers import DecisionSerializer | ||
|
||
|
||
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 serializer.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
backoffice/backoffice/workflows/migrations/0009_decision.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Generated by Django 4.2.6 on 2024-08-15 12:25 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("workflows", "0008_alter_workflow_status_alter_workflow_workflow_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Decision", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"action", | ||
models.CharField( | ||
choices=[ | ||
("accept", "author_create_approved_dag"), | ||
("reject", "author_create_rejected_dag"), | ||
("accept_curate", "author_create_approved_dag"), | ||
], | ||
max_length=30, | ||
), | ||
), | ||
("_created_at", models.DateTimeField(auto_now_add=True)), | ||
("_updated_at", models.DateTimeField(auto_now=True)), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
db_column="email", | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
to_field="email", | ||
), | ||
), | ||
( | ||
"workflow", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="workflows.workflow", | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import uuid | ||
|
||
import pytest | ||
from django.apps import apps | ||
from django.contrib.auth import get_user_model | ||
from django.test import TransactionTestCase | ||
from rest_framework.exceptions import ValidationError | ||
|
||
from backoffice.workflows import constants | ||
from backoffice.workflows.api import utils | ||
from backoffice.workflows.constants import StatusChoices | ||
|
||
User = get_user_model() | ||
Workflow = apps.get_model(app_label="workflows", model_name="Workflow") | ||
|
||
|
||
class TestUtils(TransactionTestCase): | ||
reset_sequences = True | ||
fixtures = ["backoffice/fixtures/groups.json"] | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.workflow = Workflow.objects.create( | ||
data={}, status=StatusChoices.APPROVAL, core=True, is_update=False | ||
) | ||
self.user = User.objects.create_user( | ||
email="[email protected]", password="12345" | ||
) | ||
|
||
def test_add_decision(self): | ||
decision_data = utils.add_decision( | ||
self.workflow.id, self.user, constants.ResolutionDags.accept | ||
) | ||
|
||
self.assertIsNotNone(decision_data) | ||
|
||
def test_add_decision_validation_errors(self): | ||
with pytest.raises(ValidationError): | ||
utils.add_decision(self.workflow.id, self.user, "wrong") | ||
|
||
with pytest.raises(ValidationError): | ||
utils.add_decision( | ||
uuid.UUID(int=0), self.user, constants.ResolutionDags.accept | ||
) |
Oops, something went wrong.