The document type OCR setup permission can now be granted for individual document types. Instead of the document OCR permissions, the document type OCR setting permission is required to view the global OCR error list.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -32,7 +32,10 @@ from .links import (
|
||||
link_document_submit_multiple, link_document_type_ocr_settings,
|
||||
link_document_type_submit, link_entry_list
|
||||
)
|
||||
from .permissions import permission_ocr_document, permission_ocr_content_view
|
||||
from .permissions import (
|
||||
permission_document_type_ocr_setup, permission_ocr_document,
|
||||
permission_ocr_content_view
|
||||
)
|
||||
from .queues import * # NOQA
|
||||
from .utils import get_document_ocr_content
|
||||
|
||||
@@ -71,11 +74,12 @@ class OCRApp(MayanAppConfig):
|
||||
Document = apps.get_model(
|
||||
app_label='documents', model_name='Document'
|
||||
)
|
||||
|
||||
DocumentType = apps.get_model(
|
||||
app_label='documents', model_name='DocumentType'
|
||||
)
|
||||
|
||||
DocumentTypeSettings = self.get_model(
|
||||
model_name='DocumentTypeSettings'
|
||||
)
|
||||
DocumentVersion = apps.get_model(
|
||||
app_label='documents', model_name='DocumentVersion'
|
||||
)
|
||||
@@ -95,7 +99,14 @@ class OCRApp(MayanAppConfig):
|
||||
permission_ocr_document, permission_ocr_content_view
|
||||
)
|
||||
)
|
||||
|
||||
ModelPermission.register(
|
||||
model=DocumentType, permissions=(
|
||||
permission_document_type_ocr_setup,
|
||||
)
|
||||
)
|
||||
ModelPermission.register_inheritance(
|
||||
model=DocumentTypeSettings, related='document_type',
|
||||
)
|
||||
SourceColumn(
|
||||
source=DocumentVersionOCRError, label=_('Document'),
|
||||
func=lambda context: document_link(context['object'].document_version.document)
|
||||
|
||||
@@ -2,7 +2,10 @@ from __future__ import unicode_literals
|
||||
|
||||
from documents.tests import GenericDocumentViewTestCase
|
||||
|
||||
from ..permissions import permission_ocr_content_view, permission_ocr_document
|
||||
from ..permissions import (
|
||||
permission_ocr_content_view, permission_ocr_document,
|
||||
permission_document_type_ocr_setup
|
||||
)
|
||||
from ..utils import get_document_ocr_content
|
||||
|
||||
|
||||
@@ -109,3 +112,23 @@ class OCRViewsTestCase(GenericDocumentViewTestCase):
|
||||
''.join(get_document_ocr_content(document=self.document))
|
||||
),
|
||||
)
|
||||
|
||||
def test_document_type_ocr_settings_view_no_permission(self):
|
||||
response = self.get(
|
||||
viewname='ocr:document_type_ocr_settings',
|
||||
args=(self.document.document_type.pk,)
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_document_type_ocr_settings_view_with_access(self):
|
||||
self.grant_access(
|
||||
permission=permission_document_type_ocr_setup,
|
||||
obj=self.document.document_type
|
||||
)
|
||||
response = self.get(
|
||||
viewname='ocr:document_type_ocr_settings',
|
||||
args=(self.document.document_type.pk,)
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from common.generics import (
|
||||
@@ -66,13 +66,10 @@ class DocumentSubmitView(MultipleObjectConfirmActionView):
|
||||
|
||||
|
||||
class DocumentTypeSubmitView(FormView):
|
||||
form_class = DocumentTypeSelectForm
|
||||
extra_context = {
|
||||
'title': _('Submit all documents of a type for OCR')
|
||||
}
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse('common:tools_list')
|
||||
form_class = DocumentTypeSelectForm
|
||||
|
||||
def form_valid(self, form):
|
||||
count = 0
|
||||
@@ -92,37 +89,43 @@ class DocumentTypeSubmitView(FormView):
|
||||
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse('common:tools_list')
|
||||
|
||||
|
||||
class DocumentTypeSettingsEditView(SingleObjectEditView):
|
||||
fields = ('auto_ocr',)
|
||||
view_permission = permission_document_type_ocr_setup
|
||||
object_permission = permission_document_type_ocr_setup
|
||||
post_action_redirect = reverse_lazy('documents:document_type_list')
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return get_object_or_404(
|
||||
DocumentType, pk=self.kwargs['pk']
|
||||
).ocr_settings
|
||||
def get_document_type(self):
|
||||
return get_object_or_404(DocumentType, pk=self.kwargs['pk'])
|
||||
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'object': self.get_document_type(),
|
||||
'title': _(
|
||||
'Edit OCR settings for document type: %s'
|
||||
) % self.get_object().document_type
|
||||
) % self.get_document_type()
|
||||
}
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
return self.get_document_type().ocr_settings
|
||||
|
||||
|
||||
class EntryListView(SingleObjectListView):
|
||||
extra_context = {
|
||||
'hide_object': True,
|
||||
'title': _('OCR errors'),
|
||||
}
|
||||
view_permission = permission_ocr_document
|
||||
view_permission = permission_document_type_ocr_setup
|
||||
|
||||
def get_object_list(self):
|
||||
return DocumentVersionOCRError.objects.all()
|
||||
|
||||
|
||||
class DocumentOCRErrorsListView(SingleObjectListView):
|
||||
view_permission = permission_ocr_document
|
||||
object_permission = permission_ocr_document
|
||||
|
||||
def get_document(self):
|
||||
return get_object_or_404(Document, pk=self.kwargs['pk'])
|
||||
|
||||
Reference in New Issue
Block a user