From 1de8c009901da4994e82f0e96437840e382f089a Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 12 Sep 2024 11:45:54 +0200 Subject: [PATCH] fixes an error where the payload i treated like an object but is an associative array in the controller --- .../api/frontend/v1/ProfilUpdate.php | 15 +++++++++------ .../Cis/Profil/ProfilModal/EditProfil.js | 2 +- .../Cis/Profil/ProfilModal/EditProfilSelect.js | 18 +++++++++--------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 7a528b2de..328ed3d61 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -160,13 +160,13 @@ class ProfilUpdate extends FHCAPI_Controller $res = $this->getDataOrTerminateWithError($res); //? the user cannot delete a zustelladresse/kontakt - if (isset($payload->delete) && $payload->{$identifier == "kontakt_id" ? "zustellung" : "zustelladresse"}) { + if (isset($payload["delete"]) && $payload-[$identifier == "kontakt_id" ? "zustellung" : "zustelladresse"]) { $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error')); } //? if the user tries to delete a adresse, checks whether the adresse is a heimatadresse, if so an error is raised - if (isset($payload->delete) && $identifier == "adresse_id") { - $adr = $this->AdresseModel->load($payload->$identifier); + if (isset($payload["delete"]) && $identifier == "adresse_id") { + $adr = $this->AdresseModel->load($payload[$identifier]); $adr = $this->getDataOrTerminateWithError($adr)[0]; if ($adr->heimatadresse) { $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error')); @@ -177,12 +177,15 @@ class ProfilUpdate extends FHCAPI_Controller $pending_changes = array_filter($res, function ($element) { return $element->status == (self::$STATUS_PENDING ?: "Pending"); }); - + $test = array(); foreach ($pending_changes as $update_request) { $existing_change = $update_request->requested_change; - + $this->addMeta("paylaod",$payload); + $this->addMeta("object style", $payload[$identifier]); + $this->addMeta("array style", $payload[$identifier]); + //? the user can add as many new kontakte/adressen as he likes - if (!isset($payload->add) && property_exists($existing_change, $identifier) && property_exists($payload, $identifier) && $existing_change->$identifier == $payload->$identifier) { + if (!isset($payload["add"]) && property_exists($existing_change, $identifier) && array_key_exists($identifier,$payload) && $existing_change->$identifier == $payload[$identifier]) { //? the kontakt_id / adresse_id of a change has to be unique $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_changeTwice_error')); } diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js index 62637678e..45a41d8ab 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js @@ -57,7 +57,7 @@ export default { async submitProfilChange() { //? check if data is valid before making a request - if (this.topic && this.profilUpdate) { + if (this.topic && this.profilUpdate) { //? if profil update contains any attachment if (this.fileID) { const fileData = await this.uploadFiles(this.fileID); diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfilSelect.js b/public/js/components/Cis/Profil/ProfilModal/EditProfilSelect.js index 32b669c08..b9b45a1a7 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfilSelect.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfilSelect.js @@ -45,7 +45,7 @@ export default { view: null, data: null, breadcrumbItems: [], - topic: this.topic, + modal_topic: this.topic, properties: null, }; }, @@ -53,17 +53,17 @@ export default { methods: { addItem: function () { this.view = - this.topic == this.profilUpdateTopic["Private Kontakte"] + this.modal_topic == this.profilUpdateTopic["Private Kontakte"] ? "EditKontakt" : "EditAdresse"; //? updates the topic when a Kontakt or an Address should be added - this.topic = - this.topic == this.profilUpdateTopic["Private Kontakte"] + this.modal_topic = + this.modal_topic == this.profilUpdateTopic["Private Kontakte"] ? this.profilUpdateTopic["Add Kontakt"] : this.profilUpdateTopic["Add Adresse"]; - this.$emit("update:topic", this.topic); - this.breadcrumbItems.push(this.topic); + this.$emit("update:topic", this.modal_topic); + this.breadcrumbItems.push(this.modal_topic); this.$emit("update:breadcrumb", this.breadcrumbItems); this.data = @@ -108,13 +108,13 @@ export default { }, updateOptions: function (event, item) { - this.properties = item; + this.properties = item; this.data = item.data; this.view = item.view; if (item.title) { //? emits the selected topic to the parent component - this.topic = item.topic; - this.$emit("update:topic", this.topic); + this.modal_topic = item.topic; + this.$emit("update:topic", this.modal_topic); //? emits the new item for the breadcrumb in the parent component this.breadcrumbItems.push(item.title);