From 2052caada456306ae29b46c4885e45d9a26baaaa Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 16 Aug 2017 22:11:22 -0400 Subject: [PATCH] Remove PreserveGetQuerySet mixin. Update SingleObjectList and MultipleObjectFormActionView views to use a new get_object_list method. Signed-off-by: Roberto Rosario --- mayan/apps/acls/managers.py | 9 +- mayan/apps/acls/views.py | 2 +- mayan/apps/cabinets/tests/test_views.py | 178 +++++---- mayan/apps/cabinets/views.py | 4 +- mayan/apps/checkouts/apps.py | 1 - mayan/apps/checkouts/tests/test_models.py | 7 + mayan/apps/checkouts/tests/test_views.py | 43 +-- mayan/apps/common/generics.py | 48 ++- mayan/apps/common/mixins.py | 24 +- mayan/apps/common/views.py | 2 +- mayan/apps/converter/views.py | 42 +- mayan/apps/django_gpg/views.py | 2 +- mayan/apps/document_comments/views.py | 16 +- mayan/apps/document_indexing/views.py | 44 +-- .../document_signatures/tests/test_models.py | 4 + .../document_signatures/tests/test_views.py | 84 ++-- mayan/apps/document_signatures/views.py | 2 +- mayan/apps/document_states/views.py | 66 ++-- mayan/apps/documents/tests/test_views.py | 2 +- .../documents/views/document_page_views.py | 6 +- .../documents/views/document_type_views.py | 2 +- .../documents/views/document_version_views.py | 2 +- mayan/apps/documents/views/document_views.py | 4 +- mayan/apps/dynamic_search/views.py | 2 +- mayan/apps/events/views.py | 14 +- mayan/apps/linking/views.py | 4 +- mayan/apps/mailer/views.py | 2 +- mayan/apps/metadata/tests/test_views.py | 6 +- mayan/apps/metadata/views.py | 8 +- mayan/apps/ocr/views.py | 4 +- mayan/apps/smart_settings/views.py | 4 +- mayan/apps/sources/tests/test_views.py | 6 +- mayan/apps/sources/views.py | 16 +- mayan/apps/statistics/tests/test_views.py | 16 +- mayan/apps/statistics/views.py | 4 +- mayan/apps/tags/forms.py | 2 +- mayan/apps/tags/tests/test_views.py | 362 +++++++++--------- mayan/apps/tags/views.py | 2 +- mayan/apps/user_management/views.py | 2 +- 39 files changed, 540 insertions(+), 508 deletions(-) diff --git a/mayan/apps/acls/managers.py b/mayan/apps/acls/managers.py index 6474413510..e5046af633 100644 --- a/mayan/apps/acls/managers.py +++ b/mayan/apps/acls/managers.py @@ -26,8 +26,8 @@ class AccessControlListManager(models.Manager): def check_access(self, permissions, user, obj, related=None): if user.is_superuser or user.is_staff: logger.debug( - 'Permissions "%s" on "%s" granted to user "%s" as superuser or staff', - permissions, obj, user + 'Permissions "%s" on "%s" granted to user "%s" as superuser ' + 'or staff', permissions, obj, user ) return True @@ -53,14 +53,15 @@ class AccessControlListManager(models.Manager): ) except AttributeError: # AttributeError means non model objects: ie Statistics - # These can't have ACLS so we raise PermissionDenied + # These can't have ACLs so we raise PermissionDenied raise PermissionDenied except KeyError: pass else: try: return self.check_access( - permissions, user, getattr(obj, parent_accessor) + obj=getattr(obj, parent_accessor), + permissions=permissions, user=user ) except PermissionDenied: pass diff --git a/mayan/apps/acls/views.py b/mayan/apps/acls/views.py index b2becb9056..9f156e1fc3 100644 --- a/mayan/apps/acls/views.py +++ b/mayan/apps/acls/views.py @@ -139,7 +139,7 @@ class ACLListView(SingleObjectListView): 'title': _('Access control lists for: %s' % self.content_object), } - def get_queryset(self): + def get_object_list(self): return AccessControlList.objects.filter( content_type=self.object_content_type, object_id=self.content_object.pk diff --git a/mayan/apps/cabinets/tests/test_views.py b/mayan/apps/cabinets/tests/test_views.py index 577afb8db5..be4e59249d 100644 --- a/mayan/apps/cabinets/tests/test_views.py +++ b/mayan/apps/cabinets/tests/test_views.py @@ -17,6 +17,9 @@ class CabinetViewTestCase(GenericDocumentViewTestCase): super(CabinetViewTestCase, self).setUp() self.login_user() + def _create_cabinet(self): + self.cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + def _request_create_cabinet(self, label): return self.post( 'cabinets:cabinet_create', data={ @@ -40,174 +43,179 @@ class CabinetViewTestCase(GenericDocumentViewTestCase): self.assertEqual(Cabinet.objects.first().label, TEST_CABINET_LABEL) def test_cabinet_create_duplicate_view_with_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() self.grant_permission(permission=permission_cabinet_create) response = self._request_create_cabinet(label=TEST_CABINET_LABEL) # HTTP 200 with error message self.assertEqual(response.status_code, 200) self.assertEqual(Cabinet.objects.count(), 1) - self.assertEqual(Cabinet.objects.first().pk, cabinet.pk) + self.assertEqual(Cabinet.objects.first().pk, self.cabinet.pk) - def _delete_cabinet(self, cabinet): - return self.post('cabinets:cabinet_delete', args=(cabinet.pk,)) + def _request_delete_cabinet(self): + return self.post('cabinets:cabinet_delete', args=(self.cabinet.pk,)) def test_cabinet_delete_view_no_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() - response = self._delete_cabinet(cabinet=cabinet) + response = self._request_delete_cabinet() self.assertEqual(response.status_code, 403) self.assertEqual(Cabinet.objects.count(), 1) - def test_cabinet_delete_view_with_permission(self): - self.grant_permission(permission=permission_cabinet_delete) + def test_cabinet_delete_view_with_access(self): + self._create_cabinet() + self.grant_access(obj=self.cabinet, permission=permission_cabinet_delete) - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) - - response = self._delete_cabinet(cabinet=cabinet) + response = self._request_delete_cabinet() self.assertEqual(response.status_code, 302) self.assertEqual(Cabinet.objects.count(), 0) - def _edit_cabinet(self, cabinet, label): + def _request_edit_cabinet(self): return self.post( - 'cabinets:cabinet_edit', args=(cabinet.pk,), data={ - 'label': label + 'cabinets:cabinet_edit', args=(self.cabinet.pk,), data={ + 'label': TEST_CABINET_EDITED_LABEL } ) def test_cabinet_edit_view_no_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() - response = self._edit_cabinet( - cabinet=cabinet, label=TEST_CABINET_EDITED_LABEL - ) + response = self._request_edit_cabinet() self.assertEqual(response.status_code, 403) - cabinet.refresh_from_db() - self.assertEqual(cabinet.label, TEST_CABINET_LABEL) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.label, TEST_CABINET_LABEL) - def test_cabinet_edit_view_with_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + def test_cabinet_edit_view_with_access(self): + self._create_cabinet() - self.grant_permission(permission=permission_cabinet_edit) + self.grant_access(obj=self.cabinet, permission=permission_cabinet_edit) - response = self._edit_cabinet( - cabinet=cabinet, label=TEST_CABINET_EDITED_LABEL - ) + response = self._request_edit_cabinet() self.assertEqual(response.status_code, 302) - cabinet.refresh_from_db() - self.assertEqual(cabinet.label, TEST_CABINET_EDITED_LABEL) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.label, TEST_CABINET_EDITED_LABEL) - def _add_document_to_cabinet(self, cabinet): + def _add_document_to_cabinet(self): return self.post( 'cabinets:cabinet_add_document', args=(self.document.pk,), data={ - 'cabinets': cabinet.pk + 'cabinets': self.cabinet.pk } ) def test_cabinet_add_document_view_no_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() self.grant_permission(permission=permission_cabinet_view) - response = self._add_document_to_cabinet(cabinet=cabinet) + response = self._add_document_to_cabinet() self.assertContains( response, text='Select a valid choice.', status_code=200 ) - cabinet.refresh_from_db() - self.assertEqual(cabinet.documents.count(), 0) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.documents.count(), 0) - def test_cabinet_add_document_view_with_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + def test_cabinet_add_document_view_with_access(self): + self._create_cabinet() - self.grant_permission(permission=permission_cabinet_view) - self.grant_permission(permission=permission_cabinet_add_document) - self.grant_permission(permission=permission_document_view) - - response = self._add_document_to_cabinet(cabinet=cabinet) - - cabinet.refresh_from_db() - - self.assertEqual(response.status_code, 302) - self.assertEqual(cabinet.documents.count(), 1) - self.assertQuerysetEqual( - cabinet.documents.all(), (repr(self.document),) + self.grant_access(obj=self.cabinet, permission=permission_cabinet_view) + self.grant_access( + obj=self.cabinet, permission=permission_cabinet_add_document + ) + self.grant_access( + obj=self.document, permission=permission_cabinet_add_document ) - def _add_multiple_documents_to_cabinet(self, cabinet): + response = self._add_document_to_cabinet() + + self.cabinet.refresh_from_db() + + self.assertEqual(response.status_code, 302) + self.assertEqual(self.cabinet.documents.count(), 1) + self.assertQuerysetEqual( + self.cabinet.documents.all(), (repr(self.document),) + ) + + def _request_add_multiple_documents_to_cabinet(self): return self.post( 'cabinets:cabinet_add_multiple_documents', data={ - 'id_list': (self.document.pk,), 'cabinets': cabinet.pk + 'id_list': (self.document.pk,), 'cabinets': self.cabinet.pk } ) def test_cabinet_add_multiple_documents_view_no_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() self.grant_permission(permission=permission_cabinet_view) - response = self._add_multiple_documents_to_cabinet(cabinet=cabinet) + response = self._request_add_multiple_documents_to_cabinet() self.assertContains( response, text='Select a valid choice', status_code=200 ) - cabinet.refresh_from_db() - self.assertEqual(cabinet.documents.count(), 0) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.documents.count(), 0) - def test_cabinet_add_multiple_documents_view_with_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + def test_cabinet_add_multiple_documents_view_with_access(self): + self._create_cabinet() - self.grant_permission(permission=permission_cabinet_view) - self.grant_permission(permission=permission_cabinet_add_document) - - response = self._add_multiple_documents_to_cabinet(cabinet=cabinet) - - self.assertEqual(response.status_code, 302) - cabinet.refresh_from_db() - self.assertEqual(cabinet.documents.count(), 1) - self.assertQuerysetEqual( - cabinet.documents.all(), (repr(self.document),) + self.grant_access( + obj=self.cabinet, permission=permission_cabinet_add_document + ) + self.grant_access( + obj=self.document, permission=permission_cabinet_add_document ) - def _remove_document_from_cabinet(self, cabinet): + response = self._request_add_multiple_documents_to_cabinet() + + self.assertEqual(response.status_code, 302) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.documents.count(), 1) + self.assertQuerysetEqual( + self.cabinet.documents.all(), (repr(self.document),) + ) + + def _request_remove_document_from_cabinet(self): return self.post( 'cabinets:document_cabinet_remove', args=(self.document.pk,), data={ - 'cabinets': (cabinet.pk,), + 'cabinets': (self.cabinet.pk,), } ) def test_cabinet_remove_document_view_no_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self._create_cabinet() - cabinet.documents.add(self.document) + self.cabinet.documents.add(self.document) - response = self._remove_document_from_cabinet(cabinet=cabinet) + response = self._request_remove_document_from_cabinet() self.assertContains( response, text='Select a valid choice', status_code=200 ) - cabinet.refresh_from_db() - self.assertEqual(cabinet.documents.count(), 1) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.documents.count(), 1) - def test_cabinet_remove_document_view_with_permission(self): - cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + def test_cabinet_remove_document_view_with_access(self): + self._create_cabinet() - cabinet.documents.add(self.document) + self.cabinet.documents.add(self.document) - self.grant_permission(permission=permission_cabinet_remove_document) + self.grant_access( + obj=self.cabinet, permission=permission_cabinet_remove_document + ) + self.grant_access( + obj=self.document, permission=permission_cabinet_remove_document + ) - response = self._remove_document_from_cabinet(cabinet=cabinet) + response = self._request_remove_document_from_cabinet() self.assertEqual(response.status_code, 302) - cabinet.refresh_from_db() - self.assertEqual(cabinet.documents.count(), 0) - - def _create_cabinet(self): - self.cabinet = Cabinet.objects.create(label=TEST_CABINET_LABEL) + self.cabinet.refresh_from_db() + self.assertEqual(self.cabinet.documents.count(), 0) def _request_cabinet_list(self): return self.get('cabinets:cabinet_list') @@ -219,9 +227,9 @@ class CabinetViewTestCase(GenericDocumentViewTestCase): response, text=self.cabinet.label, status_code=200 ) - def test_cabinet_list_view_with_permission(self): + def test_cabinet_list_view_with_access(self): self._create_cabinet() - self.grant_permission(permission=permission_cabinet_view) + self.grant_access(obj=self.cabinet, permission=permission_cabinet_view) response = self._request_cabinet_list() self.assertContains( diff --git a/mayan/apps/cabinets/views.py b/mayan/apps/cabinets/views.py index 37d38c324f..bd879cb041 100644 --- a/mayan/apps/cabinets/views.py +++ b/mayan/apps/cabinets/views.py @@ -153,7 +153,7 @@ class CabinetListView(SingleObjectListView): 'title': _('Cabinets'), } - def get_queryset(self): + def get_object_list(self): return Cabinet.objects.root_nodes() @@ -177,7 +177,7 @@ class DocumentCabinetListView(CabinetListView): 'title': _('Cabinets containing document: %s') % self.document, } - def get_queryset(self): + def get_object_list(self): return self.document.document_cabinets().all() diff --git a/mayan/apps/checkouts/apps.py b/mayan/apps/checkouts/apps.py index 255dbc82aa..7b78e253ab 100644 --- a/mayan/apps/checkouts/apps.py +++ b/mayan/apps/checkouts/apps.py @@ -6,7 +6,6 @@ from kombu import Exchange, Queue from django.apps import apps from django.db.models.signals import pre_save -from django.urls import reverse_lazy from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission diff --git a/mayan/apps/checkouts/tests/test_models.py b/mayan/apps/checkouts/tests/test_models.py index 987de050f0..b253a46f3e 100644 --- a/mayan/apps/checkouts/tests/test_models.py +++ b/mayan/apps/checkouts/tests/test_models.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import datetime +import logging import time from django.contrib.auth import get_user_model @@ -61,6 +62,9 @@ class DocumentCheckoutTestCase(BaseTestCase): ) def test_version_creation_blocking(self): + # Silence unrelated logging + logging.getLogger('documents.models').setLevel(logging.CRITICAL) + expiration_datetime = now() + datetime.timedelta(days=1) DocumentCheckout.objects.checkout_document( @@ -123,6 +127,9 @@ class DocumentCheckoutTestCase(BaseTestCase): self.assertFalse(self.document.is_checked_out()) def test_blocking_new_versions(self): + # Silence unrelated logging + logging.getLogger('documents.models').setLevel(logging.CRITICAL) + NewVersionBlock.objects.block(document=self.document) with self.assertRaises(NewDocumentVersionNotAllowed): diff --git a/mayan/apps/checkouts/tests/test_views.py b/mayan/apps/checkouts/tests/test_views.py index 294f9f4438..9652e99259 100644 --- a/mayan/apps/checkouts/tests/test_views.py +++ b/mayan/apps/checkouts/tests/test_views.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import datetime +import logging from django.utils.timezone import now @@ -21,9 +22,7 @@ from ..permissions import ( class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): def test_checkin_document_view_no_permission(self): - self.login( - username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD - ) + self.login_user() expiration_datetime = now() + datetime.timedelta(days=1) @@ -42,10 +41,8 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): self.assertTrue(self.document.is_checked_out()) - def test_checkin_document_view_with_permission(self): - self.login( - username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD - ) + def test_checkin_document_view_with_access(self): + self.login_user() expiration_datetime = now() + datetime.timedelta(days=1) @@ -56,11 +53,12 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): self.assertTrue(self.document.is_checked_out()) - self.role.permissions.add( - permission_document_checkin.stored_permission + self.grant_access( + obj=self.document, permission=permission_document_checkin ) - self.role.permissions.add( - permission_document_checkout_detail_view.stored_permission + self.grant_access( + obj=self.document, + permission=permission_document_checkout_detail_view ) response = self.post( @@ -78,9 +76,7 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): ) def test_checkout_document_view_no_permission(self): - self.login( - username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD - ) + self.login_user() response = self.post( 'checkouts:checkout_document', args=(self.document.pk,), data={ @@ -94,15 +90,14 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): self.assertFalse(self.document.is_checked_out()) - def test_checkout_document_view_with_permission(self): - self.login( - username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD + def test_checkout_document_view_with_access(self): + self.login_user() + self.grant_access( + obj=self.document, permission=permission_document_checkout ) - self.role.permissions.add( - permission_document_checkout.stored_permission - ) - self.role.permissions.add( - permission_document_checkout_detail_view.stored_permission + self.grant_access( + obj=self.document, + permission=permission_document_checkout_detail_view ) response = self.post( @@ -127,7 +122,6 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): - Link to upload version view should not resolve - Upload version view should reject request """ - self.login( username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD ) @@ -167,6 +161,9 @@ class DocumentCheckoutViewTestCase(GenericDocumentViewTestCase): # Forcefully checking in a document by a user without adequate # permissions throws out an error + # Silence unrelated logging + logging.getLogger('navigation.classes').setLevel(logging.CRITICAL) + expiration_datetime = now() + datetime.timedelta(days=1) DocumentCheckout.objects.checkout_document( diff --git a/mayan/apps/common/generics.py b/mayan/apps/common/generics.py index 9837d34b4a..ec946e6fc2 100644 --- a/mayan/apps/common/generics.py +++ b/mayan/apps/common/generics.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals from django.conf import settings from django.contrib import messages from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseRedirect from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy as _ @@ -25,8 +26,7 @@ from .mixins import ( DeleteExtraDataMixin, DynamicFormViewMixin, ExtraContextMixin, FormExtraKwargsMixin, MultipleObjectMixin, ObjectActionMixin, ObjectListPermissionFilterMixin, ObjectNameMixin, - ObjectPermissionCheckMixin, PreserveGetQuerysetMixin, RedirectionMixin, - ViewPermissionCheckMixin + ObjectPermissionCheckMixin, RedirectionMixin, ViewPermissionCheckMixin ) from .settings import setting_paginate_by @@ -282,17 +282,37 @@ class MultiFormView(DjangoFormView): return self.forms_invalid(forms) -class MultipleObjectFormActionView(PreserveGetQuerysetMixin, ObjectActionMixin, MultipleObjectMixin, FormExtraKwargsMixin, ViewPermissionCheckMixin, ExtraContextMixin, RedirectionMixin, DjangoFormView): +class MultipleObjectFormActionView(ObjectActionMixin, MultipleObjectMixin, FormExtraKwargsMixin, ViewPermissionCheckMixin, ExtraContextMixin, RedirectionMixin, DjangoFormView): """ This view will present a form and upon receiving a POST request will perform an action on an object or queryset """ template_name = 'appearance/generic_form.html' + def __init__(self, *args, **kwargs): + result = super(MultipleObjectFormActionView, self).__init__(*args, **kwargs) + + if self.__class__.mro()[0].get_queryset != MultipleObjectFormActionView.get_queryset: + raise ImproperlyConfigured( + '%(cls)s is overloading the get_queryset method. Subclasses ' + 'should implement the get_object_list method instead. ' % { + 'cls': self.__class__.__name__ + } + ) + + return result + def form_valid(self, form): self.view_action(form=form) return super(MultipleObjectFormActionView, self).form_valid(form=form) + def get_queryset(self): + try: + return super(MultipleObjectFormActionView, self).get_queryset() + except ImproperlyConfigured: + self.queryset = self.get_object_list() + return super(MultipleObjectFormActionView, self).get_queryset() + class MultipleObjectConfirmActionView(ObjectActionMixin, MultipleObjectMixin, ObjectListPermissionFilterMixin, ViewPermissionCheckMixin, ExtraContextMixin, RedirectionMixin, TemplateView): template_name = 'appearance/generic_confirm.html' @@ -458,8 +478,28 @@ class SingleObjectDynamicFormEditView(DynamicFormViewMixin, SingleObjectEditView pass -class SingleObjectListView(PreserveGetQuerysetMixin, PaginationMixin, ViewPermissionCheckMixin, ObjectListPermissionFilterMixin, ExtraContextMixin, RedirectionMixin, ListView): +class SingleObjectListView(PaginationMixin, ViewPermissionCheckMixin, ObjectListPermissionFilterMixin, ExtraContextMixin, RedirectionMixin, ListView): template_name = 'appearance/generic_list.html' + def __init__(self, *args, **kwargs): + result = super(SingleObjectListView, self).__init__(*args, **kwargs) + + if self.__class__.mro()[0].get_queryset != SingleObjectListView.get_queryset: + raise ImproperlyConfigured( + '%(cls)s is overloading the get_queryset method. Subclasses ' + 'should implement the get_object_list method instead. ' % { + 'cls': self.__class__.__name__ + } + ) + + return result + def get_paginate_by(self, queryset): return setting_paginate_by.value + + def get_queryset(self): + try: + return super(SingleObjectListView, self).get_queryset() + except ImproperlyConfigured: + self.queryset = self.get_object_list() + return super(SingleObjectListView, self).get_queryset() diff --git a/mayan/apps/common/mixins.py b/mayan/apps/common/mixins.py index c939826b6c..2db8cd372c 100644 --- a/mayan/apps/common/mixins.py +++ b/mayan/apps/common/mixins.py @@ -18,8 +18,8 @@ __all__ = ( 'DeleteExtraDataMixin', 'DynamicFormViewMixin', 'ExtraContextMixin', 'FormExtraKwargsMixin', 'MultipleObjectMixin', 'ObjectActionMixin', 'ObjectListPermissionFilterMixin', 'ObjectNameMixin', - 'ObjectPermissionCheckMixin', 'PreserveGetQuerysetMixin', - 'RedirectionMixin', 'ViewPermissionCheckMixin' + 'ObjectPermissionCheckMixin', 'RedirectionMixin', + 'ViewPermissionCheckMixin' ) @@ -266,26 +266,6 @@ class ObjectPermissionCheckMixin(object): ).dispatch(request, *args, **kwargs) -class PreserveGetQuerysetMixin(object): - """ - Allows class based views to define a get_queryset method that doesn't - overrided the parent classe's get_queryset method - """ - def __init__(self, *args, **kwargs): - result = super(PreserveGetQuerysetMixin, self).__init__(*args, **kwargs) - if not hasattr(self.__class__, 'original_get_queryset'): - if not self.__class__.mro()[0].get_queryset == PreserveGetQuerysetMixin.get_queryset: - setattr(self.__class__, 'original_get_queryset', self.__class__.mro()[0].get_queryset) - self.__class__.mro()[0].get_queryset = PreserveGetQuerysetMixin.get_queryset - return result - - def get_queryset(self, *args, **kwargs): - if hasattr(self.__class__, 'original_get_queryset'): - self.queryset = self.__class__.original_get_queryset(self, *args, **kwargs) - - return super(PreserveGetQuerysetMixin, self).get_queryset(*args, **kwargs) - - class RedirectionMixin(object): post_action_redirect = None action_cancel_redirect = None diff --git a/mayan/apps/common/views.py b/mayan/apps/common/views.py index 41ae7fe155..9335c085b7 100644 --- a/mayan/apps/common/views.py +++ b/mayan/apps/common/views.py @@ -177,7 +177,7 @@ class FilterResultListView(SingleObjectListView): except KeyError: raise Http404(ugettext('Filter not found')) - def get_queryset(self): + def get_object_list(self): return self.get_filter().get_queryset(user=self.request.user) diff --git a/mayan/apps/converter/views.py b/mayan/apps/converter/views.py index a0cf45cc1d..aba4aced84 100644 --- a/mayan/apps/converter/views.py +++ b/mayan/apps/converter/views.py @@ -108,6 +108,15 @@ class TransformationCreateView(SingleObjectCreateView): else: return super(TransformationCreateView, self).form_valid(form) + def get_extra_context(self): + return { + 'content_object': self.content_object, + 'navigation_object_list': ('content_object',), + 'title': _( + 'Create new transformation for: %s' + ) % self.content_object, + } + def get_post_action_redirect(self): return reverse( 'converter:transformation_list', args=( @@ -119,15 +128,6 @@ class TransformationCreateView(SingleObjectCreateView): def get_queryset(self): return Transformation.objects.get_for_model(self.content_object) - def get_extra_context(self): - return { - 'content_object': self.content_object, - 'navigation_object_list': ('content_object',), - 'title': _( - 'Create new transformation for: %s' - ) % self.content_object, - } - class TransformationEditView(SingleObjectEditView): fields = ('name', 'arguments', 'order') @@ -158,15 +158,6 @@ class TransformationEditView(SingleObjectEditView): else: return super(TransformationEditView, self).form_valid(form) - def get_post_action_redirect(self): - return reverse( - 'converter:transformation_list', args=( - self.transformation.content_type.app_label, - self.transformation.content_type.model, - self.transformation.object_id - ) - ) - def get_extra_context(self): return { 'content_object': self.transformation.content_object, @@ -180,6 +171,15 @@ class TransformationEditView(SingleObjectEditView): 'transformation': self.transformation, } + def get_post_action_redirect(self): + return reverse( + 'converter:transformation_list', args=( + self.transformation.content_type.app_label, + self.transformation.content_type.model, + self.transformation.object_id + ) + ) + class TransformationListView(SingleObjectListView): def dispatch(self, request, *args, **kwargs): @@ -204,9 +204,6 @@ class TransformationListView(SingleObjectListView): request, *args, **kwargs ) - def get_queryset(self): - return Transformation.objects.get_for_model(self.content_object) - def get_extra_context(self): return { 'content_object': self.content_object, @@ -215,3 +212,6 @@ class TransformationListView(SingleObjectListView): 'navigation_object_list': ('content_object',), 'title': _('Transformations for: %s') % self.content_object, } + + def get_object_list(self): + return Transformation.objects.get_for_model(self.content_object) diff --git a/mayan/apps/django_gpg/views.py b/mayan/apps/django_gpg/views.py index df28ecf0be..b932358d15 100644 --- a/mayan/apps/django_gpg/views.py +++ b/mayan/apps/django_gpg/views.py @@ -119,7 +119,7 @@ class KeyQueryResultView(SingleObjectListView): 'title': _('Key query results'), } - def get_queryset(self): + def get_object_list(self): term = self.request.GET.get('term') if term: return Key.objects.search(query=term) diff --git a/mayan/apps/document_comments/views.py b/mayan/apps/document_comments/views.py index 6a5855fe98..3e2ef383ff 100644 --- a/mayan/apps/document_comments/views.py +++ b/mayan/apps/document_comments/views.py @@ -90,14 +90,6 @@ class DocumentCommentListView(SingleObjectListView): def get_document(self): return get_object_or_404(Document, pk=self.kwargs['pk']) - def get_queryset(self): - AccessControlList.objects.check_access( - permissions=permission_comment_view, user=self.request.user, - obj=self.get_document() - ) - - return self.get_document().comments.all() - def get_extra_context(self): return { 'hide_link': True, @@ -105,3 +97,11 @@ class DocumentCommentListView(SingleObjectListView): 'object': self.get_document(), 'title': _('Comments for document: %s') % self.get_document(), } + + def get_object_list(self): + AccessControlList.objects.check_access( + permissions=permission_comment_view, user=self.request.user, + obj=self.get_document() + ) + + return self.get_document().comments.all() diff --git a/mayan/apps/document_indexing/views.py b/mayan/apps/document_indexing/views.py index fe51c763d4..8b64ed77b1 100644 --- a/mayan/apps/document_indexing/views.py +++ b/mayan/apps/document_indexing/views.py @@ -119,14 +119,6 @@ class SetupIndexDocumentTypesView(AssignRemoveView): class SetupIndexTreeTemplateListView(SingleObjectListView): object_permission = permission_document_indexing_edit - def get_index(self): - return get_object_or_404(Index, pk=self.kwargs['pk']) - - def get_queryset(self): - return self.get_index().template_root.get_descendants( - include_self=True - ) - def get_extra_context(self): return { 'hide_object': True, @@ -135,6 +127,14 @@ class SetupIndexTreeTemplateListView(SingleObjectListView): 'title': _('Tree template nodes for index: %s') % self.get_index(), } + def get_index(self): + return get_object_or_404(Index, pk=self.kwargs['pk']) + + def get_object_list(self): + return self.get_index().template_root.get_descendants( + include_self=True + ) + class TemplateNodeCreateView(SingleObjectCreateView): form_class = IndexTemplateNodeForm @@ -242,19 +242,6 @@ class IndexInstanceNodeView(DocumentListView): return SingleObjectListView.dispatch(self, request, *args, **kwargs) - def get_queryset(self): - if self.index_instance_node: - if self.index_instance_node.index_template_node.link_documents: - return DocumentListView.get_queryset(self) - else: - self.object_permission = None - return self.index_instance_node.get_children().order_by( - 'value' - ) - else: - self.object_permission = None - return IndexInstanceNode.objects.none() - def get_document_queryset(self): if self.index_instance_node: if self.index_instance_node.index_template_node.link_documents: @@ -286,6 +273,19 @@ class IndexInstanceNodeView(DocumentListView): return context + def get_object_list(self): + if self.index_instance_node: + if self.index_instance_node.index_template_node.link_documents: + return DocumentListView.get_queryset(self) + else: + self.object_permission = None + return self.index_instance_node.get_children().order_by( + 'value' + ) + else: + self.object_permission = None + return IndexInstanceNode.objects.none() + class DocumentIndexNodeListView(SingleObjectListView): """ @@ -317,7 +317,7 @@ class DocumentIndexNodeListView(SingleObjectListView): ) % self.get_document(), } - def get_queryset(self): + def get_object_list(self): return DocumentIndexInstanceNode.objects.get_for(self.get_document()) diff --git a/mayan/apps/document_signatures/tests/test_models.py b/mayan/apps/document_signatures/tests/test_models.py index 37a2499c35..a0da6be8cf 100644 --- a/mayan/apps/document_signatures/tests/test_models.py +++ b/mayan/apps/document_signatures/tests/test_models.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals import hashlib +import logging import time from django.core.files import File @@ -284,6 +285,9 @@ class EmbeddedSignaturesTestCase(BaseTestCase): ) def test_task_verify_missing_embedded_signature(self): + # Silence converter logging + logging.getLogger('converter.backends').setLevel(logging.CRITICAL) + old_hooks = DocumentVersion._post_save_hooks DocumentVersion._post_save_hooks = {} diff --git a/mayan/apps/document_signatures/tests/test_views.py b/mayan/apps/document_signatures/tests/test_views.py index a654bc23d9..e2a4b2fbdb 100644 --- a/mayan/apps/document_signatures/tests/test_views.py +++ b/mayan/apps/document_signatures/tests/test_views.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, unicode_literals +import logging + from django.core.files import File from django_downloadview.test import assert_download_response @@ -8,9 +10,6 @@ from django_gpg.models import Key from documents.models import DocumentVersion from documents.tests.literals import TEST_DOCUMENT_PATH from documents.tests.test_views import GenericDocumentViewTestCase -from user_management.tests import ( - TEST_USER_USERNAME, TEST_USER_PASSWORD -) from ..models import DetachedSignature, EmbeddedSignature from ..permissions import ( @@ -45,7 +44,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() response = self.get( 'signatures:document_version_signature_list', @@ -54,7 +53,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 403) - def test_signature_list_view_with_permission(self): + def test_signature_list_view_with_access(self): with open(TEST_KEY_FILE) as file_object: Key.objects.create(key_data=file_object.read()) @@ -69,10 +68,11 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_view.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_view ) response = self.get( @@ -97,7 +97,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() response = self.get( 'signatures:document_version_signature_details', @@ -106,7 +106,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 403) - def test_signature_detail_view_with_permission(self): + def test_signature_detail_view_with_access(self): with open(TEST_KEY_FILE) as file_object: Key.objects.create(key_data=file_object.read()) @@ -121,10 +121,11 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_view.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_view ) response = self.get( @@ -140,7 +141,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): file_object=file_object ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() with open(TEST_SIGNATURE_FILE_PATH) as file_object: response = self.post( @@ -152,16 +153,17 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 403) self.assertEqual(DetachedSignature.objects.count(), 0) - def test_signature_upload_view_with_permission(self): + def test_signature_upload_view_with_access(self): with open(TEST_DOCUMENT_PATH) as file_object: document = self.document_type.new_document( file_object=file_object ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_upload.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_upload ) with open(TEST_SIGNATURE_FILE_PATH) as file_object: @@ -186,7 +188,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() response = self.get( 'signatures:document_version_signature_download', @@ -195,7 +197,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 403) - def test_signature_download_view_with_permission(self): + def test_signature_download_view_with_access(self): with open(TEST_DOCUMENT_PATH) as file_object: document = self.document_type.new_document( file_object=file_object @@ -207,10 +209,11 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_download.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_download ) self.expected_content_type = 'application/octet-stream; charset=utf-8' @@ -240,10 +243,11 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_view.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_view ) response = self.post( @@ -254,7 +258,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 403) self.assertEqual(DetachedSignature.objects.count(), 1) - def test_signature_delete_view_with_permission(self): + def test_signature_delete_view_with_access(self): with open(TEST_KEY_FILE) as file_object: Key.objects.create(key_data=file_object.read()) @@ -269,13 +273,15 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): signature_file=File(file_object) ) - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_delete.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_delete ) - self.role.permissions.add( - permission_document_version_signature_view.stored_permission + self.grant_access( + obj=document, + permission=permission_document_version_signature_view ) response = self.post( @@ -287,6 +293,9 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): self.assertEqual(DetachedSignature.objects.count(), 0) def test_missing_signature_verify_view_no_permission(self): + # Silence converter logging + logging.getLogger('converter.backends').setLevel(logging.CRITICAL) + for document in self.document_type.documents.all(): document.delete(to_trash=False) @@ -311,7 +320,7 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): DocumentVersion._post_save_hooks = old_hooks - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() response = self.post( 'signatures:all_document_version_signature_verify', follow=True @@ -325,6 +334,9 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): ) def test_missing_signature_verify_view_with_permission(self): + # Silence converter logging + logging.getLogger('converter.backends').setLevel(logging.CRITICAL) + for document in self.document_type.documents.all(): document.delete(to_trash=False) @@ -349,10 +361,10 @@ class SignaturesViewTestCase(GenericDocumentViewTestCase): DocumentVersion._post_save_hooks = old_hooks - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add( - permission_document_version_signature_verify.stored_permission + self.grant_permission( + permission=permission_document_version_signature_verify ) response = self.post( diff --git a/mayan/apps/document_signatures/views.py b/mayan/apps/document_signatures/views.py index 6fc866c638..5c696e12df 100644 --- a/mayan/apps/document_signatures/views.py +++ b/mayan/apps/document_signatures/views.py @@ -300,7 +300,7 @@ class DocumentVersionSignatureListView(SingleObjectListView): ) % self.get_document_version(), } - def get_queryset(self): + def get_object_list(self): return self.get_document_version().signatures.all() diff --git a/mayan/apps/document_states/views.py b/mayan/apps/document_states/views.py index 7ab5f270ed..37d70e6cb8 100644 --- a/mayan/apps/document_states/views.py +++ b/mayan/apps/document_states/views.py @@ -61,7 +61,7 @@ class DocumentWorkflowInstanceListView(SingleObjectListView): ) % self.get_document(), } - def get_queryset(self): + def get_object_list(self): return self.get_document().workflows.all() @@ -87,7 +87,7 @@ class WorkflowInstanceDetailView(SingleObjectListView): 'workflow_instance': self.get_workflow_instance(), } - def get_queryset(self): + def get_object_list(self): return self.get_workflow_instance().log_entries.order_by('-datetime') def get_workflow_instance(self): @@ -221,7 +221,7 @@ class SetupWorkflowStateListView(SingleObjectListView): 'title': _('States of workflow: %s') % self.get_workflow() } - def get_queryset(self): + def get_object_list(self): return self.get_workflow().states.all() def get_workflow(self): @@ -330,7 +330,7 @@ class SetupWorkflowStateActionListView(SingleObjectListView): def get_form_schema(self): return {'fields': self.get_class().fields} - def get_queryset(self): + def get_object_list(self): return self.get_workflow_state().actions.all() def get_workflow_state(self): @@ -379,7 +379,7 @@ class SetupWorkflowStateCreateView(SingleObjectCreateView): def get_workflow(self): return get_object_or_404(Workflow, pk=self.kwargs['pk']) - def get_queryset(self): + def get_object_list(self): return self.get_workflow().states.all() def get_success_url(self): @@ -437,12 +437,6 @@ class SetupWorkflowStateEditView(SingleObjectEditView): class SetupWorkflowTransitionListView(SingleObjectListView): view_permission = permission_workflow_view - def get_workflow(self): - return get_object_or_404(Workflow, pk=self.kwargs['pk']) - - def get_queryset(self): - return self.get_workflow().transitions.all() - def get_extra_context(self): return { 'hide_link': True, @@ -452,11 +446,32 @@ class SetupWorkflowTransitionListView(SingleObjectListView): ) % self.get_workflow() } + def get_object_list(self): + return self.get_workflow().transitions.all() + + def get_workflow(self): + return get_object_or_404(Workflow, pk=self.kwargs['pk']) + class SetupWorkflowTransitionCreateView(SingleObjectCreateView): form_class = WorkflowTransitionForm view_permission = permission_workflow_edit + def form_valid(self, form): + self.object = form.save(commit=False) + self.object.workflow = self.get_workflow() + try: + self.object.save() + except IntegrityError: + messages.error( + self.request, _('Unable to save transition; integrity error.') + ) + return super( + SetupWorkflowTransitionCreateView, self + ).form_invalid(form) + else: + return HttpResponseRedirect(self.get_success_url()) + def get_extra_context(self): return { 'object': self.get_workflow(), @@ -472,10 +487,7 @@ class SetupWorkflowTransitionCreateView(SingleObjectCreateView): kwargs['workflow'] = self.get_workflow() return kwargs - def get_workflow(self): - return get_object_or_404(Workflow, pk=self.kwargs['pk']) - - def get_queryset(self): + def get_object_list(self): return self.get_workflow().transitions.all() def get_success_url(self): @@ -484,20 +496,8 @@ class SetupWorkflowTransitionCreateView(SingleObjectCreateView): args=(self.kwargs['pk'],) ) - def form_valid(self, form): - self.object = form.save(commit=False) - self.object.workflow = self.get_workflow() - try: - self.object.save() - except IntegrityError: - messages.error( - self.request, _('Unable to save transition; integrity error.') - ) - return super( - SetupWorkflowTransitionCreateView, self - ).form_invalid(form) - else: - return HttpResponseRedirect(self.get_success_url()) + def get_workflow(self): + return get_object_or_404(Workflow, pk=self.kwargs['pk']) class SetupWorkflowTransitionDeleteView(SingleObjectDeleteView): @@ -547,15 +547,15 @@ class SetupWorkflowTransitionEditView(SingleObjectEditView): class WorkflowListView(SingleObjectListView): view_permission = permission_workflow_view - def get_queryset(self): - return WorkflowRuntimeProxy.objects.all() - def get_extra_context(self): return { 'hide_object': True, 'title': _('Workflows') } + def get_object_list(self): + return WorkflowRuntimeProxy.objects.all() + class WorkflowDocumentListView(DocumentListView): def dispatch(self, request, *args, **kwargs): @@ -641,7 +641,7 @@ class WorkflowStateListView(SingleObjectListView): 'title': _('States of workflow: %s') % self.get_workflow() } - def get_queryset(self): + def get_object_list(self): return WorkflowStateRuntimeProxy.objects.filter( workflow=self.get_workflow() ) diff --git a/mayan/apps/documents/tests/test_views.py b/mayan/apps/documents/tests/test_views.py index 3db53590be..f213a67a8a 100644 --- a/mayan/apps/documents/tests/test_views.py +++ b/mayan/apps/documents/tests/test_views.py @@ -82,7 +82,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): response = self.get('documents:document_list') self.assertContains(response, 'Total: 0', status_code=200) - def test_document_list_view_with_permissions(self): + def test_document_list_view_with_access(self): self.grant_access( obj=self.document, permission=permission_document_view ) diff --git a/mayan/apps/documents/views/document_page_views.py b/mayan/apps/documents/views/document_page_views.py index 32faab732b..40c078327a 100644 --- a/mayan/apps/documents/views/document_page_views.py +++ b/mayan/apps/documents/views/document_page_views.py @@ -41,9 +41,6 @@ class DocumentPageListView(SingleObjectListView): def get_document(self): return get_object_or_404(Document, pk=self.kwargs['pk']) - def get_queryset(self): - return self.get_document().pages.all() - def get_extra_context(self): return { 'list_as_items': True, @@ -51,6 +48,9 @@ class DocumentPageListView(SingleObjectListView): 'title': _('Pages for document: %s') % self.get_document(), } + def get_object_list(self): + return self.get_document().pages.all() + class DocumentPageNavigationBase(RedirectView): def dispatch(self, request, *args, **kwargs): diff --git a/mayan/apps/documents/views/document_type_views.py b/mayan/apps/documents/views/document_type_views.py index f561adec2a..409c40703b 100644 --- a/mayan/apps/documents/views/document_type_views.py +++ b/mayan/apps/documents/views/document_type_views.py @@ -196,5 +196,5 @@ class DocumentTypeFilenameListView(SingleObjectListView): ) % self.get_document_type(), } - def get_queryset(self): + def get_object_list(self): return self.get_document_type().filenames.all() diff --git a/mayan/apps/documents/views/document_version_views.py b/mayan/apps/documents/views/document_version_views.py index f40b363ebd..9cd4d5c640 100644 --- a/mayan/apps/documents/views/document_version_views.py +++ b/mayan/apps/documents/views/document_version_views.py @@ -47,7 +47,7 @@ class DocumentVersionListView(SingleObjectListView): 'title': _('Versions of document: %s') % self.get_document(), } - def get_queryset(self): + def get_object_list(self): return self.get_document().versions.order_by('-timestamp') diff --git a/mayan/apps/documents/views/document_views.py b/mayan/apps/documents/views/document_views.py index 3329b19aeb..dac07b094e 100644 --- a/mayan/apps/documents/views/document_views.py +++ b/mayan/apps/documents/views/document_views.py @@ -64,7 +64,7 @@ class DocumentListView(SingleObjectListView): 'title': _('All documents'), } - def get_queryset(self): + def get_object_list(self): return self.get_document_queryset().filter(is_stub=False) @@ -203,7 +203,7 @@ class DocumentDuplicatesListView(DocumentListView): ) return context - def get_queryset(self): + def get_object_list(self): try: return DuplicatedDocument.objects.get( document=self.get_document() diff --git a/mayan/apps/dynamic_search/views.py b/mayan/apps/dynamic_search/views.py index 685058e5aa..66365ce16f 100644 --- a/mayan/apps/dynamic_search/views.py +++ b/mayan/apps/dynamic_search/views.py @@ -27,7 +27,7 @@ class ResultsView(SearchModelMixin, SingleObjectListView): return context - def get_queryset(self): + def get_object_list(self): self.search_model = self.get_search_model() if self.request.GET: diff --git a/mayan/apps/events/views.py b/mayan/apps/events/views.py index 326ba6cb18..c2f6b6a94c 100644 --- a/mayan/apps/events/views.py +++ b/mayan/apps/events/views.py @@ -19,9 +19,6 @@ from .widgets import event_object_link class EventListView(SingleObjectListView): view_permission = permission_events_view - def get_queryset(self): - return Action.objects.all() - def get_extra_context(self): return { 'extra_columns': ( @@ -36,6 +33,9 @@ class EventListView(SingleObjectListView): 'title': _('Events'), } + def get_object_list(self): + return Action.objects.all() + class ObjectEventListView(EventListView): view_permissions = None @@ -69,14 +69,11 @@ class ObjectEventListView(EventListView): 'title': _('Events for: %s') % self.content_object, } - def get_queryset(self): + def get_object_list(self): return any_stream(self.content_object) class VerbEventListView(SingleObjectListView): - def get_queryset(self): - return Action.objects.filter(verb=self.kwargs['verb']) - def get_extra_context(self): return { 'extra_columns': ( @@ -92,3 +89,6 @@ class VerbEventListView(SingleObjectListView): 'Events of type: %s' ) % Event.get_label(self.kwargs['verb']), } + + def get_object_list(self): + return Action.objects.filter(verb=self.kwargs['verb']) diff --git a/mayan/apps/linking/views.py b/mayan/apps/linking/views.py index 0295f96930..8203fb3fde 100644 --- a/mayan/apps/linking/views.py +++ b/mayan/apps/linking/views.py @@ -132,7 +132,7 @@ class SmartLinkListView(SingleObjectListView): 'title': _('Smart links'), } - def get_queryset(self): + def get_object_list(self): return self.get_smart_link_queryset() def get_smart_link_queryset(self): @@ -209,7 +209,7 @@ class SmartLinkConditionListView(SingleObjectListView): ) % self.get_smart_link(), } - def get_queryset(self): + def get_object_list(self): return self.get_smart_link().conditions.all() def get_smart_link(self): diff --git a/mayan/apps/mailer/views.py b/mayan/apps/mailer/views.py index a829d3abeb..46c8afe339 100644 --- a/mayan/apps/mailer/views.py +++ b/mayan/apps/mailer/views.py @@ -210,7 +210,7 @@ class UserMailerLogEntryListView(SingleObjectListView): 'title': _('%s error log') % self.get_user_mailer(), } - def get_queryset(self): + def get_object_list(self): return self.get_user_mailer().error_log.all() def get_user_mailer(self): diff --git a/mayan/apps/metadata/tests/test_views.py b/mayan/apps/metadata/tests/test_views.py index 98d554bdb4..98a62632d9 100644 --- a/mayan/apps/metadata/tests/test_views.py +++ b/mayan/apps/metadata/tests/test_views.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +import logging + from django.core.files.base import File from documents.models import DocumentType from documents.permissions import ( @@ -140,12 +142,14 @@ class DocumentMetadataTestCase(GenericDocumentViewTestCase): 'form-MAX_NUM_FORMS': '', }, follow=True ) - self.assertEqual(response.status_code, 200) self.assertEqual(len(self.document.metadata.all()), 1) def test_metadata_remove_view_with_permission(self): + # Silence unrelated logging + logging.getLogger('navigation.classes').setLevel(logging.CRITICAL) + self.login_user() document_metadata = self.document.metadata.create( diff --git a/mayan/apps/metadata/views.py b/mayan/apps/metadata/views.py index 5719d1a827..a0ef622424 100644 --- a/mayan/apps/metadata/views.py +++ b/mayan/apps/metadata/views.py @@ -359,7 +359,7 @@ class DocumentMetadataListView(SingleObjectListView): 'title': _('Metadata for document: %s') % document, } - def get_queryset(self): + def get_object_list(self): return self.get_document().metadata.all() @@ -545,9 +545,6 @@ class MetadataTypeEditView(SingleObjectEditView): class MetadataTypeListView(SingleObjectListView): view_permission = permission_metadata_type_view - def get_queryset(self): - return MetadataType.objects.all() - def get_extra_context(self): return { 'extra_columns': ( @@ -560,6 +557,9 @@ class MetadataTypeListView(SingleObjectListView): 'title': _('Metadata types'), } + def get_object_list(self): + return MetadataType.objects.all() + class SetupDocumentTypeMetadataTypes(FormView): form_class = DocumentTypeMetadataTypeRelationshipFormSet diff --git a/mayan/apps/ocr/views.py b/mayan/apps/ocr/views.py index c97ce8326c..fa0871735b 100644 --- a/mayan/apps/ocr/views.py +++ b/mayan/apps/ocr/views.py @@ -156,7 +156,7 @@ class EntryListView(SingleObjectListView): } view_permission = permission_ocr_document - def get_queryset(self): + def get_object_list(self): return DocumentVersionOCRError.objects.all() @@ -173,7 +173,7 @@ class DocumentOCRErrorsListView(SingleObjectListView): 'title': _('OCR errors for document: %s') % self.get_document(), } - def get_queryset(self): + def get_object_list(self): return self.get_document().latest_version.ocr_errors.all() diff --git a/mayan/apps/smart_settings/views.py b/mayan/apps/smart_settings/views.py index 5aa6ca9d6b..902a9d41b9 100644 --- a/mayan/apps/smart_settings/views.py +++ b/mayan/apps/smart_settings/views.py @@ -16,7 +16,7 @@ class NamespaceListView(SingleObjectListView): } view_permission = permission_settings_view - def get_queryset(self): + def get_object_list(self): return Namespace.get_all() @@ -37,5 +37,5 @@ class NamespaceDetailView(SingleObjectListView): _('Namespace: %s, not found') % self.kwargs['namespace_name'] ) - def get_queryset(self): + def get_object_list(self): return self.get_namespace().settings diff --git a/mayan/apps/sources/tests/test_views.py b/mayan/apps/sources/tests/test_views.py index 687d726d7b..df236f7287 100644 --- a/mayan/apps/sources/tests/test_views.py +++ b/mayan/apps/sources/tests/test_views.py @@ -5,7 +5,6 @@ import shutil from django.test import override_settings -from acls.models import AccessControlList from checkouts.models import NewVersionBlock from common.tests.test_views import GenericViewTestCase from common.utils import fs_cleanup, mkdtemp @@ -80,10 +79,9 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase): # Create an access control entry giving the role the document # create permission for the selected document type. - acl = AccessControlList.objects.create( - content_object=self.document_type, role=self.role + self.grant_access( + obj=self.document_type, permission=permission_document_create ) - acl.permissions.add(permission_document_create.stored_permission) with open(TEST_SMALL_DOCUMENT_PATH) as file_object: response = self.post( diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index 5692ba8d47..477a38f61c 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -45,14 +45,6 @@ from .utils import get_class, get_form_class, get_upload_form_class class SourceLogListView(SingleObjectListView): view_permission = permission_sources_setup_view - def get_source(self): - return get_object_or_404( - Source.objects.select_subclasses(), pk=self.kwargs['pk'] - ) - - def get_queryset(self): - return self.get_source().logs.all() - def get_extra_context(self): return { 'hide_object': True, @@ -60,6 +52,14 @@ class SourceLogListView(SingleObjectListView): 'title': _('Log entries for source: %s') % self.get_source(), } + def get_object_list(self): + return self.get_source().logs.all() + + def get_source(self): + return get_object_or_404( + Source.objects.select_subclasses(), pk=self.kwargs['pk'] + ) + class UploadBaseView(MultiFormView): template_name = 'appearance/generic_form.html' diff --git a/mayan/apps/statistics/tests/test_views.py b/mayan/apps/statistics/tests/test_views.py index f2669d4d46..93cf06d632 100644 --- a/mayan/apps/statistics/tests/test_views.py +++ b/mayan/apps/statistics/tests/test_views.py @@ -2,17 +2,13 @@ from __future__ import unicode_literals from common.tests.test_views import GenericViewTestCase -from user_management.tests.literals import ( - TEST_USER_PASSWORD, TEST_USER_USERNAME -) - from ..classes import Statistic from ..permissions import permission_statistics_view class StatisticsViewTestCase(GenericViewTestCase): def test_statistic_detail_view_no_permissions(self): - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() statistic = Statistic.get_all()[0] @@ -23,9 +19,9 @@ class StatisticsViewTestCase(GenericViewTestCase): self.assertEqual(response.status_code, 403) def test_statistic_detail_view_with_permissions(self): - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add(permission_statistics_view.stored_permission) + self.grant_permission(permission=permission_statistics_view) statistic = Statistic.get_all()[0] @@ -36,16 +32,16 @@ class StatisticsViewTestCase(GenericViewTestCase): self.assertEqual(response.status_code, 200) def test_statistic_namespace_list_view_no_permissions(self): - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() response = self.get('statistics:namespace_list') self.assertEqual(response.status_code, 403) def test_statistic_namespace_list_view_with_permissions(self): - self.login(username=TEST_USER_USERNAME, password=TEST_USER_PASSWORD) + self.login_user() - self.role.permissions.add(permission_statistics_view.stored_permission) + self.grant_permission(permission=permission_statistics_view) response = self.get('statistics:namespace_list') diff --git a/mayan/apps/statistics/views.py b/mayan/apps/statistics/views.py index b0f4c8fb9f..2c81320bfc 100644 --- a/mayan/apps/statistics/views.py +++ b/mayan/apps/statistics/views.py @@ -19,7 +19,7 @@ class NamespaceListView(SingleObjectListView): template_name = 'appearance/generic_list.html' view_permission = permission_statistics_view - def get_queryset(self): + def get_object_list(self): return StatisticNamespace.get_all() @@ -36,7 +36,7 @@ class NamespaceDetailView(SingleObjectListView): def get_namespace(self): return StatisticNamespace.get(self.kwargs['slug']) - def get_queryset(self): + def get_object_list(self): return self.get_namespace().statistics diff --git a/mayan/apps/tags/forms.py b/mayan/apps/tags/forms.py index 7fbff833ff..ea8f48851b 100644 --- a/mayan/apps/tags/forms.py +++ b/mayan/apps/tags/forms.py @@ -24,7 +24,7 @@ class TagMultipleSelectionForm(forms.Form): super(TagMultipleSelectionForm, self).__init__(*args, **kwargs) queryset = AccessControlList.objects.filter_by_access( - permission_tag_view, user, queryset=queryset + permission=permission_tag_view, queryset=queryset, user=user ) self.fields['tags'] = forms.ModelMultipleChoiceField( diff --git a/mayan/apps/tags/tests/test_views.py b/mayan/apps/tags/tests/test_views.py index 6b4301694a..39e5770544 100644 --- a/mayan/apps/tags/tests/test_views.py +++ b/mayan/apps/tags/tests/test_views.py @@ -16,30 +16,23 @@ from .literals import ( class TagViewTestCase(GenericDocumentViewTestCase): - def setUp(self): - super(TagViewTestCase, self).setUp() - + def _create_tag(self): self.tag = Tag.objects.create( color=TEST_TAG_COLOR, label=TEST_TAG_LABEL ) - def tearDown(self): - if self.tag.pk: - self.tag.delete() - super(TagViewTestCase, self).tearDown() + def _request_create_tag(self): + return self.post( + 'tags:tag_create', data={ + 'label': TEST_TAG_LABEL, + 'color': TEST_TAG_COLOR + }, follow=True + ) def test_tag_create_view_no_permissions(self): self.login_user() - self.tag.delete() - self.assertEqual(Tag.objects.count(), 0) - - response = self.post( - 'tags:tag_create', data={ - 'label': TEST_TAG_LABEL, - 'color': TEST_TAG_COLOR - } - ) + response = self._request_create_tag() self.assertEqual(response.status_code, 403) self.assertEqual(Tag.objects.count(), 0) @@ -47,204 +40,201 @@ class TagViewTestCase(GenericDocumentViewTestCase): def test_tag_create_view_with_permissions(self): self.login_user() - self.tag.delete() - self.assertEqual(Tag.objects.count(), 0) - self.grant_permission(permission=permission_tag_create) - response = self.post( - 'tags:tag_create', data={ - 'label': TEST_TAG_LABEL, - 'color': TEST_TAG_COLOR - }, follow=True - ) + response = self._request_create_tag() - self.assertContains(response, text='created', status_code=200) + self.assertEqual(response.status_code, 200) self.assertEqual(Tag.objects.count(), 1) tag = Tag.objects.first() self.assertEqual(tag.label, TEST_TAG_LABEL) self.assertEqual(tag.color, TEST_TAG_COLOR) - def test_tag_delete_view_no_permissions(self): - self.login_user() - - self.assertEqual(Tag.objects.count(), 1) - - response = self.post( - 'tags:tag_delete', args=(self.tag.pk,) - ) - - self.assertEqual(response.status_code, 302) - self.assertEqual(Tag.objects.count(), 1) - - def test_tag_delete_view_with_permissions(self): - self.login_user() - - self.assertEqual(Tag.objects.count(), 1) - - self.grant_permission(permission=permission_tag_delete) - - response = self.post( + def _request_delete_tag(self): + return self.post( 'tags:tag_delete', args=(self.tag.pk,), follow=True ) - self.assertContains(response, text='deleted', status_code=200) + def test_tag_delete_view_no_permissions(self): + self.login_user() + self._create_tag() + + response = self._request_delete_tag() + + self.assertEqual(response.status_code, 200) + self.assertEqual(Tag.objects.count(), 1) + + def test_tag_delete_view_with_access(self): + self.login_user() + self._create_tag() + + self.grant_access(obj=self.tag, permission=permission_tag_delete) + + response = self._request_delete_tag() + + self.assertEqual(response.status_code, 200) self.assertEqual(Tag.objects.count(), 0) - def test_tag_multiple_delete_view_no_permissions(self): - self.login_user() - - self.assertEqual(Tag.objects.count(), 1) - - response = self.post( - 'tags:tag_multiple_delete', data={'id_list': self.tag.pk} - ) - - self.assertEqual(response.status_code, 302) - self.assertEqual(Tag.objects.count(), 1) - - def test_tag_multiple_delete_view_with_permissions(self): - self.login_user() - - self.assertEqual(Tag.objects.count(), 1) - - self.grant_permission(permission=permission_tag_delete) - - response = self.post( + def _request_multiple_delete(self): + return self.post( 'tags:tag_multiple_delete', data={'id_list': self.tag.pk}, follow=True ) - self.assertContains(response, text='deleted', status_code=200) + def test_tag_multiple_delete_view_no_permissions(self): + self.login_user() + self._create_tag() + + response = self._request_multiple_delete() + + self.assertEqual(response.status_code, 200) + self.assertEqual(Tag.objects.count(), 1) + + def test_tag_multiple_delete_view_with_access(self): + self.login_user() + self._create_tag() + + self.grant_access(obj=self.tag, permission=permission_tag_delete) + + response = self._request_multiple_delete() + + self.assertEqual(response.status_code, 200) self.assertEqual(Tag.objects.count(), 0) - def test_tag_edit_view_no_permissions(self): - self.login_user() - - response = self.post( + def _request_edit_tag(self): + return self.post( 'tags:tag_edit', args=(self.tag.pk,), data={ 'label': TEST_TAG_LABEL_EDITED, 'color': TEST_TAG_COLOR_EDITED - } + }, follow=True ) + def test_tag_edit_view_no_permissions(self): + self.login_user() + self._create_tag() + + response = self._request_edit_tag() + self.assertEqual(response.status_code, 403) tag = Tag.objects.get(pk=self.tag.pk) self.assertEqual(tag.label, TEST_TAG_LABEL) self.assertEqual(tag.color, TEST_TAG_COLOR) - def test_tag_edit_view_with_permissions(self): + def test_tag_edit_view_with_access(self): self.login_user() + self._create_tag() - self.grant_permission(permission=permission_tag_edit) + self.grant_access(obj=self.tag, permission=permission_tag_edit) - response = self.post( - 'tags:tag_edit', args=(self.tag.pk,), data={ - 'label': TEST_TAG_LABEL_EDITED, 'color': TEST_TAG_COLOR_EDITED - }, follow=True - ) + response = self._request_edit_tag() - self.assertContains(response, text='update', status_code=200) + self.assertEqual(response.status_code, 200) tag = Tag.objects.get(pk=self.tag.pk) self.assertEqual(tag.label, TEST_TAG_LABEL_EDITED) self.assertEqual(tag.color, TEST_TAG_COLOR_EDITED) + def _request_document_list(self): + return self.get('documents:document_list') + def test_document_tags_widget_no_permissions(self): self.login_user() + self._create_tag() self.tag.documents.add(self.document) - response = self.get('documents:document_list') + response = self._request_document_list() self.assertNotContains(response, text=TEST_TAG_LABEL, status_code=200) - def test_document_tags_widget_with_permissions(self): + def test_document_tags_widget_with_access(self): self.login_user() + self._create_tag() self.tag.documents.add(self.document) - self.grant_permission(permission=permission_tag_view) - self.grant_permission(permission=permission_document_view) + self.grant_access(obj=self.tag, permission=permission_tag_view) + self.grant_access( + obj=self.document, permission=permission_document_view + ) - response = self.get('documents:document_list') + response = self._request_document_list() self.assertContains(response, text=TEST_TAG_LABEL, status_code=200) - def test_document_attach_tag_view_no_permission(self): - self.login_user() - - self.assertEqual(self.document.tags.count(), 0) - - self.grant_permission(permission=permission_tag_view) - - response = self.post( - 'tags:tag_attach', args=(self.document.pk,), data={ - 'tag': self.tag.pk, - 'user': self.user.pk - } - ) - - # Redirect to previous URL and show warning message about having to - # select at least one object. - self.assertEqual(response.status_code, 302) - self.assertEqual(self.document.tags.count(), 0) - - def test_document_attach_tag_view_with_permission(self): - self.login_user() - - self.assertEqual(self.document.tags.count(), 0) - - self.grant_permission(permission=permission_tag_attach) - # permission_tag_view is needed because the form filters the - # choices - self.grant_permission(permission=permission_tag_view) - - response = self.post( + def _request_attach_tag(self): + return self.post( 'tags:tag_attach', args=(self.document.pk,), data={ 'tags': self.tag.pk, 'user': self.user.pk }, follow=True ) + def test_document_attach_tag_view_no_permission(self): + self.login_user() + self._create_tag() + + self.assertEqual(self.document.tags.count(), 0) + + self.grant_access(obj=self.tag, permission=permission_tag_attach) + + response = self._request_attach_tag() + + # Redirect to previous URL and show warning message about having to + # select at least one object. + self.assertEqual(response.status_code, 200) + self.assertEqual(self.document.tags.count(), 0) + + def test_document_attach_tag_view_with_access(self): + self.login_user() + self._create_tag() + + self.assertEqual(self.document.tags.count(), 0) + + self.grant_access(obj=self.document, permission=permission_tag_attach) + self.grant_access(obj=self.tag, permission=permission_tag_attach) + # permission_tag_view is needed because the form filters the + # choices + self.grant_access(obj=self.tag, permission=permission_tag_view) + + response = self._request_attach_tag() + self.assertEqual(response.status_code, 200) self.assertQuerysetEqual( self.document.tags.all(), (repr(self.tag),) ) + def _request_multiple_attach_tag(self): + return self.post( + 'tags:multiple_documents_tag_attach', data={ + 'id_list': self.document.pk, 'tags': self.tag.pk, + 'user': self.user.pk + }, follow=True + ) + def test_document_multiple_attach_tag_view_no_permission(self): self.login_user() + self._create_tag() - self.assertEqual(self.document.tags.count(), 0) self.grant_permission(permission=permission_tag_view) - response = self.post( - 'tags:multiple_documents_tag_attach', data={ - 'id_list': self.document.pk, 'tags': self.tag.pk, - 'user': self.user.pk - } - ) + response = self._request_multiple_attach_tag() - self.assertEqual(response.status_code, 302) + self.assertEqual(response.status_code, 200) self.assertEqual(self.document.tags.count(), 0) - def test_document_multiple_attach_tag_view_with_permission(self): + def test_document_multiple_attach_tag_view_with_access(self): self.login_user() + self._create_tag() - self.assertEqual(self.document.tags.count(), 0) - - self.grant_permission(permission=permission_tag_attach) + self.grant_access(obj=self.document, permission=permission_tag_attach) + self.grant_access(obj=self.tag, permission=permission_tag_attach) # permission_tag_view is needed because the form filters the # choices - self.grant_permission(permission=permission_tag_view) + self.grant_access(obj=self.tag, permission=permission_tag_view) - response = self.post( - 'tags:multiple_documents_tag_attach', data={ - 'id_list': self.document.pk, 'tags': self.tag.pk, - 'user': self.user.pk - }, follow=True - ) + response = self._request_multiple_attach_tag() self.assertEqual(response.status_code, 200) @@ -252,35 +242,8 @@ class TagViewTestCase(GenericDocumentViewTestCase): self.document.tags.all(), (repr(self.tag),) ) - def test_single_document_multiple_tag_remove_view_no_permissions(self): - self.login_user() - - self.document.tags.add(self.tag) - self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - - self.grant_permission(permission=permission_tag_view) - - response = self.post( - 'tags:single_document_multiple_tag_remove', - args=(self.document.pk,), data={ - 'id_list': self.document.pk, - 'tags': self.tag.pk, - } - ) - - self.assertEqual(response.status_code, 302) - self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - - def test_single_document_multiple_tag_remove_view_with_permission(self): - self.login_user() - - self.document.tags.add(self.tag) - self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - - self.grant_permission(permission=permission_tag_remove) - self.grant_permission(permission=permission_tag_view) - - response = self.post( + def _request_single_document_multiple_tag_remove(self): + return self.post( 'tags:single_document_multiple_tag_remove', args=(self.document.pk,), data={ 'id_list': self.document.pk, @@ -288,44 +251,67 @@ class TagViewTestCase(GenericDocumentViewTestCase): }, follow=True ) + def test_single_document_multiple_tag_remove_view_no_permissions(self): + self.login_user() + self._create_tag() + + self.document.tags.add(self.tag) + + self.grant_access(obj=self.tag, permission=permission_tag_view) + + response = self._request_single_document_multiple_tag_remove() + + self.assertEqual(response.status_code, 200) + self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) + + def test_single_document_multiple_tag_remove_view_with_access(self): + self.login_user() + self._create_tag() + + self.document.tags.add(self.tag) + + self.grant_access(obj=self.document, permission=permission_tag_remove) + self.grant_access(obj=self.tag, permission=permission_tag_remove) + self.grant_access(obj=self.tag, permission=permission_tag_view) + + response = self._request_single_document_multiple_tag_remove() + self.assertEqual(response.status_code, 200) self.assertEqual(self.document.tags.count(), 0) + def _request_multiple_documents_selection_tag_remove(self): + return self.post( + 'tags:multiple_documents_selection_tag_remove', + data={ + 'id_list': self.document.pk, + 'tags': self.tag.pk, + }, follow=True + ) + def test_multiple_documents_selection_tag_remove_view_no_permissions(self): self.login_user() + self._create_tag() self.document.tags.add(self.tag) + + self.grant_access(obj=self.tag, permission=permission_tag_view) + + response = self._request_multiple_documents_selection_tag_remove() + + self.assertEqual(response.status_code, 200) self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - self.grant_permission(permission=permission_tag_view) - - response = self.post( - 'tags:multiple_documents_selection_tag_remove', - data={ - 'id_list': self.document.pk, - 'tags': self.tag.pk, - } - ) - - self.assertEqual(response.status_code, 302) - self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - - def test_multiple_documents_selection_tag_remove_view_with_permission(self): + def test_multiple_documents_selection_tag_remove_view_with_access(self): self.login_user() + self._create_tag() self.document.tags.add(self.tag) - self.assertQuerysetEqual(self.document.tags.all(), (repr(self.tag),)) - self.grant_permission(permission=permission_tag_remove) - self.grant_permission(permission=permission_tag_view) + self.grant_access(obj=self.document, permission=permission_tag_remove) + self.grant_access(obj=self.tag, permission=permission_tag_remove) + self.grant_access(obj=self.tag, permission=permission_tag_view) - response = self.post( - 'tags:multiple_documents_selection_tag_remove', - data={ - 'id_list': self.document.pk, - 'tags': self.tag.pk, - }, follow=True - ) + response = self._request_multiple_documents_selection_tag_remove() self.assertEqual(response.status_code, 200) self.assertEqual(self.document.tags.count(), 0) diff --git a/mayan/apps/tags/views.py b/mayan/apps/tags/views.py index fded552a91..9dd4e6b447 100644 --- a/mayan/apps/tags/views.py +++ b/mayan/apps/tags/views.py @@ -183,7 +183,7 @@ class TagListView(SingleObjectListView): 'title': _('Tags'), } - def get_queryset(self): + def get_object_list(self): return self.get_tag_queryset() def get_tag_queryset(self): diff --git a/mayan/apps/user_management/views.py b/mayan/apps/user_management/views.py index 52c6bb2aa8..dc7a29cb0a 100644 --- a/mayan/apps/user_management/views.py +++ b/mayan/apps/user_management/views.py @@ -240,7 +240,7 @@ class UserListView(SingleObjectListView): 'title': _('Users'), } - def get_queryset(self): + def get_object_list(self): return get_user_model().objects.exclude( is_superuser=True ).exclude(is_staff=True).order_by('last_name', 'first_name')