diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 80f168585..3b3ccf182 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -115,7 +115,7 @@ class Profil extends Auth_Controller $existing_change = json_decode($update_request->requested_change); - if(property_exists($existing_change,$type) && property_exists($payload,$type) && $existing_change->$type == $payload->$type){ + if(!isset($existing_change->add) && property_exists($existing_change,$type) && property_exists($payload,$type) && $existing_change->$type == $payload->$type){ //? the kontakt_id / adresse_id of a change has to be unique echo json_encode(error("cannot change the same resource twice")); diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index 8d3b6dc1f..66a38cd17 100644 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -38,63 +38,66 @@ class ProfilUpdate extends Auth_Controller } public function acceptProfilRequest(){ + $_POST = json_decode($this->input->raw_input_stream,true); - $id = $this->input->post('profil_update_id',true); $uid = $this->input->post('uid',true); + //? fetching person_id using UID $personID = $this->PersonModel->getByUid($uid); $personID = hasData($personID)? getData($personID)[0]->person_id : null; $status_message = $this->input->post('status_message',true); $topic = $this->input->post('topic',true); + //! somehow the xss check converted boolean false to empty string $requested_change = $this->input->post('requested_change'); - + //! check for required information if(!isset($id) || !isset($uid) || !isset($personID) || !isset($requested_change) || !isset($topic)){ return json_encode(error("missing required information")); } - if(is_array($requested_change) && array_key_exists("adresse_id",$requested_change)){ - $this->handleAdresse($requested_change, $personID); + $resID = $this->handleAdresse($requested_change, $personID); + $resID = hasData($resID) ? getData($resID) : null; + $requested_change['adresse_id'] = $resID; + }else if (is_array($requested_change) && array_key_exists("kontakt_id", $requested_change)){ - $this->handleKontakt($requested_change, $personID); + $resID = $this->handleKontakt($requested_change, $personID); + $resID = hasData($resID) ? getData($resID)[0] : null; + $requested_change['kontakt_id'] = $resID; + }else{ - - switch($topic){ case "titel": $topic ="titelpre"; break; case "postnomen": $topic = "titelpost"; break; } - $res = $this->PersonModel->update($personID,[$topic=>$requested_change]); - - echo json_encode($res); + $result = $this->PersonModel->update($personID,[$topic=>$requested_change]); + if(isError($result)){ + echo json_encode($result); + return; + } } - - echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message)); - - + echo json_encode($this->setStatusOnUpdateRequest($id, "accepted", $status_message, $requested_change)); } public function denyProfilRequest(){ - $_POST = json_decode($this->input->raw_input_stream,true); + $_POST = json_decode($this->input->raw_input_stream,true); $id = $this->input->post('profil_update_id',true); $status_message = $this->input->post('status_message',true); - echo json_encode($this->setStatusOnUpdateRequest($id, "rejected", $status_message)); - - - } - private function setStatusOnUpdateRequest($id, $status, $status_message){ - return $this->ProfilChangeModel->update([$id],["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]); + private function setStatusOnUpdateRequest($id, $status, $status_message, $requested_change=NULL){ + $update = ["status"=>$status,"status_timestamp"=>"NOW()","status_message"=>$status_message]; + if(isset($requested_change)) { $update['requested_change'] = $requested_change; } + return $this->ProfilChangeModel->update([$id], $update); } + private function handleKontakt($requested_change, $personID){ $kontakt_id = $requested_change["kontakt_id"]; //? removes the kontakt_id because we don't want to update the kontakt_id in the database diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index 4928b72e8..4c024d944 100644 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -69,7 +69,6 @@ export default { //? if the topic was passed through the prop add it to the component this.topic = this.editData.topic; } - console.log("here",this.editData); }, diff --git a/public/js/components/Cis/Profil/EditProfilSelect.js b/public/js/components/Cis/Profil/EditProfilSelect.js index 706cec63e..c91ddd683 100644 --- a/public/js/components/Cis/Profil/EditProfilSelect.js +++ b/public/js/components/Cis/Profil/EditProfilSelect.js @@ -134,7 +134,7 @@ export default { created() { this.data = JSON.parse(JSON.stringify(this.list.data)); this.view = JSON.parse(JSON.stringify(this.list.view)); - + }, mounted() { diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index ea67092d8..6b66aeccf 100644 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -278,7 +278,7 @@ export default { view:"text_input", data:{ titel:"postnomen", - value:this.data.titel, + value:this.data.postnomen, } }, } diff --git a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js index 4593fed74..23310fd2f 100644 --- a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js +++ b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js @@ -40,7 +40,6 @@ export default { } }, openModal(updateRequest) { - console.log(JSON.stringify(updateRequest)); let view = this.getView(updateRequest.topic,updateRequest.status); let data = null; @@ -74,7 +73,6 @@ export default { content['status_timestamp']=updateRequest.status_timestamp; } - //? only show the popup if also the right content is available if(content){ EditProfil.popup({ diff --git a/public/js/components/Cis/Profil/ProfilComponents/Status.js b/public/js/components/Cis/Profil/ProfilComponents/Status.js index bc69497bd..a1aed8054 100644 --- a/public/js/components/Cis/Profil/ProfilComponents/Status.js +++ b/public/js/components/Cis/Profil/ProfilComponents/Status.js @@ -1,10 +1,31 @@ -export default { +import Adresse from "./Adresse.js"; +import Kontakt from "./Kontakt.js"; +export default { + components:{ + Adresse, + Kontakt, + }, data(){ return { } }, + computed:{ + getComponentView: function(){ + let title = this.topic.toLowerCase(); + if(title.includes("adressen")) return "Adresse"; + else if(title.includes("kontakte"))return "Kontakt"; + else return "text_input"; + + }, + cardHeader: function(){ + let title = this.topic.toLowerCase(); + if(title.includes("delete")) return "Delete"; + else if(title.includes("add")) return "Add"; + else return "Update"; + } + }, props:{ data:{type:Object}, view:{type:String}, @@ -12,11 +33,12 @@ export default { status_message:{type:String}, status_timestamp:{type:String}, update:{type:Boolean}, + topic:{type:String}, }, created(){ - },template:` +