def process_namespace_edit(self, project, params, error_form=False, patch=True): """ Edit project namespace. """ namespace, error = yield self.structure.get_namespace_by_id(params.pop("_id")) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if not namespace: raise Return((None, self.NAMESPACE_NOT_FOUND)) if not project: project, error = yield self.structure.get_project_by_id(namespace["project_id"]) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if not project: raise Return((None, self.PROJECT_NOT_FOUND)) if "name" not in params: params["name"] = namespace["name"] boolean_patch_data = {} if patch: boolean_patch_data = utils.get_boolean_patch_data(NamespaceForm.BOOLEAN_FIELDS, params) form = NamespaceForm(params) if form.validate(): if "name" in params and params["name"] != namespace["name"]: existing_namespace, error = yield self.structure.get_namespace_by_name(project, params["name"]) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if existing_namespace: form.name.errors.append(self.DUPLICATE_NAME) if error_form: raise Return((None, form)) raise Return((None, form.errors)) updated_namespace = namespace.copy() if patch: data = utils.make_patch_data(form, params) else: data = form.data.copy() updated_namespace.update(data) if patch: updated_namespace.update(boolean_patch_data) namespace, error = yield self.structure.namespace_edit(namespace, **updated_namespace) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) raise Return((namespace, None)) else: if error_form: raise Return((None, form)) raise Return((None, form.errors))
def process_project_edit(self, project, params, error_form=False, patch=True): """ Edit project namespace. """ if not project: raise Return((None, self.PROJECT_NOT_FOUND)) if "name" not in params: params["name"] = project["name"] boolean_patch_data = {} if patch: boolean_patch_data = utils.get_boolean_patch_data( ProjectForm.BOOLEAN_FIELDS, params) form = ProjectForm(params) if form.validate(): if "name" in params and params["name"] != project["name"]: existing_project, error = yield self.structure.get_project_by_name( params["name"]) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if existing_project: form.name.errors.append(self.DUPLICATE_NAME) if error_form: raise Return((None, form)) raise Return((None, form.errors)) updated_project = project.copy() if patch: data = utils.make_patch_data(form, params) else: data = form.data.copy() updated_project.update(data) if patch: updated_project.update(boolean_patch_data) project, error = yield self.structure.project_edit( project, **updated_project) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) raise Return((project, None)) else: if error_form: raise Return((None, form)) raise Return((None, form.errors))
def process_project_edit(self, project, params, error_form=False, patch=True): """ Edit project namespace. """ if not project: raise Return((None, self.PROJECT_NOT_FOUND)) if "name" not in params: params["name"] = project["name"] namespaces, error = yield self.structure.get_project_namespaces(project) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) boolean_patch_data = {} if patch: boolean_patch_data = utils.get_boolean_patch_data(ProjectForm.BOOLEAN_FIELDS, params) namespace_choices = [(x["_id"], x["name"]) for x in namespaces] namespace_choices.insert(0, ("", "")) form = ProjectForm(params, namespace_choices=namespace_choices) if form.validate(): if "name" in params and params["name"] != project["name"]: existing_project, error = yield self.structure.get_project_by_name(params["name"]) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if existing_project: form.name.errors.append(self.DUPLICATE_NAME) if error_form: raise Return((None, form)) raise Return((None, form.errors)) updated_project = project.copy() if patch: data = utils.make_patch_data(form, params) else: data = form.data.copy() updated_project.update(data) if patch: updated_project.update(boolean_patch_data) project, error = yield self.structure.project_edit(project, **updated_project) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) raise Return((project, None)) else: if error_form: raise Return((None, form)) raise Return((None, form.errors))
def process_namespace_edit(self, project, params, error_form=False, patch=True): """ Edit project namespace. """ namespace, error = yield self.structure.get_namespace_by_id( params.pop('_id')) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if not namespace: raise Return((None, self.NAMESPACE_NOT_FOUND)) if not project: project, error = yield self.get_project(namespace['project_id']) if error: raise Return((None, error)) if "name" not in params: params["name"] = namespace["name"] boolean_patch_data = {} if patch: boolean_patch_data = utils.get_boolean_patch_data( NamespaceForm.BOOLEAN_FIELDS, params) form = NamespaceForm(params) if form.validate(): if "name" in params and params["name"] != namespace["name"]: existing_namespace, error = yield self.structure.get_namespace_by_name( project, params["name"]) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) if existing_namespace: form.name.errors.append(self.DUPLICATE_NAME) if error_form: raise Return((None, form)) raise Return((None, form.errors)) updated_namespace = namespace.copy() if patch: data = utils.make_patch_data(form, params) else: data = form.data.copy() updated_namespace.update(data) if patch: updated_namespace.update(boolean_patch_data) namespace, error = yield self.structure.namespace_edit( namespace, **updated_namespace) if error: raise Return((None, self.INTERNAL_SERVER_ERROR)) raise Return((namespace, None)) else: if error_form: raise Return((None, form)) raise Return((None, form.errors))