mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-05 01:16:27 +00:00
Merge branch 'end_sub_mail' into crans
This commit is contained in:
commit
bc969a3201
10 changed files with 291 additions and 2 deletions
|
@ -266,6 +266,7 @@ class ExtensionForm(FormRevMixin, ModelForm):
|
||||||
self.fields['origin'].label = 'Enregistrement A origin'
|
self.fields['origin'].label = 'Enregistrement A origin'
|
||||||
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
|
self.fields['origin_v6'].label = 'Enregistrement AAAA origin'
|
||||||
self.fields['soa'].label = 'En-tête SOA à utiliser'
|
self.fields['soa'].label = 'En-tête SOA à utiliser'
|
||||||
|
self.fielss['mail_extension'].label = 'Utilisable comme extension mail'
|
||||||
|
|
||||||
|
|
||||||
class DelExtensionForm(FormRevMixin, Form):
|
class DelExtensionForm(FormRevMixin, Form):
|
||||||
|
|
|
@ -641,6 +641,10 @@ class Extension(RevMixin, AclMixin, models.Model):
|
||||||
'SOA',
|
'SOA',
|
||||||
on_delete=models.CASCADE
|
on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
|
mail_extension = models.BooleanField(
|
||||||
|
default=False,
|
||||||
|
help_text="Determine si l'extension peut être utilisée comme extension mail interne"
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
|
|
@ -135,6 +135,8 @@ MODEL_NAME = {
|
||||||
'SwitchBay': topologie.models.SwitchBay,
|
'SwitchBay': topologie.models.SwitchBay,
|
||||||
# users
|
# users
|
||||||
'User': users.models.User,
|
'User': users.models.User,
|
||||||
|
'Mail': users.models.Mail,
|
||||||
|
'MailAlias': users.models.MailAlias,
|
||||||
'Adherent': users.models.Adherent,
|
'Adherent': users.models.Adherent,
|
||||||
'Club': users.models.Club,
|
'Club': users.models.Club,
|
||||||
'ServiceUser': users.models.ServiceUser,
|
'ServiceUser': users.models.ServiceUser,
|
||||||
|
|
|
@ -34,6 +34,8 @@ from reversion.admin import VersionAdmin
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
User,
|
User,
|
||||||
|
Mail,
|
||||||
|
MailAlias,
|
||||||
ServiceUser,
|
ServiceUser,
|
||||||
School,
|
School,
|
||||||
ListRight,
|
ListRight,
|
||||||
|
|
|
@ -53,6 +53,7 @@ from .models import (
|
||||||
School,
|
School,
|
||||||
ListRight,
|
ListRight,
|
||||||
Whitelist,
|
Whitelist,
|
||||||
|
MailAlias,
|
||||||
ListShell,
|
ListShell,
|
||||||
Ban,
|
Ban,
|
||||||
Adherent,
|
Adherent,
|
||||||
|
@ -589,3 +590,16 @@ class WhitelistForm(FormRevMixin, ModelForm):
|
||||||
model = Whitelist
|
model = Whitelist
|
||||||
exclude = ['user']
|
exclude = ['user']
|
||||||
widgets = {'date_end':DateTimePicker}
|
widgets = {'date_end':DateTimePicker}
|
||||||
|
|
||||||
|
|
||||||
|
class MailAliasForm(FormRevMixin, ModelForm):
|
||||||
|
"""Creation, edition d'un objet alias mail"""
|
||||||
|
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['extension'].label = 'extension de l\'adresse mail'
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = MailAlias
|
||||||
|
exclude = ['mail']
|
||||||
|
|
117
users/models.py
117
users/models.py
|
@ -79,7 +79,7 @@ from re2o.field_permissions import FieldPermissionModelMixin
|
||||||
from re2o.mixins import AclMixin, RevMixin
|
from re2o.mixins import AclMixin, RevMixin
|
||||||
|
|
||||||
from cotisations.models import Cotisation, Facture, Paiement, Vente
|
from cotisations.models import Cotisation, Facture, Paiement, Vente
|
||||||
from machines.models import Domain, Interface, Machine, regen
|
from machines.models import Domain, Interface, Machine, regen, Extension
|
||||||
from preferences.models import GeneralOption, AssoOption, OptionalUser
|
from preferences.models import GeneralOption, AssoOption, OptionalUser
|
||||||
from preferences.models import OptionalMachine, MailMessageOption
|
from preferences.models import OptionalMachine, MailMessageOption
|
||||||
|
|
||||||
|
@ -195,6 +195,12 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
validators=[linux_user_validator]
|
validators=[linux_user_validator]
|
||||||
)
|
)
|
||||||
email = models.EmailField()
|
email = models.EmailField()
|
||||||
|
"""
|
||||||
|
email= models.OneToOneField(
|
||||||
|
Mail,
|
||||||
|
on_delete=models.PROTECT
|
||||||
|
)
|
||||||
|
"""
|
||||||
school = models.ForeignKey(
|
school = models.ForeignKey(
|
||||||
'School',
|
'School',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
|
@ -246,7 +252,9 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
("view_user",
|
("view_user",
|
||||||
"Peut voir un objet user quelquonque"),
|
"Peut voir un objet user quelquonque"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Si il s'agit d'un adhérent, on renvoie le prénom"""
|
"""Si il s'agit d'un adhérent, on renvoie le prénom"""
|
||||||
|
@ -668,6 +676,15 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
self.pwd_ntlm = hashNT(password)
|
self.pwd_ntlm = hashNT(password)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def get_mail(self):
|
||||||
|
"""
|
||||||
|
Return the mail address choosen by the user
|
||||||
|
"""
|
||||||
|
if not self.mail.internal_activated:
|
||||||
|
return(self.mail.external)
|
||||||
|
else:
|
||||||
|
return(self.mail.mailalias_set.first())
|
||||||
|
|
||||||
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
|
||||||
this user by trying "pseudo0", "pseudo1", "pseudo2", ...
|
this user by trying "pseudo0", "pseudo1", "pseudo2", ...
|
||||||
|
@ -1575,3 +1592,99 @@ class LdapServiceUserGroup(ldapdb.models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class Mail(RevMixin, AclMixin, models.Model):
|
||||||
|
"""
|
||||||
|
Mail account of a user
|
||||||
|
|
||||||
|
Compte mail d'un utilisateur
|
||||||
|
"""
|
||||||
|
external_mail = models.EmailField(help_text="Mail externe")
|
||||||
|
user = models.ForeignKey(
|
||||||
|
'User',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
help_text="Object mail d'un User"
|
||||||
|
)
|
||||||
|
redirection = models.BooleanField(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
internal_address = models.BooleanField(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.mail
|
||||||
|
|
||||||
|
|
||||||
|
class MailAlias(RevMixin, AclMixin, models.Model):
|
||||||
|
"""
|
||||||
|
Define a alias for a user Mail
|
||||||
|
|
||||||
|
Définit un aliase pour un Mail d'utilisateur
|
||||||
|
"""
|
||||||
|
mail = models.ForeignKey(
|
||||||
|
'Mail',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
help_text="Objects Mail associé"
|
||||||
|
)
|
||||||
|
valeur = models.CharField(
|
||||||
|
max_length=64,
|
||||||
|
help_text="username de l'adresse mail"
|
||||||
|
)
|
||||||
|
extension = models.ForeignKey(
|
||||||
|
'Extension',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
help_text="Extension mail interne"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('valeur', 'extension',)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.valeur + "@" + self.extension
|
||||||
|
|
||||||
|
def can_view(self, user_request, *_args, **_kwargs):
|
||||||
|
"""
|
||||||
|
Check if the user can view the aliases
|
||||||
|
"""
|
||||||
|
|
||||||
|
if user_request.has_perm('users.view_mailalias') or user.request == self.mail.user:
|
||||||
|
return True, None
|
||||||
|
else:
|
||||||
|
return False, "Vous n'avais pas les droits suffisants et n'êtes pas propriétaire de ces alias"
|
||||||
|
|
||||||
|
def can_delete(self, user_request, *_args, **_kwargs):
|
||||||
|
"""
|
||||||
|
Check if the user can delete the alias
|
||||||
|
"""
|
||||||
|
|
||||||
|
if user_request.has_perm('users.delete_mailalias'):
|
||||||
|
return True, None
|
||||||
|
else:
|
||||||
|
if user_request == self.mail.user:
|
||||||
|
if self.id != 0:
|
||||||
|
return True, None
|
||||||
|
else:
|
||||||
|
return False, "Vous ne pouvez pas supprimer l'alias lié à votre pseudo"
|
||||||
|
else:
|
||||||
|
return False, "Vous n'avez pas les droits suffisants et n'êtes pas propriétairs de ces alias"
|
||||||
|
|
||||||
|
def can_edit(self, user_request, *_args, **_kwargs):
|
||||||
|
"""
|
||||||
|
Check if the user can edit the alias
|
||||||
|
"""
|
||||||
|
|
||||||
|
if user_request.has_perm('users.change_mailalias'):
|
||||||
|
return True, None
|
||||||
|
else:
|
||||||
|
if user_request == self.mail.user:
|
||||||
|
if self.id != 0:
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
53
users/templates/users/aff_alias.html
Normal file
53
users/templates/users/aff_alias.html
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
{% comment %}
|
||||||
|
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||||
|
se veut agnostique au réseau considéré, de manière à être installable en
|
||||||
|
quelques clics.
|
||||||
|
|
||||||
|
Copyright © 2017 Gabriel Détraz
|
||||||
|
Copyright © 2017 Goulven Kermarec
|
||||||
|
Copyright © 2017 Augustin Lemesle
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
{% endcomment %}
|
||||||
|
{% load acl %}
|
||||||
|
{% if alias_list.paginator %}
|
||||||
|
{% include "pagination.html" with list=alias_list %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Alias</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
{% for alias in alias_list %}
|
||||||
|
<td>{{ alias }}</td>
|
||||||
|
<td class="text-right">
|
||||||
|
{% can_delete alias %}
|
||||||
|
{% include 'buttons/suppr.html' with href='users:del-alias' id=alias.id %}
|
||||||
|
{% acl_end %}
|
||||||
|
{% can_edit alias %}
|
||||||
|
{% include 'buttons/edit.html' with href='users:edit-alias' id=alias.id %}
|
||||||
|
{% acl_end %}
|
||||||
|
{% include 'buttons/history.html' with href='users:history' name='alias' id=alias.id %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{% if alias_list.paginator %}
|
||||||
|
{% include "pagination.html" with list=alias_list %}
|
||||||
|
{% endif %}
|
37
users/templates/users/index_alias.html
Normal file
37
users/templates/users/index_alias.html
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
{% extends "users/sidebar.html" %}
|
||||||
|
{% comment %}
|
||||||
|
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
||||||
|
se veut agnostique au réseau considéré, de manière à être installable en
|
||||||
|
quelques clics.
|
||||||
|
|
||||||
|
Copyright © 2017 Gabriel Détraz
|
||||||
|
Copyright © 2017 Goulven Kermarec
|
||||||
|
Copyright © 2017 Augustin Lemesle
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
{% endcomment %}
|
||||||
|
|
||||||
|
{% load bootstrap3 %}
|
||||||
|
|
||||||
|
{% block title %}Utilisateurs{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Alias</h2>
|
||||||
|
{% include "users/aff_alias.html" with alias_list=alias_list %}
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -65,6 +65,9 @@ urlpatterns = [
|
||||||
url(r'^del_whitelist/(?P<whitelistid>[0-9]+)$',
|
url(r'^del_whitelist/(?P<whitelistid>[0-9]+)$',
|
||||||
views.del_whitelist,
|
views.del_whitelist,
|
||||||
name='del-whitelist'),
|
name='del-whitelist'),
|
||||||
|
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'^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,
|
||||||
|
|
|
@ -495,6 +495,66 @@ def del_whitelist(request, whitelist, **_kwargs):
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_create(MailAlias)
|
||||||
|
@can_edit(User)
|
||||||
|
def add_mailalias(request, user, userid):
|
||||||
|
""" Créer un alias """
|
||||||
|
mailalias_instance = MailAlias(mail=user.mail)
|
||||||
|
whitelist = WhitelistForm(
|
||||||
|
request.POST or None,
|
||||||
|
instance=whitelist_instance
|
||||||
|
)
|
||||||
|
if whitelist.is_valid():
|
||||||
|
whitelist.save()
|
||||||
|
messages.success(request, "Alias créé")
|
||||||
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': str(userid)}
|
||||||
|
))
|
||||||
|
|
||||||
|
return form(
|
||||||
|
{'userform': mailalias, 'action_name': 'Ajouter un alias mail'},
|
||||||
|
'users/user.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_edit(MailAlias)
|
||||||
|
def edit_mailalias(request, mailalias_instance, **_kwargs):
|
||||||
|
""" Editer un alias mail"""
|
||||||
|
mailalias = MailAliasForm(
|
||||||
|
request.POST or None,
|
||||||
|
instance=mailalias_instance
|
||||||
|
)
|
||||||
|
if whitelist.is_valid():
|
||||||
|
if whitelist.changed_data:
|
||||||
|
whitelist.save()
|
||||||
|
messages.success(request, "Alias modifiée")
|
||||||
|
return redirect(reverse('users:index'))
|
||||||
|
return form(
|
||||||
|
{'userform': mailalias, 'action_name': 'Editer un alias mail'},
|
||||||
|
'users/user.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_delete(MailAlias)
|
||||||
|
def del_mailalias(request, mailalias, **_kwargs):
|
||||||
|
""" Supprime un alias mail"""
|
||||||
|
if request.method == "POST":
|
||||||
|
mailalias.delete()
|
||||||
|
messages.success(request, "L'alias a été supprimé")
|
||||||
|
return redirect(reverse(
|
||||||
|
'users:profil',
|
||||||
|
kwargs={'userid': str(mailalias.mail.user.id)}
|
||||||
|
))
|
||||||
|
return form(
|
||||||
|
{'objet': mailalias, 'objet_name': 'mailalias'},
|
||||||
|
'users/delete.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(School)
|
@can_create(School)
|
||||||
def add_school(request):
|
def add_school(request):
|
||||||
|
|
Loading…
Reference in a new issue