Skip to content

Commit

Permalink
fix(buddy-system): perms denied when policy doesn't allow member matc…
Browse files Browse the repository at this point in the history
…hing [closes #223]
  • Loading branch information
thejoeejoee committed Nov 11, 2023
1 parent 84add1e commit db39a63
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{% load utils %}
{% load i18n %}
{% load user_profile %}

{% get_buddy_system_configuration as configuration %}

<div class="Dashboard__tiles flex flex-col md:flex-row">
<div class="Dashboard__tile Dashboard__tile--dark shadow-2xl bg-primary">
<div class="Dashboard__tile__title">Buddy System</div>
Expand Down Expand Up @@ -56,10 +59,12 @@
waiting request{{ count|pluralize:"s" }}
{% endwith %}
</div>
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
class="btn btn-lg btn-outline">show waiting requests</a>
</div>
{% if configuration.matching_policy_instance.can_member_match %}
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
class="btn btn-lg btn-outline">show waiting requests</a>
</div>
{% endif %}
{% endif %}
</div>
{% if request.membership.is_local %}
Expand All @@ -69,10 +74,15 @@
{% get_matched_buddy_requests as request_matches %}
{% if not request_matches.exists %}
<div class="Dashboard__tile__value">So empty here :(</div>
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
class="btn btn-lg btn-outline">get your first buddy</a>
</div>

{% if configuration.matching_policy_instance.can_member_match %}
<div class="Dashboard__tile__actions text-right">
<a href="{% url "buddy_system:matching-requests" %}"
class="btn btn-lg btn-outline">get your first buddy</a>
</div>
{% else %}
<div class="Dashboard__tile__desc">Buddy system team is looking for the best match for you.</div>
{% endif %}
{% else %}
<div class="Dashboard__tile__value">
<div class="avatar-group -space-x-12 justify-center p-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1 class="text-6xl font-bold text-center">{% trans "Buddy System" %}</h1>
href="{% url "buddy_system:matching-requests" %}">{% trans "Show buddy requests" %}</a>
{% else %}
<div class="alert alert-info">
{% trans "Wait for match by coordinator" %}
{% trans "Please, wait for match by coordinator." %}
{# TODO: display matches or link to them #}
</div>
{% endif %}
Expand Down
14 changes: 14 additions & 0 deletions fiesta/apps/buddy_system/templates/buddy_system/my_buddies.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<div class="alert alert-link text-xl max-w-2xl mx-auto flex flex-row justify-between py-16 px-8">
No matches found.

{% if configuration.matching_policy_instance.can_member_match %}
<a href="{% url "buddy_system:matching-requests" %}"
class="btn btn-primary btn-lg">get your first buddy</a>
{% else %}
Buddy system team is looking for the best match for you.
{% endif %}

</div>
{% endfor %}
{% endblock %}
11 changes: 11 additions & 0 deletions fiesta/apps/buddy_system/templatetags/buddy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions fiesta/apps/buddy_system/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand All @@ -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"
)
]
10 changes: 6 additions & 4 deletions fiesta/apps/buddy_system/views/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@
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 _
from django.views.generic import CreateView, TemplateView

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):
Expand Down

0 comments on commit db39a63

Please sign in to comment.