Skip to content

Commit

Permalink
Refactor is_rd to is_roomduty, remove require_room_duty decorat…
Browse files Browse the repository at this point in the history
…or in favor of directly using the `require_committee` decorator, make roomduty checks that use the RequireCommitteeMixin use the setting `ROOM_DUTY_ABBREVIATION`. Refactor `require_committee` decorator, `RequireCommitteeMixin` mixin and `RequireStrictCommitteeMixin` mixin to use the new Person.is_in_committee method.
  • Loading branch information
Kurocon committed Sep 16, 2024
1 parent a9849dd commit 4f3adbc
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion amelie/activities/templates/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h2 id="slider-carousel-title" class="h2-with-buttons">{% trans "Pictures of the
</div>

{% if obj.enrollment %}
{% if obj.organizer in request.person.current_committees or request.is_board or is_rd %}
{% if obj.organizer in request.person.current_committees or request.is_board or is_roomduty %}
<div class="col-xs-12 col-md-12">
<div class="current">
<h2 class="expand" data-target="export_options">{% trans 'Export enrollments' %}</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{% for answer in participation.enrollmentoptionanswer_set.all %}
<td>{{ answer.display_answer }}</td>
{% endfor %}
{% if request.is_board or is_rd %}
{% if request.is_board or is_roomduty %}
<td>{% if participation.has_paid %}<p class="icon pos">{{ participation.get_payment_method_display }}{% else %}<p class="icon icon-cancel"><a title="{% trans "By clicking here, you confirm to have received the full amount of money." %}" href="{% url 'calendar:pay_participation' participation.pk %}">{% trans "Register cash payment" %}</a>{% endif %}</p></td>
{% else %}
<td>{{ participation.get_payment_method_display }}</td>
Expand Down
20 changes: 10 additions & 10 deletions amelie/activities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from amelie.members.models import Person, Photographer
from amelie.members.query_forms import MailingForm
from amelie.tools import amelie_messages, types
from amelie.tools.decorators import require_actief, require_lid, require_committee, require_board, require_room_duty
from amelie.tools.decorators import require_actief, require_lid, require_committee, require_board
from amelie.tools.forms import PeriodForm, ExportForm, PeriodKeywordForm
from amelie.tools.calendar import ical_calendar
from amelie.tools.mixins import RequireActiveMemberMixin, DeleteMessageMixin, PassesTestMixin, RequireBoardMixin, \
Expand Down Expand Up @@ -252,7 +252,7 @@ def activity(request, pk, deanonymise=False):

# Enable opengraph on this page
metadata_enable_opengraph = True
is_rd = request.person.is_room_duty()
is_roomduty = request.person.is_room_duty()

return render(request, "activity.html", locals())

Expand Down Expand Up @@ -493,7 +493,7 @@ def activity_editenrollment_self(request, pk):
return render(request, "activity_enrollment_form.html", locals())


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
@transaction.atomic
def activity_editenrollment_other(request, pk, person_id):
"""
Expand Down Expand Up @@ -522,7 +522,7 @@ def activity_editenrollment_other(request, pk, person_id):
return render(request, "activity_enrollment_form.html", locals())


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
@transaction.atomic
def activity_unenrollment(request, pk, person_id):
"""
Expand Down Expand Up @@ -569,8 +569,8 @@ def activity_enrollment_person_search(request, pk):
Search for a person to enroll for this activity.
"""
activity = get_object_or_404(Activity, pk=pk)
is_rd = request.person.is_room_duty()
if not (activity.can_edit(request.person) or is_rd):
is_roomduty = request.person.is_room_duty()
if not (activity.can_edit(request.person) or is_roomduty):
raise PermissionDenied

form = PersonSearchForm(request.POST if request.POST else None)
Expand Down Expand Up @@ -678,8 +678,8 @@ def activity_enrollment_form(request, activity, person=None):
# Django messages have been set in check_enrollment_allowed
return redirect(activity)

is_rd = request.person.is_room_duty()
if indirect and not (activity.can_edit(request.person) or is_rd):
is_roomduty = request.person.is_room_duty()
if indirect and not (activity.can_edit(request.person) or is_roomduty):
raise PermissionDenied

per_mandate = (request.is_board or settings.PERSONAL_TAB_COMMITTEE_CAN_AUTHORIZE) \
Expand Down Expand Up @@ -1309,9 +1309,9 @@ def test_requirement(self, request):

is_board = hasattr(request, 'is_board') and request.is_board
is_organization = obj.organizer in request.person.current_committees()
is_rd = request.person.is_room_duty()
is_roomduty = request.person.is_room_duty()

return is_board or is_organization or is_rd
return is_board or is_organization or is_roomduty

def post(self, request, pk=None):
if pk is None:
Expand Down
3 changes: 2 additions & 1 deletion amelie/calendar/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect
from django.utils import timezone
Expand All @@ -10,7 +11,7 @@

class PayParticipationView(RequireCommitteeMixin, TemplateView):
template_name = "confirm_payment.html"
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION

def get_context_data(self, **kwargs):
context = super(PayParticipationView, self).get_context_data()
Expand Down
18 changes: 9 additions & 9 deletions amelie/members/ajax_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from amelie.members.query_views import filter_member_list_public
from amelie.personal_tab.models import Authorization
from amelie.personal_tab.pos_views import require_cookie_corner_pos
from amelie.tools.decorators import require_ajax, require_board, require_actief, require_room_duty
from amelie.tools.decorators import require_ajax, require_board, require_actief, require_committee


def person_data(request, obj, type, form_type, view_template=None, edit_template=None, *args, **kwargs):
Expand Down Expand Up @@ -113,7 +113,7 @@ def person_study_new(request, id):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_payments(request, id, membership):
obj = get_object_or_404(Person, id=id)
membership = get_object_or_404(Membership, id=membership)
Expand All @@ -135,14 +135,14 @@ def person_payments(request, id, membership):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_membership(request, id, option=None):
obj = get_object_or_404(Person, id=id)
return render(request, "person_membership.html", locals())


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_membership_new(request, id):
obj = get_object_or_404(Person, id=id)
if request.method == "POST":
Expand All @@ -161,7 +161,7 @@ def person_membership_new(request, id):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_membership_end(request, id):
obj = get_object_or_404(Person, id=id)
if request.method == "POST":
Expand All @@ -178,14 +178,14 @@ def person_membership_end(request, id):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_mandate(request, id):
obj = get_object_or_404(Person, id=id)
return render(request, "person_mandate.html", locals())


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_mandate_new(request, id):
obj = get_object_or_404(Person, id=id)
if request.method == "POST":
Expand All @@ -205,7 +205,7 @@ def person_mandate_new(request, id):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_mandate_activate(request, id, mandate):
obj = get_object_or_404(Person, id=id)
mandate = get_object_or_404(Authorization, id=mandate, person=obj,
Expand All @@ -220,7 +220,7 @@ def person_mandate_activate(request, id, mandate):


@require_ajax
@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_mandate_end(request, id, mandate):
obj = get_object_or_404(Person, id=id)
mandate = get_object_or_404(Authorization, id=mandate)
Expand Down
4 changes: 2 additions & 2 deletions amelie/members/query_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
from amelie.members.query_forms import MailingForm, QueryForm, PushNotificationForm
from amelie.members.tasks import send_push_notification
from amelie.tools import types
from amelie.tools.decorators import require_board, require_room_duty
from amelie.tools.decorators import require_board, require_committee
from amelie.tools.logic import current_association_year
from amelie.tools.mixins import RequireBoardMixin
from amelie.tools.paginator import RangedPaginator


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
@never_cache
def query(request):
page = types.get_int(request.GET, 'page', default=1, min_value=1)
Expand Down
4 changes: 2 additions & 2 deletions amelie/members/templates/person_mandate.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<th>{% trans 'Signed' %}</th>
<th>{% trans 'Starts on' %}</th>
<th>{% trans 'Ends on' %}</th>
{% if request.is_board or is_rd %}<th></th>{% endif %}
{% if request.is_board or is_roomduty %}<th></th>{% endif %}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -57,7 +57,7 @@
<td>
{{ mandate.end_date|default_if_none:"&mdash;" }}
</td>
{% if request.is_board or is_rd %}
{% if request.is_board or is_roomduty %}
<td>
{% if not mandate.is_signed and not mandate.end_date %}
<a href="{% url 'members:mandate_form' mandate.id %}" class="icon icon-printer">{% trans 'Print' %}</a><br />
Expand Down
30 changes: 15 additions & 15 deletions amelie/members/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from amelie.personal_tab.forms import RFIDCardForm
from amelie.personal_tab.models import Authorization, AuthorizationType, Transaction, SEPA_CHAR_VALIDATOR
from amelie.tools.auth import get_oauth_link_code, send_oauth_link_code_email, get_user_info
from amelie.tools.decorators import require_board, require_superuser, require_lid_or_oauth, require_room_duty
from amelie.tools.decorators import require_board, require_superuser, require_lid_or_oauth, require_committee
from amelie.tools.encodings import normalize_to_ascii
from amelie.tools.http import HttpResponseSendfile, HttpJSONResponse
from amelie.tools.logic import current_academic_year_with_holidays, current_association_year, association_year
Expand Down Expand Up @@ -301,7 +301,7 @@ def payment_statistics(request, start_year=2012):
return render(request, 'statistics/payments.html', locals())


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_view(request, id, slug):
obj = get_object_or_404(Person, id=id, slug=slug)
preference_categories = PreferenceCategory.objects.all()
Expand All @@ -314,12 +314,12 @@ def person_view(request, id, slug):
accounts = []

can_be_anonymized, unable_to_anonymize_reasons = _person_can_be_anonymized(obj)
is_rd = request.person.is_room_duty()
is_roomduty = request.person.is_room_duty()

return render(request, "person.html", locals())


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
@transaction.atomic
def person_edit(request, id, slug):
person = get_object_or_404(Person, id=id)
Expand Down Expand Up @@ -463,7 +463,7 @@ def person_anonymize(request, id, slug):


class RegisterNewGeneralWizardView(RequireCommitteeMixin, SessionWizardView):
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION
template_name = "person_registration_form_general.html"
form_list = [RegistrationFormPersonalDetails, RegistrationFormStepMemberContactDetails,
RegistrationFormStepGeneralStudyDetails, RegistrationFormStepGeneralMembershipDetails,
Expand Down Expand Up @@ -579,7 +579,7 @@ def done(self, form_list, **kwargs):
return HttpResponse(pdf, content_type='application/pdf')

class RegisterNewExternalWizardView(RequireCommitteeMixin, SessionWizardView):
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION
template_name = "person_registration_form_external.html"
form_list = [RegistrationFormPersonalDetails, RegistrationFormStepMemberContactDetails,
RegistrationFormStepAuthorizationDetails, RegistrationFormStepPersonalPreferences,
Expand Down Expand Up @@ -690,7 +690,7 @@ def done(self, form_list, **kwargs):


class RegisterNewEmployeeWizardView(RequireCommitteeMixin, SessionWizardView):
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION
template_name = "person_registration_form_employee.html"
form_list = [RegistrationFormPersonalDetailsEmployee, RegistrationFormStepMemberContactDetails,
RegistrationFormStepEmployeeDetails, RegistrationFormStepEmployeeMembershipDetails,
Expand Down Expand Up @@ -798,7 +798,7 @@ def done(self, form_list, **kwargs):


class RegisterNewFreshmanWizardView(RequireCommitteeMixin, SessionWizardView):
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION
template_name = "person_registration_form_freshmen.html"
form_list = [RegistrationFormPersonalDetails, RegistrationFormStepMemberContactDetails,
RegistrationFormStepParentsContactDetails, RegistrationFormStepFreshmenStudyDetails,
Expand Down Expand Up @@ -1066,7 +1066,7 @@ class PreRegistrationCompleteView(TemplateView):

class PreRegistrationStatus(RequireCommitteeMixin, TemplateView):
template_name = "preregistration_status.html"
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION

def get_context_data(self, **kwargs):
context = super(PreRegistrationStatus, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def get(self, request, *args, **kwargs):


class PreRegistrationPrintDogroup(RequireCommitteeMixin, TemplateView):
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION

def get(self, request, *args, **kwargs):
pre_enrollment_dogroup_id = request.GET.get('did', None)
Expand Down Expand Up @@ -1210,7 +1210,7 @@ def get(self, request, *args, **kwargs):
class PreRegistrationPrintAll(RequireCommitteeMixin, FormView):
template_name = "preregistration_print_all.html"
form_class = PreRegistrationPrintAllForm
abbreviation = "RD"
abbreviation = settings.ROOM_DUTY_ABBREVIATION

def form_valid(self, form):
sort_by = form.cleaned_data['sort_by']
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def form_valid(self, form):



@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def registration_form(request, user, membership):
from amelie.tools.pdf import pdf_enrollment_form

Expand All @@ -1269,7 +1269,7 @@ def registration_form(request, user, membership):
return HttpResponse(pdf, content_type='application/pdf')


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def membership_form(request, user, membership):
from amelie.tools.pdf import pdf_membership_form

Expand All @@ -1281,7 +1281,7 @@ def membership_form(request, user, membership):
return HttpResponse(pdf, content_type='application/pdf')


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def mandate_form(request, mandate):
from amelie.tools.pdf import pdf_authorization_form

Expand Down Expand Up @@ -1609,7 +1609,7 @@ def person_groupinfo(request):
return HttpJSONResponse({})


@require_room_duty()
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
def person_send_link_code(request, person_id):
person = get_object_or_404(Person, id=person_id)
link_code = get_oauth_link_code(person)
Expand Down
4 changes: 2 additions & 2 deletions amelie/settings/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,5 @@ def get_random_secret_key_no_dollar():
# Wo4you personal URL
BOOK_SALES_URL = env("AMELIE_BOOK_SALES_URL", default=BOOK_SALES_URL)

# Room duty
ROOM_DUTY_ABBREVIATION = env("AMELIE_ROOM_DUTY_ABBREVIATION", default="RD")
# Abbreviation of the room duty committee for access checks.
ROOM_DUTY_ABBREVIATION = env("AMELIE_ROOM_DUTY_ABBREVIATION", default="RoomDuty")
4 changes: 2 additions & 2 deletions amelie/settings/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,5 +923,5 @@
# Wo4you personal URL
BOOK_SALES_URL = "https://wo4you.nl/"

# Room duty abbreviation setting
ROOM_DUTY_ABBREVIATION = "RD"
# Abbreviation of the room duty committee for access checks.
ROOM_DUTY_ABBREVIATION = "RoomDuty"
2 changes: 0 additions & 2 deletions amelie/settings/local.py.default
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,3 @@ if ENABLE_REQUEST_PROFILING:
SILKY_AUTHORISATION = True # User must be staff
SILKY_MAX_REQUEST_BODY_SIZE = 0 # Silk takes anything <0 as no limit
SILKY_MAX_RESPONSE_BODY_SIZE = 0 # If response body>0 bytes, ignore

ROOM_DUTY_ABBREVIATION = "RD"
12 changes: 4 additions & 8 deletions amelie/tools/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ def require_committee(abbreviation):
"""

def _view(func):
return request_passes_test(lambda r: (hasattr(r, 'person') and
(r.is_board or r.person.function_set.filter(
committee__abbreviation=abbreviation, end__isnull=True))),
needs_login=True,
reden=_l('Access for members of the committee only.'))(func)
return request_passes_test(
lambda r: (r.is_board or r.person.is_in_committee(abbreviation)),
needs_login=True, reden=_l('Access for members of the committee only.')
)(func)

return _view

def require_room_duty():
return require_committee(settings.ROOM_DUTY_ABBREVIATION)
Loading

0 comments on commit 4f3adbc

Please sign in to comment.