def resource_post(): """Function which edits resource name. :return: If there is already resource with this name: {'error': 'resource already exists'}, 400 If request data is invalid: {'status': False, 'error': [list of errors]}, 400 If all ok: {'added_resource': 'resource_name', 'resource_id': 'resource_id'} """ data = request.get_json() valid = validator.resource_post(data) if valid['status']: if db.get_resource_id(data['resource_name']): return jsonify(error='Resource already exists'), 400 db.add_resource(data['resource_name']) added_res_id = db.get_resource_id(data['resource_name']) response = jsonify(added_resource=data['resource_name'], resource_id=added_res_id[0]) session['access_control'] = permission_control.reload_dct() else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response
def resource_name_exists(resource_name): """Validator function which checks if resource name is allready in database. :params: resource_name - string to check :return: True - if it is in database False - if name is free not in database """ return bool(db.get_resource_id(resource_name))
def resource_put(): """Function which edits resource name by its id. :rtype: JSON :request args: `{resource_name: "new_res_name", resource_id: 29}` :return: - If there is already resource with this name: ``{'error': 'this name already exists'}`` - If request data is invalid: ``{'status': False, 'error': [list of errors]}`` - If all ok: ``{'status': 'success', 'edited': 'resource_name'}`` :statuscode 400: resource already exists or request is invalid :statuscode 200: resource was successfully posted """ data = request.get_json() valid = validator.resource_put(data) if valid['status']: if db.get_resource_id(data['resource_name']): return jsonify(error='this name already exists'), 400 db.edit_resource_name(data['resource_name'], data['resource_id']) response = jsonify(status='success', edited=data['resource_name']) session['access_control'] = permission_control.reload_dct() else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response
def resource_name_exists(resource_name): """Validator function which checks if resource name is allready in database. :params: resource_name - string to check :return: True - if resource is free not in database False - if it is in database """ return db.get_resource_id(resource_name)
def resource_post(): """Function which adds new site resource to site-map in admin panel. :rtype: JSON :request agrs: `{resource_name: "/res_name"}` :return: - If there is already resource with this name: ``{'error': 'resource already exists'}`` - If request data is invalid: ``{'status': False, 'error': [list of errors]}`` - If all ok: ``{'added_resource': 'resource_name', 'resource_id': 'resource_id'}`` :statuscode 400: resource already exists or request is invalid :statuscode 200: resource was successfully posted """ data = request.get_json() valid = validator.resource_post(data) if valid['status']: if db.get_resource_id(data['resource_name']): return jsonify(error='Resource already exists'), 400 db.add_resource(data['resource_name']) added_res_id = db.get_resource_id(data['resource_name']) response = jsonify(added_resource=data['resource_name'], resource_id=added_res_id[0]) session['access_control'] = permission_control.reload_dct() else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response