Add cabinet add and remove workflow actions
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
3.2.8 (2019-XX-XX)
|
||||
==================
|
||||
* Add cabinet add and remove workflow actions.
|
||||
|
||||
3.2.7 (2019-08-28)
|
||||
==================
|
||||
* Fix checkout form bug. Thanks to Lucius Schaerer
|
||||
|
||||
75
mayan/apps/cabinets/tests/test_workflow_actions.py
Normal file
75
mayan/apps/cabinets/tests/test_workflow_actions.py
Normal file
@@ -0,0 +1,75 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from mayan.apps.common.tests import GenericViewTestCase
|
||||
from mayan.apps.documents.tests.mixins import DocumentTestMixin
|
||||
from mayan.apps.document_states.tests.mixins import WorkflowTestMixin
|
||||
from mayan.apps.document_states.tests.test_actions import ActionTestCase
|
||||
|
||||
from ..models import Cabinet
|
||||
from ..workflow_actions import CabinetAddAction, CabinetRemoveAction
|
||||
|
||||
from .mixins import CabinetTestMixin
|
||||
|
||||
|
||||
class CabinetWorkflowActionTestCase(CabinetTestMixin, ActionTestCase):
|
||||
def setUp(self):
|
||||
super(CabinetWorkflowActionTestCase, self).setUp()
|
||||
self._create_test_cabinet()
|
||||
|
||||
def test_cabinet_add_action(self):
|
||||
action = CabinetAddAction(
|
||||
form_data={'cabinets': Cabinet.objects.all()}
|
||||
)
|
||||
action.execute(context={'document': self.test_document})
|
||||
|
||||
self.assertTrue(
|
||||
self.test_document in self.test_cabinet.documents.all()
|
||||
)
|
||||
|
||||
def test_cabinet_remove_action(self):
|
||||
self.test_cabinet.document_add(document=self.test_document)
|
||||
|
||||
action = CabinetRemoveAction(
|
||||
form_data={'cabinets': Cabinet.objects.all()}
|
||||
)
|
||||
action.execute(context={'document': self.test_document})
|
||||
|
||||
self.assertFalse(
|
||||
self.test_document in self.test_cabinet.documents.all()
|
||||
)
|
||||
|
||||
|
||||
class CabinetWorkflowActionViewTestCase(
|
||||
CabinetTestMixin, WorkflowTestMixin, DocumentTestMixin,
|
||||
GenericViewTestCase
|
||||
):
|
||||
auto_upload_document = False
|
||||
|
||||
def test_cabinet_add_action_create_get_view(self):
|
||||
self._create_test_workflow()
|
||||
self._create_test_workflow_state()
|
||||
|
||||
response = self.get(
|
||||
viewname='document_states:setup_workflow_state_action_create',
|
||||
kwargs={
|
||||
'pk': self.test_workflow_state.pk,
|
||||
'class_path': 'mayan.apps.cabinets.workflow_actions.CabinetAddAction'
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_cabinet_remove_action_create_get_view(self):
|
||||
self._create_test_workflow()
|
||||
self._create_test_workflow_state()
|
||||
self._create_test_cabinet()
|
||||
|
||||
response = self.get(
|
||||
viewname='document_states:setup_workflow_state_action_create',
|
||||
kwargs={
|
||||
'pk': self.test_workflow_state.pk,
|
||||
'class_path': 'mayan.apps.cabinets.workflow_actions.CabinetRemoveAction'
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
81
mayan/apps/cabinets/workflow_actions.py
Normal file
81
mayan/apps/cabinets/workflow_actions.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.acls.models import AccessControlList
|
||||
from mayan.apps.document_states.classes import WorkflowAction
|
||||
|
||||
from .models import Cabinet
|
||||
from .permissions import (
|
||||
permission_cabinet_add_document, permission_cabinet_remove_document
|
||||
)
|
||||
|
||||
__all__ = ('CabinetAddAction', 'CabinetRemoveAction')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CabinetAddAction(WorkflowAction):
|
||||
fields = {
|
||||
'cabinets': {
|
||||
'label': _('Cabinets'),
|
||||
'class': 'django.forms.ModelMultipleChoiceField', 'kwargs': {
|
||||
'help_text': _(
|
||||
'Cabinets to which the document will be added.'
|
||||
),
|
||||
'queryset': Cabinet.objects.none(), 'required': False
|
||||
}
|
||||
},
|
||||
}
|
||||
label = _('Add to cabinets')
|
||||
widgets = {
|
||||
'cabinets': {
|
||||
'class': 'django.forms.widgets.SelectMultiple', 'kwargs': {
|
||||
'attrs': {'class': 'select2'},
|
||||
}
|
||||
}
|
||||
}
|
||||
permission = permission_cabinet_add_document
|
||||
|
||||
def execute(self, context):
|
||||
for cabinet in self.get_cabinets():
|
||||
cabinet.document_add(document=context['document'])
|
||||
|
||||
def get_form_schema(self, request):
|
||||
user = request.user
|
||||
logger.debug('user: %s', user)
|
||||
|
||||
queryset = AccessControlList.objects.restrict_queryset(
|
||||
permission=self.permission, queryset=Cabinet.objects.all(),
|
||||
user=user
|
||||
)
|
||||
|
||||
self.fields['cabinets']['kwargs']['queryset'] = queryset
|
||||
|
||||
return {
|
||||
'fields': self.fields,
|
||||
'widgets': self.widgets
|
||||
}
|
||||
|
||||
def get_cabinets(self):
|
||||
return Cabinet.objects.filter(pk__in=self.form_data.get('cabinets', ()))
|
||||
|
||||
|
||||
class CabinetRemoveAction(CabinetAddAction):
|
||||
fields = {
|
||||
'cabinets': {
|
||||
'label': _('Cabinet'),
|
||||
'class': 'django.forms.ModelMultipleChoiceField', 'kwargs': {
|
||||
'help_text': _(
|
||||
'Cabinets from which the document will be removed.'),
|
||||
'queryset': Cabinet.objects.none(), 'required': False
|
||||
}
|
||||
},
|
||||
}
|
||||
label = _('Remove from cabinets')
|
||||
permission = permission_cabinet_remove_document
|
||||
|
||||
def execute(self, context):
|
||||
for cabinet in self.get_cabinets():
|
||||
cabinet.document_remove(document=context['document'])
|
||||
Reference in New Issue
Block a user