mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 08:53:46 +00:00
Affichage des champs supp de mail que si compte mails actifs
This commit is contained in:
parent
283cdcace3
commit
bf189f4c4f
3 changed files with 42 additions and 8 deletions
|
@ -603,14 +603,16 @@ class MailAliasForm(FormRevMixin, ModelForm):
|
|||
model = MailAlias
|
||||
exclude = ['mail']
|
||||
|
||||
class MailForm(FormRevMixin, ModelForm):
|
||||
"""Creation, edition d'un objet mail"""
|
||||
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 = Mail
|
||||
|
|
|
@ -679,8 +679,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
|||
"""
|
||||
Return the mail address choosen by the user
|
||||
"""
|
||||
if not self.mail.internal_address:
|
||||
return self.mail.external_mail
|
||||
if not OptionalUser.get_cached_value('mail_accounts') or not self.internal_address:
|
||||
return self.external_mail
|
||||
else:
|
||||
return self.mail.mailalias_set.get(valeur=self.pseudo)
|
||||
|
||||
|
@ -802,6 +802,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
|
||||
|
@ -896,6 +922,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,
|
||||
}
|
||||
self.__original_state = self.state
|
||||
|
||||
|
|
|
@ -564,13 +564,17 @@ def edit_mail(request, mail_instance, **_kwargs):
|
|||
""" Editer un compte mail"""
|
||||
mail = MailForm(
|
||||
request.POST or None,
|
||||
instance=mail_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',
|
||||
|
|
Loading…
Reference in a new issue