From cc360be4a4ba91ffbd2221f4fb5799550b0fee1c Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 30 May 2016 06:18:06 -0400 Subject: [PATCH] Finish converting the tags app to user organizations. --- mayan/apps/tags/api_views.py | 4 ++-- mayan/apps/tags/forms.py | 2 +- mayan/apps/tags/serializers.py | 2 +- mayan/apps/tags/tests/test_api.py | 4 ++++ mayan/apps/tags/views.py | 8 ++++---- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mayan/apps/tags/api_views.py b/mayan/apps/tags/api_views.py index f24e267ef3..ec0f5ac665 100644 --- a/mayan/apps/tags/api_views.py +++ b/mayan/apps/tags/api_views.py @@ -34,7 +34,7 @@ class APITagView(generics.RetrieveUpdateDestroyAPIView): 'PATCH': (permission_tag_edit,), 'PUT': (permission_tag_edit,) } - queryset = Tag.objects.all() + queryset = Tag.on_organization.all() serializer_class = TagSerializer def delete(self, *args, **kwargs): @@ -71,7 +71,7 @@ class APITagListView(generics.ListCreateAPIView): mayan_object_permissions = {'GET': (permission_tag_view,)} mayan_view_permissions = {'POST': (permission_tag_create,)} permission_classes = (MayanPermission,) - queryset = Tag.objects.all() + queryset = Tag.on_organization.all() def get_serializer_class(self): if self.request.method == 'GET': diff --git a/mayan/apps/tags/forms.py b/mayan/apps/tags/forms.py index aa00dc857b..a6fdec2f96 100644 --- a/mayan/apps/tags/forms.py +++ b/mayan/apps/tags/forms.py @@ -40,7 +40,7 @@ class TagMultipleSelectionForm(forms.Form): logger.debug('user: %s', user) super(TagMultipleSelectionForm, self).__init__(*args, **kwargs) - queryset = Tag.objects.all() + queryset = Tag.on_organization.all() try: Permission.check_permissions(user, (permission_tag_view,)) except PermissionDenied: diff --git a/mayan/apps/tags/serializers.py b/mayan/apps/tags/serializers.py index 3f49cf2e42..2236233c2a 100644 --- a/mayan/apps/tags/serializers.py +++ b/mayan/apps/tags/serializers.py @@ -48,7 +48,7 @@ class NewDocumentTagSerializer(serializers.Serializer): def create(self, validated_data): try: - tag = Tag.objects.get(pk=validated_data['tag']) + tag = Tag.on_organization.get(pk=validated_data['tag']) try: Permission.check_permissions( diff --git a/mayan/apps/tags/tests/test_api.py b/mayan/apps/tags/tests/test_api.py index 8777e1f7a4..d13da662e7 100644 --- a/mayan/apps/tags/tests/test_api.py +++ b/mayan/apps/tags/tests/test_api.py @@ -8,6 +8,8 @@ from rest_framework.test import APITestCase from documents.models import DocumentType from documents.tests import TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH +from organizations.models import Organization +from organizations.utils import create_default_organization from user_management.tests.literals import ( TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME ) @@ -26,6 +28,7 @@ class TagAPITestCase(APITestCase): """ def setUp(self): + create_default_organization() self.admin_user = get_user_model().on_organization.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD @@ -37,6 +40,7 @@ class TagAPITestCase(APITestCase): def tearDown(self): self.admin_user.delete() + Organization.objects.clear_cache() def test_tag_create(self): response = self.client.post( diff --git a/mayan/apps/tags/views.py b/mayan/apps/tags/views.py index 6940ac25ff..1084f288a2 100644 --- a/mayan/apps/tags/views.py +++ b/mayan/apps/tags/views.py @@ -42,10 +42,10 @@ class TagCreateView(SingleObjectCreateView): def tag_attach(request, document_id=None, document_id_list=None): if document_id: - queryset = Document.objects.filter(pk=document_id) + queryset = Document.on_organization.filter(pk=document_id) post_action_redirect = reverse('tags:tag_list') elif document_id_list: - queryset = Document.objects.filter(pk__in=document_id_list) + queryset = Document.on_organization.filter(pk__in=document_id_list) try: Permission.check_permissions(request.user, (permission_tag_attach,)) @@ -282,9 +282,9 @@ class DocumentTagListView(TagListView): def tag_remove(request, document_id=None, document_id_list=None, tag_id=None, tag_id_list=None): if document_id: - documents = Document.objects.filter(pk=document_id) + documents = Document.on_organization.filter(pk=document_id) elif document_id_list: - documents = Document.objects.filter(pk__in=document_id_list) + documents = Document.on_organization.filter(pk__in=document_id_list) if not documents: messages.error(