summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-10 18:02:50 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-10 18:02:50 +0200
commit0c185f1abbe9abe0d977e1b7d1d3f0440b8d6371 (patch)
treef84171501c3d98df394c94fcc6d32cc3dd5c6539 /ishtar_common
parent389f86b06d5f6129614cb312c7034cdc4bb1b684 (diff)
downloadIshtar-0c185f1abbe9abe0d977e1b7d1d3f0440b8d6371.tar.bz2
Ishtar-0c185f1abbe9abe0d977e1b7d1d3f0440b8d6371.zip
Locks: prevent edit actions
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py8
-rw-r--r--ishtar_common/models.py2
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_nav.html2
-rw-r--r--ishtar_common/urls.py3
-rw-r--r--ishtar_common/views.py15
5 files changed, 28 insertions, 2 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 1f4d50d60..a69c65f0e 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -735,6 +735,14 @@ def get_form_selection(
if self._main_key not in cleaned_data \
or not cleaned_data[self._main_key]:
raise forms.ValidationError(self._not_selected_error)
+
+ pk = self.cleaned_data[self._main_key]
+ try:
+ item = model.objects.get(pk=pk)
+ except model.DoesNotExist:
+ raise forms.ValidationError(_("Invalid selection."))
+ if hasattr(item, "locked") and item.locked:
+ raise forms.ValidationError(_("This item is locked for edition."))
return cleaned_data
attrs['clean'] = clean
attrs['SEARCH_AND_SELECT'] = True
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index bc9e68c02..f673aed85 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1825,7 +1825,7 @@ class DocumentItem(object):
return actions
can_add_doc = self.can_do(request, 'add_document')
- if can_add_doc:
+ if can_add_doc and not getattr(self, "locked", False):
actions = [
(
reverse("create-document") + "?{}={}".format(
diff --git a/ishtar_common/templates/ishtar/blocks/window_nav.html b/ishtar_common/templates/ishtar/blocks/window_nav.html
index d76ff49e1..19b70ccd6 100644
--- a/ishtar_common/templates/ishtar/blocks/window_nav.html
+++ b/ishtar_common/templates/ishtar/blocks/window_nav.html
@@ -44,7 +44,7 @@
{% endif %}
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans 'Actions' %}">
{% block extra_actions %}{% endblock %}
- {% if modify_url %}
+ {% if modify_url and not item.locked %}
<a class="btn btn-success wait-button" href='{% url modify_url item.pk %}'
title="{% trans 'Modify' %}">
<i class="fa fa-pencil"></i>
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index 3667d46b2..13694b10f 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -291,6 +291,9 @@ urlpatterns += [
check_rights(['change_document', 'change_own_document'])(
views.QADocumentForm.as_view()),
name='document-qa-bulk-update-confirm', kwargs={"confirm": True}),
+
+ url(r'^qa-not-available/$', views.QANotAvailable.as_view(),
+ name='qa-not-available'),
]
urlpatterns += get_urls_for_model(models.Document, views)
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 2af082a0a..4ab94aae9 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -2110,6 +2110,17 @@ class AlertList(JSONResponseMixin, LoginRequiredMixin,
return {'alerts': alerts}
+class QANotAvailable(IshtarMixin, LoginRequiredMixin, TemplateView):
+ template_name = 'ishtar/forms/qa_message.html'
+ modal_size = "small"
+
+ def get_context_data(self, **kwargs):
+ data = super(QANotAvailable, self).get_context_data(**kwargs)
+ data["page_name"] = _("Not available")
+ data['message'] = _("Action not available for these items.")
+ return data
+
+
class QAItemForm(IshtarMixin, LoginRequiredMixin, FormView):
template_name = 'ishtar/forms/qa_form.html'
model = None
@@ -2168,6 +2179,10 @@ class QAItemEditForm(QAItemForm):
self.confirm = kwargs.get('confirm', False) and True
returned = super(QAItemEditForm, self).dispatch(request, *args,
**kwargs)
+ if hasattr(self.model, "locked"):
+ for item in self.items:
+ if item.locked:
+ return HttpResponseRedirect(reverse("qa-not-available"))
return returned
def get_form_class(self):