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

Fix erreurs, création alias mails

This commit is contained in:
chirac 2018-06-29 17:45:21 +02:00
parent 8e5d897615
commit 58a495db54
5 changed files with 46 additions and 16 deletions

View file

@ -594,7 +594,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

@ -51,7 +51,7 @@ import datetime
from django.db import models
from django.db.models import Q
from django import forms
from django.forms import ValidationError
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from django.utils.functional import cached_property
@ -97,7 +97,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},
)
@ -1606,13 +1606,11 @@ class MailAlias(RevMixin, AclMixin, models.Model):
User,
on_delete=models.CASCADE,
help_text="Utilisateur associé",
null=True,
blank=True
)
valeur = models.CharField(
unique=True,
max_length=64,
help_text="username de l'adresse mail"
help_text="Valeur de l'alias mail"
)
def __str__(self):
@ -1623,7 +1621,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"
@ -1636,8 +1634,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"
@ -1652,13 +1650,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

@ -68,7 +68,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

@ -515,7 +515,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',
@ -534,7 +533,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',
@ -550,7 +552,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'},