mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-09-12 01:03:09 +00:00
Affichage des champs supp de mail que si compte mails actifs
This commit is contained in:
parent
7544757606
commit
cd03f37a83
3 changed files with 40 additions and 6 deletions
|
@ -600,14 +600,16 @@ class MailAliasForm(FormRevMixin, ModelForm):
|
||||||
model = MailAlias
|
model = MailAlias
|
||||||
exclude = ['user']
|
exclude = ['user']
|
||||||
|
|
||||||
class MailForm(FormRevMixin, ModelForm):
|
class MailForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
|
||||||
"""Creation, edition des paramètres 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'
|
||||||
self.fields['redirection'].label = 'Activation de la redirection vers l\'adress externe'
|
if 'redirection' in self.fields:
|
||||||
self.fields['internal_address'].label = 'Adresse mail interne'
|
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:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
|
|
|
@ -682,7 +682,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
|
||||||
"""
|
"""
|
||||||
Return the mail address choosen by the user
|
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
|
return self.external_mail
|
||||||
else:
|
else:
|
||||||
return self.mailalias_set.get(valeur=self.pseudo)
|
return self.mailalias_set.get(valeur=self.pseudo)
|
||||||
|
@ -805,6 +805,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
|
||||||
|
@ -899,6 +925,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -566,13 +566,17 @@ def edit_mail(request, user_instance, **_kwargs):
|
||||||
""" Editer un compte mail"""
|
""" Editer un compte mail"""
|
||||||
mail = MailForm(
|
mail = MailForm(
|
||||||
request.POST or None,
|
request.POST or None,
|
||||||
instance=user_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