The index rebuild permission can now be set as part of the index ACL for each individual index. Add cascade permission check to the index rebuild tool link. The index rebuild tool now responds with the number of indexes queued to rebuild instead of a static acknowledment.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -64,6 +64,11 @@
|
||||
- Apply link permission cascade checks to the message of the day,
|
||||
indexing and parsing, setup link.
|
||||
- Add ACL support to the message of the day app.
|
||||
- The index rebuild permission can now be set as part of the index
|
||||
ACL for each individual index.
|
||||
- Add cascade permission check to the index rebuild tool link.
|
||||
- The index rebuild tool now responds with the number of indexes
|
||||
queued to rebuild instead of a static acknowledment.
|
||||
|
||||
3.0.1 (2018-07-08)
|
||||
=================
|
||||
|
||||
@@ -34,7 +34,8 @@ from .links import (
|
||||
from .licenses import * # NOQA
|
||||
from .permissions import (
|
||||
permission_document_indexing_create, permission_document_indexing_delete,
|
||||
permission_document_indexing_edit, permission_document_indexing_view
|
||||
permission_document_indexing_edit, permission_document_indexing_rebuild,
|
||||
permission_document_indexing_view
|
||||
)
|
||||
from .queues import * # NOQA
|
||||
from .widgets import get_instance_link, index_instance_item_link, node_level
|
||||
@@ -72,6 +73,7 @@ class DocumentIndexingApp(MayanAppConfig):
|
||||
permission_document_indexing_create,
|
||||
permission_document_indexing_delete,
|
||||
permission_document_indexing_edit,
|
||||
permission_document_indexing_rebuild,
|
||||
permission_document_indexing_view,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -4,19 +4,30 @@ from django import forms
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.classes import ModelAttribute
|
||||
from documents.models import Document
|
||||
|
||||
from .models import Index, IndexTemplateNode
|
||||
from .permissions import permission_document_indexing_rebuild
|
||||
|
||||
|
||||
class IndexListForm(forms.Form):
|
||||
indexes = forms.ModelMultipleChoiceField(
|
||||
help_text=_('Indexes to be queued for rebuilding.'),
|
||||
label=_('Indexes'), queryset=Index.objects.filter(enabled=True),
|
||||
label=_('Indexes'), queryset=Index.objects.none(),
|
||||
required=False, widget=forms.widgets.CheckboxSelectMultiple()
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user')
|
||||
super(IndexListForm, self).__init__(*args, **kwargs)
|
||||
queryset = AccessControlList.objects.filter_by_access(
|
||||
permission=permission_document_indexing_rebuild, user=user,
|
||||
queryset=Index.objects.filter(enabled=True)
|
||||
)
|
||||
self.fields['indexes'].queryset = queryset
|
||||
|
||||
|
||||
class IndexTemplateNodeForm(forms.ModelForm):
|
||||
"""
|
||||
|
||||
@@ -62,11 +62,13 @@ link_index_setup_document_types = Link(
|
||||
view='indexing:index_setup_document_types',
|
||||
)
|
||||
link_rebuild_index_instances = Link(
|
||||
icon_class=icon_rebuild_index_instances,
|
||||
condition=get_cascade_condition(
|
||||
app_label='document_indexing', model_name='Index',
|
||||
object_permission=permission_document_indexing_rebuild,
|
||||
), icon_class=icon_rebuild_index_instances,
|
||||
description=_(
|
||||
'Deletes and creates from scratch all the document indexes.'
|
||||
),
|
||||
permissions=(permission_document_indexing_rebuild,),
|
||||
text=_('Rebuild indexes'), view='indexing:rebuild_index_instances'
|
||||
)
|
||||
link_template_node_create = Link(
|
||||
|
||||
@@ -4,7 +4,7 @@ from django.contrib import messages
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils.html import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.views import (
|
||||
@@ -329,17 +329,31 @@ class RebuildIndexesView(FormView):
|
||||
'title': _('Rebuild indexes'),
|
||||
}
|
||||
form_class = IndexListForm
|
||||
view_permission = permission_document_indexing_rebuild
|
||||
|
||||
def form_valid(self, form):
|
||||
count = 0
|
||||
for index in form.cleaned_data['indexes']:
|
||||
task_rebuild_index.apply_async(
|
||||
kwargs=dict(index_id=index.pk)
|
||||
)
|
||||
count += 1
|
||||
|
||||
messages.success(self.request, _('Index rebuild queued successfully.'))
|
||||
messages.success(
|
||||
self.request, ungettext(
|
||||
singular='%(count)d index queued for rebuild.',
|
||||
plural='%(count)d indexes queued for rebuild.',
|
||||
number=count
|
||||
) % {
|
||||
'count': count,
|
||||
}
|
||||
)
|
||||
|
||||
return super(RebuildIndexesView, self).form_valid(form=form)
|
||||
|
||||
def get_form_extra_kwargs(self):
|
||||
return {
|
||||
'user': self.request.user
|
||||
}
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse('common:tools_list')
|
||||
|
||||
Reference in New Issue
Block a user