def workspace_create_or_update(workspace): # only admins can create workspaces validate_admin_perm() try: document = json.loads(flask.request.data) except ValueError: return build_bad_request_response('invalid json') if not document.get('name', None): return build_bad_request_response('workspace name needed') if document.get('name') != workspace: return build_bad_request_response('workspace name and route parameter don\'t match') if document.get('name').startswith('_'): return build_bad_request_response('database cannot start with an underscore') document['_id'] = document.get('name') # document dictionary does not have id, add it is_update_request = bool(document.get('_rev', False)) db_manager = get_manager() if workspace in db_manager and is_update_request: res = db_manager.update_workspace(document) elif workspace not in db_manager and not is_update_request: res = db_manager.create_workspace(document) else: abort(400) if not res: response = flask.jsonify({'error': "There was an error {0} the workspace".format("updating" if is_update_request else "creating")}) response.status_code = 500 return response return flask.jsonify({'ok': True})
def workspace_create_or_update(workspace): # only admins can create workspaces validate_admin_perm() try: document = json.loads(flask.request.data) except ValueError: return build_bad_request_response('invalid json') if not document.get('name', None): return build_bad_request_response('workspace name needed') if document.get('name') != workspace: return build_bad_request_response('workspace name and route parameter don\'t match') if document.get('name').startswith('_'): return build_bad_request_response('database cannot start with an underscore') document['_id'] = document.get('name') # document dictionary does not have id, add it is_update_request = bool(document.get('_rev', False)) db_manager = get_manager() if workspace in db_manager and is_update_request: res = db_manager.update_workspace(document) elif workspace not in db_manager and not is_update_request: res = db_manager.create_workspace(document) else: flask.abort(400) if not res: response = flask.jsonify({'error': "There was an error {0} the workspace".format("updating" if is_update_request else "creating")}) response.status_code = 500 return response return flask.jsonify({'ok': True})
def workspace_delete(workspace): # only admins can delete workspaces validate_admin_perm() validate_workspace(workspace) db_manager = get_manager() if not db_manager.delete_workspace(workspace): response = flask.jsonify({'error': "There was an error deleting the workspace"}) response.status_code = 500 return response return flask.jsonify({'ok': True})