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> </li>
{% endif %} {% endif %}
{% if request.user in team.members.all %}
<li {% if view.active_menu == "guide" %}class="active"{% endif %}> <li {% if view.active_menu == "guide" %}class="active"{% endif %}>
<a href="{% url "teams:guide" camp_slug=team.camp.slug team_slug=team.slug %}"> <a href="{% url "teams:guide" camp_slug=team.camp.slug team_slug=team.slug %}">
Team guide Team guide
</a> </a>
</li> </li>
{% endif %}
</ul> </ul>

View file

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