diff --git a/users/forms.py b/users/forms.py
index a3459eac..91b8d6dc 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -53,6 +53,7 @@ from .models import (
School,
ListRight,
Whitelist,
+ Mail,
MailAlias,
ListShell,
Ban,
@@ -597,8 +598,20 @@ class MailAliasForm(FormRevMixin, ModelForm):
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['extension'].label = 'extension de l\'adresse mail'
class Meta:
model = MailAlias
exclude = ['mail']
+
+class MailForm(FormRevMixin, ModelForm):
+ """Creation, edition d'un objet mail"""
+ def __init__(self, *args, **kwargs):
+ prefix = kwargs.pop('prefix', self.Meta.model.__name__)
+ super(MailForm, self).__init__(*args, prefix=prefix, **kwargs)
+ self.fields['external_mail'].label = 'Adresse mail externe'
+ self.fields['redirection'].label = 'Activation de la redirection vers l\'adress externe'
+ self.fields['internal_address'].label = 'Adresse mail interne'
+
+ class Meta:
+ model = Mail
+ exclude = ['user']
diff --git a/users/models.py b/users/models.py
index bbdbef58..018e1994 100644
--- a/users/models.py
+++ b/users/models.py
@@ -681,7 +681,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
if not self.mail.internal_address:
return self.mail.external_mail
else:
- return self.mail.mailalias_set.get(valeur=pseudo)
+ return self.mail.mailalias_set.get(valeur=self.pseudo)
def get_next_domain_name(self):
"""Look for an available name for a new interface for
@@ -1626,6 +1626,16 @@ class Mail(RevMixin, AclMixin, models.Model):
def __str__(self):
return self.user.get_mail()
+ def can_edit(self, user_request, *_args, **_kwargs):
+ """
+ Check if the user can edit the mail
+ """
+
+ if user_request.has_perm('users.change_mail') or user_request == self.user:
+ return True, None
+ else:
+ return False, "Vous n'avez pas les droits suffisants et n'êtes pas propriétairs de cet alias"
+
class MailAlias(RevMixin, AclMixin, models.Model):
"""
diff --git a/users/templates/users/aff_alias.html b/users/templates/users/aff_alias.html
index 59a9b6f1..ec5b7313 100644
--- a/users/templates/users/aff_alias.html
+++ b/users/templates/users/aff_alias.html
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if alias_list.paginator %}
{% include "pagination.html" with list=alias_list %}
{% endif %}
-
@@ -37,10 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{{ alias }} |
{% can_delete alias %}
- {% include 'buttons/suppr.html' with href='users:del-alias' id=alias.id %}
+ {% include 'buttons/suppr.html' with href='users:del-mailalias' id=alias.id %}
{% acl_end %}
{% can_edit alias %}
- {% include 'buttons/edit.html' with href='users:edit-alias' id=alias.id %}
+ {% include 'buttons/edit.html' with href='users:edit-mailalias' id=alias.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='users:history' name='alias' id=alias.id %}
|
diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html
index 6e960fc2..acc2c1c9 100644
--- a/users/templates/users/profil.html
+++ b/users/templates/users/profil.html
@@ -406,6 +406,46 @@ with this program; if not, write to the Free Software Foundation, Inc.,
+
+
+
+
+ Gestion des mails
+
+
+
+
+ {% can_edit user.mail %}
+
+
+ Modifier les options mail
+
+ {% acl_end %}
+
+
+
+ Adresse mail externe |
+ Compte mail {{ asso_name }} |
+ Adresse mail de contact |
+
+
+ {{ user.mail.external_mail }} |
+ {{ user.mail.internal_address|yesno:"Activé,Désactivé" }} |
+ {{ user.mail.external_mail }} |
+
+
+ {% can_create MailAlias %}
+
+
+ Ajouter un alias mail
+
+ {% acl_end %}
+ {% if alias_list %}
+ {% include "users/aff_alias.html" with alias_list=alias_list %}
+ {% endif %}
+
+
+
diff --git a/users/urls.py b/users/urls.py
index c8284d4e..5aaf893e 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -67,6 +67,7 @@ urlpatterns = [
url(r'^add_mailalias/(?P[0-9]+)$', views.add_mailalias, name='add-mailalias'),
url(r'^edit_mailalias/(?P[0-9]+)$', views.edit_mailalias, name='edit-mailalias'),
url(r'^del-mailalias/(?P[0-9]+)$', views.del_mailalias, name='del-mailalias'),
+ url(r'^edit_mail/(?P[0-9]+)$', views.edit_mail, name='edit-mail'),
url(r'^add_school/$', views.add_school, name='add-school'),
url(r'^edit_school/(?P[0-9]+)$',
views.edit_school,
diff --git a/users/views.py b/users/views.py
index c8061040..a6a79093 100644
--- a/users/views.py
+++ b/users/views.py
@@ -87,6 +87,8 @@ from .models import (
from .forms import (
BanForm,
WhitelistForm,
+ MailAliasForm,
+ MailForm,
DelSchoolForm,
DelListRightForm,
NewListRightForm,
@@ -500,12 +502,12 @@ def del_whitelist(request, whitelist, **_kwargs):
def add_mailalias(request, user, userid):
""" Créer un alias """
mailalias_instance = MailAlias(mail=user.mail)
- whitelist = WhitelistForm(
+ mailalias = MailAliasForm(
request.POST or None,
- instance=whitelist_instance
+ instance=mailalias_instance
)
- if whitelist.is_valid():
- whitelist.save()
+ if mailalias.is_valid():
+ mailalias.save()
messages.success(request, "Alias créé")
return redirect(reverse(
'users:profil',
@@ -526,9 +528,9 @@ def edit_mailalias(request, mailalias_instance, **_kwargs):
request.POST or None,
instance=mailalias_instance
)
- if whitelist.is_valid():
- if whitelist.changed_data:
- whitelist.save()
+ if mailalias.is_valid():
+ if mailalias.changed_data:
+ mailalias.save()
messages.success(request, "Alias modifiée")
return redirect(reverse('users:index'))
return form(
@@ -554,6 +556,25 @@ def del_mailalias(request, mailalias, **_kwargs):
request
)
+@login_required
+@can_edit(Mail)
+def edit_mail(request, mail_instance, **_kwargs):
+ """ Editer un compte mail"""
+ mail = MailForm(
+ request.POST or None,
+ instance=mail_instance
+ )
+ if mail.is_valid():
+ if mail.changed_data:
+ mail.save()
+ messages.success(request, "Compte mail modifiée")
+ return redirect(reverse('users:index'))
+ return form(
+ {'userform': mail, 'action_name': 'Editer un compte mail'},
+ 'users/user.html',
+ request
+ )
+
@login_required
@can_create(School)
def add_school(request):
@@ -977,6 +998,9 @@ def profil(request, users, **_kwargs):
'user_solde': user_solde,
'solde_activated': Paiement.objects.filter(is_balance=True).exists(),
'asso_name': AssoOption.objects.first().name
+ 'allow_online_payment': allow_online_payment,
+ 'asso_name': AssoOption.objects.first().name,
+ 'alias_list': users.mail.mailalias_set.all()
}
)