Prevent user from adding the same dependency multiple times (#859)

This commit is contained in:
Prospector 2023-01-11 10:03:40 -08:00 committed by GitHub
parent de212322e2
commit 61a4f15e53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1176,6 +1176,18 @@ export default {
const project = (await this.$axios.get(`project/${newDependencyId}`))
.data
if (
this.version.dependencies.some(
(dep) => project.id === dep.project_id
)
) {
this.$notify({
group: 'main',
title: 'Dependency already added',
text: 'You cannot add the same dependency twice.',
type: 'error',
})
} else {
this.version.dependencies.push({
project,
project_id: project.id,
@ -1187,6 +1199,7 @@ export default {
projects: this.dependencies.projects.concat([project]),
versions: this.dependencies.versions,
})
}
} else if (dependencyAddMode === 'version') {
const version = (
await this.$axios.get(`version/${this.newDependencyId}`)
@ -1196,6 +1209,18 @@ export default {
await this.$axios.get(`project/${version.project_id}`)
).data
if (
this.version.dependencies.some(
(dep) => version.id === dep.version_id
)
) {
this.$notify({
group: 'main',
title: 'Dependency already added',
text: 'You cannot add the same dependency twice.',
type: 'error',
})
} else {
this.version.dependencies.push({
version,
project,
@ -1212,6 +1237,7 @@ export default {
versions: this.dependencies.versions.concat([version]),
})
}
}
this.newDependencyId = ''
} catch {