8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-22 23:13:46 +00:00

ajout du nombre d'alias max

This commit is contained in:
grisel-davy 2018-06-30 14:46:35 +02:00 committed by Maël Kervella
parent b7977f493b
commit cc2dcefa8f
5 changed files with 62 additions and 20 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

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

View file

@ -64,17 +64,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Extension mail interne</th>
<td>{{ useroptions.mail_extension }}</td>
</tr>
</table>
<h4>Préférences machines</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalMachine' %}">
<i class="fa fa-edit"></i>
Editer
</a>
<p>
</p>
<table class="table table-striped">
<tr>
<th>Nombre d'alias maximum</th>
<td>{{ useroption.max_mail_alias }}<td>
</tr>
</table>
<h4>Préférences machines</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalMachine' %}">
<i class="fa fa-edit"></i>
Editer
</a>
<p>
</p>
<table class="table table-striped">
<tr>
<th>Mot de passe par machine</th>
<td>{{ machineoptions.password_machine|tick }}</td>

View file

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

View file

@ -415,8 +415,8 @@ 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.mail %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-mail' users.mail.id %}">
{% 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
</a>
@ -430,18 +430,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
@ -458,7 +457,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>