Skip to content

Commit

Permalink
backoffice: standardize workflows into authors
Browse files Browse the repository at this point in the history
  • Loading branch information
DonHaul authored and drjova committed Oct 24, 2024
1 parent 4f8d5d6 commit 7e3a8e4
Show file tree
Hide file tree
Showing 55 changed files with 385 additions and 667 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
from django_json_widget.widgets import JSONEditorWidget

from backoffice.management.permissions import IsAdminOrCuratorUser
from backoffice.workflows.models import Decision, Workflow, WorkflowTicket
from backoffice.authors.models import (
AuthorDecision,
AuthorWorkflow,
AuthorWorkflowTicket,
)


class WorkflowsAdminSite(admin.AdminSite):
class AuthorWorkflowsAdminSite(admin.AdminSite):
"""
Custom admin site for managing workflows.
Expand Down Expand Up @@ -63,8 +67,8 @@ def has_delete_permission(self, request, obj=None):
}


class WorkflowsDecisionsInline(admin.StackedInline):
model = Decision
class AuthorWorkflowsDecisionsInline(admin.StackedInline):
model = AuthorDecision
extra = 0
can_delete = False
show_change_link = True
Expand All @@ -78,8 +82,8 @@ def action_value(self, obj):
return obj.action


class WorkflowTicketsInline(admin.StackedInline):
model = WorkflowTicket
class AuthorWorkflowTicketsInline(admin.StackedInline):
model = AuthorWorkflowTicket
extra = 0
can_delete = False
show_change_link = True
Expand All @@ -89,7 +93,7 @@ def has_change_permission(self, request, obj=None):
return False


@admin.register(Workflow)
@admin.register(AuthorWorkflow)
class WorkflowAdmin(BaseModelAdmin):
"""
Admin class for Workflow model. Define get, update and delete permissions.
Expand All @@ -101,24 +105,20 @@ class WorkflowAdmin(BaseModelAdmin):
"id",
"workflow_type",
"status",
"core",
"is_update",
"_created_at",
"_updated_at",
)
list_filter = [
"workflow_type",
"status",
"core",
"is_update",
"_created_at",
"_updated_at",
]

inlines = [WorkflowsDecisionsInline, WorkflowTicketsInline]
inlines = [AuthorWorkflowsDecisionsInline, AuthorWorkflowTicketsInline]


@admin.register(Decision)
@admin.register(AuthorDecision)
class DecisionAdmin(BaseModelAdmin):
"""
Admin class for Decision model. Define get, update and delete permissions.
Expand All @@ -137,7 +137,7 @@ def action_value(self, obj):
return obj.action


@admin.register(WorkflowTicket)
@admin.register(AuthorWorkflowTicket)
class WorkflowTicketAdmin(BaseModelAdmin):
"""
Admin class for WorkflowTicket model. Define get, update and delete permissions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from requests.exceptions import RequestException
from rest_framework import status

from backoffice.workflows.constants import WORKFLOW_DAGS
from backoffice.authors.constants import WORKFLOW_DAGS

AIRFLOW_BASE_URL = environ.get("AIRFLOW_BASE_URL")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
from drf_spectacular.utils import OpenApiExample, extend_schema_serializer
from inspire_schemas.utils import get_validation_errors
from rest_framework import serializers

from backoffice.workflows.api import utils
from backoffice.workflows.constants import ResolutionDags, StatusChoices, WorkflowType
from backoffice.workflows.documents import WorkflowDocument
from backoffice.workflows.models import Decision, Workflow, WorkflowTicket
from backoffice.authors.api import utils
from backoffice.authors.constants import DECISION_CHOICES, StatusChoices, WorkflowType
from backoffice.authors.documents import AuthorWorkflowDocument
from backoffice.authors.models import (
AuthorDecision,
AuthorWorkflow,
AuthorWorkflowTicket,
)


class WorkflowTicketSerializer(serializers.ModelSerializer):
class AuthorWorkflowTicketSerializer(serializers.ModelSerializer):
ticket_url = serializers.SerializerMethodField()
workflow = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all())
workflow = serializers.PrimaryKeyRelatedField(queryset=AuthorWorkflow.objects.all())

class Meta:
model = WorkflowTicket
model = AuthorWorkflowTicket
fields = "__all__"

def get_ticket_url(self, obj):
Expand All @@ -26,26 +29,11 @@ def get_ticket_url(self, obj):
)


class DecisionSerializer(serializers.ModelSerializer):
workflow = serializers.PrimaryKeyRelatedField(queryset=Workflow.objects.all())

class Meta:
model = Decision
fields = "__all__"


class WorkflowSerializer(serializers.ModelSerializer):
tickets = WorkflowTicketSerializer(many=True, read_only=True)
decisions = DecisionSerializer(many=True, read_only=True)

class Meta:
model = Workflow
fields = "__all__"

class AuthorDecisionSerializer(serializers.ModelSerializer):
workflow = serializers.PrimaryKeyRelatedField(queryset=AuthorWorkflow.objects.all())

class WorkflowDocumentSerializer(DocumentSerializer):
class Meta:
document = WorkflowDocument
model = AuthorDecision
fields = "__all__"


Expand All @@ -69,7 +57,9 @@ class Meta:
),
],
)
class WorkflowAuthorSerializer(WorkflowSerializer):
class AuthorWorkflowSerializer(serializers.ModelSerializer):
tickets = AuthorWorkflowTicketSerializer(many=True, read_only=True)
decisions = AuthorDecisionSerializer(many=True, read_only=True)
data = serializers.JSONField(required=True)
workflow_type = serializers.ChoiceField(
choices=[
Expand All @@ -88,6 +78,34 @@ def validate_data(self, value):
raise serializers.ValidationError(validation_errors_msg)
return value

class Meta:
model = AuthorWorkflow
fields = "__all__"


@extend_schema_serializer(
exclude_fields=[
"_created_at",
"_updated_at",
], # Exclude internal fields from schema
examples=[
OpenApiExample(
"Author Workflow Serializer",
summary="Author Workflow Serializer no data",
description="Author Workflow Serializer",
value={
"workflow_type": WorkflowType.AUTHOR_CREATE,
"status": StatusChoices.RUNNING,
"data": {},
},
),
],
)
class AuthorWorkflowDocumentSerializer(DocumentSerializer):
class Meta:
document = AuthorWorkflowDocument
fields = "__all__"


@extend_schema_serializer(
examples=[
Expand All @@ -104,5 +122,5 @@ def validate_data(self, value):
],
)
class AuthorResolutionSerializer(serializers.Serializer):
value = serializers.ChoiceField(choices=ResolutionDags)
value = serializers.ChoiceField(choices=DECISION_CHOICES)
create_ticket = serializers.BooleanField(default=False)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from backoffice.workflows.api import serializers
from backoffice.authors.api.serializers import AuthorDecisionSerializer


def add_decision(workflow_id, user, action):
serializer_class = serializers.DecisionSerializer
serializer_class = AuthorDecisionSerializer
data = {"workflow": workflow_id, "user": user, "action": action}

serializer = serializer_class(data=data)
Expand Down
Loading

0 comments on commit 7e3a8e4

Please sign in to comment.