VMM: Added option `-n NOTE' to {domain,user}add. v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Sun, 13 Jan 2013 18:12:51 +0000
branchv0.7.x
changeset 686 5f4abdab738e
parent 685 c6024bc1de0f
child 687 5eb033796444
VMM: Added option `-n NOTE' to {domain,user}add.
VirtualMailManager/cli/handler.py
VirtualMailManager/cli/subcommands.py
VirtualMailManager/handler.py
--- a/VirtualMailManager/cli/handler.py	Sun Jan 13 17:24:01 2013 +0000
+++ b/VirtualMailManager/cli/handler.py	Sun Jan 13 18:12:51 2013 +0000
@@ -66,7 +66,7 @@
             raise VMMError(_("Invalid section: '%s'") % section,
                            INVALID_SECTION)
 
-    def user_add(self, emailaddress, password=None):
+    def user_add(self, emailaddress, password=None, note=None):
         """Override the parent user_add() - add the interactive password
         dialog.
 
@@ -81,6 +81,8 @@
         if password is None:
             password = (read_pass, randompw)[rand_pass]()
         acc.set_password(password)
+        if note:
+            acc.set_note(note)
         acc.save()
         self._make_account_dirs(acc)
         return (None, password)[rand_pass]
--- a/VirtualMailManager/cli/subcommands.py	Sun Jan 13 17:24:01 2013 +0000
+++ b/VirtualMailManager/cli/subcommands.py	Sun Jan 13 18:12:51 2013 +0000
@@ -167,12 +167,13 @@
     """create a new domain"""
     fqdn = ctx.args.fqdn.lower()
     transport = ctx.args.transport.lower() if ctx.args.transport else None
-    ctx.hdlr.domain_add(fqdn, transport)
+    ctx.hdlr.domain_add(fqdn, transport, ctx.args.note)
     if ctx.cget('domain.auto_postmaster'):
         w_std(_('Creating account for postmaster@%s') % fqdn)
         ctx.args.scmd = 'useradd'
         ctx.args.address = 'postmaster@%s' % fqdn
         ctx.args.password = None
+        ctx.args.note = None
         user_add(ctx)
 
 
@@ -339,7 +340,8 @@
 
 def user_add(ctx):
     """create a new e-mail user with the given address"""
-    gen_pass = ctx.hdlr.user_add(ctx.args.address.lower(), ctx.args.password)
+    gen_pass = ctx.hdlr.user_add(ctx.args.address.lower(), ctx.args.password,
+                                 ctx.args.note)
     if not ctx.args.password and gen_pass:
         w_std(_("Generated password: %s") % gen_pass)
 
@@ -615,6 +617,8 @@
                "domain.")),
            formatter_class=RawDescriptionHelpFormatter)
     da.add_argument('fqdn', help=_('a fully qualified domain name'))
+    da.add_argument('-n', metavar='NOTE', dest='note',
+                    help=_('the note that should be set'))
     da.add_argument('-t', metavar='TRANSPORT', dest='transport',
                     help=_('a Postfix transport (transport: or '
                            'transport:nexthop)'))
@@ -771,6 +775,8 @@
            formatter_class=RawDescriptionHelpFormatter)
     ua.add_argument('address',
                     help=_("an account's e-mail address (local-part@fqdn)"))
+    ua.add_argument('-n', metavar='NOTE', dest='note',
+                    help=_('the note that should be set'))
     ua.add_argument('-p', metavar='PASSWORD', dest='password',
                     help=_("the new user's password"))
     ua.set_defaults(func=user_add, scmd='useradd')
--- a/VirtualMailManager/handler.py	Sun Jan 13 17:24:01 2013 +0000
+++ b/VirtualMailManager/handler.py	Sun Jan 13 18:12:51 2013 +0000
@@ -431,7 +431,7 @@
         assert 'cfg_dget' not in builtins.__dict__
         builtins.__dict__['cfg_dget'] = self._cfg.dget
 
-    def domain_add(self, domainname, transport=None):
+    def domain_add(self, domainname, transport=None, note=None):
         """Wrapper around Domain's set_quotalimit, set_transport and save."""
         dom = self._get_domain(domainname)
         if transport is None:
@@ -439,6 +439,8 @@
                               transport=self._cfg.dget('domain.transport')))
         else:
             dom.set_transport(Transport(self._dbh, transport=transport))
+        if note:
+            dom.set_note(note)
         dom.set_quotalimit(QuotaLimit(self._dbh,
                            bytes=int(self._cfg.dget('domain.quota_bytes')),
                            messages=self._cfg.dget('domain.quota_messages')))
@@ -626,7 +628,7 @@
                                 lpattern=lpattern, llike=llike,
                                 dpattern=dpattern, dlike=dlike)
 
-    def user_add(self, emailaddress, password):
+    def user_add(self, emailaddress, password, note=None):
         """Wrapper around Account.set_password() and Account.save()."""
         acc = self._get_account(emailaddress)
         if acc:
@@ -634,6 +636,8 @@
                            acc.address, ACCOUNT_EXISTS)
         self._is_other_address(acc.address, TYPE_ACCOUNT)
         acc.set_password(password)
+        if note:
+            acc.set_note(note)
         acc.save()
         self._make_account_dirs(acc)