From b924a20793252dfafaa5b59d2aa5cbad5ac7ffbf Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 8 Dec 2017 10:45:08 +0100 Subject: [PATCH] Feature/merge sender login queries (#1322) * Merged sender login related queries. see #1164 * Added upgrade instructions. * Fixed registration. --- doc/upgrade.rst | 18 ++++++ modoboa/admin/handlers.py | 3 +- modoboa/admin/postfix_maps.py | 83 +++++++++++----------------- modoboa/admin/tests/test_mapfiles.py | 3 +- 4 files changed, 52 insertions(+), 55 deletions(-) diff --git a/doc/upgrade.rst b/doc/upgrade.rst index 7a715c4a2..227ec52ea 100644 --- a/doc/upgrade.rst +++ b/doc/upgrade.rst @@ -89,6 +89,24 @@ Rebuild Virtual Environment Specific instructions ********************* +1.9.2 +===== + +First of all, update postfix map files as follows: + +.. sourcecode:: bash + + > python manage.py generate_postfix_maps --destdir + +Then, modify postfix's configuration as follows:: + + smtpd_sender_login_maps = + :/sql-sender-login-map.cf + +Replace ```` and ```` by your values. + +Finally, reload postfix. + 1.9.0 ===== diff --git a/modoboa/admin/handlers.py b/modoboa/admin/handlers.py index 41663b927..c51e01b27 100644 --- a/modoboa/admin/handlers.py +++ b/modoboa/admin/handlers.py @@ -150,8 +150,7 @@ def register_postfix_maps(sender, **kwargs): return [ postfix_maps.DomainsMap, postfix_maps.DomainsAliasesMap, postfix_maps.AliasesMap, postfix_maps.MaintainMap, - postfix_maps.SenderLoginAliasMap, postfix_maps.SenderLoginMailboxMap, - postfix_maps.SenderLoginMailboxExtraMap + postfix_maps.SenderLoginMap ] diff --git a/modoboa/admin/postfix_maps.py b/modoboa/admin/postfix_maps.py index 1af7112fa..c904a7eeb 100644 --- a/modoboa/admin/postfix_maps.py +++ b/modoboa/admin/postfix_maps.py @@ -97,72 +97,53 @@ class MaintainMap(object): ) -class SenderLoginMailboxMap(object): +class SenderLoginMap(object): + """Map file to list authorized sender addresses for a given account: + * Its mailbox + * Its aliases + * Extra addresses + """ - """Map file to list authorized sender addresses (from mailboxes).""" - - filename = "sql-sender-login-mailboxes.cf" + filename = "sql-sender-login-map.cf" mysql = ( - "SELECT email FROM core_user WHERE email='%s' AND is_active=1 " - ) - postgres = ( - "SELECT email FROM core_user WHERE email='%s' AND is_active" - ) - sqlite = ( - "SELECT email FROM core_user WHERE email='%s' AND is_active=1" - ) - - -class SenderLoginMailboxExtraMap(object): - """Map file to list per-mailbox extra addresses.""" - - filename = "sql-sender-login-mailboxes-extra.cf" - - # FIXME: is it necessary to filter against user status? - - mysql = ( - "SELECT concat(mb.address, '@', dom.name) FROM admin_mailbox mb " + "(SELECT email FROM core_user WHERE email='%s' AND is_active=1) " + "UNION " + "(SELECT concat(mb.address, '@', dom.name) FROM admin_mailbox mb " "INNER JOIN admin_senderaddress sad ON sad.mailbox_id=mb.id " "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " - "WHERE sad.address='%s'" - ) - postgres = ( - "SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " - "INNER JOIN admin_senderaddress sad ON sad.mailbox_id=mb.id " - "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " - "WHERE sad.address='%s'" - ) - sqlite = ( - "SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " - "INNER JOIN admin_senderaddress sad ON sad.mailbox_id=mb.id " - "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " - "WHERE sad.address='%s'" - ) - - -class SenderLoginAliasMap(object): - - """Map file to list authorized sender addresses (from aliases).""" - - filename = "sql-sender-login-aliases.cf" - mysql = ( - "SELECT concat(mb.address, '@', dom.name) FROM admin_mailbox mb " + "WHERE sad.address='%s') " + "UNION " + "(SELECT concat(mb.address, '@', dom.name) FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id" " INNER JOIN admin_domain dom ON dom.id=mb.domain_id" " INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled=1 AND al.address='%s'" + "WHERE al.enabled=1 AND al.address='%s')" ) postgres = ( - "SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " + "(SELECT email FROM core_user WHERE email='%s' AND is_active) " + "UNION " + "(SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " + "INNER JOIN admin_senderaddress sad ON sad.mailbox_id=mb.id " + "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " + "WHERE sad.address='%s') " + "UNION " + "(SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id" " INNER JOIN admin_domain dom ON dom.id=mb.domain_id" " INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled AND al.address='%s'" + "WHERE al.enabled AND al.address='%s')" ) sqlite = ( - "SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " + "(SELECT email FROM core_user WHERE email='%s' AND is_active=1) " + "UNION " + "(SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " + "INNER JOIN admin_senderaddress sad ON sad.mailbox_id=mb.id " + "INNER JOIN admin_domain dom ON dom.id=mb.domain_id " + "WHERE sad.address='%s') " + "UNION " + "(SELECT mb.address || '@' || dom.name FROM admin_mailbox mb " "INNER JOIN modoboa_admin_aliasrecipient alr ON alr.r_mailbox_id=mb.id" " INNER JOIN admin_domain dom ON dom.id=mb.domain_id" " INNER JOIN admin_alias al ON alr.alias_id=al.id " - "WHERE al.enabled=1 AND al.address='%s'" + "WHERE al.enabled=1 AND al.address='%s')" ) diff --git a/modoboa/admin/tests/test_mapfiles.py b/modoboa/admin/tests/test_mapfiles.py index ff0bd2ba1..1f0104681 100644 --- a/modoboa/admin/tests/test_mapfiles.py +++ b/modoboa/admin/tests/test_mapfiles.py @@ -18,8 +18,7 @@ class MapFilesTestCase(MapFilesTestCaseMixin, TestCase): MAP_FILES = [ "sql-domains.cf", "sql-domain-aliases.cf", "sql-aliases.cf", - "sql-maintain.cf", "sql-sender-login-mailboxes.cf", - "sql-sender-login-mailboxes-extra.cf", "sql-sender-login-aliases.cf" + "sql-maintain.cf", "sql-sender-login-map.cf" ] def test_map_upgrade(self):