changes the check if a user has permissions to accept or deny a profil update

This commit is contained in:
SimonGschnell
2024-02-15 09:59:27 +01:00
parent 028be08ec3
commit fd260a6307
4 changed files with 60 additions and 63 deletions
+3 -39
View File
@@ -115,31 +115,27 @@ class Profil extends Auth_Controller
private function viewMitarbeiterProfil($uid)
{
$mailverteiler_res = $this->getMailverteiler($uid);
$benutzer_funktion_res = $this->getBenutzerFunktion($uid);
$benutzer_res = $this->getBenutzerAlias($uid);
$person_res = $this->getPersonInfo($uid);
$mitarbeiter_res = $this->getMitarbeiterInfo($uid);
$telefon_res = $this->getTelefonInfo($uid);
$res = new stdClass();
$res->username = $uid;
//? Person Info
foreach($person_res as $key => $val){
$res->$key = $val;
}
//? Mitarbeiter Info
foreach ($mitarbeiter_res as $key => $val) {
$res->$key = $val;
}
//? Email Info
$intern_email = array();
$intern_email["type"] = "intern";
$intern_email["email"] = $uid . "@" . DOMAIN;
@@ -148,32 +144,23 @@ class Profil extends Auth_Controller
$extern_email["email"] = $benutzer_res->alias . "@" . DOMAIN;
$res->emails = array($intern_email, $extern_email);
//? Benutzerfunktion Info
$res->funktionen = $benutzer_funktion_res;
//? Mailverteiler Info
$res->mailverteiler = $mailverteiler_res;
$res->standort_telefon = isset($telefon_res)? $telefon_res->kontakt : null;
return $res;
}
private function viewStudentProfil($uid)
{
$mailverteiler_res = $this->getMailverteiler($uid);
$person_res = $this->getPersonInfo($uid);
$student_res = $this->getStudentInfo($uid);
$matr_res = $this->getMatrikelNummer($uid);
$res = new stdClass();
$res->username = $uid;
//? Person Information
@@ -185,7 +172,6 @@ class Profil extends Auth_Controller
foreach ($student_res as $key => $value) {
$res->$key = $value;
}
$intern_email = array();
$intern_email["type"] = "intern";
@@ -196,8 +182,6 @@ class Profil extends Auth_Controller
$res->mailverteiler = $mailverteiler_res;
return $res;
}
private function mitarbeiterProfil()
@@ -215,7 +199,6 @@ class Profil extends Auth_Controller
$mitarbeiter_res = $this->getMitarbeiterInfo($this->uid);
$res = new stdClass();
$res->username = $this->uid;
//? Person Information
@@ -243,9 +226,7 @@ class Profil extends Auth_Controller
$res->emails = [$intern_email, $extern_email];
$res->funktionen = $benutzer_funktion_res;
$res->standort_telefon = $telefon_res;
$res->profilUpdates = $profilUpdates;
return $res;
@@ -265,10 +246,7 @@ class Profil extends Auth_Controller
$matr_res = $this->getMatrikelNummer($this->uid);
$profilUpdates = $this->getProfilUpdates($this->uid);
$res = new stdClass();
$res->username = $this->uid;
//? Person Information
@@ -291,11 +269,7 @@ class Profil extends Auth_Controller
$res->kontakte = $kontakte_res;
$res->mittel = $betriebsmittelperson_res;
$res->matrikelnummer = $matr_res->matr_nr;
$res->zuttritsgruppen = $zutrittsgruppe_res;
$res->mailverteiler = $mailverteiler_res;
$res->profilUpdates = $profilUpdates;
@@ -305,35 +279,27 @@ class Profil extends Auth_Controller
public function getView($uid)
{
//TODO: refactor
$uid = $uid != "Profil" ? $uid : null;
$isMitarbeiter = null;
if ($uid) {
if (isSuccess($this->PersonModel->addSelect(["person_id"]))) {
$pid = $this->PersonModel->getByUid($uid);
$pid = hasData($pid) ? getData($pid)[0] : null;
}
if (!$pid) {
//! if no Person_ID was found, null is returned and the vue component will show a 404 View
return null;
}
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid);
} else
$isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($this->uid);
if (isError($isMitarbeiter)) {
//catch error
}
$isMitarbeiter = hasData($isMitarbeiter) ? getData($isMitarbeiter) : null;
$res = new stdClass();
if ($uid == $this->uid || !$uid) {
@@ -359,8 +325,6 @@ class Profil extends Auth_Controller
}
}
echo json_encode($res);
}
@@ -368,7 +332,7 @@ class Profil extends Auth_Controller
public function foto_sperre_function($value) //TODO: refactor function
{
//? Nur der Index User hat die Erlaubniss das Profilbild zu sperren
$res = $this->PersonModel->update($this->pid, array("foto_sperre" => $value));
$res = $this->PersonModel->update($this->pid, ["foto_sperre" => $value]);
if (isError($res)) {
echo json_encode("error encountered when updating foto_sperre");
+43 -20
View File
@@ -23,6 +23,7 @@ class ProfilUpdate extends Auth_Controller
'selectProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
'insertFile' => ['student/anrechnung_beantragen:r', 'user:r'],
'getProfilRequestFiles' => ['student/anrechnung_beantragen:r', 'user:r'],
"sendMailTest" => ['student/anrechnung_beantragen:r', 'user:r'],
]);
@@ -51,6 +52,28 @@ class ProfilUpdate extends Auth_Controller
$this->load->view('Cis/ProfilUpdate');
}
public function sendMailTest(){
$this->load->helper('hlp_sancho_helper');
$isStudent_res = $this->StudentModel->isStudent($this->uid);
if(!isSuccess($isStudent_res)){
show_error("was not able to check whether the uid is a student");
}
$isStudent_res = getData($isStudent_res);
if($isStudent_res){
//? Send email to the Studiengangsassistentinnen
$this->PersonModel->addSelect(["public.tbl_studiengang.email"]);
$this->PersonModel->addJoin("public.tbl_prestudent","public.tbl_person.person_id = public.tbl_prestudent.person_id");
$this->PersonModel->addJoin("public.tbl_studiengang","public.tbl_studiengang.studiengang_kz = public.tbl_prestudent.studiengang_kz");
$this->PersonModel->loadWhere(["public.tbl_person.person_id"=>$this->pid,"public.tbl_prestudent."]);
}else{
//? user is not a student therefore he is a mitarbeiter, send email to Personalverwaltung
}
//$vorlage_kurzbz, $vorlage_data, $to, $subject
//sendSanchoMail("MessageMailTXT",["href"=>'test'],"simongschnell@gmail.com","subject");
}
public function show($dms_id){
$profil_update = $this->ProfilUpdateModel->loadWhere(['attachment_id'=>$dms_id]);
@@ -263,9 +286,6 @@ class ProfilUpdate extends Auth_Controller
foreach($pending_changes as $update_request){
$existing_change = $update_request->requested_change;
//? the user can add as many new kontakt/adresse as he likes
if( !isset($payload->add) && property_exists($existing_change,$identifier) && property_exists($payload,$identifier) && $existing_change->$identifier == $payload->$identifier){
//? the kontakt_id / adresse_id of a change has to be unique
@@ -332,22 +352,25 @@ class ProfilUpdate extends Auth_Controller
}
private function checkIfPermissionsContainStudentOE($student_uid){
private function getOE_from_student($student_uid){
$oe_berechtigung = $this->permissionlib->getOE_isEntitledFor('student/stammdaten');
//? query that checks if the oe_berechtigungen is contained in the organisations_einheiten that are connected to the studiengang of the student
$query ="SELECT TRUE
//? returns the oe_einheit eines Studenten
$query ="SELECT public.tbl_studiengang.oe_kurzbz
FROM public.tbl_student
JOIN public.tbl_prestudent ON public.tbl_student.prestudent_id = public.tbl_prestudent.prestudent_id
JOIN public.tbl_studiengang ON tbl_prestudent.studiengang_kz = public.tbl_studiengang.studiengang_kz
JOIN public.tbl_organisationseinheit ON public.tbl_organisationseinheit.oe_kurzbz = public.tbl_studiengang.oe_kurzbz
WHERE public.tbl_student.student_uid = ? AND public.tbl_studiengang.oe_kurzbz IN ?
LIMIT 1;";
//TODO: hardcoded student_uid replace with variable student_uid
$res = $this->StudentModel->execReadOnlyQuery($query,[$student_uid,$oe_berechtigung]);
return hasData($res) ? true : false;
JOIN public.tbl_studiengang ON tbl_student.studiengang_kz = public.tbl_studiengang.studiengang_kz
WHERE public.tbl_student.student_uid = ?;";
$res = $this->StudentModel->execReadOnlyQuery($query,[$student_uid]);
if(!isSuccess($res)){
show_error("was not able to query the oe_einheit of Student: ".$student_uid);
}
$res = hasData($res) ? getData($res) : [];
$res = array_map(
function($item){
return $item->oe_kurzbz;
},$res
);
return $res;
}
@@ -378,8 +401,8 @@ class ProfilUpdate extends Auth_Controller
//? check if the permissions are set correctly
if(
$this->permissionlib->isBerechtigt('student/stammdaten:rw') && $is_student_profil_update && $this->checkIfPermissionsContainStudentOE($uid) ||
$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten:rw') && $is_mitarbeiter_profil_update
$this->permissionlib->isBerechtigt('student/stammdaten',"suid",$this->getOE_from_student($uid)) && $is_student_profil_update ||
$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten',"suid") && $is_mitarbeiter_profil_update
)
{
@@ -441,8 +464,8 @@ class ProfilUpdate extends Auth_Controller
if(
$this->permissionlib->isBerechtigt('student/stammdaten:rw') && $is_student_profil_update && $this->checkIfPermissionsContainStudentOE($uid) ||
$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten:rw') && $is_mitarbeiter_profil_update
$this->permissionlib->isBerechtigt('student/stammdaten',"suid",$this->getOE_from_student($uid)) && $is_student_profil_update ||
$this->permissionlib->isBerechtigt('mitarbeiter/stammdaten',"suid") && $is_mitarbeiter_profil_update
)
{
echo json_encode($this->setStatusOnUpdateRequest($id, "rejected", $status_message));
@@ -88,6 +88,8 @@ class Profil_update_model extends DB_Model
$res =[];
if($studentBerechtigung) {
//? Nur wenn der/die AssistentIn auch die Berechtigung in der gleichen Organisationseinheit des Studenten hat
$parameters = [];
$query="
@@ -95,10 +97,9 @@ class Profil_update_model extends DB_Model
profil_update_id, tbl_profil_update.uid, (tbl_person.vorname || ' ' || tbl_person.nachname) AS name , topic, requested_change, tbl_profil_update.updateamum, tbl_profil_update.updatevon, tbl_profil_update.insertamum, tbl_profil_update.insertvon, status, status_timestamp, status_message, attachment_id
FROM public.tbl_profil_update
JOIN public.tbl_student ON public.tbl_student.student_uid=public.tbl_profil_update.uid
JOIN public.tbl_prestudent ON public.tbl_prestudent.prestudent_id=public.tbl_student.prestudent_id
JOIN public.tbl_person ON public.tbl_prestudent.person_id=public.tbl_person.person_id
JOIN public.tbl_studiengang ON public.tbl_studiengang.studiengang_kz=public.tbl_prestudent.studiengang_kz
JOIN public.tbl_organisationseinheit ON public.tbl_organisationseinheit.oe_kurzbz=public.tbl_studiengang.oe_kurzbz
JOIN public.tbl_benutzer ON public.tbl_benutzer.uid = public.tbl_student.student_uid
JOIN public.tbl_person ON public.tbl_benutzer.person_id=public.tbl_person.person_id
JOIN public.tbl_studiengang ON public.tbl_studiengang.studiengang_kz=public.tbl_student.studiengang_kz
Where public.tbl_studiengang.oe_kurzbz IN ? ";
$parameters[]=$oe_berechtigung;
if($whereClause){
+9
View File
@@ -89,6 +89,15 @@ export default {
return axios.post(url, requestID);
},
sendMailTest: function(){
const url =
FHC_JS_DATA_STORAGE_OBJECT.app_root +
FHC_JS_DATA_STORAGE_OBJECT.ci_router +
`/Cis/ProfilUpdate/sendMailTest`;
return axios.get(url);
},