diff --git a/CHANGELOG.md b/CHANGELOG.md index f390ba09..5ec2da1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,3 +128,11 @@ You need to ensure that your database character set is utf-8. ```sql 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 +``` diff --git a/static/js/email_address.js b/static/js/email_address.js new file mode 100644 index 00000000..10c1f544 --- /dev/null +++ b/static/js/email_address.js @@ -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(); diff --git a/users/forms.py b/users/forms.py index 97fb3fc3..dac86d71 100644 --- a/users/forms.py +++ b/users/forms.py @@ -620,7 +620,7 @@ class EMailAddressForm(FormRevMixin, ModelForm): super(EMailAddressForm, self).__init__(*args, prefix=prefix, **kwargs) self.fields['local_part'].label = "Local part of the email" self.fields['local_part'].help_text = "Can't contain @" - + def clean_local_part(self): return self.cleaned_data.get('local_part').lower() @@ -634,18 +634,11 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): def __init__(self, *args, **kwargs): prefix = kwargs.pop('prefix', self.Meta.model.__name__) 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: 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: 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'): @@ -655,4 +648,4 @@ class EmailSettingsForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): class Meta: model = User - fields = ['email', 'local_email_redirect', 'local_email_enabled'] + fields = ['email','local_email_enabled', 'local_email_redirect'] diff --git a/users/migrations/0074_auto_20180814_1059.py b/users/migrations/0074_auto_20180814_1059.py new file mode 100644 index 00000000..ced792f4 --- /dev/null +++ b/users/migrations/0074_auto_20180814_1059.py @@ -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, 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.'), + ), + ] diff --git a/users/migrations/0076_auto_20180811_0425.py b/users/migrations/0076_auto_20180811_0425.py deleted file mode 100644 index 0b53af9a..00000000 --- a/users/migrations/0076_auto_20180811_0425.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-08-11 02:25 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('users', '0075_auto_20180811_0420'), - ] - - operations = [ - migrations.AlterField( - model_name='user', - name='email', - field=models.EmailField(max_length=254, unique=True), - ), - ] diff --git a/users/models.py b/users/models.py index ff596424..7331a460 100755 --- a/users/models.py +++ b/users/models.py @@ -195,14 +195,17 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, help_text="Doit contenir uniquement des lettres, chiffres, ou tirets", validators=[linux_user_validator] ) - email = models.EmailField(unique=True) + email = models.EmailField( + blank=True, + help_text="External email address allowing us to contact you." + ) local_email_redirect = models.BooleanField( 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( default=False, - help_text="Wether or not to enable the local email account." + help_text="Enable the local email account." ) school = models.ForeignKey( 'School', @@ -565,7 +568,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, # depending on the length, we need to remove or not a $ if len(self.password)==41: user_ldap.user_password = self.password - else: + else: user_ldap.user_password = self.password[:7] + self.password[8:] user_ldap.sambat_nt_password = self.pwd_ntlm.upper() @@ -1771,7 +1774,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model): if self.local_part == self.user.pseudo.lower(): return False, ("You cannot delete a local email account whose " "local part is the same as the username.") - if user_request.has_perm('users.delete_emailaddress'): + if user_request.has_perm('users.delete_emailaddress'): return True, None if not OptionalUser.get_cached_value('local_email_accounts_enabled'): return False, "The local email accounts are not enabled." diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index c2053612..f573941b 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -27,15 +27,16 @@ with this program; if not, write to the Free Software Foundation, Inc., {% load acl %} {% load logs_extra %} {% load design %} +{% load i18n %} {% block title %}Profil{% endblock %} {% block content %}
Contact email address | -{{ users.email }} | +{{ users.get_mail }} | |||
---|---|---|---|---|---|
Enable the local email account | {{ users.local_email_enabled | tick }} | Enable the local email redirection | -{{ users.local_email_redirect | tick }} | -
{% 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 %}
+Contact email address | -{{ users.email }} | +{{ users.get_mail }} |
---|
En cliquant sur Créer ou modifier, l'utilisateur s'engage à respecter les règles d'utilisation du réseau.
diff --git a/users/views.py b/users/views.py index ca7438df..5279dbb0 100644 --- a/users/views.py +++ b/users/views.py @@ -541,7 +541,8 @@ def edit_emailaddress(request, emailaddress_instance, **_kwargs): return form( {'userform': emailaddress, 'showCGU': False, - 'action_name': 'Edit a local email account'}, + 'action_name': 'Edit a local email account', + }, 'users/user.html', request ) @@ -585,6 +586,7 @@ def edit_email_settings(request, user_instance, **_kwargs): return form( {'userform': email_settings, 'showCGU': False, + 'load_js_file': '/static/js/email_address.js', 'action_name': 'Edit the email settings'}, 'users/user.html', request @@ -1017,7 +1019,7 @@ def profil(request, users, **_kwargs): 'emailaddress_list': users.email_address, 'local_email_accounts_enabled': ( OptionalUser.objects.first().local_email_accounts_enabled - ) + ) } )