Backport individual index rebuild support

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-07-07 01:03:39 -04:00
committed by Roberto Rosario
parent 2f6cfcbc4f
commit cb7dbaf609
8 changed files with 104 additions and 14 deletions

View File

@@ -7,14 +7,14 @@
single page navigation to jump to the home view. single page navigation to jump to the home view.
* Remove redundant Celery queue declarations from the * Remove redundant Celery queue declarations from the
file_metadata app. file_metadata app.
* Add internal_name field to workflow serializer. * Add internal_name field to workflow serializer.
Fixes workflow API creation view. Fixes workflow API creation view.
* Fix document cabinet list API view. Thanks for forum user * Fix document cabinet list API view. Thanks for forum user
"jere" for the report. Forum topic 1039. "jere" for the report. Forum topic 1039.
* Fix document template column field. GitLab issue #655. * Fix document template column field. GitLab issue #655.
Thanks to Christian Wiegand (@christianwgd) for the Thanks to Christian Wiegand (@christianwgd) for the
report. report.
* Increase mailing profile password field max length * Increase mailing profile password field max length
from 48 to 128 characters. GitLab issue #657. from 48 to 128 characters. GitLab issue #657.
Thanks to sigsec (@sigsec) for the report. Thanks to sigsec (@sigsec) for the report.
* Update the Docker entrypoint to update the ownership * Update the Docker entrypoint to update the ownership

View File

@@ -34,6 +34,7 @@ Changes
for the report. for the report.
- Rename the MAYAN_USER_GUID environment variable - Rename the MAYAN_USER_GUID environment variable
to MAYAN_USER_GID. to MAYAN_USER_GID.
- Backport individual index rebuild support.
Removals Removals
-------- --------

View File

