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 516de515..42c22d53 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -90,6 +90,10 @@ class OptionalUser(AclMixin, PreferencesModel): 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 fcc889c3..83ce10bb 100755 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -64,17 +64,19 @@ with this program; if not, write to the Free Software Foundation, Inc., Extension mail interne {{ useroptions.mail_extension }} - - - -

Préférences machines

- - - Editer - -

-

- + + + +
Nombre d'alias maximum{{ useroption.max_mail_alias }} +
+

Préférences machines

+ + + Editer + +

+

+ diff --git a/users/models.py b/users/models.py index 8f0e88a2..ba7fda3a 100644 --- a/users/models.py +++ b/users/models.py @@ -1694,6 +1694,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 d1f25c29..b6e3c848 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -415,8 +415,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- {% can_edit user.mail %} - + {% can_edit users %} + Modifier les options mail @@ -430,18 +430,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- - - + + +
Mot de passe par machine {{ machineoptions.password_machine|tick }} 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 }}
- {% if user.internal_address %} - - {% can_create MailAlias %} + {% if users.internal_address %} + {% can_create MailAlias users.id %} Ajouter un alias mail @@ -458,7 +457,7 @@ with this program; if not, write to the Free Software Foundation, Inc., Adresse mail - {{ user.external_mail }} + {{ users.external_mail }}