From db39a6337b7b4cd443fe84423ddb16768a2ee481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Kol=C3=A1=C5=99?= Date: Sat, 11 Nov 2023 01:30:27 +0100 Subject: [PATCH] fix(buddy-system): perms denied when policy doesn't allow member matching [closes #223] --- .../buddy_system/dashboard_block.html | 26 +++++++++++++------ .../templates/buddy_system/index_member.html | 2 +- .../templates/buddy_system/my_buddies.html | 14 ++++++++++ .../buddy_system/templatetags/buddy_system.py | 11 ++++++++ fiesta/apps/buddy_system/views/index.py | 8 +++--- fiesta/apps/buddy_system/views/request.py | 10 ++++--- 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html b/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html index 408ac6ae..19ad07b7 100644 --- a/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html +++ b/fiesta/apps/buddy_system/templates/buddy_system/dashboard_block.html @@ -2,6 +2,9 @@ {% load utils %} {% load i18n %} {% load user_profile %} + +{% get_buddy_system_configuration as configuration %} +
Buddy System
@@ -56,10 +59,12 @@ waiting request{{ count|pluralize:"s" }} {% endwith %}
- + {% if configuration.matching_policy_instance.can_member_match %} + + {% endif %} {% endif %}
{% if request.membership.is_local %} @@ -69,10 +74,15 @@ {% get_matched_buddy_requests as request_matches %} {% if not request_matches.exists %}
So empty here :(
-
- get your first buddy -
+ + {% if configuration.matching_policy_instance.can_member_match %} +
+ get your first buddy +
+ {% else %} +
Buddy system team is looking for the best match for you.
+ {% endif %} {% else %}
diff --git a/fiesta/apps/buddy_system/templates/buddy_system/index_member.html b/fiesta/apps/buddy_system/templates/buddy_system/index_member.html index ea78856e..a73bba11 100644 --- a/fiesta/apps/buddy_system/templates/buddy_system/index_member.html +++ b/fiesta/apps/buddy_system/templates/buddy_system/index_member.html @@ -19,7 +19,7 @@

{% trans "Buddy System" %}

href="{% url "buddy_system:matching-requests" %}">{% trans "Show buddy requests" %} {% else %}
- {% trans "Wait for match by coordinator" %} + {% trans "Please, wait for match by coordinator." %} {# TODO: display matches or link to them #}
{% endif %} diff --git a/fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html b/fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html index fa39053f..0c310642 100644 --- a/fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html +++ b/fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html @@ -12,7 +12,21 @@ {% endblock upper_head %} {% block main %} + {% get_buddy_system_configuration as configuration %} + {% for match in object_list.all %} {% include "buddy_system/parts/request_match_card.html" with br=match.request title=match.request.issuer.full_name connect_with=match.request.issuer %} + {% empty %} + {% endfor %} {% endblock %} diff --git a/fiesta/apps/buddy_system/templatetags/buddy_system.py b/fiesta/apps/buddy_system/templatetags/buddy_system.py index 494d73c2..3fc28232 100644 --- a/fiesta/apps/buddy_system/templatetags/buddy_system.py +++ b/fiesta/apps/buddy_system/templatetags/buddy_system.py @@ -88,3 +88,14 @@ def request_state_to_css_variant(state: BuddyRequest.State): BuddyRequest.State.MATCHED: "success", BuddyRequest.State.CANCELLED: "danger", }.get(state) + + +@register.simple_tag(takes_context=True) +def get_buddy_system_configuration(context): + request: HttpRequest = context["request"] + + buddy_system_plugin: Plugin = request.in_space_of_section.plugins.get( + app_label=all_plugins_mapped_to_class().get(BuddySystemConfig).label + ) + + return buddy_system_plugin.configuration diff --git a/fiesta/apps/buddy_system/views/index.py b/fiesta/apps/buddy_system/views/index.py index 1d955bc1..c46c9fcb 100644 --- a/fiesta/apps/buddy_system/views/index.py +++ b/fiesta/apps/buddy_system/views/index.py @@ -7,7 +7,6 @@ from apps.buddy_system.models import BuddyRequest, BuddySystemConfiguration from apps.plugins.views import PluginConfigurationViewMixin from apps.sections.middleware.user_membership import HttpRequest -from apps.sections.models import SectionMembership from apps.sections.views.mixins.section_space import EnsureInSectionSpaceViewMixin @@ -23,7 +22,10 @@ class BuddySystemIndexView( } def get(self, request, *args, **kwargs): - if not self.request.in_space_of_section.buddy_system_requests.filter(issuer=self.request.user).exists(): + if ( + self.request.membership.is_international + and not self.request.in_space_of_section.buddy_system_requests.filter(issuer=self.request.user).exists() + ): return HttpResponseRedirect(reverse("buddy_system:wanna-buddy")) return super().get(request, *args, **kwargs) @@ -40,7 +42,7 @@ def get_template_names(self): return [ ( "buddy_system/index_international.html" - if self.request.membership.role == SectionMembership.Role.INTERNATIONAL + if self.request.membership.is_international else "buddy_system/index_member.html" ) ] diff --git a/fiesta/apps/buddy_system/views/request.py b/fiesta/apps/buddy_system/views/request.py index 0e0ebbe6..df283fef 100644 --- a/fiesta/apps/buddy_system/views/request.py +++ b/fiesta/apps/buddy_system/views/request.py @@ -5,7 +5,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.messages.views import SuccessMessageMixin from django.db import transaction -from django.http import Http404, HttpResponseRedirect +from django.http import HttpResponseRedirect from django.urls import reverse, reverse_lazy from django.utils.http import urlencode from django.utils.translation import gettext_lazy as _ @@ -13,21 +13,23 @@ from apps.accounts.models import UserProfile from apps.buddy_system.forms import NewBuddyRequestForm +from apps.buddy_system.models import BuddySystemConfiguration from apps.plugins.views import PluginConfigurationViewMixin from apps.sections.models import SectionMembership, SectionsConfiguration from apps.sections.views.mixins.membership import EnsureInternationalUserViewMixin from apps.sections.views.mixins.section_space import EnsureInSectionSpaceViewMixin -class BuddySystemEntrance(EnsureInSectionSpaceViewMixin, TemplateView): +class BuddySystemEntrance(EnsureInSectionSpaceViewMixin, PluginConfigurationViewMixin, TemplateView): def get(self, request, *args, **kwargs): if self.request.membership.is_international: return HttpResponseRedirect(reverse("buddy_system:new-request")) - if self.request.membership.is_local: + c: BuddySystemConfiguration = self.configuration + if c.matching_policy_instance.can_member_match: return HttpResponseRedirect(reverse("buddy_system:matching-requests")) - raise Http404(_("Nothing to see here")) + return HttpResponseRedirect(reverse("buddy_system:index")) class WannaBuddyView(EnsureInSectionSpaceViewMixin, TemplateView):