On crée une permission pour administrer les élections
This commit is contained in:
parent
e3c195cc14
commit
71e22a139f
3 changed files with 30 additions and 6 deletions
17
elections/migrations/0013_admin_perm.py
Normal file
17
elections/migrations/0013_admin_perm.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 2.2.19 on 2021-03-20 18:57
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("elections", "0012_auto_20210319_1613"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="user",
|
||||
options={"permissions": [("is_admin", "Peut administrer des élections")]},
|
||||
),
|
||||
]
|
|
@ -1,4 +1,4 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
@ -6,6 +6,12 @@ from django.views.generic.detail import SingleObjectMixin
|
|||
from .models import Election, Option, Question
|
||||
|
||||
|
||||
class AdminOnlyMixin(PermissionRequiredMixin):
|
||||
"""Restreint l'accès aux admins"""
|
||||
|
||||
permission_required = "elections.is_admin"
|
||||
|
||||
|
||||
class SelectElectionMixin:
|
||||
"""Sélectionne automatiquement les foreignkeys voulues"""
|
||||
|
||||
|
@ -53,7 +59,7 @@ class OpenElectionOnlyMixin(RestrictAccessMixin):
|
|||
return filters
|
||||
|
||||
|
||||
class CreatorOnlyMixin(LoginRequiredMixin, RestrictAccessMixin):
|
||||
class CreatorOnlyMixin(AdminOnlyMixin, RestrictAccessMixin):
|
||||
"""Restreint l'accès au créateurice de l'élection"""
|
||||
|
||||
def get_next_url(self):
|
||||
|
@ -76,9 +82,5 @@ class CreatorOnlyEditMixin(CreatorOnlyMixin, SingleObjectMixin):
|
|||
return filters
|
||||
|
||||
|
||||
class AdministratorOnlyMixin(LoginRequiredMixin):
|
||||
"""Restreint l'accès aux admins"""
|
||||
|
||||
|
||||
class VoterOnlyMixin:
|
||||
"""Restreint l'accès aux voteureuses de l'élection"""
|
||||
|
|
|
@ -153,3 +153,8 @@ class User(AbstractUser):
|
|||
def connection_method(self):
|
||||
method = self.username.split("__")[0]
|
||||
return CONNECTION_METHODS.get(method, _("identifiants spécifiques"))
|
||||
|
||||
class Meta:
|
||||
permissions = [
|
||||
("is_admin", _("Peut administrer des élections")),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue