def check_config(self, config): """ Check config when create auth-event. """ msg = '' try: check_contract(self.CONFIG_CONTRACT, config) return '' except CheckException as e: return json.dumps(e.data, cls=JsonTypeEncoder)
def check_config(config): ''' Implement this method to check that the input data is valid. It should be as strict as possible. By default, config is checked to be empty. ''' check_contract([{ 'check': 'lambda', 'lambda': lambda data: data is None, 'help': 'check config is empty' }], config)
def post(self, request, pk): permission_required(request.user, 'AuthEvent', 'edit', pk) ae = get_object_or_404(AuthEvent, pk=pk) req = parse_json_request(request) user_ids = req.get('user-ids', []) check_contract(CONTRACTS['list_of_ints'], user_ids) for uid in user_ids: u = get_object_or_404(User, pk=uid, userdata__event=ae) for acl in u.userdata.acls.all(): acl.delete() u.delete() return json_response()
def post(self, request, pk): permission_required(request.user, 'AuthEvent', ['edit', 'census-delete'], pk) ae = get_object_or_404(AuthEvent, pk=pk) req = parse_json_request(request) user_ids = req.get('user-ids', []) check_contract(CONTRACTS['list_of_ints'], user_ids) for uid in user_ids: u = get_object_or_404(User, pk=uid, userdata__event=ae) for acl in u.userdata.acls.all(): acl.delete() u.delete() return json_response()
def post(self, request, pk): permission_required(request.user, 'AuthEvent', 'edit', pk) ae = get_object_or_404(AuthEvent, pk=pk) req = parse_json_request(request) user_ids = req.get('user-ids', []) check_contract(CONTRACTS['list_of_ints'], user_ids) for uid in user_ids: u = get_object_or_404(User, pk=uid, userdata__event=ae) u.is_active = self.activate u.save() if self.activate: send_codes.apply_async(args=[[u for u in user_ids], get_client_ip(request)]) return json_response()
def post(self, request, pk): permission_required(request.user, 'AuthEvent', ['edit', 'census-activation'], pk) ae = get_object_or_404(AuthEvent, pk=pk) req = parse_json_request(request) user_ids = req.get('user-ids', []) check_contract(CONTRACTS['list_of_ints'], user_ids) for uid in user_ids: u = get_object_or_404(User, pk=uid, userdata__event=ae) u.is_active = self.activate u.save() if self.activate: send_codes.apply_async( args=[ [u for u in user_ids], get_client_ip(request), ae.auth_method ]) return json_response()
def check_pipeline_conf(pipeline_conf, name, checker_conf=DEFAULT_CHECKER_CONF): ''' Checks the pipeline_conf is valid ''' pipeline_pipes = Pipe.get_pipes(name) return check_contract([ { 'check': "isinstance", 'type': list }, { 'check': 'length', 'range': [0, checker_conf['max-num-pipes']] }, { 'check': "iterate-list", 'check-list': [ { 'check': 'isinstance', 'type': list }, { 'check': 'length', 'range': [2,2] }, { 'check': 'index-check-list', 'index': 0, 'check-list': [ { 'check': 'isinstance', 'type': str }, { 'check': 'length', 'range': [1,255] }, ] }, { 'check': 'lambda', 'lambda': lambda data: data[0] in pipeline_pipes.keys(), 'help': 'check the pipe is valid' }, { 'check': 'lambda', 'lambda': lambda data: pipeline_pipes[data[0]].check_config(data[1]), 'help': 'check the pipe conf is valid' } ] } ], pipeline_conf)
def check_config(config): ''' Implement this method to check that the input data is valid. Example config: { "mode": "lugo", "mode-config": { "baseurl": "http://foo/conecta/services", "query":"obterPersoa", "check_field":"empadroado", "store_fields":["nomeCompreto"], "inactive_subject": "", "inactive_msg": "", "arg_func": "lugo" } } ''' check_contract([ { 'check': 'isinstance', 'type': dict }, { 'check': 'dict-keys-exact', 'keys': ['mode', 'mode-config'] }, { 'check': 'index-check-list', 'index': 'mode', 'check-list': [ { 'check': 'isinstance', 'type': str }, { 'check': 'lambda', 'lambda': lambda d: d in ['lugo'] } ] }, { 'check': 'index-check-list', 'index': 'mode-config', 'check-list': [ { 'check': 'isinstance', 'type': dict } ] }, #{ # 'check': 'switch-contract-by-dict-key', # 'switch-key': 'mode', # 'contract-key': 'mode-config', # 'contracts': { # # start LUGO # 'lugo': [ # { # 'check': 'dict-keys-exact', # 'keys': ['baseurl', 'check_field', 'store_fields', # 'query', 'arg_func', # 'inactive_msg'] # }, # { # 'check': 'index-check-list', # 'index': 'baseurl', # 'check-list': [ # { # 'check': 'isinstance', # 'type': str # }, # { # 'check': 'length', # 'range': [1, 512] # } # ] # }, # ] # # end LUGO # } #} ], config)