Skip to content

Commit

Permalink
[#116] Allow creating transitions without any approvals and introduce…
Browse files Browse the repository at this point in the history
… TransitionMeta and Transition models
  • Loading branch information
javrasya committed Nov 11, 2019
1 parent f7e27d3 commit 64e8782
Show file tree
Hide file tree
Showing 35 changed files with 1,743 additions and 708 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ Usage
3. Create all your ``states`` on the admin page
4. Create a ``workflow`` with your model ( ``MyModel`` - ``my_state_field`` ) information on the admin page
5. Create your ``transition approval metadata`` within the workflow created earlier and authorization rules along with their priority on the admin page
6. Enjoy your ``django-river`` journey.
5. Create your ``transition metadata`` within the workflow created earlier, source and destination states
6. Create your ``transition approval metadata`` within the workflow created earlier and authorization rules along with their priority on the admin page
7. Enjoy your ``django-river`` journey.

.. code-block:: python
Expand Down
1 change: 1 addition & 0 deletions docs/admin/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ is to provide them by using their Django admin pages.
:maxdepth: 2

state
transition_meta
transition_approval_meta

10 changes: 3 additions & 7 deletions docs/admin/transition_approval_meta.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ Transition Approval Meta Administration
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| Field | Default | Optional | Format | Description |
+===========================+============+==========+====================+===========================================+
| workflow | | False | | Choice | | Your model class along with the field |
| workflow | | | | Choice | | Your model class along with the field |
| | | | | of | | that you want to use this transition |
| | | False | | Strings | | approval meta for. ``django-river`` |
| | | | | | will list all the possible model and |
| | | | | | fields you can pick on the admin page |
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| source_state | | False | State | | Source state of the transition |
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| destination_state | | False | State | | Destination state of the transition |
| transition_meta | | False | TransitionMete | | Transition information that contains |
| | | | | | source and destination states |
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| permissions | Empty List | True | List<Permission> | | List of permissions which will be |
| | | | | | authorized to approve this |
Expand Down Expand Up @@ -43,7 +42,4 @@ Transition Approval Meta Administration

.. toctree::
:maxdepth: 2

basic
advance

21 changes: 21 additions & 0 deletions docs/admin/transition_meta.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _transition-meta-administration:

Transition Meta Administration
==============================
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| Field | Default | Optional | Format | Description |
+===========================+============+==========+====================+===========================================+
| workflow | | False | | Choice | | Your model class along with the field |
| | | | | of | | that you want to use this transition |
| | | False | | Strings | | approval meta for. ``django-river`` |
| | | | | | will list all the possible model and |
| | | | | | fields you can pick on the admin page |
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| source_state | | False | State | | Source state of the transition |
+---------------------------+------------+----------+--------------------+-------------------------------------------+
| destination_state | | False | State | | Destination state of the transition |
+---------------------------+------------+----------+--------------------+-------------------------------------------+


.. toctree::
:maxdepth: 2
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Change Logs
* **Improvement** - # 113_: Support defining an approval hook with a specific approval.
* **Improvement** - # 114_: Support defining a transition hook with a specific iteration.
* **Drop** - # 115_: Drop skipping and disabling approvals to cut the unnecessary complexity.
* **Improvement** - # 116_: Allow creating transitions without any approvals. A new TransitionMeta and Transition models are introduced to keep transition information even though there is no transition approval yet.


.. _105: https://github.com/javrasya/django-river/issues/105
Expand All @@ -29,6 +30,7 @@ Change Logs
.. _113: https://github.com/javrasya/django-river/issues/113
.. _114: https://github.com/javrasya/django-river/issues/114
.. _115: https://github.com/javrasya/django-river/issues/115
.. _116: https://github.com/javrasya/django-river/issues/116

2.0.0 (Stable)
--------------
Expand Down
5 changes: 3 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Getting Started
3. Create all your ``states`` on the admin page
4. Create a ``workflow`` with your model ( ``MyModel`` - ``my_state_field`` ) information on the admin page
5. Create your ``transition approval metadata`` within the workflow created earlier and authorization rules along with their priority on the admin page
6. Enjoy your ``django-river`` journey.
5. Create your ``transition metadata`` within the workflow created earlier, source and destination states
6. Create your ``transition approval metadata`` within the workflow created earlier and authorization rules along with their priority on the admin page
7. Enjoy your ``django-river`` journey.

.. code-block:: python
Expand Down
1 change: 1 addition & 0 deletions river/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin

from river.admin.function_admin import *
from river.admin.transitionmeta import *
from river.admin.transitionapprovalmeta import *
from river.admin.workflow import *
from river.admin.hook_admins import *
Expand Down
2 changes: 1 addition & 1 deletion river/admin/hook_admins.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OnApprovedHookAdmin(admin.ModelAdmin):


class OnTransitHookAdmin(admin.ModelAdmin):
list_display = ('workflow', 'callback_function', 'source_state', 'destination_state')
list_display = ('workflow', 'callback_function', 'transition_meta')


class OnCompleteHookAdmin(admin.ModelAdmin):
Expand Down
4 changes: 2 additions & 2 deletions river/admin/transitionapprovalmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
class TransitionApprovalMetaForm(forms.ModelForm):
class Meta:
model = TransitionApprovalMeta
fields = ('workflow', 'source_state', 'destination_state', 'permissions', 'groups', 'priority')
fields = ('workflow', 'transition_meta', 'permissions', 'groups', 'priority')


class TransitionApprovalMetaAdmin(admin.ModelAdmin):
form = TransitionApprovalMetaForm
list_display = ('workflow', 'source_state', 'destination_state', 'priority')
list_display = ('workflow', 'transition_meta', 'priority')


admin.site.register(TransitionApprovalMeta, TransitionApprovalMetaAdmin)
19 changes: 19 additions & 0 deletions river/admin/transitionmeta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.contrib import admin
from django import forms

from river.models import TransitionMeta
from river.models.transitionapprovalmeta import TransitionApprovalMeta


class TransitionMetaForm(forms.ModelForm):
class Meta:
model = TransitionMeta
fields = ('workflow', 'source_state', 'destination_state')


class TransitionMetaAdmin(admin.ModelAdmin):
form = TransitionMetaForm
list_display = ('workflow', 'source_state', 'destination_state')


admin.site.register(TransitionMeta, TransitionMetaAdmin)
9 changes: 4 additions & 5 deletions river/core/classworkflowobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_available_approvals(self, as_user):
TransitionApproval.objects.filter(
workflow=self.workflow, status=PENDING
).values(
'workflow', 'object_id', 'source_state', 'destination_state'
'workflow', 'object_id', 'transition'
).annotate(min_priority=Min('priority'))
)

