Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/restrict-ns-and-id-edition #1329

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ui/src/components/graph/Topology.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
const dragging = ref(false);
const taskError = ref(store.getters["flow/taskError"])
const user = store.getters["auth/user"];
const routeParams = router.currentRoute.value.params;

const localStorageKey = computed(() => {
return (props.isCreating ? "creation" : `${flow.namespace}.${flow.id}`) + "_draft";
Expand Down Expand Up @@ -849,8 +850,16 @@
});
})
}else {
store
.dispatch("flow/saveFlow", {flow: flowYaml.value})
if(routeParams.id !== flowParsed.id || routeParams.namespace !== flowParsed.namespace){
store.dispatch("core/showMessage", {
variant: "error",
title: t("can not save"),
message: t("namespace and id readonly"),
})
flowYaml.value = YamlUtils.replaceIdAndNamespace(flowYaml.value, routeParams.id, routeParams.namespace);
return;
}
store.dispatch("flow/saveFlow", {flow: flowYaml.value})
.then((response) => {
toast.saved(response.id);
store.dispatch("core/isUnsaved", false);
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
"delete task confirm": "Do you want to delete the task <code>{taskId}</code> ?",
"can not save": "Can not save",
"flow must have id and namespace": "Flow must have an id and a namespace.",
"namespace and id readonly": "Namespace and id are read-only. They were reinitialized to their initial value.",
"avg": "Average",
"sum": "Sum",
"min": "Min",
Expand Down Expand Up @@ -837,6 +838,7 @@
"delete task confirm": "Êtes-vous sûr de vouloir supprimer la tâche <code>{taskId}</code> ?",
"can not save": "Impossible de sauvegarder",
"flow must have id and namespace": "Le flow doit avoir un id et un namespace.",
"namespace and id readonly": "Le namespace et l'id ne sont pas modifiables. Ils ont été réinitialisés à leur valeur initiale.",
"avg": "Moyenne",
"sum": "Somme",
"min": "Minimum",
Expand Down
4 changes: 4 additions & 0 deletions ui/src/utils/yamlUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ export default class YamlUtils {
return isChildrenOf;
}

static replaceIdAndNamespace(source, id, namespace) {
return source.replace(/^(id\s*:\s*(["']?))\S*/m, "$1"+id+"$2").replace(/^(namespace\s*:\s*(["']?))\S*/m, "$1"+namespace+"$2")
}

static updateMetadata(source, metadata) {
// TODO: check how to keep comments
const yamlDoc = yaml.parseDocument(source);
Expand Down