Update document transformation links and views
Update the URL nomeclature for uniformity. Add document transformation link tests and improve the transformation view tests. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -52,19 +52,19 @@ from .handlers import (
|
||||
handler_remove_empty_duplicates_lists, handler_scan_duplicates_for
|
||||
)
|
||||
from .links import (
|
||||
link_clear_image_cache, link_document_clear_transformations,
|
||||
link_document_clone_transformations, link_trashed_document_delete,
|
||||
link_clear_image_cache, link_trashed_document_delete,
|
||||
link_document_change_type, link_document_download,
|
||||
link_document_duplicates_list, link_document_edit,
|
||||
link_document_favorites_add, link_document_favorites_remove,
|
||||
link_document_list, link_trashed_document_list,
|
||||
link_document_list_favorites, link_document_list_recent_access,
|
||||
link_document_list_recent_added,
|
||||
link_document_multiple_clear_transformations,
|
||||
link_trashed_document_multiple_delete, link_document_multiple_change_type,
|
||||
link_document_multiple_change_type,
|
||||
link_document_multiple_download, link_document_multiple_favorites_add,
|
||||
link_document_multiple_favorites_remove, link_trashed_document_multiple_restore,
|
||||
link_document_multiple_trash, link_document_multiple_update_page_count,
|
||||
link_document_multiple_trash,
|
||||
link_document_multiple_transformations_clear,
|
||||
link_document_multiple_update_page_count,
|
||||
link_document_page_navigation_first, link_document_page_navigation_last,
|
||||
link_document_page_navigation_next, link_document_page_navigation_previous,
|
||||
link_document_page_return, link_document_page_rotate_left,
|
||||
@@ -82,7 +82,8 @@ from .links import (
|
||||
link_document_version_return_document, link_document_version_return_list,
|
||||
link_document_version_revert, link_document_version_view,
|
||||
link_duplicated_document_list, link_duplicated_document_scan,
|
||||
link_trash_can_empty
|
||||
link_document_transformations_clear, link_document_transformations_clone,
|
||||
link_trash_can_empty, link_trashed_document_multiple_delete
|
||||
)
|
||||
from .literals import (
|
||||
CHECK_DELETE_PERIOD_INTERVAL, CHECK_TRASH_PERIOD_INTERVAL,
|
||||
@@ -509,8 +510,8 @@ class DocumentsApp(MayanAppConfig):
|
||||
link_document_edit, link_document_change_type,
|
||||
link_document_print, link_document_trash,
|
||||
link_document_quick_download, link_document_download,
|
||||
link_document_clear_transformations,
|
||||
link_document_clone_transformations,
|
||||
link_document_transformations_clear,
|
||||
link_document_transformations_clone,
|
||||
link_document_update_page_count,
|
||||
), sources=(Document,)
|
||||
)
|
||||
@@ -550,7 +551,7 @@ class DocumentsApp(MayanAppConfig):
|
||||
links=(
|
||||
link_document_multiple_favorites_add,
|
||||
link_document_multiple_favorites_remove,
|
||||
link_document_multiple_clear_transformations,
|
||||
link_document_multiple_transformations_clear,
|
||||
link_document_multiple_trash, link_document_multiple_download,
|
||||
link_document_multiple_update_page_count,
|
||||
link_document_multiple_change_type,
|
||||
|
||||
@@ -101,18 +101,6 @@ link_document_pages = Link(
|
||||
)
|
||||
|
||||
# Actions
|
||||
link_document_clear_transformations = Link(
|
||||
args='resolved_object.id', permission=permission_transformation_delete,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Clear transformations'),
|
||||
view='documents:document_clear_transformations'
|
||||
)
|
||||
link_document_clone_transformations = Link(
|
||||
permission=permission_transformation_edit,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Clone transformations'),
|
||||
view='documents:document_clone_transformations'
|
||||
)
|
||||
link_document_favorites_add = Link(
|
||||
icon_class=icon_document_favorites_add,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
@@ -125,12 +113,6 @@ link_document_favorites_remove = Link(
|
||||
permission=permission_document_view, text=_('Remove from favorites'),
|
||||
view='documents:document_remove_from_favorites'
|
||||
)
|
||||
link_document_trash = Link(
|
||||
icon_class=icon_document_trash,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_trash, tags='dangerous',
|
||||
text=_('Move to trash'), view='documents:document_trash'
|
||||
)
|
||||
link_document_edit = Link(
|
||||
icon_class=icon_document_edit,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
@@ -148,27 +130,10 @@ link_document_download = Link(
|
||||
permission=permission_document_download, text=_('Advanced download'),
|
||||
view='documents:document_download_form'
|
||||
)
|
||||
link_document_print = Link(
|
||||
icon_class=icon_document_print,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_print, text=_('Print'),
|
||||
view='documents:document_print'
|
||||
)
|
||||
link_document_quick_download = Link(
|
||||
permission=permission_document_download,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Quick download'), view='documents:document_download'
|
||||
)
|
||||
link_document_update_page_count = Link(
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_tools,
|
||||
text=_('Recalculate page count'),
|
||||
view='documents:document_update_page_count'
|
||||
)
|
||||
link_document_multiple_clear_transformations = Link(
|
||||
link_document_multiple_transformations_clear = Link(
|
||||
permission=permission_transformation_delete,
|
||||
text=_('Clear transformations'),
|
||||
view='documents:document_multiple_clear_transformations'
|
||||
view='documents:document_multiple_transformations_clear'
|
||||
)
|
||||
link_document_multiple_trash = Link(
|
||||
tags='dangerous', text=_('Move to trash'),
|
||||
@@ -194,7 +159,41 @@ link_document_multiple_update_page_count = Link(
|
||||
text=_('Recalculate page count'),
|
||||
view='documents:document_multiple_update_page_count'
|
||||
)
|
||||
|
||||
link_document_print = Link(
|
||||
icon_class=icon_document_print,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_print, text=_('Print'),
|
||||
view='documents:document_print'
|
||||
)
|
||||
link_document_quick_download = Link(
|
||||
permission=permission_document_download,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Quick download'), view='documents:document_download'
|
||||
)
|
||||
link_document_transformations_clear = Link(
|
||||
permission=permission_transformation_delete,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Clear transformations'),
|
||||
view='documents:document_transformations_clear'
|
||||
)
|
||||
link_document_transformations_clone = Link(
|
||||
permission=permission_transformation_edit,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
text=_('Clone transformations'),
|
||||
view='documents:document_transformations_clone'
|
||||
)
|
||||
link_document_trash = Link(
|
||||
icon_class=icon_document_trash,
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_trash, tags='dangerous',
|
||||
text=_('Move to trash'), view='documents:document_trash'
|
||||
)
|
||||
link_document_update_page_count = Link(
|
||||
kwargs={'document_id': 'resolved_object.id'},
|
||||
permission=permission_document_tools,
|
||||
text=_('Recalculate page count'),
|
||||
view='documents:document_update_page_count'
|
||||
)
|
||||
link_trashed_document_delete = Link(
|
||||
icon_class=icon_trashed_document_delete,
|
||||
kwargs={'trashed_document_id': 'resolved_object.id'},
|
||||
|
||||
@@ -9,7 +9,7 @@ from .permissions import permission_document_view
|
||||
document_search = SearchModel(
|
||||
app_label='documents', model_name='Document',
|
||||
permission=permission_document_view,
|
||||
serializer_string='mayan.apps.documents.serializers.DocumentSerializer'
|
||||
serializer_path='mayan.apps.documents.serializers.DocumentSerializer'
|
||||
)
|
||||
|
||||
document_search.add_model_field(
|
||||
@@ -27,7 +27,7 @@ document_search.add_model_field(
|
||||
document_page_search = SearchModel(
|
||||
app_label='documents', model_name='DocumentPageSearchResult',
|
||||
permission=permission_document_view,
|
||||
serializer_string='mayan.apps.documents.serializers.DocumentPageSerializer'
|
||||
serializer_path='mayan.apps.documents.serializers.DocumentPageSerializer'
|
||||
)
|
||||
|
||||
document_page_search.add_model_field(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
@@ -19,6 +20,7 @@ class DocumentTestMixin(object):
|
||||
auto_upload_document = True
|
||||
test_document_filename = TEST_SMALL_DOCUMENT_FILENAME
|
||||
test_document_path = None
|
||||
use_document_stub = False
|
||||
|
||||
def _create_document_type(self):
|
||||
self.document_type = DocumentType.objects.create(
|
||||
@@ -31,6 +33,16 @@ class DocumentTestMixin(object):
|
||||
"""
|
||||
self.test_document = self.upload_document(*args, **kwargs)
|
||||
|
||||
def _create_document_version(self):
|
||||
# Needed by MySQL as timestamp value doesn't include milliseconds
|
||||
# resolution
|
||||
time.sleep(1.01)
|
||||
|
||||
self._calculate_test_document_path()
|
||||
|
||||
with open(self.test_document_path, mode='rb') as file_object:
|
||||
self.test_document.new_version(file_object=file_object)
|
||||
|
||||
def _calculate_test_document_path(self):
|
||||
if not self.test_document_path:
|
||||
self.test_document_path = os.path.join(
|
||||
@@ -46,6 +58,7 @@ class DocumentTestMixin(object):
|
||||
|
||||
if self.auto_upload_document:
|
||||
self.document = self.upload_document()
|
||||
self.test_document = self.document
|
||||
|
||||
def tearDown(self):
|
||||
for document_type in DocumentType.objects.all():
|
||||
@@ -57,11 +70,17 @@ class DocumentTestMixin(object):
|
||||
|
||||
document_type = document_type or self.document_type
|
||||
|
||||
with open(self.test_document_path, mode='rb') as file_object:
|
||||
document = document_type.new_document(
|
||||
file_object=file_object,
|
||||
if self.use_document_stub:
|
||||
document = document_type.documents.create(
|
||||
label=filename or self.test_document_filename
|
||||
)
|
||||
else:
|
||||
with open(self.test_document_path, mode='rb') as file_object:
|
||||
document = document_type.new_document(
|
||||
file_object=file_object,
|
||||
label=filename or self.test_document_filename
|
||||
)
|
||||
|
||||
return document
|
||||
|
||||
|
||||
|
||||
@@ -314,13 +314,13 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(self.document.pages.count(), page_count)
|
||||
|
||||
def _request_document_clear_transformations_view(self):
|
||||
def _request_document_transformations_clear_view(self):
|
||||
return self.post(
|
||||
viewname='documents:document_clear_transformations',
|
||||
viewname='documents:document_transformations_clear',
|
||||
kwargs={'document_id': self.document.pk}
|
||||
)
|
||||
|
||||
def test_document_clear_transformations_view_no_permission(self):
|
||||
def test_document_transformations_clear_view_no_permission(self):
|
||||
document_page = self.document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
transformation = Transformation.objects.create(
|
||||
@@ -338,14 +338,14 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
obj=self.document, permission=permission_document_view
|
||||
)
|
||||
|
||||
response = self._request_document_clear_transformations_view()
|
||||
response = self._request_document_transformations_clear_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertQuerysetEqual(
|
||||
Transformation.objects.get_for_model(document_page),
|
||||
(repr(transformation),)
|
||||
)
|
||||
|
||||
def test_document_clear_transformations_view_with_access(self):
|
||||
def test_document_transformations_clear_view_with_access(self):
|
||||
document_page = self.document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
transformation = Transformation.objects.create(
|
||||
@@ -365,19 +365,19 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
obj=self.document, permission=permission_document_view
|
||||
)
|
||||
|
||||
response = self._request_document_clear_transformations_view()
|
||||
response = self._request_document_transformations_clear_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(
|
||||
Transformation.objects.get_for_model(document_page).count(), 0
|
||||
)
|
||||
|
||||
def _request_document_multiple_clear_transformations(self):
|
||||
def _request_document_multiple_transformations_clear(self):
|
||||
return self.post(
|
||||
viewname='documents:document_multiple_clear_transformations',
|
||||
viewname='documents:document_multiple_transformations_clear',
|
||||
data={'id_list': self.document.pk}
|
||||
)
|
||||
|
||||
def test_document_multiple_clear_transformations_view_no_permission(self):
|
||||
def test_document_multiple_transformations_clear_view_no_permission(self):
|
||||
document_page = self.document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
transformation = Transformation.objects.create(
|
||||
@@ -393,14 +393,14 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
|
||||
self.grant_permission(permission=permission_document_view)
|
||||
|
||||
response = self._request_document_multiple_clear_transformations()
|
||||
response = self._request_document_multiple_transformations_clear()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertQuerysetEqual(
|
||||
Transformation.objects.get_for_model(document_page),
|
||||
(repr(transformation),)
|
||||
)
|
||||
|
||||
def test_document_multiple_clear_transformations_view_with_access(self):
|
||||
def test_document_multiple_transformations_clear_view_with_access(self):
|
||||
document_page = self.document.pages.first()
|
||||
content_type = ContentType.objects.get_for_model(document_page)
|
||||
transformation = Transformation.objects.create(
|
||||
@@ -421,7 +421,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
|
||||
obj=self.document, permission=permission_transformation_delete
|
||||
)
|
||||
|
||||
response = self._request_document_multiple_clear_transformations()
|
||||
response = self._request_document_multiple_transformations_clear()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(
|
||||
Transformation.objects.get_for_model(document_page).count(), 0
|
||||
|
||||
@@ -1,54 +1,45 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import time
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from mayan.apps.converter.permissions import (
|
||||
permission_transformation_delete, permission_transformation_edit
|
||||
)
|
||||
|
||||
from ..links import (
|
||||
link_trashed_document_restore, link_document_version_download,
|
||||
link_document_version_revert
|
||||
link_document_transformations_clear, link_document_transformations_clone,
|
||||
link_document_version_revert, link_trashed_document_restore
|
||||
)
|
||||
from ..models import TrashedDocument
|
||||
from ..permissions import (
|
||||
permission_document_download, permission_trashed_document_restore,
|
||||
permission_document_version_revert
|
||||
permission_trashed_document_restore, permission_document_version_revert
|
||||
)
|
||||
|
||||
from .base import GenericDocumentViewTestCase
|
||||
from .literals import TEST_SMALL_DOCUMENT_PATH
|
||||
|
||||
|
||||
class DocumentsLinksTestCase(GenericDocumentViewTestCase):
|
||||
def test_document_version_revert_link_no_permission(self):
|
||||
with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object:
|
||||
self.document.new_version(file_object=file_object)
|
||||
|
||||
self.assertTrue(self.document.versions.count(), 2)
|
||||
use_document_stub = False
|
||||
|
||||
def _resolve_document_version_revert_link(self):
|
||||
self.add_test_view(test_object=self.document.versions.first())
|
||||
context = self.get_test_view()
|
||||
resolved_link = link_document_version_revert.resolve(context=context)
|
||||
return link_document_version_revert.resolve(context=context)
|
||||
|
||||
def test_document_version_revert_link_no_permission(self):
|
||||
self._create_document_version()
|
||||
|
||||
resolved_link = self._resolve_document_version_revert_link()
|
||||
self.assertEqual(resolved_link, None)
|
||||
|
||||
def test_document_version_revert_link_with_access(self):
|
||||
# Needed by MySQL as milliseconds value is not store in timestamp
|
||||
# field
|
||||
time.sleep(1.01)
|
||||
|
||||
with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object:
|
||||
self.document.new_version(file_object=file_object)
|
||||
|
||||
self.assertTrue(self.document.versions.count(), 2)
|
||||
self._create_document_version()
|
||||
|
||||
self.grant_access(
|
||||
obj=self.document, permission=permission_document_version_revert
|
||||
)
|
||||
|
||||
self.add_test_view(test_object=self.document.versions.first())
|
||||
context = self.get_test_view()
|
||||
resolved_link = link_document_version_revert.resolve(context=context)
|
||||
|
||||
resolved_link = self._resolve_document_version_revert_link()
|
||||
self.assertNotEqual(resolved_link, None)
|
||||
self.assertEqual(
|
||||
resolved_link.url,
|
||||
@@ -58,34 +49,59 @@ class DocumentsLinksTestCase(GenericDocumentViewTestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_document_version_download_link_no_permission(self):
|
||||
self.add_test_view(test_object=self.document.latest_version)
|
||||
def _resolve_document_transformations_clear_link(self):
|
||||
self.add_test_view(test_object=self.document)
|
||||
context = self.get_test_view()
|
||||
resolved_link = link_document_version_download.resolve(context=context)
|
||||
return link_document_transformations_clear.resolve(context=context)
|
||||
|
||||
def test_document_transformations_clone_link_no_permission(self):
|
||||
resolved_link = self._resolve_document_transformations_clear_link()
|
||||
self.assertEqual(resolved_link, None)
|
||||
|
||||
def test_document_version_download_link_with_access(self):
|
||||
def test_document_transformations_clone_link_with_access(self):
|
||||
self.grant_access(
|
||||
obj=self.document, permission=permission_document_download
|
||||
obj=self.document, permission=permission_transformation_delete
|
||||
)
|
||||
|
||||
self.add_test_view(test_object=self.document.latest_version)
|
||||
context = self.get_test_view()
|
||||
resolved_link = link_document_version_download.resolve(context=context)
|
||||
|
||||
resolved_link = self._resolve_document_transformations_clear_link()
|
||||
self.assertNotEqual(resolved_link, None)
|
||||
self.assertEqual(
|
||||
resolved_link.url,
|
||||
reverse(
|
||||
viewname='documents:document_version_download_form',
|
||||
kwargs={'document_version_id': self.document.latest_version.pk}
|
||||
viewname='documents:document_transformations_clear',
|
||||
kwargs={'document_id': self.document.pk}
|
||||
)
|
||||
)
|
||||
|
||||
def _resolve_document_transformations_clone_link(self):
|
||||
self.add_test_view(test_object=self.document)
|
||||
context = self.get_test_view()
|
||||
return link_document_transformations_clone.resolve(context=context)
|
||||
|
||||
def test_document_transformations_clone_link_no_permission(self):
|
||||
resolved_link = self._resolve_document_transformations_clone_link()
|
||||
self.assertEqual(resolved_link, None)
|
||||
|
||||
def test_document_transformations_clone_link_with_access(self):
|
||||
self.grant_access(
|
||||
obj=self.document, permission=permission_transformation_edit
|
||||
)
|
||||
|
||||
resolved_link = self._resolve_document_transformations_clone_link()
|
||||
self.assertNotEqual(resolved_link, None)
|
||||
self.assertEqual(
|
||||
resolved_link.url,
|
||||
reverse(
|
||||
viewname='documents:document_transformations_clone',
|
||||
kwargs={'document_id': self.document.pk}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class DeletedDocumentsLinksTestCase(GenericDocumentViewTestCase):
|
||||
def _request_trashed_document_restore_link(self):
|
||||
use_document_stub = True
|
||||
|
||||
def _resolve_trashed_document_restore_link(self):
|
||||
self.add_test_view(
|
||||
test_object=TrashedDocument.objects.get(pk=self.document.pk)
|
||||
)
|
||||
@@ -95,7 +111,7 @@ class DeletedDocumentsLinksTestCase(GenericDocumentViewTestCase):
|
||||
def test_deleted_document_restore_link_no_permission(self):
|
||||
self.document.delete()
|
||||
|
||||
resolved_link = self._request_trashed_document_restore_link()
|
||||
resolved_link = self._resolve_trashed_document_restore_link()
|
||||
|
||||
self.assertEqual(resolved_link, None)
|
||||
|
||||
@@ -106,7 +122,7 @@ class DeletedDocumentsLinksTestCase(GenericDocumentViewTestCase):
|
||||
obj=self.document, permission=permission_trashed_document_restore
|
||||
)
|
||||
|
||||
resolved_link = self._request_trashed_document_restore_link()
|
||||
resolved_link = self._resolve_trashed_document_restore_link()
|
||||
|
||||
self.assertNotEqual(resolved_link, None)
|
||||
self.assertEqual(
|
||||
|
||||
@@ -183,12 +183,12 @@ urlpatterns = [
|
||||
),
|
||||
url(
|
||||
regex=r'^documents/(?P<document_id>\d+)/transformations/clear/$',
|
||||
name='document_clear_transformations',
|
||||
name='document_transformations_clear',
|
||||
view=DocumentTransformationsClearView.as_view()
|
||||
),
|
||||
url(
|
||||
regex=r'^documents/(?P<document_id>\d+)/transformations/clone/$',
|
||||
name='document_clone_transformations',
|
||||
name='document_transformations_clone',
|
||||
view=DocumentTransformationsCloneView.as_view()
|
||||
),
|
||||
url(
|
||||
@@ -222,7 +222,7 @@ urlpatterns = [
|
||||
),
|
||||
url(
|
||||
regex=r'^documents/multiple/transformations/clear/$',
|
||||
name='document_multiple_clear_transformations',
|
||||
name='document_multiple_transformations_clear',
|
||||
view=DocumentTransformationsClearView.as_view()
|
||||
),
|
||||
url(
|
||||
|
||||
Reference in New Issue
Block a user