0001-agendas-add-management-role-for-shared-custody-66671.patch
chrono/agendas/migrations/0131_sharedcustodysettings.py | ||
---|---|---|
1 |
# Generated by Django 2.2.26 on 2022-06-27 16:02 |
|
2 | ||
3 |
import django.db.models.deletion |
|
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('auth', '0011_update_proxy_permissions'), |
|
11 |
('agendas', '0130_event_date_range_constraint'), |
|
12 |
] |
|
13 | ||
14 |
operations = [ |
|
15 |
migrations.CreateModel( |
|
16 |
name='SharedCustodySettings', |
|
17 |
fields=[ |
|
18 |
( |
|
19 |
'id', |
|
20 |
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), |
|
21 |
), |
|
22 |
( |
|
23 |
'management_role', |
|
24 |
models.ForeignKey( |
|
25 |
blank=True, |
|
26 |
default=None, |
|
27 |
null=True, |
|
28 |
on_delete=django.db.models.deletion.SET_NULL, |
|
29 |
related_name='+', |
|
30 |
to='auth.Group', |
|
31 |
verbose_name='Management role', |
|
32 |
), |
|
33 |
), |
|
34 |
], |
|
35 |
), |
|
36 |
] |
chrono/agendas/models.py | ||
---|---|---|
3487 | 3487 |
date_format(self.date_end, 'SHORT_DATE_FORMAT'), |
3488 | 3488 |
) |
3489 | 3489 |
return '%s, %s' % (self.guardian, exc_repr) |
3490 | ||
3491 | ||
3492 |
class SharedCustodySettings(models.Model): |
|
3493 |
management_role = models.ForeignKey( |
|
3494 |
Group, |
|
3495 |
blank=True, |
|
3496 |
null=True, |
|
3497 |
default=None, |
|
3498 |
related_name='+', |
|
3499 |
verbose_name=_('Management role'), |
|
3500 |
on_delete=models.SET_NULL, |
|
3501 |
) |
|
3502 | ||
3503 |
@classmethod |
|
3504 |
def get_singleton(cls): |
|
3505 |
try: |
|
3506 |
return cls.objects.get() |
|
3507 |
except cls.DoesNotExist: |
|
3508 |
return cls() |
chrono/manager/forms.py | ||
---|---|---|
57 | 57 |
SharedCustodyHolidayRule, |
58 | 58 |
SharedCustodyPeriod, |
59 | 59 |
SharedCustodyRule, |
60 |
SharedCustodySettings, |
|
60 | 61 |
Subscription, |
61 | 62 |
TimePeriod, |
62 | 63 |
TimePeriodException, |
... | ... | |
1550 | 1551 |
self.add_error('date_end', _('End date must be greater than start date.')) |
1551 | 1552 | |
1552 | 1553 |
return cleaned_data |
1554 | ||
1555 | ||
1556 |
class SharedCustodySettingsForm(forms.ModelForm): |
|
1557 |
management_role = forms.ModelChoiceField( |
|
1558 |
label=_('Management role'), required=False, queryset=Group.objects.all().order_by('name') |
|
1559 |
) |
|
1560 | ||
1561 |
class Meta: |
|
1562 |
model = SharedCustodySettings |
|
1563 |
fields = '__all__' |
chrono/manager/templates/chrono/manager_home.html | ||
---|---|---|
12 | 12 |
<li><a rel="popup" href="{% url 'chrono-manager-agendas-export' %}" data-autoclose-dialog="true">{% trans 'Export' %}</a></li> |
13 | 13 |
<li><a href="{% url 'chrono-manager-events-type-list' %}">{% trans 'Events types' %}</a></li> |
14 | 14 |
<li><a href="{% url 'chrono-manager-check-type-list' %}">{% trans 'Check types' %}</a></li> |
15 |
<li><a rel="popup" href="{% url 'chrono-manager-shared-custody-settings' %}">{% trans 'Shared custody' %}</a></li> |
|
15 | 16 |
{% endif %} |
16 | 17 |
{% if has_access_to_unavailability_calendars %} |
17 | 18 |
<li><a href="{% url 'chrono-manager-unavailability-calendar-list' %}">{% trans 'Unavailability calendars' %}</a></li> |
chrono/manager/urls.py | ||
---|---|---|
400 | 400 |
views.agenda_import_events_sample_csv, |
401 | 401 |
name='chrono-manager-sample-events-csv', |
402 | 402 |
), |
403 |
url( |
|
404 |
r'^shared-custody/settings/$', |
|
405 |
views.shared_custody_settings, |
|
406 |
name='chrono-manager-shared-custody-settings', |
|
407 |
), |
|
403 | 408 |
url( |
404 | 409 |
r'^shared-custody/(?P<pk>\d+)/$', |
405 | 410 |
views.shared_custody_agenda_view, |
chrono/manager/views.py | ||
---|---|---|
80 | 80 |
SharedCustodyHolidayRule, |
81 | 81 |
SharedCustodyPeriod, |
82 | 82 |
SharedCustodyRule, |
83 |
SharedCustodySettings, |
|
83 | 84 |
TimePeriod, |
84 | 85 |
TimePeriodException, |
85 | 86 |
TimePeriodExceptionSource, |
... | ... | |
122 | 123 |
SharedCustodyHolidayRuleForm, |
123 | 124 |
SharedCustodyPeriodForm, |
124 | 125 |
SharedCustodyRuleForm, |
126 |
SharedCustodySettingsForm, |
|
125 | 127 |
SubscriptionCheckFilterSet, |
126 | 128 |
TimePeriodAddForm, |
127 | 129 |
TimePeriodExceptionForm, |
... | ... | |
3685 | 3687 |
return super().dispatch(request, *args, **kwargs) |
3686 | 3688 | |
3687 | 3689 |
def check_permissions(self, user): |
3688 |
return user.is_staff |
|
3690 |
if user.is_staff: |
|
3691 |
return True |
|
3692 |
management_role = SharedCustodySettings.get_singleton().management_role |
|
3693 |
return bool(management_role in user.groups.all()) |
|
3689 | 3694 | |
3690 | 3695 |
def get_context_data(self, **kwargs): |
3691 | 3696 |
context = super().get_context_data(**kwargs) |
... | ... | |
3863 | 3868 |
shared_custody_agenda_delete_period = SharedCustodyAgendaDeletePeriodView.as_view() |
3864 | 3869 | |
3865 | 3870 | |
3871 |
class SharedCustodySettingsView(UpdateView): |
|
3872 |
title = _('Shared custody settings') |
|
3873 |
template_name = 'chrono/manager_agenda_form.html' |
|
3874 |
form_class = SharedCustodySettingsForm |
|
3875 |
model = SharedCustodySettings |
|
3876 |
success_url = reverse_lazy('chrono-manager-homepage') |
|
3877 | ||
3878 |
def dispatch(self, request, *args, **kwargs): |
|
3879 |
if not request.user.is_staff: |
|
3880 |
raise PermissionDenied() |
|
3881 |
return super().dispatch(request, *args, **kwargs) |
|
3882 | ||
3883 |
def get_object(self): |
|
3884 |
return SharedCustodySettings.get_singleton() |
|
3885 | ||
3886 | ||
3887 |
shared_custody_settings = SharedCustodySettingsView.as_view() |
|
3888 | ||
3889 | ||
3866 | 3890 |
def menu_json(request): |
3867 | 3891 |
if not request.user.is_staff: |
3868 | 3892 |
homepage_view = HomepageView(request=request) |
tests/manager/test_shared_custody_agenda.py | ||
---|---|---|
286 | 286 | |
287 | 287 |
resp = app.get('/manage/shared-custody/%s/2022/12/' % agenda.pk) |
288 | 288 |
assert 'John Doe (Vacances de Noël)' in resp.text |
289 | ||
290 | ||
291 |
def test_shared_custody_settings_management_role(app, admin_user, manager_user): |
|
292 |
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe') |
|
293 |
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe') |
|
294 |
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother) |
|
295 | ||
296 |
app = login(app, username='manager', password='manager') |
|
297 |
app.get('/manage/shared-custody/%s/settings/' % agenda.pk, status=403) |
|
298 | ||
299 |
app.reset() |
|
300 |
app = login(app) |
|
301 |
resp = app.get('/manage/') |
|
302 |
resp = resp.click('Shared custody') |
|
303 |
resp.form['management_role'] = manager_user.groups.all()[0].pk |
|
304 |
resp.form.submit() |
|
305 | ||
306 |
app.reset() |
|
307 |
app = login(app, username='manager', password='manager') |
|
308 |
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk) |
|
309 |
assert 'Custody agenda of John Doe and Jane Doe' in resp.text |
|
289 |
- |