Add some restrictions on deletion

This commit is contained in:
Ludovic Stephan 2019-05-24 16:16:20 +02:00
parent 08ac0ac890
commit 52521e89a6
2 changed files with 12 additions and 2 deletions

View file

@ -152,7 +152,7 @@ class Account(models.Model):
@property
def readable(self):
return self.trigramme != "GNR"
return self.trigramme not in [KFET_DELETED_TRIGRAMME, KFET_GENERIC_TRIGRAMME]
@property
def is_team(self):

View file

@ -24,7 +24,7 @@ from django.views.generic.detail import BaseDetailView
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from gestioncof.models import CofProfile
from kfet import consumers
from kfet import KFET_DELETED_TRIGRAMME, consumers
from kfet.config import kfet_config
from kfet.decorators import teamkfet_required
from kfet.forms import (
@ -79,6 +79,7 @@ from kfet.models import (
)
from kfet.statistic import ScaleMixin, WeekScale, last_stats_manifest
from .auth import KFET_GENERIC_TRIGRAMME
from .auth.views import ( # noqa
AccountGroupCreate,
AccountGroupUpdate,
@ -492,6 +493,15 @@ class AccountDeleteView(PermissionRequiredMixin, DeleteView):
)
return redirect("kfet.account.read", self.object.trigramme)
if self.object.trigramme in [
"LIQ",
KFET_GENERIC_TRIGRAMME,
KFET_DELETED_TRIGRAMME,
"#13",
]:
messages.error(request, "Impossible de supprimer un trigramme protégé !")
return redirect("kfet.account.read", self.object.trigramme)
# SuccessMessageMixin does not work with DeleteView, see :
# https://code.djangoproject.com/ticket/21926
messages.success(request, self.success_message)