From 74aed1992ecba20dd801254bafed6a6b6c6c703e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 Jul 2022 16:09:40 +0200 Subject: [PATCH] Bug 32030: Unique - Prevent agreement to have the same license several times Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../vue/components/ERM/AgreementsFormAdd.vue | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue index 87e54b49e6..81de526bf3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue @@ -215,7 +215,7 @@ import AgreementRelationships from './AgreementRelationships.vue' import AgreementDocuments from './AgreementDocuments.vue' import { useVendorStore } from "../../stores/vendors" import { useAVStore } from "../../stores/authorised_values" -import { setMessage, setError } from "../../messages" +import { setMessage, setError, setWarning } from "../../messages" import { fetchAgreement } from '../../fetch' import { storeToRefs } from "pinia" @@ -281,11 +281,34 @@ export default { this.agreement = agreement this.initialized = true }, + checkForm(agreement) { + let errors = [] + + let agreement_licenses = agreement.agreement_licenses + // Do not use al.license.name here! Its name is not the one linked with al.license_id + // At this point al.license is meaningless, form/template only modified al.license_id + const license_ids = agreement_licenses.map(al => al.license_id) + const duplicate_license_ids = license_ids.filter((id, i) => license_ids.indexOf(id) !== i) + + if (duplicate_license_ids.length) { + errors.push(this.$t("A license is used several times")) + } + + errors.forEach(function (e) { + setWarning(e) + }) + return !errors.length + }, onSubmit(e) { e.preventDefault() //let agreement= Object.assign( {} ,this.agreement); // copy let agreement = JSON.parse(JSON.stringify(this.agreement)) // copy + + if (!this.checkForm(agreement)) { + return false + } + let apiUrl = '/api/v1/erm/agreements' let method = 'POST' -- 2.39.5