-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync funcs with @workflow_action_step decorator
- Loading branch information
1 parent
44f981e
commit d6149c8
Showing
9 changed files
with
290 additions
and
60 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,38 @@ | ||
""" | ||
Decorators for workflows app. | ||
""" | ||
|
||
from django.db.models import Q | ||
|
||
from enterprise_access.apps.workflows.models import WorkflowActionStep | ||
from enterprise_access.apps.workflows.registry import WorkflowActionRegistry | ||
|
||
|
||
def workflow_action_step(slug, name): | ||
""" | ||
A single decorator that registers the workflow action with the registry | ||
and ensures that a WorkflowActionStep exists in the database. | ||
:param slug: Unique identifier for the workflow action step. | ||
:param name: Human-readable name for the workflow action step. | ||
""" | ||
def decorator(func): | ||
# Register the action step in the workflow registry | ||
WorkflowActionRegistry.register_action_step(slug, name)(func) | ||
|
||
# Check if the action step already exists and whether its name has changed | ||
existing_step = WorkflowActionStep.objects.filter( | ||
Q(action_reference=slug) & Q(name=name) | ||
).first() | ||
|
||
if not existing_step: | ||
# Only update or create if the existing step was not found | ||
WorkflowActionStep.objects.update_or_create( | ||
action_reference=slug, | ||
defaults={"name": name} | ||
) | ||
|
||
# Return the original function to allow it to be used as normal | ||
return func | ||
|
||
return decorator |
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
Oops, something went wrong.