Skip to content

Commit

Permalink
Fix layer exclusion for priority value of 0
Browse files Browse the repository at this point in the history
This fixes the preview layer priority when editing the
redactions of pages that also contain transformations in
other layers.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
  • Loading branch information
Roberto Rosario committed Aug 4, 2021
1 parent ed3f53d commit 9f6151a
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 6 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
===================
- Fix a regression in the document version page image cache maximum size
setting callback.
- Fix converter layer priority exclusion for layers with a priority of 0.
This fixes the preview layer priority when editing the redactions of pages
that also contain transformations in other layers.

4.0.13 (2021-08-02)
===================
Expand Down
2 changes: 1 addition & 1 deletion mayan/apps/converter/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def add_transformation_to(

if self in transformation_class._layer_transformations:
return object_layer.transformations.create(
arguments=arguments, order=order,
arguments=arguments or '', order=order,
name=transformation_class.name
)
else:
Expand Down
8 changes: 4 additions & 4 deletions mayan/apps/converter/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def get_for_object(
object_layer__object_id=obj.pk, object_layer__enabled=True
)

access_layers = StoredLayer.objects.all()
exclude_layers = StoredLayer.objects.none()

if maximum_layer_order:
if maximum_layer_order is not None:
access_layers = StoredLayer.objects.filter(
order__lte=maximum_layer_order
)
exclude_layers = StoredLayer.objects.filter(
order__gt=maximum_layer_order
)
else:
access_layers = StoredLayer.objects.all()
exclude_layers = StoredLayer.objects.none()

for stored_layer in access_layers:
try:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions mayan/apps/redactions/tests/literals.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
import os

from django.conf import settings

TEST_REDACTION_ARGUMENT = "{'left': 10, 'top': 10, 'right': 10, 'bottom': 10}"
TEST_REDACTION_ARGUMENT_EDITED = "{'left': 20, 'top': 20, 'right': 20, 'bottom': 20}"

TEST_REDACTION_DOCUMENT_FILENAME = 'black_upper_left_corner.png'
TEST_REDACTION_DOCUMENT_PATH = os.path.join(
settings.BASE_DIR, 'apps', 'redactions', 'tests', 'contrib',
'sample_documents', TEST_REDACTION_DOCUMENT_FILENAME
)
12 changes: 12 additions & 0 deletions mayan/apps/redactions/tests/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from ..layers import layer_redactions


class LayerMaximumOrderAPIViewTestMixin:
def _request_document_file_page_image_api_view_with_maximum_layer_order(self):
return self.get(
viewname='rest_api:documentfilepage-image', kwargs={
'document_id': self.test_document.pk,
'document_file_id': self.test_document_file.pk,
'document_file_page_id': self.test_document_file_page.pk,
}, query={'maximum_layer_order': layer_redactions.order}
)
44 changes: 44 additions & 0 deletions mayan/apps/redactions/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from io import BytesIO

from PIL import Image

from rest_framework import status

from mayan.apps.rest_api.tests.base import BaseAPITestCase

from mayan.apps.converter.layers import layer_saved_transformations
from mayan.apps.converter.transformations import TransformationRotate270
from mayan.apps.documents.permissions import permission_document_file_view
from mayan.apps.documents.tests.mixins.document_mixins import DocumentTestMixin

from .literals import TEST_REDACTION_DOCUMENT_PATH
from .mixins import LayerMaximumOrderAPIViewTestMixin


class LayerMaximumOrderAPIViewTestCase(
LayerMaximumOrderAPIViewTestMixin, DocumentTestMixin, BaseAPITestCase
):
test_document_path = TEST_REDACTION_DOCUMENT_PATH

def test_redaction_maximum_layer_order(self):
self.grant_access(
obj=self.test_document, permission=permission_document_file_view
)

layer_saved_transformations.add_transformation_to(
obj=self.test_document_file_page,
transformation_class=TransformationRotate270
)

self._clear_events()

response = self._request_document_file_page_image_api_view_with_maximum_layer_order()
self.assertEqual(response.status_code, status.HTTP_200_OK)

image_buffer = BytesIO(response.content)
image = Image.open(fp=image_buffer)

self.assertEqual(image.getpixel(xy=(0, 0)), (0, 0, 0))

events = self._get_test_events()
self.assertEqual(events.count(), 0)
2 changes: 1 addition & 1 deletion mayan/apps/redactions/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)


class RedactionViewsTestCase(
class RedactionViewTestCase(
TransformationTestMixin, TransformationViewsTestMixin,
GenericDocumentViewTestCase
):
Expand Down

0 comments on commit 9f6151a

Please sign in to comment.