8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-09-12 01:03:09 +00:00

ajout du nombre d'alias max

This commit is contained in:
grisel-davy 2018-06-30 14:46:35 +02:00
parent fcbb916676
commit 0348eefeda
5 changed files with 53 additions and 8 deletions

View file

@ -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"),
),
]

View file

@ -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 = (

View file

@ -81,6 +81,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Extension mail interne</th>
<td>{{ useroptions.mail_extension }}</td>
</tr>
<tr>
<th>Nombre d'alias maximum</th>
<td>{{ useroption.max_mail_alias }}<td>
</tr>
</table>
<h4>Préférences machines</h4>

View file

@ -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

View file

@ -436,7 +436,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</div>
<div id="collapse7" class="panel-collapse collapse">
<div class="panel-body">
{% can_edit user %}
{% can_edit users %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-mail' users.id %}">
<i class="fa fa-plus-square"></i>
Modifier les options mail
@ -451,17 +451,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Adresse mail de contact</th>
</tr>
<tr>
<td>{{ user.external_mail }}</td>
<td>{{ user.internal_address|yesno:"Activé,Désactivé" }}</td>
<td>{{ user.get_mail }}</td>
<td>{{ users.external_mail }}</td>
<td>{{ users.internal_address|yesno:"Activé,Désactivé" }}</td>
<td>{{ users.get_mail }}</td>
</table>
<div class="alert alert-info" role="alert">
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.
</div>
</div>
{% if user.internal_address %}
{% can_create MailAlias %}
{% if users.internal_address %}
{% can_create MailAlias users.id %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-mailalias' users.id %}">
<i class="fa fa-plus-square"></i>
Ajouter un alias mail
@ -478,7 +478,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Adresse mail</th>
</tr>
<tr>
<td>{{ user.external_mail }}</td>
<td>{{ users.external_mail }}</td>
</tr>
</table>
</div>