mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-16 00:13:12 +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,13 +603,15 @@ class MailAliasForm(FormRevMixin, ModelForm):
|
||||||
model = MailAlias
|
model = MailAlias
|
||||||
exclude = ['mail']
|
exclude = ['mail']
|
||||||
|
|
||||||
class MailForm(FormRevMixin, ModelForm):
|
class MailForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
"""Creation, edition d'un objet mail"""
|
"""Creation, edition des paramètres mail"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(MailForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(MailForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['external_mail'].label = 'Adresse mail externe'
|
self.fields['external_mail'].label = 'Adresse mail externe'
|
||||||
|
if 'redirection' in self.fields:
|
||||||
self.fields['redirection'].label = 'Activation de la redirection vers l\'adress externe'
|
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'
|
self.fields['internal_address'].label = 'Adresse mail interne'
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -679,8 +679,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
"""
|
"""
|
||||||
Return the mail address choosen by the user
|
Return the mail address choosen by the user
|
||||||
"""
|
"""
|
||||||
if not self.mail.internal_address:
|
if not OptionalUser.get_cached_value('mail_accounts') or not self.internal_address:
|
||||||
return self.mail.external_mail
|
return self.external_mail
|
||||||
else:
|
else:
|
||||||
return self.mail.mailalias_set.get(valeur=self.pseudo)
|
return self.mail.mailalias_set.get(valeur=self.pseudo)
|
||||||
|
|
||||||
|
@ -802,6 +802,32 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
"Droit requis pour changer le shell"
|
"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
|
@staticmethod
|
||||||
def can_change_force(user_request, *_args, **_kwargs):
|
def can_change_force(user_request, *_args, **_kwargs):
|
||||||
""" Check if a user can change a force
|
""" Check if a user can change a force
|
||||||
|
@ -896,6 +922,8 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
'shell': self.can_change_shell,
|
'shell': self.can_change_shell,
|
||||||
'force': self.can_change_force,
|
'force': self.can_change_force,
|
||||||
'selfpasswd': self.check_selfpasswd,
|
'selfpasswd': self.check_selfpasswd,
|
||||||
|
'redirection': self.can_change_redirection,
|
||||||
|
'internal_address' : self.can_change_internal_address,
|
||||||
}
|
}
|
||||||
self.__original_state = self.state
|
self.__original_state = self.state
|
||||||
|
|
||||||
|
|
|
@ -564,13 +564,17 @@ def edit_mail(request, mail_instance, **_kwargs):
|
||||||
""" Editer un compte mail"""
|
""" Editer un compte mail"""
|
||||||
mail = MailForm(
|
mail = MailForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=mail_instance
|
instance=user_instance,
|
||||||
|
user=request.user
|
||||||
)
|
)
|
||||||
if mail.is_valid():
|
if mail.is_valid():
|
||||||
if mail.changed_data:
|
if mail.changed_data:
|
||||||
mail.save()
|
mail.save()
|
||||||
messages.success(request, "Compte mail modifiée")
|
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(
|
return form(
|
||||||
{'userform': mail, 'action_name': 'Editer un compte mail'},
|
{'userform': mail, 'action_name': 'Editer un compte mail'},
|
||||||
'users/user.html',
|
'users/user.html',
|
||||||
|
|
Loading…
Reference in a new issue