Skip to content

Commit

Permalink
Merge pull request #891 from Inter-Actief/890-room-duty-committee-rights
Browse files Browse the repository at this point in the history
890 room duty committee rights
  • Loading branch information
bramvandartel authored Sep 17, 2024
2 parents 4e3b3c9 + 5592657 commit 1cb7a8c
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 66 deletions.
25 changes: 10 additions & 15 deletions amelie/about/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ def get_redirect_url(self, *args, **kwargs):

def page(request, pk, slug):
obj = get_object_or_404(Page, pk=pk)
is_www = (hasattr(request, 'is_board') and request.is_board) or \
(hasattr(request, 'person') and request.person.function_set.filter(committee__abbreviation='WWW',
end__isnull=True))
is_educational = hasattr(request, 'person') and request.person.function_set.filter(committee__abbreviation='OnderwijsCommissie',
end__isnull=True)
is_www = hasattr(request, 'person') and (request.person.is_board() or request.person.is_in_committee('WWW'))
is_educational = hasattr(request, 'person') and (request.person.is_board() or request.person.is_in_committee('OnderwijsCommissie'))
return render(request, 'page.html', {'obj': obj, 'is_www': is_www, 'is_educational': is_educational})


def page_edit(request, pk, slug):
obj = get_object_or_404(Page, pk=pk)
if hasattr(request, 'person') and (
request.person.is_board() or request.person.function_set.filter(committee__abbreviation='WWW',
end__isnull=True).exists() or (
obj.educational and request.person.function_set.filter(committee__abbreviation='OnderwijsCommissie',
end__isnull=True).exists())):
is_board = hasattr(request, 'person') and request.person.is_board()
is_www = hasattr(request, 'person') and request.person.is_in_committee('WWW')
is_educational = hasattr(request, 'person') and request.person.is_in_committee('OnderwijsCommissie')
if is_board or is_www or (obj.educational and is_educational):
form = PageForm(instance=obj) if request.method != "POST" else PageForm(request.POST, instance=obj)
is_new = False

Expand All @@ -50,11 +46,10 @@ def page_edit(request, pk, slug):

def page_delete(request, pk, slug):
obj = get_object_or_404(Page, pk=pk)
if hasattr(request, 'person') and (
request.person.is_board() or request.person.function_set.filter(committee__abbreviation='WWW',
end__isnull=True).exists() or (
obj.educational and request.person.function_set.filter(committee__abbreviation='OnderwijsCommissie',
end__isnull=True).exists())):
is_board = hasattr(request, 'person') and request.person.is_board()
is_www = hasattr(request, 'person') and request.person.is_in_committee('WWW')
is_educational = hasattr(request, 'person') and request.person.is_in_committee('OnderwijsCommissie')
if is_board or is_www or (obj.educational and is_educational):
if request.method == "POST":
obj.delete()
return HttpResponseRedirect("/")
Expand Down
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 %}
{% 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 %}
{% 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
14 changes: 9 additions & 5 deletions amelie/activities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def activity(request, pk, deanonymise=False):

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

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

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


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


@require_board
@require_committee(settings.ROOM_DUTY_ABBREVIATION)
@transaction.atomic
def activity_unenrollment(request, pk, person_id):
"""
Expand Down Expand Up @@ -568,7 +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)
if not activity.can_edit(request.person):
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 @@ -676,7 +678,8 @@ def activity_enrollment_form(request, activity, person=None):
# Django messages have been set in check_enrollment_allowed
return redirect(activity)

if indirect and not activity.can_edit(request.person):
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 @@ -1306,8 +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_roomduty = request.person.is_room_duty()

return is_board or is_organization
return is_board or is_organization or is_roomduty

def post(self, request, pk=None):
if pk is None:
Expand Down
6 changes: 4 additions & 2 deletions amelie/calendar/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from django.conf import settings
from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect
from django.utils import timezone
from django.utils.translation import gettext_lazy as _l
from django.views.generic import TemplateView

from amelie.calendar.models import Participation
from amelie.tools.mixins import RequireBoardMixin
from amelie.tools.mixins import RequireBoardMixin, RequireCommitteeMixin


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

def get_context_data(self, **kwargs):
context = super(PayParticipationView, self).get_context_data()
Expand Down
19 changes: 10 additions & 9 deletions amelie/members/ajax_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import re

from django.conf import settings
from django.contrib import messages
from django.forms.models import inlineformset_factory
from django.http import JsonResponse
Expand All @@ -16,7 +17,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
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 +114,7 @@ def person_study_new(request, id):


@require_ajax
@require_board
@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 +136,14 @@ def person_payments(request, id, membership):


@require_ajax
@require_board
@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_board
@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 +162,7 @@ def person_membership_new(request, id):


@require_ajax
@require_board
@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 +179,14 @@ def person_membership_end(request, id):


@require_ajax
@require_board
@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_board
@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 +206,7 @@ def person_mandate_new(request, id):


@require_ajax
@require_board
@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 +221,7 @@ def person_mandate_activate(request, id, mandate):


@require_ajax
@require_board
@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
6 changes: 6 additions & 0 deletions amelie/members/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ def is_member(self):
def is_board(self):
return self.function_set.filter(committee__superuser=True, committee__abolished__isnull=True,
end__isnull=True).exists()

def is_in_committee(self, abbreviation):
return self.function_set.filter(committee__abbreviation=abbreviation, end__isnull=True).exists()

def is_room_duty(self):
return self.is_in_committee(settings.ROOM_DUTY_ABBREVIATION)

is_board.boolean = True

Expand Down
5 changes: 3 additions & 2 deletions amelie/members/query_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import date
import csv

from django.conf import settings
from django.urls import reverse
from django.views import View
from django.views.generic import CreateView
Expand All @@ -24,13 +25,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
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_board
@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
6 changes: 6 additions & 0 deletions amelie/members/templates/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2 class="expand" data-target="person_employee">{% trans 'Employee data' %}</h2
</div>
</div></div>

{% if request.is_board %}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="ia">
<h2 class="expand" data-target="person_functions">{% trans 'Committees' %}</h2>
<div class="content">
Expand All @@ -57,7 +58,9 @@ <h2 class="expand" data-target="person_functions">{% trans 'Committees' %}</h2>
</div>
</div>
</div></div>
{% endif %}

{% if request.is_board %}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="ia">
<h2 class="expand" data-target="person_preferences">{% trans 'Preferences' %}</h2>
<div class="content">
Expand All @@ -66,6 +69,7 @@ <h2 class="expand" data-target="person_preferences">{% trans 'Preferences' %}</h
</div>
</div>
</div></div>
{% endif %}

{% if request.user.is_superuser %}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"><div class="ia">
Expand All @@ -78,6 +82,7 @@ <h2 class="expand" data-target="person_accounts">{% trans 'User accounts and log
</div></div>
{% endif %}

{% if request.is_board %}
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12i"><div class="ia">
<h2 class="expand" data-target="person_anonymize">{% trans 'Anonymize person' %}</h2>
<div class="content">
Expand All @@ -99,5 +104,6 @@ <h2 class="expand" data-target="person_anonymize">{% trans 'Anonymize person' %}
</div>
</div>
</div></div>
{% endif %}
</div>
{% endblock content %}
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 %}<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 %}
{% 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
Loading

0 comments on commit 1cb7a8c

Please sign in to comment.