manager: allow deletion of custody agenda by superuser (#66324)
This commit is contained in:
parent
efed292e54
commit
dece1657f7
|
@ -9,11 +9,19 @@
|
|||
{% block appbar %}
|
||||
<h2>{% trans "Settings" %}</h2>
|
||||
<span class="actions">
|
||||
{% if user.is_staff %}
|
||||
<a class="extra-actions-menu-opener"></a>
|
||||
{% endif %}
|
||||
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-period' pk=object.id %}">{% trans 'Add custody period' %}</a>
|
||||
{% if has_holidays %}
|
||||
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-holiday-rule' pk=object.id %}">{% trans 'Add custody rule during holidays' %}</a>
|
||||
{% endif %}
|
||||
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-rule' pk=object.id %}">{% trans 'Add custody rule' %}</a>
|
||||
{% if user.is_staff %}
|
||||
<ul class="extra-actions-menu">
|
||||
<li><a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-delete' pk=object.id %}">{% trans 'Delete' %}</a></li>
|
||||
</ul>
|
||||
{% endif %}
|
||||
</span>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -420,6 +420,11 @@ urlpatterns = [
|
|||
views.shared_custody_agenda_settings,
|
||||
name='chrono-manager-shared-custody-agenda-settings',
|
||||
),
|
||||
url(
|
||||
r'^shared-custody/(?P<pk>\d+)/delete$',
|
||||
views.shared_custody_agenda_delete,
|
||||
name='chrono-manager-shared-custody-agenda-delete',
|
||||
),
|
||||
url(
|
||||
r'^shared-custody/(?P<pk>\d+)/add-rule$',
|
||||
views.shared_custody_agenda_add_rule,
|
||||
|
|
|
@ -3790,6 +3790,23 @@ class SharedCustodyAgendaSettings(SharedCustodyAgendaMixin, DetailView):
|
|||
shared_custody_agenda_settings = SharedCustodyAgendaSettings.as_view()
|
||||
|
||||
|
||||
class SharedCustodyAgendaDeleteView(SharedCustodyAgendaMixin, DeleteView):
|
||||
template_name = 'chrono/manager_confirm_delete.html'
|
||||
model = SharedCustodyAgenda
|
||||
pk_url_kwarg = 'pk'
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if not request.user.is_staff:
|
||||
raise PermissionDenied()
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('chrono-manager-homepage')
|
||||
|
||||
|
||||
shared_custody_agenda_delete = SharedCustodyAgendaDeleteView.as_view()
|
||||
|
||||
|
||||
class SharedCustodyAgendaAddRuleView(SharedCustodyAgendaMixin, CreateView):
|
||||
title = _('Add custody rule')
|
||||
template_name = 'chrono/manager_agenda_form.html'
|
||||
|
|
|
@ -327,3 +327,20 @@ def test_shared_custody_settings_management_role(app, admin_user, manager_user):
|
|||
app = login(app, username='manager', password='manager')
|
||||
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
|
||||
assert 'Custody agenda of John Doe and Jane Doe' in resp.text
|
||||
|
||||
|
||||
def test_shared_custody_agenda_delete(app, admin_user, manager_user):
|
||||
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
|
||||
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
|
||||
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
|
||||
SharedCustodySettings.objects.create(management_role=manager_user.groups.all()[0])
|
||||
|
||||
app = login(app, username='manager', password='manager')
|
||||
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
|
||||
assert 'Delete' not in resp.text
|
||||
|
||||
app = login(app)
|
||||
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
|
||||
resp = resp.click('Delete')
|
||||
resp = resp.form.submit().follow()
|
||||
assert not SharedCustodyAgenda.objects.exists()
|
||||
|
|
Loading…
Reference in New Issue