mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 15:33:45 +00:00
users: plus de granularité dans les bans
This commit is contained in:
parent
147cb78e9e
commit
332a6a8149
4 changed files with 108 additions and 10 deletions
31
users/migrations/0056_1_bantype_alter.py
Normal file
31
users/migrations/0056_1_bantype_alter.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-10-09
|
||||
# Modified by Tudor, with love
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0055_auto_20171003_0556'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='BanType',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=255)),
|
||||
('description', models.TextField(help_text="Description de l'effet et des raisons de la blacklist")),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='ban',
|
||||
name='ban_type',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='users.BanType'),
|
||||
),
|
||||
]
|
43
users/migrations/0056_2_bantype_pop.py
Normal file
43
users/migrations/0056_2_bantype_pop.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-10-09
|
||||
# Modified by Tudor, with love
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
def add_foreign_bans(apps, schema_editor):
|
||||
Ban = apps.get_model('users', 'Ban')
|
||||
BanType = apps.get_model('users', 'BanType')
|
||||
b_hard = BanType(name='HARD', description="aucun accès")
|
||||
b_soft = BanType(name='SOFT', description="accès local seulement")
|
||||
b_bridage = BanType(name='BRIDAGE', description="bridage du débit")
|
||||
|
||||
# Ajoute et synchronise le nouveau field à partir du field state
|
||||
db_alias = schema_editor.connection.alias
|
||||
for b_type in [b_hard, b_soft, b_bridage]:
|
||||
b_type.save(using=db_alias)
|
||||
bans = Ban.objects.using(db_alias).all()
|
||||
for b in bans:
|
||||
if b.state == 0:
|
||||
b.ban_type = b_hard
|
||||
elif b.state == 1:
|
||||
b.ban_type = b_soft
|
||||
elif b.state == 2:
|
||||
b.ban_type = b_bridage
|
||||
else:
|
||||
raise Exception("Un ban state inconnu %r n'a pu être converti" % b.state)
|
||||
b.save(using=db_alias)
|
||||
|
||||
def remove_foreign_bans(apps, schema_editor):
|
||||
pass
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0056_1_bantype_alter'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(add_foreign_bans, remove_foreign_bans),
|
||||
]
|
25
users/migrations/0056_3_bantype_clean.py
Normal file
25
users/migrations/0056_3_bantype_clean.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2017-10-09 20:59
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0056_2_bantype_pop'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='ban',
|
||||
name='state',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='ban',
|
||||
name='ban_type',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.BanType'),
|
||||
),
|
||||
]
|
|
@ -725,25 +725,24 @@ class ListShell(models.Model):
|
|||
def __str__(self):
|
||||
return self.shell
|
||||
|
||||
class BanType(models.Model):
|
||||
"""Type de bannissement"""
|
||||
name = models.CharField(max_length=255)
|
||||
description = models.TextField(help_text="Description de l'effet et des "
|
||||
"raisons de la blacklist")
|
||||
# d'autres champs pour décrire les effets viendront si besoin
|
||||
|
||||
|
||||
class Ban(models.Model):
|
||||
""" Bannissement. Actuellement a un effet tout ou rien.
|
||||
Gagnerait à être granulaire"""
|
||||
PRETTY_NAME = "Liste des bannissements"
|
||||
|
||||
STATE_HARD = 0
|
||||
STATE_SOFT = 1
|
||||
STATE_BRIDAGE = 2
|
||||
STATES = (
|
||||
(0, 'HARD (aucun accès)'),
|
||||
(1, 'SOFT (accès local seulement)'),
|
||||
(2, 'BRIDAGE (bridage du débit)'),
|
||||
)
|
||||
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
raison = models.CharField(max_length=255)
|
||||
date_start = models.DateTimeField(auto_now_add=True)
|
||||
date_end = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
|
||||
state = models.IntegerField(choices=STATES, default=STATE_HARD)
|
||||
ban_type = models.ForeignKey(BanType)
|
||||
|
||||
def notif_ban(self):
|
||||
""" Prend en argument un objet ban, envoie un mail de notification """
|
||||
|
|
Loading…
Reference in a new issue