def batch_bind_customer_to_device(customer_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) empty_check(customer_id, error_message='The "customer_id" can not be empty.') customer = DccaCustomer.query_by_id(customer_id) empty_check(customer, error_message='The customer not exists or cannot accessable.') check_json(request) device_ids = get_json(request).get('device_ids', []) devices = Host.batch_bind_customer(device_ids, customer) data = [] success = set() try: for device in devices: data.append(device.as_dict(schema=DeviceShortSchema)) success.add(device.id) session.add(device) session.commit() except Exception: raise DCCAException('Fail to bind customer to devices') results = OrderedDict() results['customer'] = customer.as_dict(schema=CustomerSchema) results['devices'] = data results['failure'] = list(set(device_ids) - success) return jsonify(results)
def grant_user_one_role(user_id, role_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) user_id_empty(user_id) user = DccaUser.get_by_id(user_id) user_not_exist(user) role_id_empty(role_id) role = DccaRole.get_by_id(role_id) role_not_exist(role) if not user.has_role(role): try: user.roles.append(role) session.add(user) session.commit() except Exception: raise DCCAException('Fail to grant the role to user') return jsonify({ 'status': 'success', 'message': 'Success to grant role to user %s' % user.username, 'role': role.as_dict(schema=RoleSchema), 'user': user.as_dict(schema=UserSchema) })
def query_devices_by_solution(): """ To-Do: need improvement """ uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) solution_id = request.args.get('solution_id') limit = request.args.get('limit') if request.args.get('limit') else 200 offset = request.args.get('offset') if request.args.get('offset') else 0 results = OrderedDict() results['limit'] = limit results['offset'] = offset results['results'] = [] total, devices = Host.query_ota_devices(solution_id, limit, offset) results['total'] = total if devices: devices = as_dict(devices, DeviceSchema, many=True) for device in devices: device_status = query_one_device_status(device['name']) device.update(device_status) results['results'].append(device) return jsonify(results)
def get_all(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) # is_public = request.args.get('is_public') # TODO not support this now limit = request.args.get('limit') if request.args.get('limit') else 10 offset = request.args.get('offset') if request.args.get('offset') else 0 apps, total = DccaApplication.query_all(limit, offset) data = [] for app in apps: item = app.as_dict(schema=AppSchema) item['image'] = app.full_image(app.owner.username, app.image) item['tags'] = [{'id': t.id, 'name': t.name} for t in app.tags] item['version'] = [s.version for s in app.softapps] data.append(item) results = OrderedDict() results['limit'] = limit results['offset'] = offset results['total'] = total results['applications'] = data return jsonify(results)
def revoke_user_one_role(user_id, role_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) user_id_empty(user_id) user = DccaUser.get_by_id(user_id) user_not_exist(user) role_id_empty(role_id) role = DccaRole.get_by_id(role_id) role_not_exist(role) if user.has_role(role): try: user.revoke_role(role) session.add(user) session.commit() except Exception: raise DCCAException('Fail to revoke the role from user') return jsonify({ 'status': 'success', 'message': 'Success to remove role from user', 'role': role.as_dict(schema=RoleSchema), 'user': user.as_dict(schema=UserSchema) }) else: return jsonify({ 'status': 'success', 'message': 'User hasn\'t been granted of this role.' })
def update_solution(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) solution_id = get_json(request).get('id') url = get_json(request).get('url') is_default = bool_helper(get_json(request).get('is_default')) is_owner = DccaAssSolutionImage.is_solution_owner(solution_id) if not is_owner: return jsonify({ 'status': 'fail', 'message': 'Solution not exist or you are not permit to access' }) image = url.split('/')[-1] if not image: return jsonify({'status': 'fail', 'message': 'Bad URL format'}) solution = DccaAssSolutionImage.query_by_id(solution_id) solution.image = image solution.link = url if is_default: if not DccaModel.check_model_owner(solution.model_id): return jsonify({ 'status': "fail", 'message': "Not the model owner, can't set default solution" }) if solution.is_public != DccaModel.check_model_permission( solution.model_id): return jsonify({ 'status': "fail", 'message': "Solution and model have different permission, can't set default solution" }) solution.model.default_solution_id = solution_id else: solution.model.default_solution_id = None try: session.commit() except Exception as e: err_msg = "Fail to update solution. {}".format(str(e)) raise DCCAException(err_msg) return jsonify({ 'id': solution_id, 'status': 'success', 'message': 'Update the solution successfully' })
def query_device_groups(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') or DEFAULT_GROUP_LIMTI offset = request.args.get('offset') or DEFAULT_GROUP_OFFSET filter_name = request.args.get('filter_name') order_by = request.args.get('order_by') groups, size = DccaDeviceGroup.query_all(DeviceGroupSchema, order_column=order_by, uid=uid, filter_name=filter_name, limit=limit, offset=offset) results = OrderedDict() results['limit'] = limit results['offset'] = offset results['total'] = size results['groups'] = [] for group in groups: results['groups'].append(group.as_dict(schema=DeviceGroupSchema)) return jsonify(results)
def create_device_group(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) name = get_json(request).get('name') desc = get_json(request).get('description') customer = get_json(request).get('customer') if desc is None: desc = '' empty_check(name, error_message='Name cannot be empty') DccaDeviceGroup.is_name_taken(name, ctx.current_user) group = DccaDeviceGroup(name, description=desc, customer=customer) try: session.add(group) session.commit() except Exception: raise DCCAException('Fail to create device group') results = OrderedDict() results['status'] = 'success' results['message'] = 'Success to create a group' results['group'] = group.as_dict(schema=DeviceGroupSchema) return jsonify(results)
def query_all_task_devices(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') if request.args.get('limit') else 100 offset = request.args.get('offset') if request.args.get('offset') else 0 device_set = set() tasks, total = EsTask.query_many(limit, offset) for task in tasks: devices = EsTask.query_task_devices(task) device_set = device_set | devices results = OrderedDict() results['total'] = total results['limit'] = limit results['offset'] = offset results['devices'] = [ d.as_dict(schema=ShortDeviceSchema) for d in device_set ] return jsonify(results)
def query_all_customers(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') if request.args.get('limit') else 20 offset = request.args.get('offset') if request.args.get('offset') else 0 filter_name = request.args.get('filter_name', '') customers, total = DccaCustomer.query_all(filter_name, limit=limit, offset=offset) data = [] for cust in customers: data.append(cust.as_dict(schema=CustomerSchema)) result = OrderedDict() result['limit'] = limit result['offset'] = offset result['total'] = total result['customers'] = data return jsonify(result)
def delete_one_customer(customer_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) empty_check(customer_id, error_message='The "customer_id" can not be empty.') customer = DccaCustomer.query_by_id(customer_id) empty_check(customer, error_message='Not exist or cannot accessable.') try: session.delete(customer) session.commit() except Exception: if IS_DEBUG: import traceback traceback.print_exc() raise DCCAException('Fail to delete customer') return jsonify({ 'status': 'success', 'message': 'Success to delete customer', 'customer': customer.as_dict(schema=CustomerSchema) })
def query_one_group(group_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') if request.args.get( 'limit') else DEFAULT_GROUP_LIMTI offset = request.args.get('offset') if request.args.get( 'offset') else DEFAULT_GROUP_OFFSET empty_check(group_id, error_message='The "group_id" cannot be empty.') results = OrderedDict() # workaround it is not a uuid, group id if group_id and len(str(group_id)) < 32: devices_group_list = DccaAssHostModel.get_model_deviceid(int(group_id)) r = DccaModel.get_by_id(int(group_id)) if not r: raise Exception("%s: group or model not found" % (str(group_id))) results['id'] = r.id name = "%s-%s-%s-%s" % (r.model, r.type, r.platform, r.vendor) results['name'] = name results["description"] = "%s: model group" % name else: group = DccaDeviceGroup.get_by_id(group_id, uid) empty_check(group, error_message='The "group" is not accessable.') devices_group_list = group.query_bind_devices(limit=limit, offset=offset) results['id'] = group_id results["name"] = group.name results["description"] = group.desc results["device"] = OrderedDict() results["device"]['limit'] = limit results["device"]['offset'] = offset results['devices'] = [] total = 0 for device_group in devices_group_list: device_id = device_group[0] device = Host.get_id(device_id) if device: model_id = Host.get_model_id(device_id) devices = device.as_dict(schema=DeviceSchema) devices['status'] = query_one_device_status(devices['name']) total += 1 results['devices'].append(devices) if model_id[0]: model = DccaModel.get_by_id(model_id) devices['model'] = model.as_dict(schema=ModelSchema) results['device']['total'] = total return jsonify(results)
def query_group_devices_statistics(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') if request.args.get( 'limit') else DEFAULT_GROUP_LIMTI_STATISTICS offset = request.args.get('offset') if request.args.get( 'offset') else DEFAULT_GROUP_OFFSET filter_name = request.args.get('filter_name') empty_check(filter_name, error_message='Please pass in filter_name.') model_id = int(filter_name.split("-")[0]) device_ids = DccaAssHostModel.get_model_deviceid(model_id) # print(device_ids) if not device_ids: return jsonify({}) statistics = OrderedDict() statistics['by_continent'] = OrderedDict() statistics['by_continent']['others'] = OrderedDict() statistics['by_continent']['others']['total'] = 0 statistics['by_status'] = OrderedDict() for device_id in device_ids: query_all_location_info_command = query_all_location_info_sql.format( limit=limit, offset=offset, user_id=uid, device_id=device_id[0]) request.cursor.execute(query_all_location_info_command) location_items = request.cursor.fetchall() for loc_item in location_items: status = query_one_device_status(loc_item[1])["status"] loc_item = LocationItem._make(loc_item + (status, )) continent = loc_item.continent status = loc_item.status if continent is None: statistics['by_continent']['others']['total'] += 1 set_status(statistics, continent, status) elif continent not in statistics['by_continent']: statistics['by_continent'][continent] = {'total': 1} set_status(statistics, continent, status) else: statistics['by_continent'][continent]['total'] += 1 set_status(statistics, continent, status) if status is None: statistics['by_status']['others'] += 1 elif status not in statistics['by_status']: statistics['by_status'][status] = 1 else: statistics['by_status'][status] += 1 return jsonify(statistics)
def query_self_role_resource(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) current_user = DccaUser.get_by_id(uid) user = current_user.as_dict(schema=UserItemSchema) user['permissions'] = current_user.role_perm() return jsonify(user)
def query_image_version(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) versions = DccaAssSolutionImage.query_solution_image_versions() return jsonify(versions)
def create_audit_request(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) solution_id = get_json(request).get('solution_id') comments = get_json(request).get('description') permission = get_json(request).get('permission') if not DccaAssSolutionImage.is_solution_owner(solution_id): return jsonify({ 'status': "fail", 'message': "Solution not exist or you are not permit to access." }) solution = DccaAssSolutionImage.get(solution_id) if not DccaModel.check_model_permission( solution.model_id) and not solution.is_public: return jsonify({ 'status': "fail", 'message': "Model is private, Fail ro create request." }) if DccaModel.check_model_permission( solution.model_id) and solution.is_public: if DccaModel.is_bind_solution(solution_id): return jsonify({ 'status': "fail", 'message': "Solution is default solution of public model, Fail to create request." }) to_public = check_permission(permission) req = DccaSolutionAudit(uid, comments, solution_id, to_public) try: session.add(req) session.commit() except Exception as e: err_msg = "Fail to create request. {}".format(str(e)) raise DCCAException(err_msg) return jsonify({ "status": "success", "message": "Request has been created, please wait for approval", "id": req.id })
def batch_delete_device_group(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) group_ids = get_json(request).get('group_ids') empty_check(group_ids, error_message='The "group_ids" cannot be empty.') remove_fail_list = [] remove_list = [] results = OrderedDict() results['groups'] = OrderedDict() results['groups']['success'] = [] results['groups']['fail'] = [] for group_id in group_ids: group = DccaDeviceGroup.get_by_id(group_id, uid) if group: try: remove_list.append(group) group.remove() session.commit() except Exception as e: remove_fail_dict = {'id': group_id, 'message': e} remove_fail_list.append(remove_fail_dict) raise DCCAException('Fail to remove device group') else: message = 'Fail to remove device group' remove_fail_dict = {'id': group_id, 'message': message} remove_fail_list.append(remove_fail_dict) if len(remove_list) == 0: results['status'] = "fail" results['message'] = "Fail to remove device group" for group_fail in remove_fail_list: results['groups']['fail'].append(group_fail) results['groups']['fail_total'] = len(remove_fail_list) else: for group in remove_list: results['status'] = "success" results['message'] = "Success to remove group" results['groups']['success'].append( group.as_dict(schema=DeviceGroupBindSchema)) results['groups']['success_total'] = len(remove_list) for group_fail in remove_fail_list: results['groups']['fail'].append(group_fail) results['groups']['fail_total'] = len(remove_fail_list) return jsonify(results)
def query_solution_name(): """ Get all the owner's solutions """ uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) solution_names = DccaAssSolutionImage.query_solution_names() return jsonify(solution_names)
def query_one_customer(customer_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) empty_check(customer_id, error_message='The "customer_id" can not be empty.') customer = DccaCustomer.query_by_id(customer_id) empty_check(customer, error_message='Not exist or cannot accessable.') return jsonify(customer.as_dict(schema=CustomerSchema))
def query_app_statistics(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) params = { "limit": request.args.get('limit', 10), "offset": request.args.get('offset', 0), "appname": request.args.get('appname', ""), "device": request.args.get('device', "") } ctx.current_user = DccaUser.get_by_id(uid) return jsonify( DccaApplication.get_app_statistics(APPSERVER_HOST, APPSERVER_PORT, params))
def modify_one_group(group_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) empty_check(group_id, error_message='The "group_id" cannot be empty.') check_json(request) name = get_json(request).get('name') input_valid_check(name, error_message='Invalid characters in name.') group = DccaDeviceGroup.get_by_id(group_id, uid) empty_check(group, error_message='The "group" is not accessable.') desc = get_json(request).get('description') if not name and not desc: return jsonify({ 'status': 'fail', 'message': 'Empty parameters, not modified' }) if name: group.name = name if desc: group.desc = desc elif desc == '': group.desc = '' group.updated_at = datetime.utcnow() try: session.add(group) session.commit() except Exception: raise DCCAException('Fail to update group') results = OrderedDict() results['status'] = 'success' results['message'] = 'Success to update group' results['group'] = group.as_dict(schema=DeviceGroupSchema) return jsonify(results)
def query_solutions(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) limit = request.args.get('limit') or 20 offset = request.args.get('offset') or 0 solution_name = request.args.get('solution') model_id = request.args.get('model_id') image = request.args.get('image') version = request.args.get('version') my_solution = bool_helper(request.args.get('my_solution')) results = OrderedDict() results['offset'] = offset results['limit'] = limit results['results'] = [] total, solutions = DccaAssSolutionImage.query_solutions( solution_name, model_id, image, version, my_solution, limit, offset) results['total'] = total if solutions: solutions = as_dict(solutions, SolutionSchema, many=True) for solution in solutions: if solution['owner_id'] == int(uid): solution['is_owner'] = True else: solution['is_owner'] = False del solution['owner_id'] if solution['model']['owner_id'] == int(uid): solution['model']['is_owner'] = True else: solution['model']['is_owner'] = False del solution['model']['owner_id'] if solution['model']['default_solution_id'] == solution['id']: solution['is_default'] = True else: solution['is_default'] = False del solution['model']['default_solution_id'] results['results'].append(solution) return jsonify(results)
def bind_device_to_group(group_id, device_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) empty_check(group_id, error_message='The "group_id" cannot be empty.') empty_check(device_id, error_message='The "device_id" cannot be empty') group = DccaDeviceGroup.get_by_id(group_id, uid) if group is None: return jsonify({ 'status': 'fail', 'message': "The group_id does not exist" }) device = Host.get_by_id(device_id) if device is None: return jsonify({ 'status': 'fail', 'message': "The device_id does not exist" }) results = OrderedDict() if not device.has_group(group): try: device.groups.append(group) session.add(device) session.commit() except Exception: raise DCCAException('Fail to bind device to group') results['status'] = 'success' results['message'] = 'Success to add device to group' results['group'] = group.as_dict(schema=DeviceGroupBindSchema) results['device'] = device.as_dict(schema=DeviceIDSchema) else: results['status'] = 'fail' results[ 'message'] = 'This device already exists in the {} group, please do not add it repeatedly'.format( group.name) return jsonify(results)
def delete_solution(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) solution_id = get_json(request).get('id') if not DccaAssSolutionImage.is_solution_owner(solution_id): return jsonify({ 'status': "fail", 'message': "Solution not exist or you are not permit to access." }) if DccaAssSolutionImage.check_solution_permission(solution_id): return jsonify({ 'status': "fail", 'message': "Can't delete public solution, change it to private solution then delete it" }) if DccaModel.is_bind_solution(solution_id): return jsonify({ 'status': "fail", 'message': "Fail to delete model's default solution. Edit solution to remove the default setting." }) solution = DccaAssSolutionImage.query_by_id(solution_id) try: solution.remove(BUCKET) session.commit() except Exception as e: err_msg = "Fail to delete solution. {}".format(str(e)) raise DCCAException(err_msg) return jsonify({ 'status': 'success', 'message': 'Delete solution successfully' })
def query_solutions_statistics(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) results = {} statistics = Host.query_ota_statistics() if statistics: statistics = as_dict(statistics, DeviceShortSchema, many=True) for stat in statistics: solution = stat['solution'] if solution["id"] not in results: results[solution["id"]] = {} results[solution["id"]].update(solution) results[solution["id"]]["count"] = 1 else: results[solution["id"]]["count"] += 1 return jsonify(list(results.values()))
def handle_audit_request(audit_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) if not ctx.current_user.admin: return jsonify({ 'status': 'fail', 'message': 'Not admin, cannot access' }) action = get_json(request).get('action') audit = DccaSolutionAudit.get(audit_id) if action == 'accept': approved = True if audit.to_public: audit.solution.is_public = True else: audit.solution.is_public = False else: approved = False audit.approved = approved audit.status = True try: session.commit() except Exception as e: err_msg = "Fail to handle the audit request. {}".format(str(e)) raise DCCAException(err_msg) return jsonify({ 'status': 'success', 'message': 'Handle the audit request successfully' })
def query_audit_requests(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) if not ctx.current_user.admin: return jsonify({ 'status': 'fail', 'message': 'Not admin, cannot access' }) limit = request.args.get('limit') or 20 offset = request.args.get('offset') or 0 filter_text = request.args.get('filter_text') or '' order_by = request.args.get('orderBy') or '' order_type = request.args.get('orderType') or 'desc' if order_type not in ['asc', 'desc']: return jsonify({'status': "fail", 'message': "Invalid order type"}) if order_by not in ['created_at', 'status', '']: return jsonify({'status': "fail", 'message': "Invalid orderBy value"}) results = OrderedDict() results['orderType'] = order_type results['orderBy'] = order_by results['offset'] = offset results['limit'] = limit results['results'] = [] total, audits = DccaSolutionAudit.query_audits(filter_text, order_by, order_type, limit, offset) results['total'] = total if audits: results['results'] = as_dict(audits, SolutionAuditSchema, many=True) return jsonify(results)
def modify_customer(customer_id): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) check_json(request) name = get_json(request).get('name') is_active = get_json(request).get('is_active') description = get_json(request).get('description') empty_check(customer_id, error_message='The "customer_id" can not be empty.') customer = DccaCustomer.query_by_id(customer_id) empty_check(customer, error_message='Not exist or cannot accessable.') if name: customer.name = name if is_active is not None: customer.is_active = is_active if description: customer.description = description customer.updated_at = datetime.utcnow() try: session.add(customer) session.commit() except Exception: raise DCCAException('Fail to update customer') return jsonify({ 'status': 'success', 'message': 'Success to update customer', 'customer': customer.as_dict(schema=CustomerSchema) })
def remove_tasks_by_ids(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) ctx.current_user = DccaUser.get_by_id(uid) task_ids_str = request.args.get('task_ids') empty_check(task_ids_str, error_message='The "task_ids" cannot be empty.') task_ids = task_ids_str.split(',') tasks = EsTask.query_in(task_ids) if len(tasks) < len(task_ids): return jsonify({ 'status': 'fail', 'message': 'Not exist or cannot access', 'unauthorized': list(set(task_ids) - set([t.id for t in tasks])) }) try: data = [] for task in tasks: task.logical_delete = True task.ended_at = datetime.utcnow() session.add(task) data.append(task.as_dict(schema=TaskSchema)) session.commit() except Exception: raise DCCAException('Fail to remove task') return jsonify({ 'status': 'success', 'message': 'Success to remove tasks', 'tasks': data })
def check_solution_name(): uid, err = get_oemid(request=request) if err is not None: return jsonify(UNAUTH_RESULT) check_json(request) solution_name = get_json(request).get('solution') model_id = get_json(request).get('model_id') ctx.current_user = DccaUser.get_by_id(uid) is_exist = DccaAssSolutionImage.check_solution_name( solution_name, model_id) if not is_exist: return jsonify({ 'status': 'success', 'message': 'solution name not exist' }) else: return jsonify({ 'status': 'fail', 'message': 'solution name already exists' })