Make team guide only visible for approved members. Fix #369.

This commit is contained in:
Víðir Valberg Guðmundsson 2019-07-31 21:14:17 +02:00
parent 37d40469c2
commit b89f09105c
2 changed files with 17 additions and 8 deletions

View file

@ -53,11 +53,14 @@ Team: {{ team.name }} | {{ block.super }}
</li>
{% endif %}
{% if request.user in team.members.all %}
<li {% if view.active_menu == "guide" %}class="active"{% endif %}>
<a href="{% url "teams:guide" camp_slug=team.camp.slug team_slug=team.slug %}">
Team guide
</a>
</li>
{% endif %}
</ul>

View file

@ -1,22 +1,28 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView, DetailView
from django.views.generic import DetailView
from camps.mixins import CampViewMixin
from django.contrib.auth.mixins import UserPassesTestMixin, LoginRequiredMixin
from ..models import Team
from ..models import Team, TeamMember
class TeamGuideView(LoginRequiredMixin, CampViewMixin, DetailView):
class TeamGuideView(LoginRequiredMixin, CampViewMixin, UserPassesTestMixin, DetailView):
template_name = "team_guide.html"
context_object_name = "team"
model = Team
slug_url_kwarg = "team_slug"
active_menu = "guide"
def get_queryset(self):
qs = CampViewMixin.get_queryset(self)
qs.filter(teammember__approved=True, teammember__user=self.request.user)
return qs
def test_func(self):
# Make sure that the user is an approved member of the team
try:
TeamMember.objects.get(
user=self.request.user, team=self.get_object(), approved=True
)
except TeamMember.DoesNotExist:
return False
else:
return True
class TeamGuidePrintView(TeamGuideView):