8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Fix erreurs, création alias mails

This commit is contained in:
chirac 2018-06-29 17:45:21 +02:00 committed by Maël Kervella
parent ec3cb33a69
commit 283cdcace3
5 changed files with 47 additions and 14 deletions

View file

@ -597,7 +597,7 @@ class MailAliasForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
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:
model = MailAlias

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

View file

@ -53,6 +53,7 @@ from django.db import models
from django.db.models import Q
from django import forms
from django.db.models.signals import post_save, post_delete, m2m_changed
from django.forms import ValidationError
from django.dispatch import receiver
from django.utils.functional import cached_property
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
pas les contraintes unix (maj, min, chiffres ou tiret)"""
if not linux_user_check(login):
raise forms.ValidationError(
raise ValidationError(
", ce pseudo ('%(label)s') contient des carractères interdits",
params={'label': login},
)
@ -1646,12 +1647,12 @@ class MailAlias(RevMixin, AclMixin, models.Model):
mail = models.ForeignKey(
'Mail',
on_delete=models.CASCADE,
help_text="Objects Mail associé"
help_text="Compte mail",
)
valeur = models.CharField(
unique=True,
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
"""
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
else:
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'):
return True, None
else:
if user_request == self.mail.user:
if self.valeur == self.mail.user.pseudo:
if user_request == self.user:
if self.valeur != self.user.pseudo:
return True, None
else:
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'):
return True, None
else:
if user_request == self.mail.user:
if self.valeur == self.mail.user.pseudo:
if user_request == self.user:
if self.valeur != self.user.pseudo:
return True, None
else:
return False, "Vous ne pouvez pas modifier l'alias lié à votre pseudo"
else:
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)

View file

@ -67,7 +67,7 @@ urlpatterns = [
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'^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'^edit_school/(?P<schoolid>[0-9]+)$',
views.edit_school,

View file

@ -513,7 +513,6 @@ def add_mailalias(request, user, userid):
'users:profil',
kwargs={'userid': str(userid)}
))
return form(
{'userform': mailalias, 'action_name': 'Ajouter un alias mail'},
'users/user.html',
@ -532,7 +531,10 @@ def edit_mailalias(request, mailalias_instance, **_kwargs):
if mailalias.changed_data:
mailalias.save()
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(
{'userform': mailalias, 'action_name': 'Editer un alias mail'},
'users/user.html',
@ -548,7 +550,7 @@ def del_mailalias(request, mailalias, **_kwargs):
messages.success(request, "L'alias a été supprimé")
return redirect(reverse(
'users:profil',
kwargs={'userid': str(mailalias.mail.user.id)}
kwargs={'userid': str(mailalias.user.id)}
))
return form(
{'objet': mailalias, 'objet_name': 'mailalias'},