mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-09 03:16:25 +00:00
Affichage et modification du compte mail et des alias mail
This commit is contained in:
parent
415a393bfa
commit
1f3f557944
6 changed files with 99 additions and 13 deletions
|
@ -53,6 +53,7 @@ from .models import (
|
||||||
School,
|
School,
|
||||||
ListRight,
|
ListRight,
|
||||||
Whitelist,
|
Whitelist,
|
||||||
|
Mail,
|
||||||
MailAlias,
|
MailAlias,
|
||||||
ListShell,
|
ListShell,
|
||||||
Ban,
|
Ban,
|
||||||
|
@ -596,8 +597,20 @@ class MailAliasForm(FormRevMixin, ModelForm):
|
||||||
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 = 'nom de l\'adresse mail'
|
||||||
self.fields['extension'].label = 'extension de l\'adresse mail'
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MailAlias
|
model = MailAlias
|
||||||
exclude = ['mail']
|
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']
|
||||||
|
|
|
@ -675,7 +675,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
if not self.mail.internal_address:
|
if not self.mail.internal_address:
|
||||||
return self.mail.external_mail
|
return self.mail.external_mail
|
||||||
else:
|
else:
|
||||||
return self.mail.mailalias_set.get(valeur=pseudo)
|
return self.mail.mailalias_set.get(valeur=self.pseudo)
|
||||||
|
|
||||||
def get_next_domain_name(self):
|
def get_next_domain_name(self):
|
||||||
"""Look for an available name for a new interface for
|
"""Look for an available name for a new interface for
|
||||||
|
@ -1608,6 +1608,16 @@ class Mail(RevMixin, AclMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.get_mail()
|
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):
|
class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% if alias_list.paginator %}
|
{% if alias_list.paginator %}
|
||||||
{% include "pagination.html" with list=alias_list %}
|
{% include "pagination.html" with list=alias_list %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -37,10 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{ alias }}</td>
|
<td>{{ alias }}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{% can_delete 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 %}
|
{% acl_end %}
|
||||||
{% can_edit alias %}
|
{% 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 %}
|
{% acl_end %}
|
||||||
{% include 'buttons/history.html' with href='users:history' name='alias' id=alias.id %}
|
{% include 'buttons/history.html' with href='users:history' name='alias' id=alias.id %}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -427,6 +427,46 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading clearfix" data-parent="#accordion" data-toggle="collapse" data-target="#collapse7">
|
||||||
|
<h3 class="panel-title pull-left">
|
||||||
|
<i class="fa fa-envelope"></i>
|
||||||
|
Gestion des mails
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div id="collapse7" class="panel-collapse collapse">
|
||||||
|
<div class="panel-body">
|
||||||
|
{% can_edit user.mail %}
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-mail' users.mail.id %}">
|
||||||
|
<i class="fa fa-plus-square"></i>
|
||||||
|
Modifier les options mail
|
||||||
|
</a>
|
||||||
|
{% acl_end %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>Adresse mail externe</th>
|
||||||
|
<th>Compte mail {{ asso_name }}</th>
|
||||||
|
<th>Adresse mail de contact</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>{{ user.mail.external_mail }}</td>
|
||||||
|
<td>{{ user.mail.internal_address|yesno:"Activé,Désactivé" }}</td>
|
||||||
|
<td>{{ user.mail.external_mail }}</td>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% can_create MailAlias %}
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-mailalias' users.id %}">
|
||||||
|
<i class="fa fa-plus-square"></i>
|
||||||
|
Ajouter un alias mail
|
||||||
|
</a>
|
||||||
|
{% acl_end %}
|
||||||
|
{% if alias_list %}
|
||||||
|
{% include "users/aff_alias.html" with alias_list=alias_list %}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -68,6 +68,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'^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,
|
||||||
|
|
|
@ -86,6 +86,8 @@ from .models import (
|
||||||
from .forms import (
|
from .forms import (
|
||||||
BanForm,
|
BanForm,
|
||||||
WhitelistForm,
|
WhitelistForm,
|
||||||
|
MailAliasForm,
|
||||||
|
MailForm,
|
||||||
DelSchoolForm,
|
DelSchoolForm,
|
||||||
DelListRightForm,
|
DelListRightForm,
|
||||||
NewListRightForm,
|
NewListRightForm,
|
||||||
|
@ -503,12 +505,12 @@ def del_whitelist(request, whitelist, **_kwargs):
|
||||||
def add_mailalias(request, user, userid):
|
def add_mailalias(request, user, userid):
|
||||||
""" Créer un alias """
|
""" Créer un alias """
|
||||||
mailalias_instance = MailAlias(mail=user.mail)
|
mailalias_instance = MailAlias(mail=user.mail)
|
||||||
whitelist = WhitelistForm(
|
mailalias = MailAliasForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=whitelist_instance
|
instance=mailalias_instance
|
||||||
)
|
)
|
||||||
if whitelist.is_valid():
|
if mailalias.is_valid():
|
||||||
whitelist.save()
|
mailalias.save()
|
||||||
messages.success(request, "Alias créé")
|
messages.success(request, "Alias créé")
|
||||||
return redirect(reverse(
|
return redirect(reverse(
|
||||||
'users:profil',
|
'users:profil',
|
||||||
|
@ -529,9 +531,9 @@ def edit_mailalias(request, mailalias_instance, **_kwargs):
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=mailalias_instance
|
instance=mailalias_instance
|
||||||
)
|
)
|
||||||
if whitelist.is_valid():
|
if mailalias.is_valid():
|
||||||
if whitelist.changed_data:
|
if mailalias.changed_data:
|
||||||
whitelist.save()
|
mailalias.save()
|
||||||
messages.success(request, "Alias modifiée")
|
messages.success(request, "Alias modifiée")
|
||||||
return redirect(reverse('users:index'))
|
return redirect(reverse('users:index'))
|
||||||
return form(
|
return form(
|
||||||
|
@ -557,6 +559,25 @@ def del_mailalias(request, mailalias, **_kwargs):
|
||||||
request
|
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
|
@login_required
|
||||||
@can_create(School)
|
@can_create(School)
|
||||||
def add_school(request):
|
def add_school(request):
|
||||||
|
@ -957,7 +978,9 @@ def profil(request, users, **_kwargs):
|
||||||
'white_list': whitelists,
|
'white_list': whitelists,
|
||||||
'user_solde': user_solde,
|
'user_solde': user_solde,
|
||||||
'allow_online_payment': allow_online_payment,
|
'allow_online_payment': allow_online_payment,
|
||||||
'solde_activated': OptionalUser.objects.first().user_solde
|
'solde_activated': OptionalUser.objects.first().user_solde,
|
||||||
|
'asso_name': AssoOption.objects.first().name,
|
||||||
|
'alias_list': users.mail.mailalias_set.all()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue