diff --git a/preferences/migrations/0037_optionaluser_max_mail_alias.py b/preferences/migrations/0037_optionaluser_max_mail_alias.py
new file mode 100644
index 00000000..8d6ca609
--- /dev/null
+++ b/preferences/migrations/0037_optionaluser_max_mail_alias.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2018-06-30 12:32
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('preferences', '0036_optionaluser_mail_accounts'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='optionaluser',
+ name='max_mail_alias',
+ field=models.IntegerField(default=15, help_text="Nombre maximal d'alias pour un utilisateur lambda"),
+ ),
+ ]
diff --git a/preferences/models.py b/preferences/models.py
index 0f4d21ba..be392b72 100644
--- a/preferences/models.py
+++ b/preferences/models.py
@@ -111,7 +111,11 @@ class OptionalUser(AclMixin, PreferencesModel):
max_length = 32,
default = "@example.org",
help_text="Extension principale pour les mails internes",
- )
+ )
+ max_mail_alias = models.IntegerField(
+ default = 15,
+ help_text = "Nombre maximal d'alias pour un utilisateur lambda"
+ )
class Meta:
permissions = (
diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html
index 7e402cef..71bf60f8 100644
--- a/preferences/templates/preferences/display_preferences.html
+++ b/preferences/templates/preferences/display_preferences.html
@@ -81,6 +81,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Extension mail interne |
{{ useroptions.mail_extension }} |
+
+ Nombre d'alias maximum |
+ {{ useroption.max_mail_alias }} |
+ |
Préférences machines
diff --git a/users/models.py b/users/models.py
index 6cf51c09..d31f0e59 100644
--- a/users/models.py
+++ b/users/models.py
@@ -1651,6 +1651,23 @@ class MailAlias(RevMixin, AclMixin, models.Model):
def __str__(self):
return self.valeur + OptionalUser.get_cached_value('mail_extension')
+ @staticmethod
+ def can_create(user_request, userid, *_args, **_kwargs):
+ """Check if an user can create an mailalias object.
+
+ :param user_request: The user who wants to create a mailalias object.
+ :return: a message and a boolean which is True if the user can create
+ an user or if the `options.all_can_create` is set.
+ """
+ if not user_request.has_perm('users.add_mailalias'):
+ if int(user_request.id) != int(userid):
+ return False, 'Vous n\'avez pas le droit d\'ajouter un alias à une autre personne'
+ elif user_request.mailalias_set.all().count() >= OptionalUser.get_cached_value('max_mail_alias'):
+ return False, "Vous avez atteint la limite de {} alias".format(OptionalUser.get_cached_value('max_mail_alias'))
+ else:
+ return True, None
+ return True, None
+
def can_view(self, user_request, *_args, **_kwargs):
"""
Check if the user can view the aliases
diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html
index 3940e490..62bbf1e5 100644
--- a/users/templates/users/profil.html
+++ b/users/templates/users/profil.html
@@ -436,7 +436,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- {% can_edit user %}
+ {% can_edit users %}
Modifier les options mail
@@ -451,17 +451,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Adresse mail de contact |
- {{ user.external_mail }} |
- {{ user.internal_address|yesno:"Activé,Désactivé" }} |
- {{ user.get_mail }} |
+ {{ users.external_mail }} |
+ {{ users.internal_address|yesno:"Activé,Désactivé" }} |
+ {{ users.get_mail }} |
Vous pouvez bénéficier d'une adresse mail {{ asso_name }}.
Vous pouvez également la rediriger vers une adresse externe en modifiant les options mail.
- {% if user.internal_address %}
- {% can_create MailAlias %}
+ {% if users.internal_address %}
+ {% can_create MailAlias users.id %}
Ajouter un alias mail
@@ -478,7 +478,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Adresse mail |
- {{ user.external_mail }} |
+ {{ users.external_mail }} |