Close GitLab issue #302 'New Document' button available to users who do not have permission.

Thanks to kg @kgraves.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-04-03 01:13:59 -04:00
parent 92bd82320b
commit ed5d7cd812
4 changed files with 53 additions and 3 deletions

View File

@@ -112,6 +112,8 @@
solution.
- Update the role permission edit view require the permission grant or permission
revoke permissions for the selected role.
- Only show the new document link if the user has access to create documents of
at least one document type. GitLab Issue #302. Thanks to kg @kgraves.
2.7.3 (2017-09-11)
==================

View File

@@ -372,7 +372,6 @@ Other changes worth mentioning
- Sort permission namespaces and permissions in the role permission views.
- Invert the columns in the ACL detail view.
Removals
--------
* None
@@ -431,6 +430,7 @@ Bugs fixed or issues closed
===========================
* `GitLab issue #262 <https://gitlab.com/mayan-edms/mayan-edms/issues/262>`_ Event notifications
* `GitLab issue #302 <https://gitlab.com/mayan-edms/mayan-edms/issues/302>`_ 'New Document' button available to users who do not have permission
* `GitLab issue #454 <https://gitlab.com/mayan-edms/mayan-edms/issues/454>`_ Invalid next month calculation in statistics app, causes failstop
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/

View File

@@ -18,6 +18,23 @@ from .permissions import (
)
def condition_check_document_creation_acls(context):
AccessControlList = apps.get_model(
app_label='acls', model_name='AccessControlList'
)
DocumentType = apps.get_model(
app_label='documents', model_name='DocumentType'
)
queryset = AccessControlList.objects.filter_by_access(
permission=permission_document_create, user=context['user'],
queryset=DocumentType.objects.all()
)
if queryset:
return True
def document_new_version_not_blocked(context):
NewVersionBlock = apps.get_model(
app_label='checkouts', model_name='NewVersionBlock'
@@ -27,8 +44,8 @@ def document_new_version_not_blocked(context):
link_document_create_multiple = Link(
icon='fa fa-upload', text=_('New document'),
view='sources:document_create_multiple'
condition=condition_check_document_creation_acls, icon='fa fa-upload',
text=_('New document'), view='sources:document_create_multiple'
)
link_setup_sources = Link(
icon='fa fa-upload', permissions=(permission_sources_setup_view,),

View File

@@ -0,0 +1,31 @@
from __future__ import unicode_literals
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from acls.models import AccessControlList
from documents.tests import GenericDocumentViewTestCase
from documents.permissions import permission_document_create
from ..links import link_document_create_multiple
class SourcesLinksTestCase(GenericDocumentViewTestCase):
def setUp(self):
super(SourcesLinksTestCase, self).setUp()
self.login_user()
def _get_document_create_link(self):
self.add_test_view(test_object=self.document)
context = self.get_test_view()
context['user'] = self.user
return link_document_create_multiple.resolve(context=context)
def test_document_create_link_no_access(self):
resolved_link = self._get_document_create_link()
self.assertEqual(resolved_link, None)
def test_document_create_link_with_access(self):
self.grant_access(permission=permission_document_create, obj=self.document_type)
resolved_link = self._get_document_create_link()
self.assertNotEqual(resolved_link, None)