Change UI to accept 'default' to restore inherited values v0.6.x
authormartin f. krafft <madduck@madduck.net>
Sat, 14 Apr 2012 00:36:43 +0200
branchv0.6.x
changeset 533 2676dbf43e1c
parent 532 2bb40aaef94e
child 534 6a27c7529cd7
Change UI to accept 'default' to restore inherited values Instead of explicit values for tid/ssid/qid, the UI now accepts 'default', which removed user-pecific settings and hence causes domain defaults to be used.
VirtualMailManager/cli/subcommands.py
VirtualMailManager/handler.py
man/de/man1/vmm.1
man/man1/vmm.1
--- a/VirtualMailManager/cli/subcommands.py	Fri Apr 13 23:24:12 2012 +0200
+++ b/VirtualMailManager/cli/subcommands.py	Sat Apr 14 00:36:43 2012 +0200
@@ -617,7 +617,8 @@
     elif ctx.argc < 4:
         usage(EX_MISSING_ARGS, _(u'Missing storage value.'), ctx.scmd)
     try:
-        bytes_ = size_in_bytes(ctx.args[3])
+        bytes_ = ctx.args[3] if ctx.args[3] == 'default' \
+                             else size_in_bytes(ctx.args[3])
     except (ValueError, TypeError):
         usage(INVALID_ARGUMENT, _(u"Invalid storage value: '%s'") %
               ctx.args[3], ctx.scmd)
@@ -641,7 +642,7 @@
     if ctx.argc >= 4:
         services.extend([service.lower() for service in ctx.args[3:]])
         unknown = [service for service in services if service not in SERVICES]
-        if unknown:
+        if unknown and ctx.args[3] != 'default':
             usage(INVALID_ARGUMENT, _(u'Invalid service arguments: %s') %
                   ' '.join(unknown), ctx.scmd)
     ctx.hdlr.user_services(ctx.args[2].lower(), *services)
@@ -719,14 +720,14 @@
                         'address [password]',
                         _(u'update the password for the given address')),
     'userquota': cmd('userquota', 'uq', user_quota,
-                     'address storage [messages]',
+                     'address storage [messages] | address default',
                      _(u'update the quota limit for the given address')),
     'userservices': cmd('userservices', 'us', user_services,
-                        'address [service ...]',
+                        'address [service ...] | address default',
                         _(u'enables the specified services and disables all '
                           u'not specified services')),
     'usertransport': cmd('usertransport', 'ut', user_transport,
-                         'address transport',
+                         'address transport | address default',
                          _(u'update the transport of the given address')),
     # Alias commands
     'aliasadd': cmd('aliasadd', 'aa', alias_add, 'address destination ...',
--- a/VirtualMailManager/handler.py	Fri Apr 13 23:24:12 2012 +0200
+++ b/VirtualMailManager/handler.py	Sat Apr 14 00:36:43 2012 +0200
@@ -763,15 +763,19 @@
 
     def user_quotalimit(self, emailaddress, bytes_, messages=0):
         """Wrapper for Account.update_quotalimit(QuotaLimit)."""
-        if not all(isinstance(i, (int, long)) for i in (bytes_, messages)):
-            raise TypeError("'bytes_' and 'messages' have to be "
-                            "integers or longs.")
         acc = self._get_account(emailaddress)
         if not acc:
             raise VMMError(_(u"The account '%s' does not exist.") %
-                           acc.address, NO_SUCH_ACCOUNT)
-        acc.update_quotalimit(QuotaLimit(self._dbh, bytes=bytes_,
-                                         messages=messages))
+                        acc.address, NO_SUCH_ACCOUNT)
+        if bytes_ == 'default':
+            quotalimit = None
+        else:
+            if not all(isinstance(i, (int, long)) for i in (bytes_, messages)):
+                raise TypeError("'bytes_' and 'messages' have to be "
+                                "integers or longs.")
+            quotalimit = QuotaLimit(self._dbh, bytes=bytes_,
+                                    messages=messages)
+        acc.update_quotalimit(quotalimit)
 
     def user_transport(self, emailaddress, transport):
         """Wrapper for Account.update_transport(Transport)."""
@@ -782,21 +786,26 @@
         if not acc:
             raise VMMError(_(u"The account '%s' does not exist.") %
                            acc.address, NO_SUCH_ACCOUNT)
-        acc.update_transport(Transport(self._dbh, transport=transport))
+        transport = None if transport == 'default' \
+                         else Transport(self._dbh, transport=transport)
+        acc.update_transport(transport)
 
     def user_services(self, emailaddress, *services):
         """Wrapper around Account.update_serviceset()."""
