From df74bade9bbf4ac33c760d82efb49dbb6012d3e8 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jan 2024 11:00:43 +0100 Subject: [PATCH] fixes bug when getting all the profil update requests and makes it possible to add a message when dening or accepting a profil update --- application/controllers/Cis/Profil.php | 15 ++-- application/controllers/Cis/ProfilUpdate.php | 20 ++--- .../models/person/Profil_change_model.php | 1 + public/js/apps/Cis/ProfilUpdateRequests.js | 2 + public/js/apps/api/profilUpdate.js | 8 +- public/js/apps/api/userdata.js | 4 +- .../components/Cis/Profil/EditProfilSelect.js | 13 ++-- .../Cis/Profil/MitarbeiterProfil.js | 27 ++++--- .../Profil/ProfilComponents/EditAdresse.js | 4 +- .../Profil/ProfilComponents/EditKontakt.js | 2 +- .../ProfilComponents/FetchProfilUpdates.js | 28 ++++--- .../Cis/ProfilUpdate/AcceptDenyUpdate.js | 73 ++++++++++++++++--- 12 files changed, 133 insertions(+), 64 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 797db3ed9..20fb65e22 100644 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -69,8 +69,11 @@ class Profil extends Auth_Controller public function selectProfilRequest(){ - $uid =json_decode($this->input->get("uid")); - $id =json_decode($this->input->get("id")); + $_GET = json_decode($this->input->raw_input_stream, true); + $uid = $this->input->get('uid'); + $id = $this->input->get('id'); + echo $uid; + echo $id; if($uid && $id){ $res= $this->ProfilChangeModel->getProfilUpdate($uid, $id); @@ -93,7 +96,8 @@ class Profil extends Auth_Controller $json = json_decode($this->input->raw_input_stream); $payload = $json->payload; - $type = isset($json->payload->kontakt_id)? "kontakt_id" : "adresse_id"; + $type = property_exists($json->payload,"kontakt_id")? "kontakt_id" : "adresse_id"; + $data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($payload), "change_timestamp" => "NOW()","status"=>"pending" ]; @@ -104,10 +108,9 @@ class Profil extends Auth_Controller if($res){ foreach($res as $update_request){ $existing_change = json_decode($update_request->requested_change); - echo json_encode($existing_change); - echo property_exists($existing_change,$type); + - if(property_exists($existing_change,$type) && $existing_change->$type == $payload->$type){ + if(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 fcbda43e2..c82096020 100644 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -37,28 +37,24 @@ class ProfilUpdate extends Auth_Controller public function acceptProfilRequest(){ $_POST = json_decode($this->input->raw_input_stream,true); - - $id = $this->input->post('requestID',true); + $id = $this->input->post('profil_update_id',true); + $status_message = $this->input->post('status_message',true); if(isset($id)){ - $res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()"]); + $res =$this->ProfilChangeModel->update([$id], ["status"=>"accepted","status_timestamp"=>"NOW()","status_message"=>$status_message]); echo json_encode($res); - } + } } public function denyProfilRequest(){ $_POST = json_decode($this->input->raw_input_stream,true); - - $id = $this->input->post('requestID',true); + + $id = $this->input->post('profil_update_id',true); + $status_message = $this->input->post('status_message',true); if(isset($id)){ - var_dump($id); - //! instead of deleting the rejected profil update, the status of the db entry is set to rejected - //$res = $this->ProfilChangeModel->delete([$id]); - - - $res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()"]); + $res = $this->ProfilChangeModel->update([$id],["status"=>"rejected","status_timestamp"=>"NOW()","status_mesage"=>$status_message]); echo json_encode($res); } diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php index 2f33068c6..b8c487a5a 100644 --- a/application/models/person/Profil_change_model.php +++ b/application/models/person/Profil_change_model.php @@ -49,6 +49,7 @@ class Profil_change_model extends DB_Model foreach($res->retval as $update){ $update->requested_change = json_decode($update->requested_change); $update->change_timestamp = date_create($update->change_timestamp)->format('d.m.Y'); + $update->status_timestamp = date_create($update->status_timestamp)->format('d.m.Y'); } } } diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 5f6f1b31c..c45283876 100644 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -73,6 +73,7 @@ const app = Vue.createApp({ //! function that is called when clicking on a row in the table let cellData = cell.getRow().getData(); + AcceptDenyUpdate.popup({value:cellData}).then(res=>{ console.log("res of the modal: ",res); //? refetches the data, if any request was denied or accepted @@ -82,6 +83,7 @@ const app = Vue.createApp({ //? catches the rejected Promise if the result of the modal was falsy console.log("catch of the modal: ",e); }); + }, //responsive:0, diff --git a/public/js/apps/api/profilUpdate.js b/public/js/apps/api/profilUpdate.js index b9aa01731..7f0bdc63e 100644 --- a/public/js/apps/api/profilUpdate.js +++ b/public/js/apps/api/profilUpdate.js @@ -7,14 +7,14 @@ export default { return axios.get(url); }, - acceptProfilRequest: function(requestID){ + acceptProfilRequest: function(payload){ const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/Cis/ProfilUpdate/acceptProfilRequest'; - return axios.post(url,{requestID: requestID}); + return axios.post(url,payload); }, - denyProfilRequest: function(requestID){ + denyProfilRequest: function(payload){ const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + '/Cis/ProfilUpdate/denyProfilRequest'; - return axios.post(url,{requestID: requestID}); + return axios.post(url,payload); } } \ No newline at end of file diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js index 6c881393d..be6092dd4 100644 --- a/public/js/apps/api/userdata.js +++ b/public/js/apps/api/userdata.js @@ -5,9 +5,9 @@ export default { selectProfilRequest: function(uid=null,id=null) { const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router+ - `/Cis/Profil/selectProfilRequest?uid=${uid}&id=${id}`; + `/Cis/Profil/selectProfilRequest`; - return axios.get(url); + return axios.get(url,{uid:uid, id:id}); }, insertProfilRequest: function(topic, payload) { diff --git a/public/js/components/Cis/Profil/EditProfilSelect.js b/public/js/components/Cis/Profil/EditProfilSelect.js index a5869eb75..b620c2848 100644 --- a/public/js/components/Cis/Profil/EditProfilSelect.js +++ b/public/js/components/Cis/Profil/EditProfilSelect.js @@ -55,6 +55,7 @@ export default { addItem: function(){ + this.view= this.topic == "Private Kontakte"?"EditKontakt":"EditAdresse" ; //? updates the topic when a Kontakt or an Address should be added @@ -63,7 +64,6 @@ export default { this.breadcrumbItems.push(this.topic); this.$emit('update:breadcrumb',this.breadcrumbItems); - this.data= this.view=="EditAdresse"? { added:true, @@ -72,8 +72,7 @@ export default { adr_typ: null, plz: null, ort: null - }: - { + }: { added:true, kontakt_id: null, kontakttyp: null, @@ -81,7 +80,8 @@ export default { anmerkung: null, zustellung: false } - + + }, deleteItem: function(item){ @@ -138,8 +138,6 @@ export default { }, template: ` - -