From 17757800b8adb137c2af82022b9088a8bb67d9ab Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Wed, 22 Nov 2023 19:15:01 +0100 Subject: [PATCH] mailbox not change pass on single reload --- orchestra/contrib/mailboxes/admin.py | 2 ++ orchestra/contrib/mailboxes/backends.py | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/orchestra/contrib/mailboxes/admin.py b/orchestra/contrib/mailboxes/admin.py index 09924dd6..5315a86c 100644 --- a/orchestra/contrib/mailboxes/admin.py +++ b/orchestra/contrib/mailboxes/admin.py @@ -213,6 +213,8 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo old = Mailbox.objects.get(pk=obj.pk) if old.custom_filtering != obj.custom_filtering: messages.warning(request, msg) + # pass var to the backend so you don't change the password + obj.changepass = None elif obj.custom_filtering: messages.warning(request, msg) super(MailboxAdmin, self).save_model(request, obj, form, change) diff --git a/orchestra/contrib/mailboxes/backends.py b/orchestra/contrib/mailboxes/backends.py index c15c42fb..8de35114 100644 --- a/orchestra/contrib/mailboxes/backends.py +++ b/orchestra/contrib/mailboxes/backends.py @@ -69,13 +69,15 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController): self.append(textwrap.dedent(""" # Update/create %(user)s user state if id %(user)s ; then - old_password=$(getent shadow %(user)s | cut -d':' -f2) - usermod %(user)s \\ - --shell %(initial_shell)s \\ - --password '%(password)s' - if [[ "$old_password" != '%(password)s' ]]; then - # Postfix SASL caches passwords - RESTART_POSTFIX=1 + if [[ "%(changepass)s" == "True" ]]; then + old_password=$(getent shadow %(user)s | cut -d':' -f2) + usermod %(user)s \\ + --shell %(initial_shell)s \\ + --password '%(password)s' + if [[ "$old_password" != '%(password)s' ]]; then + # Postfix SASL caches passwords + RESTART_POSTFIX=1 + fi fi else useradd %(user)s \\ @@ -135,6 +137,11 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController): super().commit() def get_context(self, mailbox): + # Check if you have to change password + try: + changepass = mailbox.changepass + except: + changepass = True context = { 'user': mailbox.name, 'group': mailbox.name, @@ -144,6 +151,7 @@ class UNIXUserMaildirController(SieveFilteringMixin, ServiceController): 'maildir': os.path.join(mailbox.get_home(), 'Maildir'), 'initial_shell': self.SHELL, 'banner': self.get_banner(), + 'changepass': changepass, } context['deleted_home'] = settings.MAILBOXES_MOVE_ON_DELETE_PATH % context return context