# HG changeset patch # User Goffi # Date 1491171781 -7200 # Node ID 0d27d95652a72e9cee03726f4e49c438e78ef8ae # Parent 77a3d0a28642a93d58d5e8ae2118f31a748a053d jp (invitation): added modify command diff -r 77a3d0a28642 -r 0d27d95652a7 frontends/src/jp/cmd_invitation.py --- a/frontends/src/jp/cmd_invitation.py Mon Apr 03 00:23:01 2017 +0200 +++ b/frontends/src/jp/cmd_invitation.py Mon Apr 03 00:23:01 2017 +0200 @@ -130,8 +130,51 @@ exit_code=C.EXIT_BRIDGE_ERRBACK)) +class Modify(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'modify', use_profile=False, help=_(u'modify existing invitation')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("--replace", action='store_true', help='replace the whole data') + self.parser.add_argument("-n", "--name", type=base.unicode_decoder, default='', help='name of the invitee') + self.parser.add_argument("-N", "--host-name", type=base.unicode_decoder, default='', help='name of the host') + self.parser.add_argument("-e", "--email", type=base.unicode_decoder, default='', help='email to send the invitation to (if --no-email is set, email will just be saved)') + self.parser.add_argument("-l", "--lang", type=base.unicode_decoder, default='', help='main language spoken by the invitee') + self.parser.add_argument("-x", "--extra", metavar=('KEY', 'VALUE'), type=base.unicode_decoder, action='append', nargs=2, default=[], help='extra data to associate with invitation/invitee') + self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default='', help="profile doing the invitation (default: don't associate profile") + self.parser.add_argument("id", type=base.unicode_decoder, + help=_(u"invitation UUID")) + + def invitationModifyCb(self): + self.disp(_(u'invitations have been modified correctly')) + self.host.quit(C.EXIT_OK) + + def invitationModifyEb(self, failure_): + self.disp(u"can't create invitation: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def start(self): + extra = dict(self.args.extra) + for arg_name in ('name', 'host_name', 'email', 'lang', 'profile'): + value = getattr(self.args, arg_name) + if not value: + continue + if arg_name in extra: + self.parser.error(_(u"you can't set {arg_name} in both optional argument and extra").format(arg_name=arg_name)) + extra[arg_name] = value + self.host.bridge.invitationModify( + self.args.id, + extra, + self.args.replace, + callback=self.invitationModifyCb, + errback=self.invitationModifyEb) + + class Invitation(base.CommandBase): - subcommands = (Create, Get) + subcommands = (Create, Get, Modify) def __init__(self, host): super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))