Expand All @@ -43,8 +43,7 @@ def get_available_approvals(self, as_user):
self._authorized_approvals(as_user),
workflow_id=those_with_max_priority.col.workflow_id,
object_id=those_with_max_priority.col.object_id,
source_state_id=those_with_max_priority.col.source_state_id,
destination_state_id=those_with_max_priority.col.destination_state_id,
transition_id=those_with_max_priority.col.transition_id,
).with_cte(
those_with_max_priority
).annotate(
Expand All @@ -56,7 +55,7 @@ def get_available_approvals(self, as_user):
approvals_with_max_priority, object_id_as_int=workflow_objects.col.pk
).with_cte(
workflow_objects
).filter(source_state=getattr(workflow_objects.col, self.field_name + "_id"))
).filter(transition__source_state=getattr(workflow_objects.col, self.field_name + "_id"))

@property
def initial_state(self):
Expand All @@ -66,7 +65,7 @@ def initial_state(self):
@property
def final_states(self):
final_approvals = TransitionApprovalMeta.objects.filter(workflow=self.workflow, children__isnull=True)
return State.objects.filter(pk__in=final_approvals.values_list("destination_state", flat=True))
return State.objects.filter(pk__in=final_approvals.values_list("transition_meta__destination_state", flat=True))

def _authorized_approvals(self, as_user):
group_q = Q()
Expand Down
Loading

0 comments on commit 64e8782

Please sign in to comment.