0001-manager-allow-deletion-of-custody-agenda-by-superuse.patch
chrono/manager/templates/chrono/manager_shared_custody_agenda_settings.html | ||
---|---|---|
9 | 9 |
{% block appbar %} |
10 | 10 |
<h2>{% trans "Settings" %}</h2> |
11 | 11 |
<span class="actions"> |
12 |
{% if user.is_staff %} |
|
13 |
<a class="extra-actions-menu-opener"></a> |
|
14 |
{% endif %} |
|
12 | 15 |
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-period' pk=object.id %}">{% trans 'Add custody period' %}</a> |
13 | 16 |
{% if has_holidays %} |
14 | 17 |
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-holiday-rule' pk=object.id %}">{% trans 'Add custody rule during holidays' %}</a> |
15 | 18 |
{% endif %} |
16 | 19 |
<a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-add-rule' pk=object.id %}">{% trans 'Add custody rule' %}</a> |
20 |
{% if user.is_staff %} |
|
21 |
<ul class="extra-actions-menu"> |
|
22 |
<li><a rel="popup" href="{% url 'chrono-manager-shared-custody-agenda-delete' pk=object.id %}">{% trans 'Delete' %}</a></li> |
|
23 |
</ul> |
|
24 |
{% endif %} |
|
17 | 25 |
</span> |
18 | 26 |
{% endblock %} |
19 | 27 |
chrono/manager/urls.py | ||
---|---|---|
420 | 420 |
views.shared_custody_agenda_settings, |
421 | 421 |
name='chrono-manager-shared-custody-agenda-settings', |
422 | 422 |
), |
423 |
url( |
|
424 |
r'^shared-custody/(?P<pk>\d+)/delete$', |
|
425 |
views.shared_custody_agenda_delete, |
|
426 |
name='chrono-manager-shared-custody-agenda-delete', |
|
427 |
), |
|
423 | 428 |
url( |
424 | 429 |
r'^shared-custody/(?P<pk>\d+)/add-rule$', |
425 | 430 |
views.shared_custody_agenda_add_rule, |
chrono/manager/views.py | ||
---|---|---|
3790 | 3790 |
shared_custody_agenda_settings = SharedCustodyAgendaSettings.as_view() |
3791 | 3791 | |
3792 | 3792 | |
3793 |
class SharedCustodyAgendaDeleteView(SharedCustodyAgendaMixin, DeleteView): |
|
3794 |
template_name = 'chrono/manager_confirm_delete.html' |
|
3795 |
model = SharedCustodyAgenda |
|
3796 |
pk_url_kwarg = 'pk' |
|
3797 | ||
3798 |
def dispatch(self, request, *args, **kwargs): |
|
3799 |
if not request.user.is_staff: |
|
3800 |
raise PermissionDenied() |
|
3801 |
return super().dispatch(request, *args, **kwargs) |
|
3802 | ||
3803 |
def get_success_url(self): |
|
3804 |
return reverse('chrono-manager-homepage') |
|
3805 | ||
3806 | ||
3807 |
shared_custody_agenda_delete = SharedCustodyAgendaDeleteView.as_view() |
|
3808 | ||
3809 | ||
3793 | 3810 |
class SharedCustodyAgendaAddRuleView(SharedCustodyAgendaMixin, CreateView): |
3794 | 3811 |
title = _('Add custody rule') |
3795 | 3812 |
template_name = 'chrono/manager_agenda_form.html' |
tests/manager/test_shared_custody_agenda.py | ||
---|---|---|
327 | 327 |
app = login(app, username='manager', password='manager') |
328 | 328 |
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk) |
329 | 329 |
assert 'Custody agenda of John Doe and Jane Doe' in resp.text |
330 | ||
331 | ||
332 |
def test_shared_custody_agenda_delete(app, admin_user, manager_user): |
|
333 |
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe') |
|
334 |
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe') |
|
335 |
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother) |
|
336 |
SharedCustodySettings.objects.create(management_role=manager_user.groups.all()[0]) |
|
337 | ||
338 |
app = login(app, username='manager', password='manager') |
|
339 |
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk) |
|
340 |
assert 'Delete' not in resp.text |
|
341 | ||
342 |
app = login(app) |
|
343 |
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk) |
|
344 |
resp = resp.click('Delete') |
|
345 |
resp = resp.form.submit().follow() |
|
346 |
assert not SharedCustodyAgenda.objects.exists() |
|
330 |
- |