Force object to text

Force text display of object when raising PermissionDenied
to avoid UnicodeDecodeError. Thanks to Mathias Behrle
(@mbehrle) for the report and the debug information.
GitLab issue #576.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-04 01:39:06 -04:00
parent a56e3ca111
commit 912675bf99
3 changed files with 14 additions and 2 deletions

View File

@@ -34,6 +34,9 @@
(@mbru) for the report and debug information. GitLab issue #557.
* Add the MIMETYPE_FILE_READ_SIZE setting to limit the number of bytes read
to determine the MIME type of a new document.
* Force object to text when raising PermissionDenied to avoid
UnicodeDecodeError. Thanks to Mathias Behrle (@mbehrle) for the report
and the debug information. GitLab issue #576.
3.1.9 (2018-11-01)

View File

@@ -182,5 +182,7 @@ Bugs fixed or issues closed
* :gitlab-issue:`572` Error when sending compressed files: ziparchive object
has no attribute children
* :gitlab-issue:`574` import of E-Mails with empty attachment fails
* :gitlab-issue:`576` Exception with access check for cabinets containing
NON-ASCII chars
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/

View File

@@ -6,6 +6,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
from django.db import models
from django.db.models import Q
from django.utils.encoding import force_text
from django.utils.translation import ugettext, ugettext_lazy as _
from common.utils import return_attrib, return_related
@@ -54,7 +55,11 @@ class AccessControlListManager(models.Manager):
except AttributeError:
# AttributeError means non model objects: ie Statistics
# These can't have ACLs so we raise PermissionDenied
raise PermissionDenied(_('Insufficient access for: %s') % obj)
# Force object to text to avoid UnicodeDecodeError
raise PermissionDenied(
ugettext('Insufficient access for: %s') % force_text(obj)
)
except KeyError:
pass
else:
@@ -93,7 +98,9 @@ class AccessControlListManager(models.Manager):
'Permissions "%s" on "%s" denied for user "%s"',
permissions, obj, user
)
raise PermissionDenied(ugettext('Insufficient access for: %s') % obj)
raise PermissionDenied(
ugettext('Insufficient access for: %s') % force_text(obj)
)
logger.debug(
'Permissions "%s" on "%s" granted to user "%s" through roles "%s" by direct ACL',