def handle_validated(self, *args, **options): email_address = options['email-address'] user = get_user_by_email(email_address) user_api = vumi_api_for_user(user) self.show_opt_outs(user_api, email_address)
def handle_validated(self, *args, **options): email_address = options['email-address'] tagpool = unicode(options['tagpool']) max_keys = int(options['max-keys']) or None user = get_user_by_email(email_address) account = user.get_profile().get_user_account() existing_tagpools = [] for permissions in account.tagpools.load_all_bunches(): existing_tagpools.extend([ p for p in permissions if p.tagpool == tagpool]) if existing_tagpools: if options['update']: if len(existing_tagpools) == 1: self.update_permission(existing_tagpools[0], max_keys) else: raise CommandError('%s permissions specified for ' 'the same tagpool. Please fix manually' % ( len(existing_tagpools),)) else: raise CommandError('Permission already exists, use ' '--update to update the value of max-keys') else: self.create_permission(user, account, tagpool, max_keys)
def handle_validated(self, *args, **options): email_address = options['email-address'] application_module = unicode(options['application-module']) enable = options['enable'] disable = options['disable'] if (enable and disable) or not (enable or disable): raise CommandError( 'Please specify either --enable or --disable.') user = get_user_by_email(email_address) account = user.get_profile().get_user_account() all_permissions = [] for permissions in account.applications.load_all_bunches(): all_permissions.extend(permissions) existing_applications = [p.application for p in all_permissions] if disable: if application_module in existing_applications: [permission] = [p for p in all_permissions if p.application == application_module] self.disable_application(permission, account) else: raise CommandError('User does not have this permission') if enable: if application_module not in existing_applications: self.enable_application(user, account, application_module) else: raise CommandError('User already has this permission')
def handle(self, *args, **options): options = options.copy() for opt in self.LOCAL_OPTIONS: if options.get(opt.dest) is None: value = raw_input("%s: " % (opt.help,)) if value: options[opt.dest] = value else: raise CommandError('Please provide %s:' % (opt.dest,)) command_options = [c for c in self.CONFLICTING_OPTIONS if options[c]] if len(command_options) != 1: raise CommandError('Please provide exactly one of: %s' % ( ['--%s' % c for c in self.CONFLICTING_OPTIONS],)) user = get_user_by_email(options['email-address']) user_api = vumi_api_for_user(user) if options['show']: return self.handle_show(user_api, options) elif options['clear']: return self.handle_clear(user_api, options) elif options['add']: return self.handle_add(user_api, options) elif options['remove']: return self.handle_remove(user_api, options) raise NotImplementedError('Unknown command.')
def handle(self, *args, **options): options = options.copy() for opt in self.LOCAL_OPTIONS: if options.get(opt.dest) is None: value = raw_input("%s: " % (opt.help, )) if value: options[opt.dest] = value else: raise CommandError('Please provide %s:' % (opt.dest, )) command_options = [c for c in self.CONFLICTING_OPTIONS if options[c]] if len(command_options) != 1: raise CommandError('Please provide exactly one of: %s' % (['--%s' % c for c in self.CONFLICTING_OPTIONS], )) user = get_user_by_email(options['email-address']) user_api = vumi_api_for_user(user) if options['show']: return self.handle_show(user_api, options) elif options['clear']: return self.handle_clear(user_api, options) elif options['add']: return self.handle_add(user_api, options) elif options['remove']: return self.handle_remove(user_api, options) raise NotImplementedError('Unknown command.')
def handle_validated(self, *args, **options): email_address = options['email-address'] application_module = unicode(options['application-module']) enable = options['enable'] disable = options['disable'] if (enable and disable) or not (enable or disable): raise CommandError('Please specify either --enable or --disable.') user = get_user_by_email(email_address) account = user.get_profile().get_user_account() all_permissions = [] for permissions in account.applications.load_all_bunches(): all_permissions.extend(permissions) existing_applications = [p.application for p in all_permissions] if disable: if application_module in existing_applications: [permission] = [ p for p in all_permissions if p.application == application_module ] self.disable_application(permission, account) else: raise CommandError('User does not have this permission') if enable: if application_module not in existing_applications: self.enable_application(user, account, application_module) else: raise CommandError('User already has this permission')
def handle(self, *args, **options): options = options.copy() self.ask_for_options(options, ['email-address', 'contacts-csv']) user = get_user_by_email(options['email-address']) user_api = vumi_api_for_user(user) groups = [g.key for g in user_api.list_groups()] for group in options['groups']: if group not in groups: raise CommandError('Group not found: %s' % (group,)) return self.import_contacts(user_api, options)
def handle(self, *args, **options): if len(args) == 0: self.print_command_summary() return elif len(args) < 2: self.err(u'Usage <email-address> <command>\n') return email_address = args[0] command = args[1] user = get_user_by_email(email=email_address) api = self.get_api(user) handler = getattr(self, 'handle_%s' % (command, ), self.unknown_command) handler(user, api, args[2:])
def handle(self, *args, **options): if len(args) == 0: self.print_command_summary() return elif len(args) < 2: self.err(u'Usage <email-address> <command>\n') return email_address = args[0] command = args[1] user = get_user_by_email(email=email_address) api = self.get_api(user) handler = getattr(self, 'handle_%s' % (command,), self.unknown_command) handler(user, api, args[2:])
def handle(self, *args, **options): options = options.copy() operation = self.get_operation(options, ("list", "create", "create-smart", "delete")) self.ask_for_options(options, ["email-address"]) user = get_user_by_email(options["email-address"]) user_api = vumi_api_for_user(user) if operation == "list": return self.handle_list(user_api, options) elif operation == "create": self.ask_for_options(options, ["group"]) return self.handle_create(user_api, options) elif operation == "create-smart": self.ask_for_options(options, ["group", "query"]) return self.handle_create_smart(user_api, options) elif operation == "delete": self.ask_for_options(options, ["group"]) return self.handle_delete(user_api, options)
def handle(self, *args, **options): options = options.copy() operation = self.get_operation( options, ('list', 'create', 'create-smart', 'delete')) self.ask_for_options(options, ['email-address']) user = get_user_by_email(options['email-address']) user_api = vumi_api_for_user(user) if operation == 'list': return self.handle_list(user_api, options) elif operation == 'create': self.ask_for_options(options, ['group']) return self.handle_create(user_api, options) elif operation == 'create-smart': self.ask_for_options(options, ['group', 'query']) return self.handle_create_smart(user_api, options) elif operation == 'delete': self.ask_for_options(options, ['group']) return self.handle_delete(user_api, options)
def handle(self, *args, **options): user = get_user_by_email(options['email_address']) user_api = vumi_api_for_user(user) conversation = user_api.get_wrapped_conversation( options['conversation_key']) if conversation is None: raise CommandError('Conversation does not exist') elif (conversation.conversation_type not in self.allowed_conversation_types): raise CommandError('Conversation is not allowed for an HTTP API') if options.get('create_token'): self.create_token(conversation) elif options.get('remove_token'): self.remove_token(conversation, options['remove_token']) elif options.get('set_message_url'): self.set_message_url(conversation, options['set_message_url']) elif options.get('remove_message_url'): self.remove_message_url(conversation) elif options.get('set_event_url'): self.set_event_url(conversation, options['set_event_url']) elif options.get('remove_event_url'): self.remove_event_url(conversation)
def get_user_api(self, email): return vumi_api_for_user(get_user_by_email(email))