-        kwargs = dict.fromkeys(SERVICES, False)
-        for service in set(services):
-            if service not in SERVICES:
-                raise VMMError(_(u"Unknown service: '%s'") % service,
-                               UNKNOWN_SERVICE)
-            kwargs[service] = True
         acc = self._get_account(emailaddress)
         if not acc:
             raise VMMError(_(u"The account '%s' does not exist.") %
-                           acc.address, NO_SUCH_ACCOUNT)
-        serviceset = ServiceSet(self._dbh, **kwargs)
+                        acc.address, NO_SUCH_ACCOUNT)
+        if len(services) == 1 and services[0] == 'default':
+            serviceset = None
+        else:
+            kwargs = dict.fromkeys(SERVICES, False)
+            for service in set(services):
+                if service not in SERVICES:
+                    raise VMMError(_(u"Unknown service: '%s'") % service,
+                                UNKNOWN_SERVICE)
+                kwargs[service] = True
+            serviceset = ServiceSet(self._dbh, **kwargs)
         acc.update_serviceset(serviceset)
 
     def relocated_add(self, emailaddress, targetaddress):
--- a/man/de/man1/vmm.1	Fri Apr 13 23:24:12 2012 +0200
+++ b/man/de/man1/vmm.1	Sat Apr 14 00:36:43 2012 +0200
@@ -734,10 +734,15 @@
 .B 0
 (null) als Anzahl von Nachrichten angewendet werden.
 .PP
+Anstelle einer Limite, bewirkt das Wort 'default', daß die Limite des
+Kontos gelöscht wird und somit wieder der in der Domain gespeicherte
+Wert für das Konto gilt.
+.PP
 Beispiel:
 .PP
 .nf
 .B vmm userquota d.user@example.com 750m
+.B vmm userquote d.user@example.com default
 .fi
 .\" ------------------------------------
 .SS userservices (us)
@@ -750,10 +755,15 @@
 Der Zugriff auf alle nicht genannten Services wird dem Anwender, mit der
 angegebenen Adresse, verwehrt werden.
 .PP
+Anstelle einer Liste, bewirkt das Wort 'default', daß die benutzerspezifische
+Liste gelöscht wird und somit wieder die in der Domain gespeicherte
+Liste für das Konto gilt.
+.PP
 Beispiel:
-.PP\
+.PP
 .nf
 .B vmm userservices d.user@example.com SMTP IMAP
+.B vmm userservices d.user@example.com default
 .\" ------------------------------------
 .SS usertransport (ut)
 .BI "vmm usertransport" " address transport"
@@ -762,6 +772,11 @@
 .I transport
 für das Konto mit der angegebenen Adresse bestimmt werden.
 .PP
+Wird als
+.I transport
+das Wort 'default' übergeben, so wird der explizite Transport des Kontos
+wieder gelöscht und der in der Domain gespeicherte Wert benutzt.
+.PP
 Beispiel:
 .br
 Angenommen, Sie wollen mit Dovecots
@@ -773,8 +788,8 @@
 .nf
 .B vmm ut d.user@example.com \(dqretry:4.0.0 Mailbox being migrated\(dq
 # Konvertieren der Mailbox …
-# … danach den Transport auf Dovecots lmtp setzen
-.B vmm usertransport d.user@example.com lmtp:unix:private/dovecot\-lmtp
+# … danach den Transport auf den Domain-Default setzen
+.B vmm usertransport d.user@example.com default
 .fi
 .\" -----------------------------------------------------------------------
 .SH ALIAS UNTERBEFEHLE
--- a/man/man1/vmm.1	Fri Apr 13 23:24:12 2012 +0200
+++ b/man/man1/vmm.1	Sat Apr 14 00:36:43 2012 +0200
@@ -700,6 +700,11 @@
 .B 0
 (zero) will be applied.
 .PP
+Instead of
+.I transport
+pass 'default' to remove the account-specific override, causing the
+domain's value to be in effect.
+.PP
 Example:
 .PP
 .nf
@@ -716,6 +721,11 @@
 given
 .IR address .
 .PP
+Instead of
+.I transport
+pass 'default' to remove the account-specific override, causing the
+domain's value to be in effect.
+.PP
 Example:
 .PP\
 .nf
@@ -728,6 +738,11 @@
 .I transport
 for an account can be specified with this subcommand.
 .PP
+Instead of
+.I transport
+pass 'default' to remove the account-specific override, causing the
+domain's value to be in effect.
+.PP
 Example:
 .br
 Assumed you want to use Dovecot's