def migrate_tasks_to_task20(): if not config.DEBUG: limit_to_acl() limit_to_password() task20_migrate_tasks() return jsonify(status='ok')
def unblock_user_from_truex_task_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() payload = request.get_json(silent=True) user_id = payload.get('user_id', None) unblock_user_from_truex_tasks(user_id) return jsonify(status='ok')
def update_extra_data_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() payload = request.get_json(silent=True) categories_extra_data = payload.get('categories_extra_data') update_categories_extra_data(categories_extra_data) return jsonify(status='ok')
def system_versions_force_update_below_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() payload = request.get_json(silent=True) os_type = payload.get('os_type', None) app_version = payload.get('version', None) set_force_update_below(os_type, app_version) return jsonify(status='ok')
def switch_task_ids_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() payload = request.get_json(silent=True) task_id1 = payload.get('task_id1', None) task_id2 = payload.get('task_id2', None) switch_task_ids(task_id1, task_id2) return jsonify(status='ok')
def remove_task_from_completed_tasks_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() payload = request.get_json(silent=True) user_id = payload.get('user_id', None) task_id = payload.get('task_id', None) remove_task_from_completed_tasks(user_id, task_id) return jsonify(status='ok')
def post_task_results_endpoint(): """an endpoint that can be used to return task results for bi""" limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) task_id = payload.get('task_id', None) if task_id is None: raise InvalidUsage('bad-request') except Exception as e: print(e) raise InvalidUsage('bad-request') return jsonify(status='ok', results=get_task_results(task_id))
def user_goods_report_endpoint(): """returns a summary of the user's goods data""" limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) user_id = payload.get('user_id', None) user_phone = payload.get('phone', None) if (user_id is None and user_phone is None) or (user_id is not None and user_phone is not None): print('user_goods_report_endpoint: userid %s, user_phone %s' % (user_id, user_phone)) raise InvalidUsage('bad-request') except Exception as e: print(e) raise InvalidUsage('bad-request') try: # sanitize user_id: if user_id: UUID(user_id) except Exception as e: log.error('cant generate tx report for user_id: %s ' % user_id) return jsonify(error='invalid_userid') if user_id: if not user_exists(user_id): print( 'user_goods_report_endpoint: user_id %s does not exist. aborting' % user_id) return jsonify(erorr='no_such_user') else: return jsonify(report=[get_user_goods_report(user_id)]) else: # user_phone user_ids = get_all_user_id_by_phone( user_phone) # there may be a few users with this phone if not user_ids: print( 'user_goods_report_endpoint: user_phone %s does not exist. aborting' % user_phone) return jsonify(erorr='no_such_phone') else: return jsonify(report=[ get_user_goods_report(user_id) for user_id in user_ids ])
def user_set_captcha_endpoint(): if not config.DEBUG: limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) user_ids = payload.get('user_ids') should_show = payload.get('set_captcha', 0) except Exception as e: log.error('failed to process user-set-captcha') else: for user_id in user_ids: print('user_set_captcha_endpoint: setting user_id %s to %s' % (user_id, should_show)) set_should_solve_captcha(user_id, should_show) return jsonify(status='ok')
def blacklist_user_endpoint(): """""" if not config.DEBUG: limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) user_id = payload.get('user_id', None) if user_id is None: raise InvalidUsage('bad-request') except Exception as e: print(e) raise InvalidUsage('bad-request') else: if blacklist_phone_by_user_id(user_id): return jsonify(status='ok') else: return jsonify(status='error')
def skip_wait_endpoint(): """sets the next task's timestamp to the past for the given user""" limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) user_id = payload.get('user_id', None) cat_id = payload.get('cat_id', None) next_ts = payload.get('next_ts', 1) # optional if user_id is None: raise InvalidUsage('bad-request') except Exception as e: print(e) raise InvalidUsage('bad-request') else: store_next_task_results_ts(user_id, 'fake_task_id', next_ts, cat_id) increment_metric('skip-wait') return jsonify(status='ok')
def nuke_user_api(): """internal endpoint used to nuke a user's task and tx data. use with care""" if not config.DEBUG: limit_to_acl() limit_to_password() try: payload = request.get_json(silent=True) phone_number = payload.get('phone_number', None) nuke_all = payload.get('nuke_all', False) == True if None in (phone_number, ): raise InvalidUsage('bad-request') except Exception as e: print(e) raise InvalidUsage('bad-request') user_ids = nuke_user_data(phone_number, nuke_all) if user_ids is None: print('could not find any user with this number: %s' % phone_number) return jsonify(status='error', reason='no_user') else: print('nuked users with phone number: %s and user_ids %s' % (phone_number, user_ids)) return jsonify(status='ok', user_id=user_ids)