From 286c7be83d9d341a53058e3d8aa6bb824cf894ab Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 7 Feb 2024 13:25:50 +0100 Subject: [PATCH] only displays profil update requests the uid has permissions for (mitarbeiter/stammdaten or student/stammdaten), also fixes bug and adds JSON.parse to get the value in the sessionStorage --- application/controllers/Cis/Profil.php | 19 ++-- application/controllers/Cis/ProfilUpdate.php | 20 ++-- .../models/person/Profil_change_model.php | 50 ++++++--- public/js/apps/Cis/Profil.js | 8 +- public/js/apps/Cis/ProfilUpdateRequests.js | 10 +- public/js/components/Cis/Profil/EditProfil.js | 4 +- .../Cis/Profil/MitarbeiterProfil.js | 33 ++---- .../js/components/Cis/Profil/StudentProfil.js | 101 ++---------------- 8 files changed, 88 insertions(+), 157 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index 5f69264ed..8e7c1a26a 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -16,7 +16,7 @@ class Profil extends Auth_Controller public function __construct() { parent::__construct([ - 'index' => ['student/anrechnung_beantragen:r', 'user:r'], // TODO(chris): permissions? + 'index' => ['student/anrechnung_beantragen:r', 'user:r'], 'foto_sperre_function' => ['student/anrechnung_beantragen:r', 'user:r'], 'getView' => ['student/anrechnung_beantragen:r', 'user:r'], 'View' => ['student/anrechnung_beantragen:r', 'user:r'], @@ -63,6 +63,16 @@ class Profil extends Auth_Controller * @return void */ + public function test(){ + + // Loads permission lib + $this->load->library('PermissionLib'); + $mit_daten =$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','suid'); + var_dump($mit_daten); + $stud_daten = $this->permissionlib->isBerechtigt('student/stammdaten','suid'); + var_dump($stud_daten); + } + public function index() { @@ -149,12 +159,7 @@ class Profil extends Auth_Controller echo json_encode($res); } - public function test(){ - - // Loads permission lib - $this->load->library('PermissionLib'); - var_dump($this->permissionlib->getOE_isEntitledFor()); - } + diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index 44fce82af..bb4f1d407 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -11,10 +11,10 @@ class ProfilUpdate extends Auth_Controller public function __construct(){ parent::__construct([ - 'index' => ['student/anrechnung_beantragen:r', 'user:r'], // TODO(chris): permissions? - 'getProfilUpdates' => ['student/anrechnung_beantragen:r', 'user:r'], - 'acceptProfilRequest'=>['user:r'], - 'denyProfilRequest'=>['user:r'], + 'index' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], + 'getProfilUpdates' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], + 'acceptProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'], + 'denyProfilRequest'=>['student/stammdaten:rw','mitarbeiter/stammdaten:rw'], 'show'=>['user:r'], @@ -46,12 +46,16 @@ class ProfilUpdate extends Auth_Controller } public function getProfilUpdates($status=null){ + $this->load->library('PermissionLib'); + $studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten','s'); + $mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten','s'); + + $options = ["mitarbeiterView"=>$mitarbeiterBerechtigung,"studentView"=>$studentBerechtigung]; if(isset($status)){ - $res = $this->ProfilChangeModel->getProfilUpdate(["status"=>$status]); - }else{ - $res = $this->ProfilChangeModel->getProfilUpdate(); + $options['status'] = $status; } - $res = hasData($res)? getData($res) : null; + $res = $this->ProfilChangeModel->getProfilUpdate($options); + echo json_encode($res); } diff --git a/application/models/person/Profil_change_model.php b/application/models/person/Profil_change_model.php index 134395dd6..e364b33e2 100755 --- a/application/models/person/Profil_change_model.php +++ b/application/models/person/Profil_change_model.php @@ -12,6 +12,9 @@ class Profil_change_model extends DB_Model $this->pk = ['profil_update_id']; $this->hasSequence = true; + + $this->load->model('crm/Student_model','StudentModel'); + $this->load->model('ressource/Mitarbeiter_model','MitarbeiterModel'); } /** @@ -50,22 +53,41 @@ class Profil_change_model extends DB_Model * returns all profil updates if id is set to null */ public function getProfilUpdate($whereClause=null){ - - $res = $this->loadWhere($whereClause); - if(isError($res)){ - // catch error - }else{ - if(hasData($res)){ - - foreach($res->retval as $update){ - $update->requested_change = json_decode($update->requested_change); - $update->insertamum = !is_null($update->insertamum)?date_create($update->insertamum)->format('d.m.Y'):null; - $update->updateamum = !is_null($update->updateamum)?date_create($update->updateamum)->format('d.m.Y'):null; - $update->status_timestamp = !is_null($update->status_timestamp)?date_create($update->status_timestamp)->format('d.m.Y'):null; - - } + $res =[]; + if($whereClause["studentView"]) { + $this->addJoin('tbl_student','tbl_student.student_uid=tbl_cis_profil_update.uid'); + $studentRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]); + if(isError($studentRequests)) return error("db error: ". getData($studentRequests)); + $studentRequests = getData($studentRequests)?:[]; + foreach($studentRequests as $request){ + array_push($res,$request); } } + if($whereClause["mitarbeiterView"]) { + $this->addJoin('tbl_mitarbeiter','tbl_mitarbeiter.mitarbeiter_uid=tbl_cis_profil_update.uid'); + $mitarbeiterRequests = $this->loadWhere(isset($whereClause['status']) && $whereClause['status']? ['status'=>$whereClause['status']]:[]); + if(isError($mitarbeiterRequests)) return error("db error: ". getData($mitarbeiterRequests)); + $mitarbeiterRequests = getData($mitarbeiterRequests)?:[]; + foreach($mitarbeiterRequests as $request){ + array_push($res,$request); + } + } + + + + if($res){ + + foreach($res as $update){ + + + $update->requested_change = json_decode($update->requested_change); + $update->insertamum = !is_null($update->insertamum)?date_create($update->insertamum)->format('d.m.Y'):null; + $update->updateamum = !is_null($update->updateamum)?date_create($update->updateamum)->format('d.m.Y'):null; + $update->status_timestamp = !is_null($update->status_timestamp)?date_create($update->status_timestamp)->format('d.m.Y'):null; + + } + } + return $res; } diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 12a037973..935dd2ab2 100755 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -46,7 +46,7 @@ const app = Vue.createApp({ }, data() { return { - editData: this.filteredEditData, + view:null, data:null, // notfound is null by default, but contains an UID if no user exists with that UID @@ -58,7 +58,7 @@ const app = Vue.createApp({ provide() { return { - editData:this.editData, + collapseFunction: (e, column)=> { //* check if property doesn't exist already and add it to the reactive this properties @@ -229,14 +229,14 @@ const app = Vue.createApp({ }, template:`
-
{{JSON.stringify(data.profilUpdates.length,null,2)}}
+

Es wurden keine oder mehrere Profile für {{this.notFoundUID}} gefunden

- +
` diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 9a9766cb6..0d936fe97 100755 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -36,7 +36,9 @@ const app = Vue.createApp({ //params - the parameters passed with the request //response - the JSON object returned in the body of the response. //? sorts the response data from the backend + if(response) response.sort(sortProfilUpdates); + return response; }, //? adds tooltip with the status message of a profil update request if its status is not pending @@ -122,11 +124,11 @@ const app = Vue.createApp({ ajaxURLGenerator: (url,config,params)=>{ //? this function needs to be an array function in order to access the this properties of the Vue component if(this.showAll){ - return url +"getProfilUpdates"; + return url +"getProfilUpdates"; }else{ return url +"getProfilUpdates/pending"; } - + }, height: 600, layout: "fitColumns", @@ -238,13 +240,13 @@ const app = Vue.createApp({ this.$refs.UpdatesTable.tabulator.setData(); //? store the selected view in the session storage of the browser - sessionStorage.setItem("showAll",event.target.value); + sessionStorage.setItem("showAll",JSON.stringify(event.target.value)); } }, mounted() { if(!(sessionStorage.getItem("showAll")===null)) { - this.showAll = sessionStorage.getItem("showAll"); + this.showAll = JSON.parse(sessionStorage.getItem("showAll")); } }, diff --git a/public/js/components/Cis/Profil/EditProfil.js b/public/js/components/Cis/Profil/EditProfil.js index 413a60416..07e62cd30 100755 --- a/public/js/components/Cis/Profil/EditProfil.js +++ b/public/js/components/Cis/Profil/EditProfil.js @@ -109,9 +109,7 @@ export default { if(filesToDelete.length > 0) { Vue.$fhcapi.UserData.deleteOldVersionFiles( filesToDelete - ).then((res) => { - console.log(res); - }); + ); } diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index da1812ca2..979246d45 100755 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -26,7 +26,7 @@ export default { RoleInformation, ProfilInformation, }, - inject: ['sortProfilUpdates','collapseFunction','editData'], + inject: ['sortProfilUpdates','collapseFunction'], data() { return { @@ -136,6 +136,7 @@ export default { props: { data: Object, + editData: Object, }, methods: { @@ -218,33 +219,11 @@ export default { }; }, - personEmails() { - return this.data?.emails ? this.data.emails : []; - }, - - privateKontakte() { - if (!this.data) { - return {}; - } - - return this.data.kontakte; - - }, - - privateAdressen() { - if (!this.data) { - return {}; - } - - return this.data.adressen; - - }, - }, created() { - + //? sorts the profil Updates: pending -> accepted -> rejected this.data.profilUpdates.sort(this.sortProfilUpdates); @@ -348,7 +327,7 @@ export default {
- +
@@ -365,7 +344,7 @@ export default {
-
+
@@ -387,7 +366,7 @@ export default {
-
+
diff --git a/public/js/components/Cis/Profil/StudentProfil.js b/public/js/components/Cis/Profil/StudentProfil.js index 0a3b9a8dd..bf926c82e 100755 --- a/public/js/components/Cis/Profil/StudentProfil.js +++ b/public/js/components/Cis/Profil/StudentProfil.js @@ -24,6 +24,7 @@ export default { FetchProfilUpdates, }, + inject:['sortProfilUpdates'], data() { return { @@ -76,14 +77,17 @@ export default { }; }, - props: ["data"], + props: { + data:Object, + editData:Object, + }, methods: { fetchProfilUpdates: function(){ Vue.$fhcapi.UserData.selectProfilRequest().then((res)=>{ if(!res.error){ - this.data.profilUpdates = res.data.retval?.length ? res.data.retval : null ; + this.data.profilUpdates = res.data.retval?.length ? res.data.retval.sort(this.sortProfilUpdates) : null ; } }); }, @@ -91,14 +95,14 @@ export default { showModal() { EditProfil.popup({ - value:JSON.parse(JSON.stringify(this.data.editData)), + value:JSON.parse(JSON.stringify(this.editData)), title:"Profil bearbeiten", }).then((popup_result) => { if(popup_result){ Vue.$fhcapi.UserData.selectProfilRequest() .then((res) =>{ if(!res.error){ - this.data.profilUpdates = res.data.retval; + this.data.profilUpdates = res.data.retval.sort(this.sortProfilUpdates); }else{ alert("Error when fetching profile updates: " +res.data.retval); } @@ -133,10 +137,6 @@ export default { }; }, - personEmails() { - return this.data?.emails ? this.data.emails : []; - }, - roleInformation() { if (!this.data) { @@ -154,89 +154,10 @@ export default { }; }, - privateKontakte() { - if (!this.data) { - return {}; - } - return this.data.kontakte; - }, - - privateAdressen() { - if (!this.data) { - return {}; - } - return this.data.adressen; - }, }, created(){ - this.data.editData = { - view:null, - data:{ - Personen_Informationen : { - title:"Personen Informationen", - view:null, - data:{ - - vorname: { - title:"vorname", - view:"TextInputDokument", - withFiles:true, - data:{ - titel:"vorname", - value:this.data.vorname, - }}, - nachname: { - title:"nachname", - view:"TextInputDokument", - withFiles:true, - data:{ - titel:"nachname", - value:this.data.nachname, - } - }, - titel:{ - title:"titel", - view:"TextInputDokument", - withFiles:true, - data:{ - titel:"titel", - value:this.data.titel, - } - }, - postnomen:{ - title:"postnomen", - view:"TextInputDokument", - withFiles:true, - data:{ - titel:"postnomen", - value:this.data.postnomen, - } - }, - } - }, - Private_Kontakte: { - title:"Private Kontakte" , - data:this.privateKontakte.map(kontakt => { - return { - listview:'Kontakt', - view:'EditKontakt', - data:kontakt - }}) - }, - Private_Adressen: { - title: "Private Adressen", - data:this.privateAdressen.map(kontakt => { - return { - listview:'Adresse', - view:'EditAdresse', - data:kontakt - }}) - }, - }, - - }; }, mounted() { @@ -361,7 +282,7 @@ export default {
- +
@@ -379,7 +300,7 @@ export default {
-
+
@@ -400,7 +321,7 @@ export default {
-
+