Meilleure détection de connexion par CAS
This commit is contained in:
parent
fd80f23112
commit
ffaf29145e
2 changed files with 10 additions and 4 deletions
|
@ -107,14 +107,20 @@ class User(AbstractUser):
|
|||
def get_username(self):
|
||||
return "__".join(self.username.split("__")[1:])
|
||||
|
||||
def can_vote(self, election):
|
||||
def can_vote(self, request, election):
|
||||
# Si c'est un·e utilisateur·ice CAS, iel peut voter dans les élections
|
||||
# ouvertes à tou·te·s
|
||||
if self.election is None:
|
||||
return not election.restricted
|
||||
# If the user is connected via CAS, request.session["CASCONNECTED"] is set
|
||||
# to True by authens
|
||||
return not election.restricted and request.session.get("CASCONNECTED")
|
||||
|
||||
# Pour les élections restreintes, il faut y être associé
|
||||
return election.restricted and (self.election == election)
|
||||
|
||||
def get_prefix(self):
|
||||
return self.username.split("__")[0]
|
||||
|
||||
def connection_method(self):
|
||||
method = self.username.split("__")[0]
|
||||
return CONNECTION_METHODS.get(method, _("identifiants spécifiques"))
|
||||
|
|
|
@ -351,7 +351,7 @@ class ElectionView(DetailView):
|
|||
context = super().get_context_data(**kwargs)
|
||||
context["current_time"] = timezone.now()
|
||||
context["can_vote"] = user.is_authenticated and user.can_vote(
|
||||
context["election"]
|
||||
self.request, context["election"]
|
||||
)
|
||||
return context
|
||||
|
||||
|
@ -392,7 +392,7 @@ class VoteView(OpenElectionOnlyMixin, DetailView):
|
|||
question = super().get_object()
|
||||
# Seulement les utilisateur·ice·s ayant le droit de voter dans l'élection
|
||||
# peuvent voir la page
|
||||
if not self.request.user.can_vote(question.election):
|
||||
if not self.request.user.can_vote(self.request, question.election):
|
||||
raise Http404
|
||||
return question
|
||||
|
||||
|
|
Loading…
Reference in a new issue