mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 08:23:46 +00:00
Fix erreurs, création alias mails
This commit is contained in:
parent
ec3cb33a69
commit
283cdcace3
5 changed files with 47 additions and 14 deletions
|
@ -597,7 +597,7 @@ class MailAliasForm(FormRevMixin, ModelForm):
|
||||||
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__)
|
||||||
super(MailAliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(MailAliasForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['valeur'].label = 'nom de l\'adresse mail'
|
self.fields['valeur'].label = "Prefixe de l'alias mail. Ne peut contenir de @"
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MailAlias
|
model = MailAlias
|
||||||
|
|
27
users/migrations/0074_auto_20180629_1717.py
Normal file
27
users/migrations/0074_auto_20180629_1717.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-06-29 15:17
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0073_auto_20180629_1614'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='mailalias',
|
||||||
|
name='user',
|
||||||
|
field=models.ForeignKey(help_text='Utilisateur associé', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='mailalias',
|
||||||
|
name='valeur',
|
||||||
|
field=models.CharField(help_text="Valeur de l'alias mail", max_length=64, unique=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -53,6 +53,7 @@ from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.db.models.signals import post_save, post_delete, m2m_changed
|
from django.db.models.signals import post_save, post_delete, m2m_changed
|
||||||
|
from django.forms import ValidationError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
|
@ -97,7 +98,7 @@ def linux_user_validator(login):
|
||||||
""" Retourne une erreur de validation si le login ne respecte
|
""" Retourne une erreur de validation si le login ne respecte
|
||||||
pas les contraintes unix (maj, min, chiffres ou tiret)"""
|
pas les contraintes unix (maj, min, chiffres ou tiret)"""
|
||||||
if not linux_user_check(login):
|
if not linux_user_check(login):
|
||||||
raise forms.ValidationError(
|
raise ValidationError(
|
||||||
", ce pseudo ('%(label)s') contient des carractères interdits",
|
", ce pseudo ('%(label)s') contient des carractères interdits",
|
||||||
params={'label': login},
|
params={'label': login},
|
||||||
)
|
)
|
||||||
|
@ -1646,12 +1647,12 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
mail = models.ForeignKey(
|
mail = models.ForeignKey(
|
||||||
'Mail',
|
'Mail',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
help_text="Objects Mail associé"
|
help_text="Compte mail",
|
||||||
)
|
)
|
||||||
valeur = models.CharField(
|
valeur = models.CharField(
|
||||||
unique=True,
|
unique=True,
|
||||||
max_length=64,
|
max_length=64,
|
||||||
help_text="username de l'adresse mail"
|
help_text="Valeur de l'alias mail"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1663,7 +1664,7 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
Check if the user can view the aliases
|
Check if the user can view the aliases
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if user_request.has_perm('users.view_mailalias') or user.request == self.mail.user:
|
if user_request.has_perm('users.view_mailalias') or user.request == self.user:
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
return False, "Vous n'avais pas les droits suffisants et n'êtes pas propriétaire de ces alias"
|
return False, "Vous n'avais pas les droits suffisants et n'êtes pas propriétaire de ces alias"
|
||||||
|
@ -1676,8 +1677,8 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
if user_request.has_perm('users.delete_mailalias'):
|
if user_request.has_perm('users.delete_mailalias'):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
if user_request == self.mail.user:
|
if user_request == self.user:
|
||||||
if self.valeur == self.mail.user.pseudo:
|
if self.valeur != self.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"
|
||||||
|
@ -1692,13 +1693,16 @@ class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
if user_request.has_perm('users.change_mailalias'):
|
if user_request.has_perm('users.change_mailalias'):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
if user_request == self.mail.user:
|
if user_request == self.user:
|
||||||
if self.valeur == self.mail.user.pseudo:
|
if self.valeur != self.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"
|
||||||
else:
|
else:
|
||||||
return False, "Vous n'avez pas les droits suffisants et n'êtes pas propriétairs de cet alias"
|
return False, "Vous n'avez pas les droits suffisants et n'êtes pas propriétairs de cet alias"
|
||||||
|
|
||||||
|
def clean(self, *args, **kwargs):
|
||||||
|
if "@" in self.valeur:
|
||||||
|
raise ValidationError("Cet alias ne peut contenir un @")
|
||||||
|
super(MailAlias, self).clean(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ urlpatterns = [
|
||||||
url(r'^add_mailalias/(?P<userid>[0-9]+)$', views.add_mailalias, name='add-mailalias'),
|
url(r'^add_mailalias/(?P<userid>[0-9]+)$', views.add_mailalias, name='add-mailalias'),
|
||||||
url(r'^edit_mailalias/(?P<mailaliasid>[0-9]+)$', views.edit_mailalias, name='edit-mailalias'),
|
url(r'^edit_mailalias/(?P<mailaliasid>[0-9]+)$', views.edit_mailalias, name='edit-mailalias'),
|
||||||
url(r'^del-mailalias/(?P<mailaliasid>[0-9]+)$', views.del_mailalias, name='del-mailalias'),
|
url(r'^del-mailalias/(?P<mailaliasid>[0-9]+)$', views.del_mailalias, name='del-mailalias'),
|
||||||
url(r'^edit_mail/(?P<mailid>[0-9]+)$', views.edit_mail, name='edit-mail'),
|
url(r'^edit_mail/(?P<userid>[0-9]+)$', views.edit_mail, name='edit-mail'),
|
||||||
url(r'^add_school/$', views.add_school, name='add-school'),
|
url(r'^add_school/$', views.add_school, name='add-school'),
|
||||||
url(r'^edit_school/(?P<schoolid>[0-9]+)$',
|
url(r'^edit_school/(?P<schoolid>[0-9]+)$',
|
||||||
views.edit_school,
|
views.edit_school,
|
||||||
|
|
|
@ -513,7 +513,6 @@ def add_mailalias(request, user, userid):
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid': str(userid)}
|
kwargs={'userid': str(userid)}
|
||||||
))
|
))
|
||||||
|
|
||||||
return form(
|
return form(
|
||||||
{'userform': mailalias, 'action_name': 'Ajouter un alias mail'},
|
{'userform': mailalias, 'action_name': 'Ajouter un alias mail'},
|
||||||
'users/user.html',
|
'users/user.html',
|
||||||
|
@ -532,7 +531,10 @@ def edit_mailalias(request, mailalias_instance, **_kwargs):
|
||||||
if mailalias.changed_data:
|
if mailalias.changed_data:
|
||||||
mailalias.save()
|
mailalias.save()
|
||||||
messages.success(request, "Alias modifiée")
|
messages.success(request, "Alias modifiée")
|
||||||
return redirect(reverse('users:index'))
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': str(mailalias_instance.user.id)}
|
||||||
|
))
|
||||||
return form(
|
return form(
|
||||||
{'userform': mailalias, 'action_name': 'Editer un alias mail'},
|
{'userform': mailalias, 'action_name': 'Editer un alias mail'},
|
||||||
'users/user.html',
|
'users/user.html',
|
||||||
|
@ -548,7 +550,7 @@ def del_mailalias(request, mailalias, **_kwargs):
|
||||||
messages.success(request, "L'alias a été supprimé")
|
messages.success(request, "L'alias a été supprimé")
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'users:profil',
|
'users:profil',
|
||||||
kwargs={'userid': str(mailalias.mail.user.id)}
|
kwargs={'userid': str(mailalias.user.id)}
|
||||||
))
|
))
|
||||||
return form(
|
return form(
|
||||||
{'objet': mailalias, 'objet_name': 'mailalias'},
|
{'objet': mailalias, 'objet_name': 'mailalias'},
|
||||||
|
|
Loading…
Reference in a new issue