Update linking app

Add keyword arguments. Update URL parameters to the '_id' form.
Movernize tests and update them to use the latest test case
improvements.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-01-21 02:00:22 -04:00
parent c0b34067ef
commit 2e5d05403a
10 changed files with 233 additions and 216 deletions
+5 -5
View File
@@ -32,7 +32,7 @@ class APIResolvedSmartLinkDocumentListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkDocumentSerializer serializer_class = ResolvedSmartLinkDocumentSerializer
def get_document(self): def get_document(self):
document = get_object_or_404(klass=Document, pk=self.kwargs['pk']) document = get_object_or_404(klass=Document, pk=self.kwargs['document_pk'])
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user, permissions=permission_document_view, user=self.request.user,
@@ -86,7 +86,7 @@ class APIResolvedSmartLinkView(generics.RetrieveAPIView):
serializer_class = ResolvedSmartLinkSerializer serializer_class = ResolvedSmartLinkSerializer
def get_document(self): def get_document(self):
document = get_object_or_404(klass=Document, pk=self.kwargs['pk']) document = get_object_or_404(klass=Document, pk=self.kwargs['document_pk'])
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user, permissions=permission_document_view, user=self.request.user,
@@ -123,7 +123,7 @@ class APIResolvedSmartLinkListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkSerializer serializer_class = ResolvedSmartLinkSerializer
def get_document(self): def get_document(self):
document = get_object_or_404(klass=Document, pk=self.kwargs['pk']) document = get_object_or_404(klass=Document, pk=self.kwargs['document_pk'])
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user, permissions=permission_document_view, user=self.request.user,
@@ -182,7 +182,7 @@ class APISmartLinkConditionListView(generics.ListCreateAPIView):
else: else:
permission_required = permission_smart_link_edit permission_required = permission_smart_link_edit
smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['pk']) smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['smart_link_pk'])
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_required, user=self.request.user, permissions=permission_required, user=self.request.user,
@@ -225,7 +225,7 @@ class APISmartLinkConditionView(generics.RetrieveUpdateDestroyAPIView):
else: else:
permission_required = permission_smart_link_edit permission_required = permission_smart_link_edit
smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['pk']) smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['smart_link_pk'])
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_required, user=self.request.user, permissions=permission_required, user=self.request.user,
+1 -1
View File
@@ -45,5 +45,5 @@ class SmartLinkConditionForm(forms.ModelForm):
) )
class Meta: class Meta:
model = SmartLinkCondition
exclude = ('smart_link',) exclude = ('smart_link',)
model = SmartLinkCondition
+23 -19
View File
@@ -17,23 +17,25 @@ from .permissions import (
) )
link_smart_link_condition_create = Link( link_smart_link_condition_create = Link(
args='object.pk', icon_class=icon_smart_link_condition_create, icon_class=icon_smart_link_condition_create,
kwargs={'smart_link_id': 'object.pk'},
permissions=(permission_smart_link_edit,), text=_('Create condition'), permissions=(permission_smart_link_edit,), text=_('Create condition'),
view='linking:smart_link_condition_create', view='linking:smart_link_condition_create'
) )
link_smart_link_condition_delete = Link( link_smart_link_condition_delete = Link(
args='resolved_object.pk', permissions=(permission_smart_link_edit,), kwargs={'smart_link_condition_id': 'resolved_object.pk'},
tags='dangerous', text=_('Delete'), permissions=(permission_smart_link_edit,), tags='dangerous',
view='linking:smart_link_condition_delete', text=_('Delete'), view='linking:smart_link_condition_delete'
) )
link_smart_link_condition_edit = Link( link_smart_link_condition_edit = Link(
args='resolved_object.pk', permissions=(permission_smart_link_edit,), kwargs={'smart_link_condition_id': 'resolved_object.pk'},
text=_('Edit'), view='linking:smart_link_condition_edit', permissions=(permission_smart_link_edit,), text=_('Edit'),
view='linking:smart_link_condition_edit'
) )
link_smart_link_condition_list = Link( link_smart_link_condition_list = Link(
args='object.pk', icon_class=icon_smart_link_condition, icon_class=icon_smart_link_condition, kwargs={'smart_link_id': 'object.pk'},
permissions=(permission_smart_link_edit,), text=_('Conditions'), permissions=(permission_smart_link_edit,), text=_('Conditions'),
view='linking:smart_link_condition_list', view='linking:smart_link_condition_list'
) )
link_smart_link_create = Link( link_smart_link_create = Link(
icon_class=icon_smart_link_create, icon_class=icon_smart_link_create,
@@ -41,35 +43,37 @@ link_smart_link_create = Link(
text=_('Create new smart link'), view='linking:smart_link_create' text=_('Create new smart link'), view='linking:smart_link_create'
) )
link_smart_link_delete = Link( link_smart_link_delete = Link(
args='object.pk', permissions=(permission_smart_link_delete,), kwargs={'smart_link_id': 'object.pk'},
tags='dangerous', text=_('Delete'), view='linking:smart_link_delete', permissions=(permission_smart_link_delete,),
tags='dangerous', text=_('Delete'), view='linking:smart_link_delete'
) )
link_smart_link_document_types = Link( link_smart_link_document_types = Link(
args='object.pk', icon_class=icon_document_type, icon_class=icon_document_type, kwargs={'document_type_id': 'object.pk'},
permissions=(permission_smart_link_edit,), text=_('Document types'), permissions=(permission_smart_link_edit,), text=_('Document types'),
view='linking:smart_link_document_types', view='linking:smart_link_document_types',
) )
link_smart_link_edit = Link( link_smart_link_edit = Link(
args='object.pk', permissions=(permission_smart_link_edit,), kwargs={'smart_link_id': 'object.pk'},
permissions=(permission_smart_link_edit,),
text=_('Edit'), view='linking:smart_link_edit', text=_('Edit'), view='linking:smart_link_edit',
) )
link_smart_link_instance_view = Link( link_smart_link_instance_view = Link(
args=('document.pk', 'object.pk',), kwargs={'document_id': 'document.pk', 'smart_link_id': 'object.pk'},
permissions=(permission_smart_link_view,), text=_('Documents'), permissions=(permission_smart_link_view,), text=_('Documents'),
view='linking:smart_link_instance_view', view='linking:resolved_smart_link_details'
) )
link_smart_link_instances_for_document = Link( link_smart_link_instances_for_document = Link(
args='resolved_object.pk',
icon_class=icon_smart_link_instances_for_document, icon_class=icon_smart_link_instances_for_document,
kwargs={'document_id': 'resolved_object.pk'},
permissions=(permission_document_view,), text=_('Smart links'), permissions=(permission_document_view,), text=_('Smart links'),
view='linking:smart_link_instances_for_document', view='linking:resolved_smart_links_for_document',
) )
link_smart_link_list = Link( link_smart_link_list = Link(
permissions=(permission_smart_link_create,), text=_('Smart links'), permissions=(permission_smart_link_view,), text=_('Smart links'),
view='linking:smart_link_list' view='linking:smart_link_list'
) )
link_smart_link_setup = Link( link_smart_link_setup = Link(
icon_class=icon_smart_link_setup, icon_class=icon_smart_link_setup,
permissions=(permission_smart_link_create,), text=_('Smart links'), permissions=(permission_smart_link_view,), text=_('Smart links'),
view='linking:smart_link_list' view='linking:smart_link_list'
) )
+6 -6
View File
@@ -6,15 +6,15 @@ from mayan.apps.permissions import PermissionNamespace
namespace = PermissionNamespace(label=_('Smart links'), name='linking') namespace = PermissionNamespace(label=_('Smart links'), name='linking')
permission_smart_link_view = namespace.add_permission(
name='smart_link_view', label=_('View existing smart links')
)
permission_smart_link_create = namespace.add_permission( permission_smart_link_create = namespace.add_permission(
name='smart_link_create', label=_('Create new smart links') label=_('Create new smart links'), name='smart_link_create'
) )
permission_smart_link_delete = namespace.add_permission( permission_smart_link_delete = namespace.add_permission(
name='smart_link_delete', label=_('Delete smart links') label=_('Delete smart links'), name='smart_link_delete'
) )
permission_smart_link_edit = namespace.add_permission( permission_smart_link_edit = namespace.add_permission(
name='smart_link_edit', label=_('Edit smart links') label=_('Edit smart links'), name='smart_link_edit'
)
permission_smart_link_view = namespace.add_permission(
label=_('View existing smart links'), name='smart_link_view'
) )
+13
View File
@@ -0,0 +1,13 @@
from __future__ import unicode_literals
from ..models import SmartLink
from .literals import TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL
class SmartLinkTestMixin(object):
def _create_test_smart_link(self):
self.test_smart_link = SmartLink.objects.create(
label=TEST_SMART_LINK_LABEL,
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
)
+6 -4
View File
@@ -66,7 +66,7 @@ class SmartLinkAPITestCase(DocumentTestMixin, BaseAPITestCase):
return self.post( return self.post(
viewname='rest_api:smartlink-list', data={ viewname='rest_api:smartlink-list', data={
'label': TEST_SMART_LINK_LABEL, 'label': TEST_SMART_LINK_LABEL,
'document_types_pk_list': self.document_type.pk 'document_types_id_list': self.document_type.pk
}, },
) )
@@ -135,7 +135,7 @@ class SmartLinkAPITestCase(DocumentTestMixin, BaseAPITestCase):
viewname='rest_api:smartlink-detail', viewname='rest_api:smartlink-detail',
args=(self.smart_link.pk,), data={ args=(self.smart_link.pk,), data={
'label': TEST_SMART_LINK_LABEL_EDITED, 'label': TEST_SMART_LINK_LABEL_EDITED,
'document_types_pk_list': self.document_type.pk 'document_types_id_list': self.document_type.pk
} }
) )
@@ -163,7 +163,7 @@ class SmartLinkAPITestCase(DocumentTestMixin, BaseAPITestCase):
viewname='rest_api:smartlink-detail', viewname='rest_api:smartlink-detail',
args=(self.smart_link.pk,), data={ args=(self.smart_link.pk,), data={
'label': TEST_SMART_LINK_LABEL_EDITED, 'label': TEST_SMART_LINK_LABEL_EDITED,
'document_types_pk_list': self.document_type.pk 'document_types_id_list': self.document_type.pk
} }
) )
@@ -253,7 +253,9 @@ class SmartLinkConditionAPITestCase(BaseAPITestCase):
self._create_smart_link() self._create_smart_link()
self._create_smart_link_condition() self._create_smart_link_condition()
self._create_document() self._create_document()
self.grant_access(permission=permission_smart_link_view, obj=self.smart_link) self.grant_access(
obj=self.smart_link, permission=permission_smart_link_view
)
response = self._request_resolved_smart_link_detail_view() response = self._request_resolved_smart_link_detail_view()
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertFalse('label' in response.data) self.assertFalse('label' in response.data)
+6 -10
View File
@@ -2,20 +2,16 @@ from __future__ import unicode_literals
from mayan.apps.documents.tests import GenericDocumentTestCase from mayan.apps.documents.tests import GenericDocumentTestCase
from ..models import SmartLink from .mixins import SmartLinkTestMixin
from .literals import TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL
class SmartLinkTestCase(GenericDocumentTestCase): class SmartLinkTestCase(SmartLinkTestMixin, GenericDocumentTestCase):
def test_dynamic_label(self): def test_dynamic_label(self):
smart_link = SmartLink.objects.create( self._create_test_smart_link()
label=TEST_SMART_LINK_LABEL,
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL self.test_smart_link.document_types.add(self.document_type)
)
smart_link.document_types.add(self.document_type)
self.assertEqual( self.assertEqual(
smart_link.get_dynamic_label(document=self.document), self.test_smart_link.get_dynamic_label(document=self.document),
self.document.label self.document.label
) )
+72 -84
View File
@@ -14,121 +14,116 @@ from .literals import (
TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL, TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL,
TEST_SMART_LINK_LABEL_EDITED TEST_SMART_LINK_LABEL_EDITED
) )
from .mixins import SmartLinkTestMixin
class SmartLinkViewTestCase(GenericViewTestCase): class SmartLinkViewTestCase(SmartLinkTestMixin, GenericViewTestCase):
def setUp(self): def _request_smart_link_create_view(self):
super(SmartLinkViewTestCase, self).setUp() return self.post(
self.login_user() viewname='linking:smart_link_create', data={
def test_smart_link_create_view_no_permission(self):
response = self.post(
'linking:smart_link_create', data={
'label': TEST_SMART_LINK_LABEL 'label': TEST_SMART_LINK_LABEL
} }
) )
self.assertEquals(response.status_code, 403) def test_smart_link_create_view_no_permission(self):
response = self._request_smart_link_create_view()
self.assertEqual(response.status_code, 403)
self.assertEqual(SmartLink.objects.count(), 0) self.assertEqual(SmartLink.objects.count(), 0)
def test_smart_link_create_view_with_permission(self): def test_smart_link_create_view_with_permission(self):
self.role.permissions.add( self.grant_permission(permission=permission_smart_link_create)
permission_smart_link_create.stored_permission
) response = self._request_smart_link_create_view()
self.assertEqual(response.status_code, 302)
response = self.post(
'linking:smart_link_create', data={
'label': TEST_SMART_LINK_LABEL
}, follow=True
)
self.assertContains(response, text='created', status_code=200)
self.assertEqual(SmartLink.objects.count(), 1) self.assertEqual(SmartLink.objects.count(), 1)
self.assertEqual( self.assertEqual(
SmartLink.objects.first().label, TEST_SMART_LINK_LABEL SmartLink.objects.first().label, TEST_SMART_LINK_LABEL
) )
def test_smart_link_delete_view_no_permission(self): def _request_smart_link_delete_view(self):
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL) return self.post(
viewname='linking:smart_link_delete',
response = self.post( kwargs={'smart_link_id': self.test_smart_link.pk}
'linking:smart_link_delete', args=(smart_link.pk,)
) )
self.assertEqual(response.status_code, 403)
def test_smart_link_delete_view_no_permission(self):
self._create_test_smart_link()
response = self._request_smart_link_delete_view()
self.assertEqual(response.status_code, 404)
self.assertEqual(SmartLink.objects.count(), 1) self.assertEqual(SmartLink.objects.count(), 1)
def test_smart_link_delete_view_with_permission(self): def test_smart_link_delete_view_with_access(self):
self.role.permissions.add( self._create_test_smart_link()
permission_smart_link_delete.stored_permission self.grant_access(
obj=self.test_smart_link, permission=permission_smart_link_delete
) )
response = self._request_smart_link_delete_view()
self.assertEqual(response.status_code, 302)
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
response = self.post(
'linking:smart_link_delete', args=(smart_link.pk,), follow=True
)
self.assertContains(response, text='deleted', status_code=200)
self.assertEqual(SmartLink.objects.count(), 0) self.assertEqual(SmartLink.objects.count(), 0)
def test_smart_link_edit_view_no_permission(self): def _request_smart_link_edit_view(self):
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL) return self.post(
viewname='linking:smart_link_edit',
response = self.post( kwargs={'smart_link_id': self.test_smart_link.pk}, data={
'linking:smart_link_edit', args=(smart_link.pk,), data={
'label': TEST_SMART_LINK_LABEL_EDITED 'label': TEST_SMART_LINK_LABEL_EDITED
} }
) )
self.assertEqual(response.status_code, 403)
smart_link = SmartLink.objects.get(pk=smart_link.pk)
self.assertEqual(smart_link.label, TEST_SMART_LINK_LABEL)
def test_smart_link_edit_view_with_permission(self): def test_smart_link_edit_view_no_permission(self):
self.role.permissions.add( self._create_test_smart_link()
permission_smart_link_edit.stored_permission
response = self._request_smart_link_edit_view()
self.assertEqual(response.status_code, 404)
self.test_smart_link.refresh_from_db()
self.assertEqual(self.test_smart_link.label, TEST_SMART_LINK_LABEL)
def test_smart_link_edit_view_with_access(self):
self._create_test_smart_link()
self.grant_access(
obj=self.test_smart_link, permission=permission_smart_link_edit
) )
response = self._request_smart_link_edit_view()
self.assertEqual(response.status_code, 302)
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL) self.test_smart_link.refresh_from_db()
self.assertEqual(
response = self.post( self.test_smart_link.label, TEST_SMART_LINK_LABEL_EDITED
'linking:smart_link_edit', args=(smart_link.pk,), data={
'label': TEST_SMART_LINK_LABEL_EDITED
}, follow=True
) )
smart_link = SmartLink.objects.get(pk=smart_link.pk)
self.assertContains(response, text='update', status_code=200)
self.assertEqual(smart_link.label, TEST_SMART_LINK_LABEL_EDITED)
class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase): class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase):
def setUp(self): def _setup_smart_links(self):
super(SmartLinkDocumentsViewTestCase, self).setUp() self.test_smart_link = SmartLink.objects.create(
self.login_user()
def setup_smart_links(self):
smart_link = SmartLink.objects.create(
label=TEST_SMART_LINK_LABEL, label=TEST_SMART_LINK_LABEL,
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
) )
smart_link.document_types.add(self.document_type) self.test_smart_link.document_types.add(self.document_type)
smart_link_2 = SmartLink.objects.create( self.test_smart_link_2 = SmartLink.objects.create(
label=TEST_SMART_LINK_LABEL, label=TEST_SMART_LINK_LABEL,
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
) )
smart_link_2.document_types.add(self.document_type) self.test_smart_link_2.document_types.add(self.document_type)
def _request_document_resolved_smart_links_for_document_view(self):
return self.get(
viewname='linking:resolved_smart_links_for_document',
kwargs={'document_id': self.document.pk}
)
def test_document_smart_link_list_view_no_permission(self): def test_document_smart_link_list_view_no_permission(self):
self.setup_smart_links() self._setup_smart_links()
self.role.permissions.add( self.grant_access(obj=self.document, permission=permission_document_view)
permission_document_view.stored_permission
)
response = self.get( response = self._request_document_resolved_smart_links_for_document_view()
'linking:smart_link_instances_for_document',
args=(self.document.pk,)
)
# Text must appear 3 times, 2 for the window titles and template # Text must appear 3 times, 2 for the window titles and template
# heading. The two smart links are not shown. # heading. The two smart links are not shown.
@@ -137,20 +132,13 @@ class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase):
) )
def test_document_smart_link_list_view_with_permission(self): def test_document_smart_link_list_view_with_permission(self):
self.setup_smart_links() self._setup_smart_links()
self.role.permissions.add( self.grant_access(obj=self.document, permission=permission_document_view)
permission_smart_link_view.stored_permission self.grant_access(
) obj=self.test_smart_link, permission=permission_smart_link_view
self.role.permissions.add(
permission_document_view.stored_permission
)
response = self.get(
'linking:smart_link_instances_for_document',
args=(self.document.pk,)
) )
response = self._request_document_resolved_smart_links_for_document_view()
# Text must appear 5 times: 3 for the window titles and template # Text must appear 5 times: 3 for the window titles and template
# heading, plus 2 for the test. # heading, plus 2 for the test.
+52 -49
View File
@@ -17,86 +17,89 @@ from .views import (
urlpatterns = [ urlpatterns = [
url( url(
r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(), regex=r'^smart_links/$', name='smart_link_list',
name='smart_link_instances_for_document' view=SmartLinkListView.as_view()
), ),
url( url(
r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$', regex=r'^smart_links/create/$', name='smart_link_create',
ResolvedSmartLinkView.as_view(), name='smart_link_instance_view' view=SmartLinkCreateView.as_view()
),
url(
r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'
), ),
url( url(
r'^setup/create/$', SmartLinkCreateView.as_view(), regex=r'^smart_links/(?P<smart_link_id>\d+)/delete/$',
name='smart_link_create' name='smart_link_delete', view=SmartLinkDeleteView.as_view()
), ),
url( url(
r'^setup/(?P<pk>\d+)/delete/$', regex=r'^smart_links/(?P<smart_link_id>\d+)/edit/$',
SmartLinkDeleteView.as_view(), name='smart_link_delete' name='smart_link_edit', view=SmartLinkEditView.as_view()
), ),
url( url(
r'^setup/(?P<pk>\d+)/edit/$', SmartLinkEditView.as_view(), regex=r'^smart_links/(?P<smart_link_id>\d+)/document_types/$',
name='smart_link_edit' name='smart_link_document_types',
view=SetupSmartLinkDocumentTypesView.as_view()
), ),
url( url(
r'^setup/(?P<pk>\d+)/document_types/$', regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/$',
SetupSmartLinkDocumentTypesView.as_view(), name='smart_link_condition_list',
name='smart_link_document_types' view=SmartLinkConditionListView.as_view()
),
url(
r'^setup/(?P<pk>\d+)/condition/list/$',
SmartLinkConditionListView.as_view(), name='smart_link_condition_list'
), ),
url( url(
r'^setup/(?P<pk>\d+)/condition/create/$', regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/create/$',
SmartLinkConditionCreateView.as_view(), name='smart_link_condition_create',
name='smart_link_condition_create' view=SmartLinkConditionCreateView.as_view()
), ),
url( url(
r'^setup/smart_link/condition/(?P<pk>\d+)/edit/$', regex=r'^smart_links/conditions/(?P<smart_link_condition_id>\d+)/edit/$',
SmartLinkConditionEditView.as_view(), name='smart_link_condition_edit' name='smart_link_condition_edit',
view=SmartLinkConditionEditView.as_view()
), ),
url( url(
r'^setup/smart_link/condition/(?P<pk>\d+)/delete/$', regex=r'^smart_links/conditions/(?P<smart_link_condition_id>\d+)/delete/$',
SmartLinkConditionDeleteView.as_view(), name='smart_link_condition_delete',
name='smart_link_condition_delete' view=SmartLinkConditionDeleteView.as_view()
), ),
url(
regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/$',
name='resolved_smart_links_for_document',
view=DocumentSmartLinkListView.as_view()
),
url(
regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/(?P<smart_link_id>\d+)/$',
name='resolved_smart_link_details', view=ResolvedSmartLinkView.as_view()
)
] ]
api_urls = [ api_urls = [
url( url(
r'^smart_links/$', APISmartLinkListView.as_view(), regex=r'^smart_links/$', name='smartlink-list',
name='smartlink-list' view=APISmartLinkListView.as_view()
), ),
url( url(
r'^smart_links/(?P<pk>[0-9]+)/$', APISmartLinkView.as_view(), regex=r'^smart_links/(?P<smart_link_id>\d+)/$',
name='smartlink-detail' name='smartlink-detail', view=APISmartLinkView.as_view()
), ),
url( url(
r'^smart_links/(?P<pk>[0-9]+)/conditions/$', regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/$',
APISmartLinkConditionListView.as_view(), name='smartlinkcondition-list' name='smartlinkcondition-list',
view=APISmartLinkConditionListView.as_view()
), ),
url( url(
r'^smart_links/(?P<pk>[0-9]+)/conditions/(?P<condition_pk>[0-9]+)/$', regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/(?P<condition_id>\d+)/$',
APISmartLinkConditionView.as_view(), name='smartlinkcondition-detail',
name='smartlinkcondition-detail' view=APISmartLinkConditionView.as_view()
), ),
url( url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/$', regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/$',
APIResolvedSmartLinkListView.as_view(), name='resolvedsmartlink-list',
name='resolvedsmartlink-list' view=APIResolvedSmartLinkListView.as_view()
), ),
url( url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/(?P<smart_link_pk>[0-9]+)/$', regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/(?P<smart_link_id>\d+)/$',
APIResolvedSmartLinkView.as_view(), name='resolvedsmartlink-detail',
name='resolvedsmartlink-detail' view=APIResolvedSmartLinkView.as_view()
), ),
url( url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/(?P<smart_link_pk>[0-9]+)/documents/$', regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/(?P<smart_link_id>\d+)/documents/$',
APIResolvedSmartLinkDocumentListView.as_view(), name='resolvedsmartlinkdocument-list',
name='resolvedsmartlinkdocument-list' view=APIResolvedSmartLinkDocumentListView.as_view()
), )
] ]
+49 -38
View File
@@ -33,20 +33,20 @@ logger = logging.getLogger(__name__)
class ResolvedSmartLinkView(DocumentListView): class ResolvedSmartLinkView(DocumentListView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404( self.document = get_object_or_404(
klass=Document, pk=self.kwargs['document_pk'] klass=Document, pk=self.kwargs['document_id']
) )
self.smart_link = get_object_or_404( self.smart_link = get_object_or_404(
klass=SmartLink, pk=self.kwargs['smart_link_pk'] klass=SmartLink, pk=self.kwargs['smart_link_id']
) )
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user, obj=self.document, permissions=permission_document_view,
obj=self.document user=request.user
) )
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_smart_link_view, user=request.user, obj=self.smart_link, permissions=permission_smart_link_view,
obj=self.smart_link user=request.user
) )
return super( return super(
@@ -55,20 +55,24 @@ class ResolvedSmartLinkView(DocumentListView):
def get_document_queryset(self): def get_document_queryset(self):
try: try:
queryset = self.smart_link.get_linked_document_for(self.document) queryset = self.smart_link.get_linked_document_for(
document=self.document
)
except Exception as exception: except Exception as exception:
queryset = Document.objects.none() queryset = Document.objects.none()
try: try:
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=self.request.user, obj=self.smart_link, permissions=permission_smart_link_edit,
obj=self.smart_link user=self.request.user
) )
except PermissionDenied: except PermissionDenied:
pass pass
else: else:
messages.error( messages.error(
self.request, _('Smart link query error: %s' % exception) message=_(
'Smart link query error: %s' % exception
), request=self.request,
) )
return queryset return queryset
@@ -114,12 +118,14 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
} }
def get_object(self): def get_object(self):
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk']) return get_object_or_404(
klass=SmartLink, pk=self.kwargs['smart_link_id']
)
def left_list(self): def left_list(self):
# TODO: filter document type list by user ACL # TODO: filter document type list by user ACL
return AssignRemoveView.generate_choices( return AssignRemoveView.generate_choices(
DocumentType.objects.exclude( choices=DocumentType.objects.exclude(
pk__in=self.get_object().document_types.all() pk__in=self.get_object().document_types.all()
) )
) )
@@ -130,7 +136,7 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
def right_list(self): def right_list(self):
# TODO: filter document type list by user ACL # TODO: filter document type list by user ACL
return AssignRemoveView.generate_choices( return AssignRemoveView.generate_choices(
self.get_object().document_types.all() choices=self.get_object().document_types.all()
) )
@@ -166,11 +172,13 @@ class SmartLinkListView(SingleObjectListView):
class DocumentSmartLinkListView(SmartLinkListView): class DocumentSmartLinkListView(SmartLinkListView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404(klass=Document, pk=self.kwargs['pk']) self.document = get_object_or_404(
klass=Document, pk=self.kwargs['document_id']
)
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user, obj=self.document, permissions=permission_document_view,
obj=self.document user=request.user
) )
return super( return super(
@@ -202,15 +210,16 @@ class DocumentSmartLinkListView(SmartLinkListView):
class SmartLinkCreateView(SingleObjectCreateView): class SmartLinkCreateView(SingleObjectCreateView):
extra_context = {'title': _('Create new smart link')} extra_context = {'title': _('Create new smart link')}
form_class = SmartLinkForm form_class = SmartLinkForm
post_action_redirect = reverse_lazy('linking:smart_link_list') post_action_redirect = reverse_lazy(viewname='linking:smart_link_list')
view_permission = permission_smart_link_create view_permission = permission_smart_link_create
class SmartLinkEditView(SingleObjectEditView): class SmartLinkEditView(SingleObjectEditView):
form_class = SmartLinkForm form_class = SmartLinkForm
model = SmartLink model = SmartLink
post_action_redirect = reverse_lazy('linking:smart_link_list') object_permission = permission_smart_link_edit
view_permission = permission_smart_link_edit pk_url_kwarg = 'smart_link_id'
post_action_redirect = reverse_lazy(viewname='linking:smart_link_list')
def get_extra_context(self): def get_extra_context(self):
return { return {
@@ -221,8 +230,9 @@ class SmartLinkEditView(SingleObjectEditView):
class SmartLinkDeleteView(SingleObjectDeleteView): class SmartLinkDeleteView(SingleObjectDeleteView):
model = SmartLink model = SmartLink
post_action_redirect = reverse_lazy('linking:smart_link_list') object_permission = permission_smart_link_delete
view_permission = permission_smart_link_delete pk_url_kwarg = 'smart_link_id'
post_action_redirect = reverse_lazy(viewname='linking:smart_link_list')
def get_extra_context(self): def get_extra_context(self):
return { return {
@@ -262,7 +272,9 @@ class SmartLinkConditionListView(SingleObjectListView):
return self.get_smart_link().conditions.all() return self.get_smart_link().conditions.all()
def get_smart_link(self): def get_smart_link(self):
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk']) return get_object_or_404(
klass=SmartLink, pk=self.kwargs['smart_link_id']
)
class SmartLinkConditionCreateView(SingleObjectCreateView): class SmartLinkConditionCreateView(SingleObjectCreateView):
@@ -270,8 +282,8 @@ class SmartLinkConditionCreateView(SingleObjectCreateView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=request.user, obj=self.get_smart_link(), permissions=permission_smart_link_edit,
obj=self.get_smart_link() user=request.user
) )
return super( return super(
@@ -291,16 +303,17 @@ class SmartLinkConditionCreateView(SingleObjectCreateView):
def get_post_action_redirect(self): def get_post_action_redirect(self):
return reverse( return reverse(
'linking:smart_link_condition_list', args=( viewname='linking:smart_link_condition_list',
self.get_smart_link().pk, kwargs={'smart_link_id': self.get_smart_link().pk}
)
) )
def get_queryset(self): def get_queryset(self):
return self.get_smart_link().conditions.all() return self.get_smart_link().conditions.all()
def get_smart_link(self): def get_smart_link(self):
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk']) return get_object_or_404(
klass=SmartLink, pk=self.kwargs['smart_link_id']
)
class SmartLinkConditionEditView(SingleObjectEditView): class SmartLinkConditionEditView(SingleObjectEditView):
@@ -309,8 +322,8 @@ class SmartLinkConditionEditView(SingleObjectEditView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=request.user, obj=self.get_object().smart_link,
obj=self.get_object().smart_link permissions=permission_smart_link_edit, user=request.user
) )
return super( return super(
@@ -327,9 +340,8 @@ class SmartLinkConditionEditView(SingleObjectEditView):
def get_post_action_redirect(self): def get_post_action_redirect(self):
return reverse( return reverse(
'linking:smart_link_condition_list', args=( viewname='linking:smart_link_condition_list',
self.get_object().smart_link.pk, kwargs={'smart_link_id': self.get_object().smart_link.pk}
)
) )
@@ -338,8 +350,8 @@ class SmartLinkConditionDeleteView(SingleObjectDeleteView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
AccessControlList.objects.check_access( AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=request.user, obj=self.get_object().smart_link,
obj=self.get_object().smart_link permissions=permission_smart_link_edit, user=request.user
) )
return super( return super(
@@ -358,7 +370,6 @@ class SmartLinkConditionDeleteView(SingleObjectDeleteView):
def get_post_action_redirect(self): def get_post_action_redirect(self):
return reverse( return reverse(
'linking:smart_link_condition_list', args=( viewname='linking:smart_link_condition_list',
self.get_object().smart_link.pk, kwargs={'smart_link_id': self.get_object().smart_link.pk}
)
) )