8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 15:33:45 +00:00

Affichage des champs supp de mail que si compte mails actifs

This commit is contained in:
chirac 2018-06-29 18:48:27 +02:00
parent 7544757606
commit cd03f37a83
3 changed files with 40 additions and 6 deletions

View file

@ -600,14 +600,16 @@ class MailAliasForm(FormRevMixin, ModelForm):
model = MailAlias
exclude = ['user']
class MailForm(FormRevMixin, ModelForm):
class MailForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Creation, edition des paramètres mail"""
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(MailForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['external_mail'].label = 'Adresse mail externe'
self.fields['redirection'].label = 'Activation de la redirection vers l\'adress externe'
self.fields['internal_address'].label = 'Adresse mail interne'
if 'redirection' in self.fields:
self.fields['redirection'].label = 'Activation de la redirection vers l\'adress externe'
if 'internal_address' in self.fields:
self.fields['internal_address'].label = 'Adresse mail interne'
class Meta:
model = User

View file

@ -682,7 +682,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"""
Return the mail address choosen by the user
"""
if not self.internal_address:
if not OptionalUser.get_cached_value('mail_accounts') or not self.internal_address:
return self.external_mail
else:
return self.mailalias_set.get(valeur=self.pseudo)
@ -805,6 +805,32 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"Droit requis pour changer le shell"
)
@staticmethod
def can_change_redirection(user_request, *_args, **_kwargs):
""" Check if a user can change redirection.
:param user_request: The user who request
:returns: a message and a boolean which is True if the user has
the right to change a redirection
"""
return (
OptionalUser.get_cached_value('mail_accounts'),
"La gestion des comptes mails doit être activée"
)
@staticmethod
def can_change_internal_address(user_request, *_args, **_kwargs):
""" Check if a user can change internal address .
:param user_request: The user who request
:returns: a message and a boolean which is True if the user has
the right to change internal address
"""
return (
OptionalUser.get_cached_value('mail_accounts'),
"La gestion des comptes mails doit être activée"
)
@staticmethod
def can_change_force(user_request, *_args, **_kwargs):
""" Check if a user can change a force
@ -899,6 +925,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
'shell': self.can_change_shell,
'force': self.can_change_force,
'selfpasswd': self.check_selfpasswd,
'redirection': self.can_change_redirection,
'internal_address' : self.can_change_internal_address,
}
def __str__(self):

View file

@ -566,13 +566,17 @@ def edit_mail(request, user_instance, **_kwargs):
""" Editer un compte mail"""
mail = MailForm(
request.POST or None,
instance=user_instance
instance=user_instance,
user=request.user
)
if mail.is_valid():
if mail.changed_data:
mail.save()
messages.success(request, "Compte mail modifiée")
return redirect(reverse('users:index'))
return redirect(reverse(
'users:profil',
kwargs={'userid': str(user_instance.id)}
))
return form(
{'userform': mail, 'action_name': 'Editer un compte mail'},
'users/user.html',