8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Ajout de l'extension mail dans preference et debut de frontend

This commit is contained in:
grisel-davy 2018-06-26 22:27:33 +02:00
parent 99bd78aabe
commit 8105a61324
11 changed files with 132 additions and 44 deletions

View file

@ -266,7 +266,6 @@ class ExtensionForm(FormRevMixin, ModelForm):
self.fields['origin'].label = 'Enregistrement A origin'
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
self.fields['soa'].label = 'En-tête SOA à utiliser'
self.fielss['mail_extension'].label = 'Utilisable comme extension mail'
class DelExtensionForm(FormRevMixin, Form):

View file

@ -641,10 +641,6 @@ class Extension(RevMixin, AclMixin, models.Model):
'SOA',
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:
permissions = (

View 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),
),
]

View file

@ -31,6 +31,7 @@ from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.cache import cache
from django.forms import ValidationError
import cotisations.models
import machines.models
from re2o.mixins import AclMixin
@ -102,6 +103,11 @@ class OptionalUser(AclMixin, PreferencesModel):
blank=True,
null=True
)
mail_extension = models.CharField(
max_length = 32,
default = "@example.org",
help_text="Extension principale pour les mails internes",
)
class Meta:
permissions = (
@ -109,13 +115,18 @@ class OptionalUser(AclMixin, PreferencesModel):
)
def clean(self):
"""Creation du mode de paiement par solde"""
"""Clean du model:
Creation du mode de paiement par solde
Vérifie que l'extension mail commence bien par @
"""
if self.user_solde:
p = cotisations.models.Paiement.objects.filter(moyen="Solde")
if not len(p):
c = cotisations.models.Paiement(moyen="Solde")
c.save()
if self.mail_extension[0] != "@":
raise ValidationError("L'extension mail doit commencer par un @")
@receiver(post_save, sender=OptionalUser)
def optionaluser_post_save(**kwargs):

View file

@ -71,6 +71,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Shell par défaut des utilisateurs</th>
<td>{{ useroptions.shell_default }}</td>
</tr>
<tr>
<th>Extension mail interne</th>
<td>{{ useroptions.mail_extension }}</td>
</tr>
</table>
<h4>Préférences machines</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalMachine' %}">

View file

@ -127,7 +127,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
list_display = (
'pseudo',
'surname',
'email',
'school',
'is_admin',
'shell'
@ -141,7 +140,7 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
'Personal info',
{
'fields':
('surname', 'email', 'school', 'shell', 'uid_number')
('surname', 'school', 'shell', 'uid_number')
}
),
('Permissions', {'fields': ('is_admin', )}),
@ -156,7 +155,6 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
'fields': (
'pseudo',
'surname',
'email',
'school',
'is_admin',
'password1',

View file

@ -140,7 +140,7 @@ class UserCreationForm(FormRevMixin, forms.ModelForm):
class Meta:
model = Adherent
fields = ('pseudo', 'surname', 'email')
fields = ('pseudo', 'surname')
def clean_password2(self):
"""Verifie que password1 et 2 sont identiques"""
@ -220,7 +220,7 @@ class UserChangeForm(FormRevMixin, forms.ModelForm):
class Meta:
model = Adherent
fields = ('pseudo', 'password', 'surname', 'email')
fields = ('pseudo', 'password', 'surname')
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
@ -313,7 +313,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'name',
'surname',
'pseudo',
'email',
'school',
'comment',
'room',
@ -365,7 +364,6 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
fields = [
'surname',
'pseudo',
'email',
'school',
'comment',
'room',

View 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),
),
]

View 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)
]

View file

@ -79,7 +79,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
from re2o.mixins import AclMixin, RevMixin
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 OptionalMachine, MailMessageOption
@ -134,7 +134,6 @@ class UserManager(BaseUserManager):
self,
pseudo,
surname,
email,
password=None,
su=False
):
@ -148,7 +147,6 @@ class UserManager(BaseUserManager):
pseudo=pseudo,
surname=surname,
name=surname,
email=self.normalize_email(email),
)
user.set_password(password)
@ -157,19 +155,19 @@ class UserManager(BaseUserManager):
user.save(using=self._db)
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,
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,
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,
@ -188,19 +186,13 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
)
surname = models.CharField(max_length=255)
email = models.EmailField()
pseudo = models.CharField(
max_length=32,
unique=True,
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
validators=[linux_user_validator]
)
email = models.EmailField()
"""
email= models.OneToOneField(
Mail,
on_delete=models.PROTECT
)
"""
school = models.ForeignKey(
'School',
on_delete=models.PROTECT,
@ -233,7 +225,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
)
USERNAME_FIELD = 'pseudo'
REQUIRED_FIELDS = ['surname', 'email']
REQUIRED_FIELDS = ['surname']
objects = UserManager()
@ -680,10 +672,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"""
Return the mail address choosen by the user
"""
if not self.mail.internal_activated:
return(self.mail.external)
if not self.mail.internal_address:
return self.mail.external_mail
else:
return(self.mail.mailalias_set.first())
return self.mail.mailalias_set.get(valeur=pseudo)
def get_next_domain_name(self):
"""Look for an available name for a new interface for
@ -1601,7 +1593,7 @@ class Mail(RevMixin, AclMixin, models.Model):
Compte mail d'un utilisateur
"""
external_mail = models.EmailField(help_text="Mail externe")
user = models.ForeignKey(
user = models.OneToOneField(
'User',
on_delete=models.CASCADE,
help_text="Object mail d'un User"
@ -1614,7 +1606,7 @@ class Mail(RevMixin, AclMixin, models.Model):
)
def __str__(self):
return self.mail
return self.user.get_mail()
class MailAlias(RevMixin, AclMixin, models.Model):
@ -1629,20 +1621,14 @@ class MailAlias(RevMixin, AclMixin, models.Model):
help_text="Objects Mail associé"
)
valeur = models.CharField(
unique=True,
max_length=64,
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):
return self.valeur + "@" + self.extension
return self.valeur + OptionalUser.get_cached_value('mail_extension')
def can_view(self, user_request, *_args, **_kwargs):
"""
@ -1663,7 +1649,7 @@ class MailAlias(RevMixin, AclMixin, models.Model):
return True, None
else:
if user_request == self.mail.user:
if self.id != 0:
if self.valeur == self.mail.user.pseudo:
return True, None
else:
return False, "Vous ne pouvez pas supprimer l'alias lié à votre pseudo"
@ -1679,7 +1665,7 @@ class MailAlias(RevMixin, AclMixin, models.Model):
return True, None
else:
if user_request == self.mail.user:
if self.id != 0:
if self.valeur == self.mail.user.pseudo:
return True, None
else:
return False, "Vous ne pouvez pas modifier l'alias lié à votre pseudo"

View file

@ -80,6 +80,8 @@ from .models import (
Adherent,
Club,
ListShell,
MailAlias,
Mail,
)
from .forms import (
BanForm,