manager: lock check if flag check_locked is enabled (#75416)
gitea/chrono/pipeline/head This commit looks good Details

Lauréline Guérin 2023-03-17 10:40:37 +01:00
parent b05153364b
commit 141ff5b038
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 104 additions and 30 deletions

View File

@ -49,6 +49,9 @@
{% if event.main_list_full %}
<span class="full tag">{% trans "Full" %}</span>
{% endif %}
{% if event.check_locked %}
<span class="check-locked tag">{% trans "Check locked" %}</span>
{% endif %}
{% if event.checked %}
<span class="checked tag">{% trans "Checked" %}</span>
{% endif %}

View File

@ -16,7 +16,7 @@
({% trans "Cancelled" %})
{% endif %}
{% if not event.checked or not agenda.disable_check_update %}
{% if booking.user_was_present is not None %}
{% if booking.user_was_present is not None and not event.check_locked %}
<form method="post" action="{% url 'chrono-manager-booking-reset' pk=agenda.pk booking_pk=booking.pk %}" class="with-ajax reset">
{% csrf_token %}
<a href="#">{% trans "Reset" context "check" %}</a>
@ -33,45 +33,47 @@
{% endif %}
{% endif %}
</td>
{% if not event.checked or not agenda.disable_check_update %}
<td class="booking-actions" data-{{ booking.kind }}-id="{{ booking.id }}">
{% if not event.check_locked %}
{% if not event.checked or not agenda.disable_check_update %}
<td class="booking-actions" data-{{ booking.kind }}-id="{{ booking.id }}">
{% if booking.kind == "subscription" %}
<form method="post" action="{% url 'chrono-manager-subscription-presence' pk=agenda.pk subscription_pk=booking.pk event_pk=event.pk %}" class="with-ajax presence">
{% else %}
<form method="post" action="{% url 'chrono-manager-booking-presence' pk=agenda.pk booking_pk=booking.pk %}" class="with-ajax presence">
{% endif %}
{% csrf_token %}
<button class="submit-button"
{% if booking.user_was_present is True %}disabled{% endif %}
>{% trans "Presence" %}</button>
{% if booking.presence_form.check_type.field.choices.1 %}{{ booking.presence_form.check_type }}{% endif %}
<script>
$(function() {
$('td.booking-actions[data-{{ booking.kind }}-id="{{ booking.id }}"] form.presence select').on('change',
function() {
$(this).parents('form.presence').submit();
});
});
</script>
</form>
{% if booking.kind == "subscription" %}
<form method="post" action="{% url 'chrono-manager-subscription-presence' pk=agenda.pk subscription_pk=booking.pk event_pk=event.pk %}" class="with-ajax presence">
<form method="post" action="{% url 'chrono-manager-subscription-absence' pk=agenda.pk subscription_pk=booking.pk event_pk=event.pk %}" class="with-ajax absence">
{% else %}
<form method="post" action="{% url 'chrono-manager-booking-presence' pk=agenda.pk booking_pk=booking.pk %}" class="with-ajax presence">
<form method="post" action="{% url 'chrono-manager-booking-absence' pk=agenda.pk booking_pk=booking.pk %}" class="with-ajax absence">
{% endif %}
{% csrf_token %}
<button class="submit-button"
{% if booking.user_was_present is True %}disabled{% endif %}
>{% trans "Presence" %}</button>
{% if booking.presence_form.check_type.field.choices.1 %}{{ booking.presence_form.check_type }}{% endif %}
{% if booking.user_was_present is False %}disabled{% endif %}
>{% trans "Absence" %}</button>
{% if booking.absence_form.check_type.field.choices.1 %}{{ booking.absence_form.check_type }}{% endif %}
<script>
$(function() {
$('td.booking-actions[data-{{ booking.kind }}-id="{{ booking.id }}"] form.presence select').on('change',
$('td.booking-actions[data-{{ booking.kind }}-id="{{ booking.id }}"] form.absence select').on('change',
function() {
$(this).parents('form.presence').submit();
$(this).parents('form.absence').submit();
});
});
</script>
</form>
{% if booking.kind == "subscription" %}
<form method="post" action="{% url 'chrono-manager-subscription-absence' pk=agenda.pk subscription_pk=booking.pk event_pk=event.pk %}" class="with-ajax absence">
{% else %}
<form method="post" action="{% url 'chrono-manager-booking-absence' pk=agenda.pk booking_pk=booking.pk %}" class="with-ajax absence">
</form>
</td>
{% endif %}
{% csrf_token %}
<button class="submit-button"
{% if booking.user_was_present is False %}disabled{% endif %}
>{% trans "Absence" %}</button>
{% if booking.absence_form.check_type.field.choices.1 %}{{ booking.absence_form.check_type }}{% endif %}
<script>
$(function() {
$('td.booking-actions[data-{{ booking.kind }}-id="{{ booking.id }}"] form.absence select').on('change',
function() {
$(this).parents('form.absence').submit();
});
});
</script>
</form>
</td>
{% endif %}

View File

@ -27,6 +27,7 @@
<div class="event-title-meta">
{% if event.cancellation_status %}<span class="tag">{{ event.cancellation_status }}</span>{% endif %}
{% if event.main_list_full %}<span class="tag">{% trans "Full" %}</span>{% endif %}
{% if event.check_locked %}<span class="check-locked tag">{% trans "Check locked" %}</span>{% endif %}
{% if event.checked %}<span class="checked tag">{% trans "Checked" %}</span>{% endif %}
{% if event.is_day_past and not event.cancelled %}
{% if event.present_count %}<span class="meta meta-success">{% blocktrans with count=event.present_count %}Presents {{ count }}{% endblocktrans %}</span>{% endif %}

View File

@ -2671,6 +2671,7 @@ class EventCheckMixin:
pk=kwargs.get('event_pk'),
agenda=self.agenda,
cancelled=False,
check_locked=False,
)
def get_bookings(self):
@ -3495,6 +3496,7 @@ class BookingCheckMixin:
pk=kwargs['booking_pk'],
event__agenda=self.agenda,
event__cancelled=False,
event__check_locked=False,
in_waiting_list=False,
primary_booking__isnull=True,
)
@ -3596,6 +3598,7 @@ class SubscriptionCheckMixin(BookingCheckMixin):
Q(start_datetime__date__lte=now().date()) | Q(agenda__enable_check_for_future_events=True),
agenda=self.agenda,
cancelled=False,
check_locked=False,
pk=kwargs['event_pk'],
)
subscription = get_object_or_404(

View File

@ -1716,6 +1716,7 @@ def test_event_checked(app, admin_user):
for url in urls:
resp = app.get(url)
assert '<span class="checked tag">Checked</span>' not in resp
assert 'check-locked' not in resp
assert '<span class="meta meta-success">Presents 3</span>' in resp
assert '<span class="meta meta-error">Absents 4</span>' in resp
assert '<span class="meta meta-disabled">Not checked 1</span>' in resp
@ -1736,6 +1737,7 @@ def test_event_checked(app, admin_user):
for url in urls:
resp = app.get(url)
assert '<span class="checked tag">Checked</span>' in resp
assert 'check-locked' not in resp
assert '<span class="meta meta-success">Presents 4</span>' in resp
assert '<span class="meta meta-error">Absents 4</span>' in resp
assert 'meta meta-disabled' not in resp
@ -1761,6 +1763,29 @@ def test_event_checked(app, admin_user):
status=302,
)
# event check is locked
event.checked = False
event.check_locked = True
event.save()
urls = [
'/manage/agendas/%s/events/%s/' % (agenda.pk, event.pk),
'/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk),
'/manage/agendas/%s/month/%d/%d/%d/'
% (agenda.pk, event.start_datetime.year, event.start_datetime.month, event.start_datetime.day),
'/manage/agendas/%s/week/%d/%d/%d/'
% (agenda.pk, event.start_datetime.year, event.start_datetime.month, event.start_datetime.day),
'/manage/agendas/%s/day/%d/%d/%d/'
% (agenda.pk, event.start_datetime.year, event.start_datetime.month, event.start_datetime.day),
]
for url in urls:
resp = app.get(url)
assert '<span class="check-locked tag">Check locked</span>' in resp
app.post(
'/manage/agendas/%s/events/%s/checked' % (agenda.pk, event.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
@mock.patch('chrono.manager.forms.get_agenda_check_types')
def test_event_check_filters(check_types, app, admin_user):
@ -2416,7 +2441,32 @@ def test_event_check_booking(check_types, app, admin_user):
status=302,
)
# event check is locked
event.check_locked = True
event.save()
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk))
assert '/manage/agendas/%s/bookings/%s/presence' % (agenda.pk, booking.pk) not in resp
assert '/manage/agendas/%s/bookings/%s/absence' % (agenda.pk, booking.pk) not in resp
assert '/manage/agendas/%s/bookings/%s/reset' % (agenda.pk, booking.pk) not in resp
app.post(
'/manage/agendas/%s/bookings/%s/absence' % (agenda.pk, booking.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
app.post(
'/manage/agendas/%s/bookings/%s/presence' % (agenda.pk, booking.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
app.post(
'/manage/agendas/%s/bookings/%s/reset' % (agenda.pk, booking.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
# now disable check update
event.check_locked = False
event.save()
agenda.disable_check_update = True
agenda.save()
resp = app.get('/manage/agendas/%s/events/%s/check' % (agenda.pk, event.pk))
@ -2790,6 +2840,21 @@ def test_event_check_subscription(check_types, app, admin_user):
params={'csrfmiddlewaretoken': token},
status=302,
)
Booking.objects.all().delete()
# event check is locked
event.check_locked = True
event.save()
app.post(
'/manage/agendas/%s/subscriptions/%s/absence/%s' % (agenda.pk, subscription.pk, event.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
app.post(
'/manage/agendas/%s/subscriptions/%s/presence/%s' % (agenda.pk, subscription.pk, event.pk),
params={'csrfmiddlewaretoken': token},
status=404,
)
@mock.patch('chrono.manager.forms.get_agenda_check_types')