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

View File

@@ -32,7 +32,7 @@ class APIResolvedSmartLinkDocumentListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkDocumentSerializer
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(
permissions=permission_document_view, user=self.request.user,
@@ -86,7 +86,7 @@ class APIResolvedSmartLinkView(generics.RetrieveAPIView):
serializer_class = ResolvedSmartLinkSerializer
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(
permissions=permission_document_view, user=self.request.user,
@@ -123,7 +123,7 @@ class APIResolvedSmartLinkListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkSerializer
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(
permissions=permission_document_view, user=self.request.user,
@@ -182,7 +182,7 @@ class APISmartLinkConditionListView(generics.ListCreateAPIView):
else:
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(
permissions=permission_required, user=self.request.user,
@@ -225,7 +225,7 @@ class APISmartLinkConditionView(generics.RetrieveUpdateDestroyAPIView):
else:
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(
permissions=permission_required, user=self.request.user,

View File

@@ -45,5 +45,5 @@ class SmartLinkConditionForm(forms.ModelForm):
)
class Meta:
model = SmartLinkCondition
exclude = ('smart_link',)
model = SmartLinkCondition

View File

@@ -17,23 +17,25 @@ from .permissions import (
)
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'),
view='linking:smart_link_condition_create',
view='linking:smart_link_condition_create'
)
link_smart_link_condition_delete = Link(
args='resolved_object.pk', permissions=(permission_smart_link_edit,),
tags='dangerous', text=_('Delete'),
view='linking:smart_link_condition_delete',
kwargs={'smart_link_condition_id': 'resolved_object.pk'},
permissions=(permission_smart_link_edit,), tags='dangerous',
text=_('Delete'), view='linking:smart_link_condition_delete'
)
link_smart_link_condition_edit = Link(
args='resolved_object.pk', permissions=(permission_smart_link_edit,),
text=_('Edit'), view='linking:smart_link_condition_edit',
kwargs={'smart_link_condition_id': 'resolved_object.pk'},
permissions=(permission_smart_link_edit,), text=_('Edit'),
view='linking:smart_link_condition_edit'
)
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'),
view='linking:smart_link_condition_list',
view='linking:smart_link_condition_list'
)
link_smart_link_create = Link(
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'
)
link_smart_link_delete = Link(
args='object.pk', permissions=(permission_smart_link_delete,),
tags='dangerous', text=_('Delete'), view='linking:smart_link_delete',
kwargs={'smart_link_id': 'object.pk'},
permissions=(permission_smart_link_delete,),
tags='dangerous', text=_('Delete'), view='linking:smart_link_delete'
)
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'),
view='linking:smart_link_document_types',
)
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',
)
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'),
view='linking:smart_link_instance_view',
view='linking:resolved_smart_link_details'
)
link_smart_link_instances_for_document = Link(
args='resolved_object.pk',
icon_class=icon_smart_link_instances_for_document,
kwargs={'document_id': 'resolved_object.pk'},
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(
permissions=(permission_smart_link_create,), text=_('Smart links'),
permissions=(permission_smart_link_view,), text=_('Smart links'),
view='linking:smart_link_list'
)
link_smart_link_setup = Link(
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 File

@@ -6,15 +6,15 @@ from mayan.apps.permissions import PermissionNamespace
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(
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(
name='smart_link_delete', label=_('Delete smart links')
label=_('Delete smart links'), name='smart_link_delete'
)
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'
)

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
)

View File

@@ -66,7 +66,7 @@ class SmartLinkAPITestCase(DocumentTestMixin, BaseAPITestCase):
return self.post(
viewname='rest_api:smartlink-list', data={
'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',
args=(self.smart_link.pk,), data={
'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',
args=(self.smart_link.pk,), data={
'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_condition()
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()
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertFalse('label' in response.data)

View File

@@ -2,20 +2,16 @@ from __future__ import unicode_literals
from mayan.apps.documents.tests import GenericDocumentTestCase
from ..models import SmartLink
from .literals import TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL
from .mixins import SmartLinkTestMixin
class SmartLinkTestCase(GenericDocumentTestCase):
class SmartLinkTestCase(SmartLinkTestMixin, GenericDocumentTestCase):
def test_dynamic_label(self):
smart_link = SmartLink.objects.create(
label=TEST_SMART_LINK_LABEL,
dynamic_label=TEST_SMART_LINK_DYNAMIC_LABEL
)
smart_link.document_types.add(self.document_type)
self._create_test_smart_link()
self.test_smart_link.document_types.add(self.document_type)
self.assertEqual(
smart_link.get_dynamic_label(document=self.document),
self.test_smart_link.get_dynamic_label(document=self.document),
self.document.label
)

View File

@@ -14,121 +14,116 @@ from .literals import (
TEST_SMART_LINK_DYNAMIC_LABEL, TEST_SMART_LINK_LABEL,
TEST_SMART_LINK_LABEL_EDITED
)
from .mixins import SmartLinkTestMixin
class SmartLinkViewTestCase(GenericViewTestCase):
def setUp(self):
super(SmartLinkViewTestCase, self).setUp()
self.login_user()
def test_smart_link_create_view_no_permission(self):
response = self.post(
'linking:smart_link_create', data={
class SmartLinkViewTestCase(SmartLinkTestMixin, GenericViewTestCase):
def _request_smart_link_create_view(self):
return self.post(
viewname='linking:smart_link_create', data={
'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)
def test_smart_link_create_view_with_permission(self):
self.role.permissions.add(
permission_smart_link_create.stored_permission
)
self.grant_permission(permission=permission_smart_link_create)
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.first().label, TEST_SMART_LINK_LABEL
)
def test_smart_link_delete_view_no_permission(self):
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
response = self.post(
'linking:smart_link_delete', args=(smart_link.pk,)
def _request_smart_link_delete_view(self):
return self.post(
viewname='linking:smart_link_delete',
kwargs={'smart_link_id': self.test_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)
def test_smart_link_delete_view_with_permission(self):
self.role.permissions.add(
permission_smart_link_delete.stored_permission
def test_smart_link_delete_view_with_access(self):
self._create_test_smart_link()
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)
def test_smart_link_edit_view_no_permission(self):
smart_link = SmartLink.objects.create(label=TEST_SMART_LINK_LABEL)
response = self.post(
'linking:smart_link_edit', args=(smart_link.pk,), data={
def _request_smart_link_edit_view(self):
return self.post(
viewname='linking:smart_link_edit',
kwargs={'smart_link_id': self.test_smart_link.pk}, data={
'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):
self.role.permissions.add(
permission_smart_link_edit.stored_permission
def test_smart_link_edit_view_no_permission(self):
self._create_test_smart_link()
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)
response = self.post(
'linking:smart_link_edit', args=(smart_link.pk,), data={
'label': TEST_SMART_LINK_LABEL_EDITED
}, follow=True
self.test_smart_link.refresh_from_db()
self.assertEqual(
self.test_smart_link.label, TEST_SMART_LINK_LABEL_EDITED
)
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):
def setUp(self):
super(SmartLinkDocumentsViewTestCase, self).setUp()
self.login_user()
def setup_smart_links(self):
smart_link = SmartLink.objects.create(
def _setup_smart_links(self):
self.test_smart_link = SmartLink.objects.create(
label=TEST_SMART_LINK_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,
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):
self.setup_smart_links()
self._setup_smart_links()
self.role.permissions.add(
permission_document_view.stored_permission
)
self.grant_access(obj=self.document, permission=permission_document_view)
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 3 times, 2 for the window titles and template
# 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):
self.setup_smart_links()
self._setup_smart_links()
self.role.permissions.add(
permission_smart_link_view.stored_permission
)
self.role.permissions.add(
permission_document_view.stored_permission
)
response = self.get(
'linking:smart_link_instances_for_document',
args=(self.document.pk,)
self.grant_access(obj=self.document, permission=permission_document_view)
self.grant_access(
obj=self.test_smart_link, permission=permission_smart_link_view
)
response = self._request_document_resolved_smart_links_for_document_view()
# Text must appear 5 times: 3 for the window titles and template
# heading, plus 2 for the test.

View File

@@ -17,86 +17,89 @@ from .views import (
urlpatterns = [
url(
r'^document/(?P<pk>\d+)/list/$', DocumentSmartLinkListView.as_view(),
name='smart_link_instances_for_document'
regex=r'^smart_links/$', name='smart_link_list',
view=SmartLinkListView.as_view()
),
url(
r'^document/(?P<document_pk>\d+)/(?P<smart_link_pk>\d+)/$',
ResolvedSmartLinkView.as_view(), name='smart_link_instance_view'
),
url(
r'^setup/list/$', SmartLinkListView.as_view(), name='smart_link_list'
regex=r'^smart_links/create/$', name='smart_link_create',
view=SmartLinkCreateView.as_view()
),
url(
r'^setup/create/$', SmartLinkCreateView.as_view(),
name='smart_link_create'
regex=r'^smart_links/(?P<smart_link_id>\d+)/delete/$',
name='smart_link_delete', view=SmartLinkDeleteView.as_view()
),
url(
r'^setup/(?P<pk>\d+)/delete/$',
SmartLinkDeleteView.as_view(), name='smart_link_delete'
regex=r'^smart_links/(?P<smart_link_id>\d+)/edit/$',
name='smart_link_edit', view=SmartLinkEditView.as_view()
),
url(
r'^setup/(?P<pk>\d+)/edit/$', SmartLinkEditView.as_view(),
name='smart_link_edit'
regex=r'^smart_links/(?P<smart_link_id>\d+)/document_types/$',
name='smart_link_document_types',
view=SetupSmartLinkDocumentTypesView.as_view()
),
url(
r'^setup/(?P<pk>\d+)/document_types/$',
SetupSmartLinkDocumentTypesView.as_view(),
name='smart_link_document_types'
),
url(
r'^setup/(?P<pk>\d+)/condition/list/$',
SmartLinkConditionListView.as_view(), name='smart_link_condition_list'
regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/$',
name='smart_link_condition_list',
view=SmartLinkConditionListView.as_view()
),
url(
r'^setup/(?P<pk>\d+)/condition/create/$',
SmartLinkConditionCreateView.as_view(),
name='smart_link_condition_create'
regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/create/$',
name='smart_link_condition_create',
view=SmartLinkConditionCreateView.as_view()
),
url(
r'^setup/smart_link/condition/(?P<pk>\d+)/edit/$',
SmartLinkConditionEditView.as_view(), name='smart_link_condition_edit'
regex=r'^smart_links/conditions/(?P<smart_link_condition_id>\d+)/edit/$',
name='smart_link_condition_edit',
view=SmartLinkConditionEditView.as_view()
),
url(
r'^setup/smart_link/condition/(?P<pk>\d+)/delete/$',
SmartLinkConditionDeleteView.as_view(),
name='smart_link_condition_delete'
regex=r'^smart_links/conditions/(?P<smart_link_condition_id>\d+)/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 = [
url(
r'^smart_links/$', APISmartLinkListView.as_view(),
name='smartlink-list'
regex=r'^smart_links/$', name='smartlink-list',
view=APISmartLinkListView.as_view()
),
url(
r'^smart_links/(?P<pk>[0-9]+)/$', APISmartLinkView.as_view(),
name='smartlink-detail'
regex=r'^smart_links/(?P<smart_link_id>\d+)/$',
name='smartlink-detail', view=APISmartLinkView.as_view()
),
url(
r'^smart_links/(?P<pk>[0-9]+)/conditions/$',
APISmartLinkConditionListView.as_view(), name='smartlinkcondition-list'
regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/$',
name='smartlinkcondition-list',
view=APISmartLinkConditionListView.as_view()
),
url(
r'^smart_links/(?P<pk>[0-9]+)/conditions/(?P<condition_pk>[0-9]+)/$',
APISmartLinkConditionView.as_view(),
name='smartlinkcondition-detail'
regex=r'^smart_links/(?P<smart_link_id>\d+)/conditions/(?P<condition_id>\d+)/$',
name='smartlinkcondition-detail',
view=APISmartLinkConditionView.as_view()
),
url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/$',
APIResolvedSmartLinkListView.as_view(),
name='resolvedsmartlink-list'
regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/$',
name='resolvedsmartlink-list',
view=APIResolvedSmartLinkListView.as_view()
),
url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/(?P<smart_link_pk>[0-9]+)/$',
APIResolvedSmartLinkView.as_view(),
name='resolvedsmartlink-detail'
regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/(?P<smart_link_id>\d+)/$',
name='resolvedsmartlink-detail',
view=APIResolvedSmartLinkView.as_view()
),
url(
r'^documents/(?P<pk>[0-9]+)/resolved_smart_links/(?P<smart_link_pk>[0-9]+)/documents/$',
APIResolvedSmartLinkDocumentListView.as_view(),
name='resolvedsmartlinkdocument-list'
),
regex=r'^documents/(?P<document_id>\d+)/resolved_smart_links/(?P<smart_link_id>\d+)/documents/$',
name='resolvedsmartlinkdocument-list',
view=APIResolvedSmartLinkDocumentListView.as_view()
)
]

View File

@@ -33,20 +33,20 @@ logger = logging.getLogger(__name__)
class ResolvedSmartLinkView(DocumentListView):
def dispatch(self, request, *args, **kwargs):
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(
klass=SmartLink, pk=self.kwargs['smart_link_pk']
klass=SmartLink, pk=self.kwargs['smart_link_id']
)
AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user,
obj=self.document
obj=self.document, permissions=permission_document_view,
user=request.user
)
AccessControlList.objects.check_access(
permissions=permission_smart_link_view, user=request.user,
obj=self.smart_link
obj=self.smart_link, permissions=permission_smart_link_view,
user=request.user
)
return super(
@@ -55,20 +55,24 @@ class ResolvedSmartLinkView(DocumentListView):
def get_document_queryset(self):
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:
queryset = Document.objects.none()
try:
AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=self.request.user,
obj=self.smart_link
obj=self.smart_link, permissions=permission_smart_link_edit,
user=self.request.user
)
except PermissionDenied:
pass
else:
messages.error(
self.request, _('Smart link query error: %s' % exception)
message=_(
'Smart link query error: %s' % exception
), request=self.request,
)
return queryset
@@ -114,12 +118,14 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
}
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):
# TODO: filter document type list by user ACL
return AssignRemoveView.generate_choices(
DocumentType.objects.exclude(
choices=DocumentType.objects.exclude(
pk__in=self.get_object().document_types.all()
)
)
@@ -130,7 +136,7 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
def right_list(self):
# TODO: filter document type list by user ACL
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):
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(
permissions=permission_document_view, user=request.user,
obj=self.document
obj=self.document, permissions=permission_document_view,
user=request.user
)
return super(
@@ -202,15 +210,16 @@ class DocumentSmartLinkListView(SmartLinkListView):
class SmartLinkCreateView(SingleObjectCreateView):
extra_context = {'title': _('Create new smart link')}
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
class SmartLinkEditView(SingleObjectEditView):
form_class = SmartLinkForm
model = SmartLink
post_action_redirect = reverse_lazy('linking:smart_link_list')
view_permission = permission_smart_link_edit
object_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):
return {
@@ -221,8 +230,9 @@ class SmartLinkEditView(SingleObjectEditView):
class SmartLinkDeleteView(SingleObjectDeleteView):
model = SmartLink
post_action_redirect = reverse_lazy('linking:smart_link_list')
view_permission = permission_smart_link_delete
object_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):
return {
@@ -262,7 +272,9 @@ class SmartLinkConditionListView(SingleObjectListView):
return self.get_smart_link().conditions.all()
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):
@@ -270,8 +282,8 @@ class SmartLinkConditionCreateView(SingleObjectCreateView):
def dispatch(self, request, *args, **kwargs):
AccessControlList.objects.check_access(
permissions=permission_smart_link_edit, user=request.user,
obj=self.get_smart_link()
obj=self.get_smart_link(), permissions=permission_smart_link_edit,
user=request.user
)
return super(
@@ -291,16 +303,17 @@ class SmartLinkConditionCreateView(SingleObjectCreateView):
def get_post_action_redirect(self):
return reverse(
'linking:smart_link_condition_list', args=(
self.get_smart_link().pk,
)
viewname='linking:smart_link_condition_list',
kwargs={'smart_link_id': self.get_smart_link().pk}
)
def get_queryset(self):
return self.get_smart_link().conditions.all()
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):
@@ -309,8 +322,8 @@ class SmartLinkConditionEditView(SingleObjectEditView):
def dispatch(self, request, *args, **kwargs):
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(
@@ -327,9 +340,8 @@ class SmartLinkConditionEditView(SingleObjectEditView):
def get_post_action_redirect(self):
return reverse(
'linking:smart_link_condition_list', args=(
self.get_object().smart_link.pk,
)
viewname='linking:smart_link_condition_list',
kwargs={'smart_link_id': self.get_object().smart_link.pk}
)
@@ -338,8 +350,8 @@ class SmartLinkConditionDeleteView(SingleObjectDeleteView):
def dispatch(self, request, *args, **kwargs):
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(
@@ -358,7 +370,6 @@ class SmartLinkConditionDeleteView(SingleObjectDeleteView):
def get_post_action_redirect(self):
return reverse(
'linking:smart_link_condition_list', args=(
self.get_object().smart_link.pk,
)
viewname='linking:smart_link_condition_list',
kwargs={'smart_link_id': self.get_object().smart_link.pk}
)