@@ -31,9 +31,10 @@ from .html_widgets import (
) )
from .links import ( from .links import (
link_document_index_instance_list, link_document_type_index_templates, link_document_index_instance_list, link_document_type_index_templates,
link_index_instance_menu, link_index_template_setup, link_index_instance_menu, link_index_instance_rebuild,
link_index_template_create, link_index_template_document_types, link_index_template_setup, link_index_template_create,
link_index_template_delete, link_index_template_edit, link_index_template_list, link_index_template_document_types, link_index_template_delete,
link_index_template_edit, link_index_template_list,
link_index_template_node_tree_view, link_index_instances_rebuild, link_index_template_node_tree_view, link_index_instances_rebuild,
link_index_template_node_create, link_index_template_node_delete, link_index_template_node_create, link_index_template_node_delete,
link_index_template_node_edit link_index_template_node_edit
@@ -192,6 +193,7 @@ class DocumentIndexingApp(MayanAppConfig):
menu_object.bind_links( menu_object.bind_links(
links=( links=(
link_index_template_delete, link_index_template_edit, link_index_template_delete, link_index_template_edit,
link_index_instance_rebuild
), sources=(Index,) ), sources=(Index,)
) )
menu_object.bind_links( menu_object.bind_links(

View File

@@ -49,6 +49,12 @@ link_index_instances_rebuild = Link(
), ),
text=_('Rebuild indexes'), view='indexing:rebuild_index_instances' text=_('Rebuild indexes'), view='indexing:rebuild_index_instances'
) )
link_index_instance_rebuild = Link(
args='resolved_object.pk',
icon_class_path='mayan.apps.document_indexing.icons.icon_index_instances_rebuild',
permissions=(permission_document_indexing_rebuild,),
text=_('Rebuild index'), view='indexing:index_setup_rebuild'
)
link_index_template_setup = Link( link_index_template_setup = Link(
condition=get_cascade_condition( condition=get_cascade_condition(

View File

@@ -50,3 +50,10 @@ class IndexViewTestMixin(object):
'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG 'label': TEST_INDEX_LABEL_EDITED, 'slug': TEST_INDEX_SLUG
} }
) )
def _request_test_index_rebuild_view(self):
return self.post(
viewname='indexing:index_setup_rebuild', kwargs={
'pk': self.test_index.pk
}
)

View File

@@ -2,7 +2,7 @@ from __future__ import absolute_import, unicode_literals
from mayan.apps.documents.tests import GenericDocumentViewTestCase from mayan.apps.documents.tests import GenericDocumentViewTestCase
from ..models import Index from ..models import Index, IndexInstanceNode
from ..permissions import ( from ..permissions import (
permission_document_indexing_create, permission_document_indexing_delete, permission_document_indexing_create, permission_document_indexing_delete,
permission_document_indexing_edit, permission_document_indexing_edit,
@@ -10,7 +10,10 @@ from ..permissions import (
permission_document_indexing_rebuild permission_document_indexing_rebuild
) )
from .literals import TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED from .literals import (
TEST_INDEX_LABEL, TEST_INDEX_LABEL_EDITED,
TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION
)
from .mixins import IndexTestMixin, IndexViewTestMixin from .mixins import IndexTestMixin, IndexViewTestMixin
@@ -77,9 +80,42 @@ class IndexViewTestCase(
self.assertEqual(self.test_index.label, TEST_INDEX_LABEL_EDITED) self.assertEqual(self.test_index.label, TEST_INDEX_LABEL_EDITED)
class IndexInstanceViewTestCase( class IndexInstaceViewTestCase(
IndexTestMixin, IndexViewTestMixin, GenericDocumentViewTestCase IndexTestMixin, IndexViewTestMixin, GenericDocumentViewTestCase
): ):
def _create_index_template_node(self):
self.test_index.node_templates.create(
parent=self.test_index.template_root,
expression=TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION,
link_documents=True
)
def test_index_rebuild_view_no_permission(self):
self.upload_document()
self._create_test_index()
self._create_index_template_node()
response = self._request_test_index_rebuild_view()
self.assertEqual(response.status_code, 404)
self.assertEqual(IndexInstanceNode.objects.count(), 0)
def test_index_rebuild_view_with_access(self):
self.upload_document()
self._create_test_index()
self._create_index_template_node()
self.grant_access(
obj=self.test_index,
permission=permission_document_indexing_rebuild
)
response = self._request_test_index_rebuild_view()
self.assertEqual(response.status_code, 302)
self.assertNotEqual(IndexInstanceNode.objects.count(), 0)
def _request_index_instance_node_view(self, index_instance_node): def _request_index_instance_node_view(self, index_instance_node):
return self.get( return self.get(
viewname='indexing:index_instance_node_view', kwargs={ viewname='indexing:index_instance_node_view', kwargs={
@@ -108,9 +144,13 @@ class IndexInstanceViewTestCase(
) )
self.assertContains(response, text=TEST_INDEX_LABEL, status_code=200) self.assertContains(response, text=TEST_INDEX_LABEL, status_code=200)
class IndexToolsViewTestCase(
IndexTestMixin, IndexViewTestMixin, GenericDocumentViewTestCase
):
def _request_indexes_rebuild_get_view(self): def _request_indexes_rebuild_get_view(self):
return self.get( return self.get(
viewname='indexing:rebuild_index_instances', viewname='indexing:rebuild_index_instances'
) )
def _request_indexes_rebuild_post_view(self): def _request_indexes_rebuild_post_view(self):

View File

@@ -11,8 +11,8 @@ from .views import (
DocumentIndexNodeListView, DocumentTypeIndexesView, IndexInstanceNodeView, DocumentIndexNodeListView, DocumentTypeIndexesView, IndexInstanceNodeView,
IndexListView, IndexesRebuildView, SetupIndexDocumentTypesView, IndexListView, IndexesRebuildView, SetupIndexDocumentTypesView,
SetupIndexCreateView, SetupIndexDeleteView, SetupIndexEditView, SetupIndexCreateView, SetupIndexDeleteView, SetupIndexEditView,
SetupIndexListView, SetupIndexTreeTemplateListView, TemplateNodeCreateView, SetupIndexListView, SetupIndexRebuildView, SetupIndexTreeTemplateListView,
TemplateNodeDeleteView, TemplateNodeEditView TemplateNodeCreateView, TemplateNodeDeleteView, TemplateNodeEditView
) )
urlpatterns = [ urlpatterns = [
@@ -46,6 +46,10 @@ urlpatterns = [
view=SetupIndexDocumentTypesView.as_view(), view=SetupIndexDocumentTypesView.as_view(),
name='index_setup_document_types' name='index_setup_document_types'
), ),
url(
regex=r'^setup/index/(?P<pk>\d+)/rebuild/$',
view=SetupIndexRebuildView.as_view(), name='index_setup_rebuild'
),
url( url(
regex=r'^setup/template/node/(?P<pk>\d+)/create/child/$', regex=r'^setup/template/node/(?P<pk>\d+)/create/child/$',
view=TemplateNodeCreateView.as_view(), name='template_node_create' view=TemplateNodeCreateView.as_view(), name='template_node_create'

View File

@@ -9,8 +9,8 @@ from django.utils.translation import ugettext_lazy as _, ungettext
from mayan.apps.acls.models import AccessControlList from mayan.apps.acls.models import AccessControlList
from mayan.apps.common.generics import ( from mayan.apps.common.generics import (
AddRemoveView, FormView, SingleObjectCreateView, SingleObjectDeleteView, AddRemoveView, ConfirmView, FormView, SingleObjectCreateView,
SingleObjectEditView, SingleObjectListView SingleObjectDeleteView, SingleObjectEditView, SingleObjectListView
) )
from mayan.apps.documents.events import event_document_type_edited from mayan.apps.documents.events import event_document_type_edited
from mayan.apps.documents.models import Document, DocumentType from mayan.apps.documents.models import Document, DocumentType
@@ -32,7 +32,7 @@ from .permissions import (
permission_document_indexing_create, permission_document_indexing_delete, permission_document_indexing_create, permission_document_indexing_delete,
permission_document_indexing_edit, permission_document_indexing_edit,
permission_document_indexing_instance_view, permission_document_indexing_instance_view,
permission_document_indexing_view permission_document_indexing_rebuild, permission_document_indexing_view
) )
from .tasks import task_rebuild_index from .tasks import task_rebuild_index
@@ -150,6 +150,36 @@ class SetupIndexListView(SingleObjectListView):
} }
class SetupIndexRebuildView(ConfirmView):
post_action_redirect = reverse_lazy(
viewname='indexing:index_setup_list'
)
def get_extra_context(self):
return {
'object': self.get_object(),
'title': _('Rebuild index: %s') % self.get_object()
}
def get_object(self):
return get_object_or_404(klass=self.get_queryset(), pk=self.kwargs['pk'])
def get_queryset(self):
return AccessControlList.objects.restrict_queryset(
permission=permission_document_indexing_rebuild,
queryset=Index.objects.all(), user=self.request.user
)
def view_action(self):
task_rebuild_index.apply_async(
kwargs=dict(index_id=self.get_object().pk)
)
messages.success(
message='Index queued for rebuild.', request=self.request
)
class SetupIndexDocumentTypesView(AddRemoveView): class SetupIndexDocumentTypesView(AddRemoveView):
main_object_method_add = 'document_types_add' main_object_method_add = 'document_types_add'
main_object_method_remove = 'document_types_remove' main_object_method_remove = 'document_types_remove'