mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 09:26:27 +00:00
Ajout de l'extension mail dans preference et debut de frontend
This commit is contained in:
parent
7c1a674491
commit
099e7ff875
11 changed files with 134 additions and 42 deletions
|
@ -262,7 +262,6 @@ class ExtensionForm(FormRevMixin, ModelForm):
|
||||||
self.fields['origin'].label = 'Enregistrement A origin'
|
self.fields['origin'].label = 'Enregistrement A origin'
|
||||||
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
|
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
|
||||||
self.fields['soa'].label = 'En-tête SOA à utiliser'
|
self.fields['soa'].label = 'En-tête SOA à utiliser'
|
||||||
self.fielss['mail_extension'].label = 'Utilisable comme extension mail'
|
|
||||||
|
|
||||||
|
|
||||||
class DelExtensionForm(FormRevMixin, Form):
|
class DelExtensionForm(FormRevMixin, Form):
|
||||||
|
|
|
@ -546,10 +546,6 @@ class Extension(RevMixin, AclMixin, models.Model):
|
||||||
'SOA',
|
'SOA',
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
mail_extension = models.BooleanField(
|
|
||||||
default=False,
|
|
||||||
help_text="Determine si l'extension peut être utilisée comme extension mail interne"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
|
20
preferences/migrations/0035_optionaluser_mail_extension.py
Normal file
20
preferences/migrations/0035_optionaluser_mail_extension.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-06-26 19:31
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('preferences', '0034_auto_20180416_1120'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='optionaluser',
|
||||||
|
name='mail_extension',
|
||||||
|
field=models.CharField(default='@example.org', help_text='Extension principale pour les mails internes', max_length=32),
|
||||||
|
),
|
||||||
|
]
|
|
@ -31,6 +31,8 @@ from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
from django.forms import ValidationError
|
||||||
|
import cotisations.models
|
||||||
import machines.models
|
import machines.models
|
||||||
from re2o.mixins import AclMixin
|
from re2o.mixins import AclMixin
|
||||||
|
|
||||||
|
@ -83,12 +85,25 @@ class OptionalUser(AclMixin, PreferencesModel):
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
mail_extension = models.CharField(
|
||||||
|
max_length = 32,
|
||||||
|
default = "@example.org",
|
||||||
|
help_text="Extension principale pour les mails internes",
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
("view_optionaluser", "Peut voir les options de l'user"),
|
("view_optionaluser", "Peut voir les options de l'user"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
"""Clean du model:
|
||||||
|
Creation du mode de paiement par solde
|
||||||
|
Vérifie que l'extension mail commence bien par @
|
||||||
|
"""
|
||||||
|
if self.mail_extension[0] != "@":
|
||||||
|
raise ValidationError("L'extension mail doit commencer par un @")
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=OptionalUser)
|
@receiver(post_save, sender=OptionalUser)
|
||||||
def optionaluser_post_save(**kwargs):
|
def optionaluser_post_save(**kwargs):
|
||||||
|
|
|
@ -56,6 +56,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<th>Creations de clubs par tous</th>
|
<th>Creations de clubs par tous</th>
|
||||||
<td>{{ useroptions.all_can_create_club|tick }}</td>
|
<td>{{ useroptions.all_can_create_club|tick }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>Extension mail interne</th>
|
||||||
|
<td>{{ useroptions.mail_extension }}</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'pseudo',
|
'pseudo',
|
||||||
'surname',
|
'surname',
|
||||||
'email',
|
|
||||||
'school',
|
'school',
|
||||||
'is_admin',
|
'is_admin',
|
||||||
'shell'
|
'shell'
|
||||||
|
@ -141,7 +140,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
'Personal info',
|
'Personal info',
|
||||||
{
|
{
|
||||||
'fields':
|
'fields':
|
||||||
('surname', 'email', 'school', 'shell', 'uid_number')
|
('surname', 'school', 'shell', 'uid_number')
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
('Permissions', {'fields': ('is_admin', )}),
|
('Permissions', {'fields': ('is_admin', )}),
|
||||||
|
@ -156,7 +155,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
|
||||||
'fields': (
|
'fields': (
|
||||||
'pseudo',
|
'pseudo',
|
||||||
'surname',
|
'surname',
|
||||||
'email',
|
|
||||||
'school',
|
'school',
|
||||||
'is_admin',
|
'is_admin',
|
||||||
'password1',
|
'password1',
|
||||||
|
|
|
@ -140,7 +140,7 @@ class UserCreationForm(FormRevMixin, forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Adherent
|
model = Adherent
|
||||||
fields = ('pseudo', 'surname', 'email')
|
fields = ('pseudo', 'surname')
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
"""Verifie que password1 et 2 sont identiques"""
|
"""Verifie que password1 et 2 sont identiques"""
|
||||||
|
@ -220,7 +220,7 @@ class UserChangeForm(FormRevMixin, forms.ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Adherent
|
model = Adherent
|
||||||
fields = ('pseudo', 'password', 'surname', 'email')
|
fields = ('pseudo', 'password', 'surname')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
@ -313,7 +313,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
'name',
|
'name',
|
||||||
'surname',
|
'surname',
|
||||||
'pseudo',
|
'pseudo',
|
||||||
'email',
|
|
||||||
'school',
|
'school',
|
||||||
'comment',
|
'comment',
|
||||||
'room',
|
'room',
|
||||||
|
@ -365,7 +364,6 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
fields = [
|
fields = [
|
||||||
'surname',
|
'surname',
|
||||||
'pseudo',
|
'pseudo',
|
||||||
'email',
|
|
||||||
'school',
|
'school',
|
||||||
'comment',
|
'comment',
|
||||||
'room',
|
'room',
|
||||||
|
|
38
users/migrations/0073_mail_mailalias.py
Normal file
38
users/migrations/0073_mail_mailalias.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-06-26 19:07
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import re2o.mixins
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0072_auto_20180426_2021'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Mail',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('external_mail', models.EmailField(help_text='Mail externe', max_length=254)),
|
||||||
|
('redirection', models.BooleanField(default=False)),
|
||||||
|
('internal_address', models.BooleanField(default=False)),
|
||||||
|
('user', models.OneToOneField(help_text="Object mail d'un User", on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='MailAlias',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('valeur', models.CharField(help_text="username de l'adresse mail", max_length=64, unique=True)),
|
||||||
|
('mail', models.ForeignKey(help_text='Objects Mail associé', on_delete=django.db.models.deletion.CASCADE, to='users.Mail')),
|
||||||
|
],
|
||||||
|
bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model),
|
||||||
|
),
|
||||||
|
]
|
36
users/migrations/0074_transfermail.py
Normal file
36
users/migrations/0074_transfermail.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-06-26 18:34
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0073_mail_mailalias'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def create_mail(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
user = apps.get_model('users','User')
|
||||||
|
mail = apps.get_model('users','Mail')
|
||||||
|
mailalias = apps.get_model('users','MailAlias')
|
||||||
|
users = user.objects.using(db_alias).all()
|
||||||
|
for us in users:
|
||||||
|
ma = mail()
|
||||||
|
ma.user=us
|
||||||
|
ma.external_mail = us.email
|
||||||
|
ma.save()
|
||||||
|
al = mailalias()
|
||||||
|
al.mail = ma
|
||||||
|
al.valeur = us.pseudo
|
||||||
|
al.save()
|
||||||
|
|
||||||
|
def uncreatemail(apps,schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(create_mail, uncreatemail)
|
||||||
|
]
|
|
@ -79,7 +79,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
|
||||||
from re2o.mixins import AclMixin, RevMixin
|
from re2o.mixins import AclMixin, RevMixin
|
||||||
|
|
||||||
from cotisations.models import Cotisation, Facture, Paiement, Vente
|
from cotisations.models import Cotisation, Facture, Paiement, Vente
|
||||||
from machines.models import Domain, Interface, Machine, regen, Extension
|
from machines.models import Domain, Interface, Machine, regen
|
||||||
from preferences.models import GeneralOption, AssoOption, OptionalUser
|
from preferences.models import GeneralOption, AssoOption, OptionalUser
|
||||||
from preferences.models import OptionalMachine, MailMessageOption
|
from preferences.models import OptionalMachine, MailMessageOption
|
||||||
|
|
||||||
|
@ -134,7 +134,6 @@ class UserManager(BaseUserManager):
|
||||||
self,
|
self,
|
||||||
pseudo,
|
pseudo,
|
||||||
surname,
|
surname,
|
||||||
email,
|
|
||||||
password=None,
|
password=None,
|
||||||
su=False
|
su=False
|
||||||
):
|
):
|
||||||
|
@ -148,7 +147,6 @@ class UserManager(BaseUserManager):
|
||||||
pseudo=pseudo,
|
pseudo=pseudo,
|
||||||
surname=surname,
|
surname=surname,
|
||||||
name=surname,
|
name=surname,
|
||||||
email=self.normalize_email(email),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
|
@ -157,19 +155,19 @@ class UserManager(BaseUserManager):
|
||||||
user.save(using=self._db)
|
user.save(using=self._db)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def create_user(self, pseudo, surname, email, password=None):
|
def create_user(self, pseudo, surname, password=None):
|
||||||
"""
|
"""
|
||||||
Creates and saves a User with the given pseudo, name, surname, email,
|
Creates and saves a User with the given pseudo, name, surname, email,
|
||||||
and password.
|
and password.
|
||||||
"""
|
"""
|
||||||
return self._create_user(pseudo, surname, email, password, False)
|
return self._create_user(pseudo, surname, password, False)
|
||||||
|
|
||||||
def create_superuser(self, pseudo, surname, email, password):
|
def create_superuser(self, pseudo, surname, password):
|
||||||
"""
|
"""
|
||||||
Creates and saves a superuser with the given pseudo, name, surname,
|
Creates and saves a superuser with the given pseudo, name, surname,
|
||||||
email, and password.
|
email, and password.
|
||||||
"""
|
"""
|
||||||
return self._create_user(pseudo, surname, email, password, True)
|
return self._create_user(pseudo, surname, password, True)
|
||||||
|
|
||||||
|
|
||||||
class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
|
@ -188,19 +186,13 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
)
|
)
|
||||||
|
|
||||||
surname = models.CharField(max_length=255)
|
surname = models.CharField(max_length=255)
|
||||||
|
email = models.EmailField()
|
||||||
pseudo = models.CharField(
|
pseudo = models.CharField(
|
||||||
max_length=32,
|
max_length=32,
|
||||||
unique=True,
|
unique=True,
|
||||||
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
|
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
|
||||||
validators=[linux_user_validator]
|
validators=[linux_user_validator]
|
||||||
)
|
)
|
||||||
email = models.EmailField()
|
|
||||||
"""
|
|
||||||
email= models.OneToOneField(
|
|
||||||
Mail,
|
|
||||||
on_delete=models.PROTECT
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
school = models.ForeignKey(
|
school = models.ForeignKey(
|
||||||
'School',
|
'School',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
|
@ -233,7 +225,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
)
|
)
|
||||||
|
|
||||||
USERNAME_FIELD = 'pseudo'
|
USERNAME_FIELD = 'pseudo'
|
||||||
REQUIRED_FIELDS = ['surname', 'email']
|
REQUIRED_FIELDS = ['surname']
|
||||||
|
|
||||||
objects = UserManager()
|
objects = UserManager()
|
||||||
|
|
||||||
|
@ -686,10 +678,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
"""
|
"""
|
||||||
Return the mail address choosen by the user
|
Return the mail address choosen by the user
|
||||||
"""
|
"""
|
||||||
if not self.mail.internal_activated:
|
if not self.mail.internal_address:
|
||||||
return(self.mail.external)
|
return self.mail.external_mail
|
||||||
else:
|
else:
|
||||||
return(self.mail.mailalias_set.first())
|
return self.mail.mailalias_set.get(valeur=pseudo)
|
||||||
|
|
||||||
def get_next_domain_name(self):
|
def get_next_domain_name(self):
|
||||||
"""Look for an available name for a new interface for
|
"""Look for an available name for a new interface for
|
||||||
|
@ -1619,7 +1611,7 @@ class Mail(RevMixin, AclMixin, models.Model):
|
||||||
Compte mail d'un utilisateur
|
Compte mail d'un utilisateur
|
||||||
"""
|
"""
|
||||||
external_mail = models.EmailField(help_text="Mail externe")
|
external_mail = models.EmailField(help_text="Mail externe")
|
||||||
user = models.ForeignKey(
|
user = models.OneToOneField(
|
||||||
'User',
|
'User',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
help_text="Object mail d'un User"
|
help_text="Object mail d'un User"
|
||||||
|
@ -1632,7 +1624,7 @@ class Mail(RevMixin, AclMixin, models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.mail
|
return self.user.get_mail()
|
||||||
|
|
||||||
|
|
||||||
class MailAlias(RevMixin, AclMixin, models.Model):
|
class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
|
@ -1647,20 +1639,14 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
help_text="Objects Mail associé"
|
help_text="Objects Mail associé"
|
||||||
)
|
)
|
||||||
valeur = models.CharField(
|
valeur = models.CharField(
|
||||||
|
unique=True,
|
||||||
max_length=64,
|
max_length=64,
|
||||||
help_text="username de l'adresse mail"
|
help_text="username de l'adresse mail"
|
||||||
)
|
)
|
||||||
extension = models.ForeignKey(
|
|
||||||
'machines.Extension',
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
help_text="Extension mail interne"
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
unique_together = ('valeur', 'extension',)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.valeur + "@" + self.extension
|
return self.valeur + OptionalUser.get_cached_value('mail_extension')
|
||||||
|
|
||||||
def can_view(self, user_request, *_args, **_kwargs):
|
def can_view(self, user_request, *_args, **_kwargs):
|
||||||
"""
|
"""
|
||||||
|
@ -1681,7 +1667,7 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
if user_request == self.mail.user:
|
if user_request == self.mail.user:
|
||||||
if self.id != 0:
|
if self.valeur == self.mail.user.pseudo:
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
return False, "Vous ne pouvez pas supprimer l'alias lié à votre pseudo"
|
return False, "Vous ne pouvez pas supprimer l'alias lié à votre pseudo"
|
||||||
|
@ -1697,7 +1683,7 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
if user_request == self.mail.user:
|
if user_request == self.mail.user:
|
||||||
if self.id != 0:
|
if self.valeur == self.mail.user.pseudo:
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
return False, "Vous ne pouvez pas modifier l'alias lié à votre pseudo"
|
return False, "Vous ne pouvez pas modifier l'alias lié à votre pseudo"
|
||||||
|
|
|
@ -81,6 +81,8 @@ from .models import (
|
||||||
Adherent,
|
Adherent,
|
||||||
Club,
|
Club,
|
||||||
ListShell,
|
ListShell,
|
||||||
|
MailAlias,
|
||||||
|
Mail,
|
||||||
)
|
)
|
||||||
from .forms import (
|
from .forms import (
|
||||||
BanForm,
|
BanForm,
|
||||||
|
|
Loading…
Reference in a new issue