mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Merge branch 'mail_interne_fix' into 'dev'
Mail interne fix See merge request federez/re2o!247
This commit is contained in:
commit
008fd836e0
8 changed files with 144 additions and 44 deletions
|
@ -128,3 +128,11 @@ You need to ensure that your database character set is utf-8.
|
||||||
```sql
|
```sql
|
||||||
ALTER DATABASE re2o CHARACTER SET utf8;
|
ALTER DATABASE re2o CHARACTER SET utf8;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## MR 247: Fix des comptes mails
|
||||||
|
|
||||||
|
Fix several issues with email accounts, you need to collect the static files.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./manage.py collectstatic
|
||||||
|
```
|
||||||
|
|
17
static/js/email_address.js
Normal file
17
static/js/email_address.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/** To enable the redirection has no meaning if the local email adress is not
|
||||||
|
* enabled. Thus this function enable the checkbox if needed and changes its
|
||||||
|
* state.
|
||||||
|
*/
|
||||||
|
function enable_redirection_chkbox() {
|
||||||
|
var redirect = document.getElementById('id_User-local_email_redirect');
|
||||||
|
var enabled = document.getElementById('id_User-local_email_enabled').checked;
|
||||||
|
if(!enabled)
|
||||||
|
{
|
||||||
|
redirect.checked = false;
|
||||||
|
}
|
||||||
|
redirect.disabled = !enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
var enabled_chkbox = document.getElementById('id_User-local_email_enabled');
|
||||||
|
enabled_chkbox.onclick = enable_redirection_chkbox;
|
||||||
|
enable_redirection_chkbox();
|
|
@ -138,6 +138,12 @@ class UserCreationForm(FormRevMixin, forms.ModelForm):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(UserCreationForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(UserCreationForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
||||||
|
def clean_email(self):
|
||||||
|
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
|
||||||
|
return self.cleaned_data.get('email').lower()
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError("You can't use an internal address as your external address.")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Adherent
|
model = Adherent
|
||||||
fields = ('pseudo', 'surname', 'email')
|
fields = ('pseudo', 'surname', 'email')
|
||||||
|
@ -308,6 +314,12 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
self.fields['room'].empty_label = "Pas de chambre"
|
self.fields['room'].empty_label = "Pas de chambre"
|
||||||
self.fields['school'].empty_label = "Séléctionner un établissement"
|
self.fields['school'].empty_label = "Séléctionner un établissement"
|
||||||
|
|
||||||
|
def clean_email(self):
|
||||||
|
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
|
||||||
|
return self.cleaned_data.get('email').lower()
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError("Vous ne pouvez pas utiliser une addresse {}".format(OptionalUser.objects.first().local_email_domain))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Adherent
|
model = Adherent
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -323,6 +335,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
'gpg_fingerprint'
|
'gpg_fingerprint'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def clean_telephone(self):
|
def clean_telephone(self):
|
||||||
"""Verifie que le tel est présent si 'option est validée
|
"""Verifie que le tel est présent si 'option est validée
|
||||||
dans preferences"""
|
dans preferences"""
|
||||||
|
@ -608,6 +621,9 @@ class EMailAddressForm(FormRevMixin, ModelForm):
|
||||||
self.fields['local_part'].label = "Local part of the email"
|
self.fields['local_part'].label = "Local part of the email"
|
||||||
self.fields['local_part'].help_text = "Can't contain @"
|
self.fields['local_part'].help_text = "Can't contain @"
|
||||||
|
|
||||||
|
def clean_local_part(self):
|
||||||
|
return self.cleaned_data.get('local_part').lower()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = EMailAddress
|
model = EMailAddress
|
||||||
exclude = ['user']
|
exclude = ['user']
|
||||||
|
@ -618,19 +634,18 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(EmailSettingsForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['email'].label = "Contact email address"
|
self.fields['email'].label = "Main email address"
|
||||||
if 'local_email_redirect' in self.fields:
|
if 'local_email_redirect' in self.fields:
|
||||||
self.fields['local_email_redirect'].label = "Redirect local emails"
|
self.fields['local_email_redirect'].label = "Redirect local emails"
|
||||||
self.fields['local_email_redirect'].help_text = (
|
|
||||||
"Enable the automated redirection of the local email address "
|
|
||||||
"to the contact email address"
|
|
||||||
)
|
|
||||||
if 'local_email_enabled' in self.fields:
|
if 'local_email_enabled' in self.fields:
|
||||||
self.fields['local_email_enabled'].label = "Use local emails"
|
self.fields['local_email_enabled'].label = "Use local emails"
|
||||||
self.fields['local_email_enabled'].help_text = (
|
|
||||||
"Enable the use of the local email account"
|
def clean_email(self):
|
||||||
)
|
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
|
||||||
|
return self.cleaned_data.get('email').lower()
|
||||||
|
else:
|
||||||
|
raise forms.ValidationError("Vous ne pouvez pas utiliser une addresse {}".format(OptionalUser.objects.first().local_email_domain))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
fields = ['email', 'local_email_redirect', 'local_email_enabled']
|
fields = ['email','local_email_enabled', 'local_email_redirect']
|
||||||
|
|
30
users/migrations/0074_auto_20180814_1059.py
Normal file
30
users/migrations/0074_auto_20180814_1059.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-08-14 08:59
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0073_auto_20180629_1614'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(blank=True, null=True, help_text='External email address allowing us to contact you.', max_length=254),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='local_email_enabled',
|
||||||
|
field=models.BooleanField(default=False, help_text='Enable the local email account.'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='local_email_redirect',
|
||||||
|
field=models.BooleanField(default=False, help_text='Enable redirection of the local email messages to the main email.'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -53,6 +53,7 @@ import sys
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.forms import ValidationError
|
||||||
from django.db.models.signals import post_save, post_delete, m2m_changed
|
from django.db.models.signals import post_save, post_delete, m2m_changed
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
|
@ -131,6 +132,7 @@ def get_fresh_gid():
|
||||||
|
|
||||||
class UserManager(BaseUserManager):
|
class UserManager(BaseUserManager):
|
||||||
"""User manager basique de django"""
|
"""User manager basique de django"""
|
||||||
|
|
||||||
def _create_user(
|
def _create_user(
|
||||||
self,
|
self,
|
||||||
pseudo,
|
pseudo,
|
||||||
|
@ -195,14 +197,18 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
|
help_text="Doit contenir uniquement des lettres, chiffres, ou tirets",
|
||||||
validators=[linux_user_validator]
|
validators=[linux_user_validator]
|
||||||
)
|
)
|
||||||
email = models.EmailField()
|
email = models.EmailField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
help_text="External email address allowing us to contact you."
|
||||||
|
)
|
||||||
local_email_redirect = models.BooleanField(
|
local_email_redirect = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
help_text="Whether or not to redirect the local email messages to the main email."
|
help_text="Enable redirection of the local email messages to the main email."
|
||||||
)
|
)
|
||||||
local_email_enabled = models.BooleanField(
|
local_email_enabled = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
help_text="Wether or not to enable the local email account."
|
help_text="Enable the local email account."
|
||||||
)
|
)
|
||||||
school = models.ForeignKey(
|
school = models.ForeignKey(
|
||||||
'School',
|
'School',
|
||||||
|
@ -286,7 +292,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
if not OptionalUser.get_cached_value('local_email_accounts_enabled') or not self.local_email_enabled or self.local_email_redirect:
|
if not OptionalUser.get_cached_value('local_email_accounts_enabled') or not self.local_email_enabled or self.local_email_redirect:
|
||||||
return str(self.email)
|
return str(self.email)
|
||||||
else:
|
else:
|
||||||
return str(self.emailaddress_set.get(local_part=self.pseudo))
|
return str(self.emailaddress_set.get(local_part=self.pseudo.lower()))
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def class_name(self):
|
def class_name(self):
|
||||||
|
@ -560,13 +566,15 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
user_ldap.gid = LDAP['user_gid']
|
user_ldap.gid = LDAP['user_gid']
|
||||||
if '{SSHA}' in self.password or '{SMD5}' in self.password:
|
if '{SSHA}' in self.password or '{SMD5}' in self.password:
|
||||||
# We remove the extra $ added at import from ldap
|
# We remove the extra $ added at import from ldap
|
||||||
user_ldap.user_password = self.password[:6] + self.password[7:]
|
user_ldap.user_password = self.password[:6] + \
|
||||||
|
self.password[7:]
|
||||||
elif '{crypt}' in self.password:
|
elif '{crypt}' in self.password:
|
||||||
# depending on the length, we need to remove or not a $
|
# depending on the length, we need to remove or not a $
|
||||||
if len(self.password) == 41:
|
if len(self.password) == 41:
|
||||||
user_ldap.user_password = self.password
|
user_ldap.user_password = self.password
|
||||||
else:
|
else:
|
||||||
user_ldap.user_password = self.password[:7] + self.password[8:]
|
user_ldap.user_password = self.password[:7] + \
|
||||||
|
self.password[8:]
|
||||||
|
|
||||||
user_ldap.sambat_nt_password = self.pwd_ntlm.upper()
|
user_ldap.sambat_nt_password = self.pwd_ntlm.upper()
|
||||||
if self.get_shell:
|
if self.get_shell:
|
||||||
|
@ -966,9 +974,22 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
"""Check if this pseudo is already used by any mailalias.
|
"""Check if this pseudo is already used by any mailalias.
|
||||||
Better than raising an error in post-save and catching it"""
|
Better than raising an error in post-save and catching it"""
|
||||||
if (EMailAddress.objects
|
if (EMailAddress.objects
|
||||||
.filter(local_part=self.pseudo)
|
.filter(local_part=self.pseudo.lower()).exclude(user_id=self.id)
|
||||||
.exclude(user=self)):
|
):
|
||||||
raise ValidationError("This pseudo is already in use.")
|
raise ValidationError("This pseudo is already in use.")
|
||||||
|
if not self.local_email_enabled and not self.email:
|
||||||
|
raise ValidationError(
|
||||||
|
{'email': (
|
||||||
|
'There is neither a local email address nor an external'
|
||||||
|
' email address for this user.'
|
||||||
|
), }
|
||||||
|
)
|
||||||
|
if self.local_email_redirect and not self.email:
|
||||||
|
raise ValidationError(
|
||||||
|
{'local_email_redirect': (
|
||||||
|
'You cannot redirect your local email if no external email '
|
||||||
|
'has been set.'), }
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.pseudo
|
return self.pseudo
|
||||||
|
@ -1106,7 +1127,8 @@ def user_post_save(**kwargs):
|
||||||
Synchronise le ldap"""
|
Synchronise le ldap"""
|
||||||
is_created = kwargs['created']
|
is_created = kwargs['created']
|
||||||
user = kwargs['instance']
|
user = kwargs['instance']
|
||||||
EMailAddress.objects.get_or_create(local_part=user.pseudo, user=user)
|
EMailAddress.objects.get_or_create(
|
||||||
|
local_part=user.pseudo.lower(), user=user)
|
||||||
if is_created:
|
if is_created:
|
||||||
user.notif_inscription()
|
user.notif_inscription()
|
||||||
user.state_sync()
|
user.state_sync()
|
||||||
|
@ -1129,6 +1151,7 @@ def user_group_relation_changed(**kwargs):
|
||||||
mac_refresh=False,
|
mac_refresh=False,
|
||||||
group_refresh=True)
|
group_refresh=True)
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_delete, sender=Adherent)
|
@receiver(post_delete, sender=Adherent)
|
||||||
@receiver(post_delete, sender=Club)
|
@receiver(post_delete, sender=Club)
|
||||||
@receiver(post_delete, sender=User)
|
@receiver(post_delete, sender=User)
|
||||||
|
@ -1768,7 +1791,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
|
||||||
a message and a boolean which is True if the user can delete
|
a message and a boolean which is True if the user can delete
|
||||||
the local email account.
|
the local email account.
|
||||||
"""
|
"""
|
||||||
if self.local_part == self.user.pseudo:
|
if self.local_part == self.user.pseudo.lower():
|
||||||
return False, ("You cannot delete a local email account whose "
|
return False, ("You cannot delete a local email account whose "
|
||||||
"local part is the same as the username.")
|
"local part is the same as the username.")
|
||||||
if user_request.has_perm('users.delete_emailaddress'):
|
if user_request.has_perm('users.delete_emailaddress'):
|
||||||
|
@ -1790,7 +1813,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
|
||||||
a message and a boolean which is True if the user can edit
|
a message and a boolean which is True if the user can edit
|
||||||
the local email account.
|
the local email account.
|
||||||
"""
|
"""
|
||||||
if self.local_part == self.user.pseudo:
|
if self.local_part == self.user.pseudo.lower():
|
||||||
return False, ("You cannot edit a local email account whose "
|
return False, ("You cannot edit a local email account whose "
|
||||||
"local part is the same as the username.")
|
"local part is the same as the username.")
|
||||||
if user_request.has_perm('users.change_emailaddress'):
|
if user_request.has_perm('users.change_emailaddress'):
|
||||||
|
@ -1803,7 +1826,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
|
||||||
"local email account")
|
"local email account")
|
||||||
|
|
||||||
def clean(self, *args, **kwargs):
|
def clean(self, *args, **kwargs):
|
||||||
|
self.local_part = self.local_part.lower()
|
||||||
if "@" in self.local_part:
|
if "@" in self.local_part:
|
||||||
raise ValidationError("The local part cannot contain a @")
|
raise ValidationError("The local part cannot contain a @")
|
||||||
super(EMailAddress, self).clean(*args, **kwargs)
|
super(EMailAddress, self).clean(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% load acl %}
|
{% load acl %}
|
||||||
{% load logs_extra %}
|
{% load logs_extra %}
|
||||||
{% load design %}
|
{% load design %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
{% block title %}Profil{% endblock %}
|
{% block title %}Profil{% endblock %}
|
||||||
|
|
||||||
|
@ -437,7 +438,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2">Contact email address</th>
|
<th colspan="2">Contact email address</th>
|
||||||
<td colspan="2">{{ users.email }}</td>
|
<td colspan="2">{{ users.get_mail }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Enable the local email account</th>
|
<th>Enable the local email account</th>
|
||||||
|
@ -446,6 +447,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{ users.local_email_redirect | tick }}</td>
|
<td>{{ users.local_email_redirect | tick }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<p>{% blocktrans %}The Contact email is the email address where we send email to contact you. If you would like to use your external email address for that, you can either disable your local email address or enable the local email redirection.{% endblocktrans %}</p>
|
||||||
</div>
|
</div>
|
||||||
{% if users.local_email_enabled %}
|
{% if users.local_email_enabled %}
|
||||||
{% can_create EMailAddress users.id %}
|
{% can_create EMailAddress users.id %}
|
||||||
|
@ -462,7 +464,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Contact email address</th>
|
<th>Contact email address</th>
|
||||||
<td>{{ users.email }}</td>
|
<td>{{ users.get_mail }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% massive_bootstrap_form userform 'room,school,administrators,members' %}
|
{% massive_bootstrap_form userform 'room,school,administrators,members' %}
|
||||||
{% bootstrap_button action_name button_type="submit" icon="star" %}
|
{% bootstrap_button action_name button_type="submit" icon="star" %}
|
||||||
</form>
|
</form>
|
||||||
|
{% if load_js_file %}
|
||||||
|
<script src="{{ load_js_file }}"></script>
|
||||||
|
{% endif %}
|
||||||
<br>
|
<br>
|
||||||
{% if showCGU %}
|
{% if showCGU %}
|
||||||
<p>En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les <a href="/media/{{ GTU }}" download="CGU" >règles d'utilisation du réseau</a>.</p>
|
<p>En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les <a href="/media/{{ GTU }}" download="CGU" >règles d'utilisation du réseau</a>.</p>
|
||||||
|
|
|
@ -541,7 +541,8 @@ def edit_emailaddress(request, emailaddress_instance, **_kwargs):
|
||||||
return form(
|
return form(
|
||||||
{'userform': emailaddress,
|
{'userform': emailaddress,
|
||||||
'showCGU': False,
|
'showCGU': False,
|
||||||
'action_name': 'Edit a local email account'},
|
'action_name': 'Edit a local email account',
|
||||||
|
},
|
||||||
'users/user.html',
|
'users/user.html',
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
@ -585,6 +586,7 @@ def edit_email_settings(request, user_instance, **_kwargs):
|
||||||
return form(
|
return form(
|
||||||
{'userform': email_settings,
|
{'userform': email_settings,
|
||||||
'showCGU': False,
|
'showCGU': False,
|
||||||
|
'load_js_file': '/static/js/email_address.js',
|
||||||
'action_name': 'Edit the email settings'},
|
'action_name': 'Edit the email settings'},
|
||||||
'users/user.html',
|
'users/user.html',
|
||||||
request
|
request
|
||||||
|
|
Loading…
Reference in a new issue