mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
- All permission functionalities now are in the library PermissionLib
- All return messages functions are in the message helper and it is loaded by the core classes - Added the missing constant FHC_NOPK - Updated all the interested classes with the new permission method - Updated all the interested classes with the new return message functions
This commit is contained in:
@@ -8,8 +8,8 @@ class Recipient_model extends DB_Model
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->dbTable = "public.tbl_msg_recipient";
|
||||
$this->pk = array("person_id", "message_id");
|
||||
$this->dbTable = 'public.tbl_msg_recipient';
|
||||
$this->pk = array('person_id', 'message_id');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
|
||||
@@ -18,17 +18,17 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessage($message_id, $person_id)
|
||||
{
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_person"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_person"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_kontakt"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_kontakt"), FHC_MODEL_ERROR);
|
||||
|
||||
$query = "SELECT mr.message_id,
|
||||
// Checks if the operation is permitted by the API caller
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_recipient', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_person', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_kontakt', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
|
||||
$query = 'SELECT mr.message_id,
|
||||
mr.person_id,
|
||||
mm.subject,
|
||||
mm.body,
|
||||
@@ -40,18 +40,18 @@ class Recipient_model extends DB_Model
|
||||
INNER JOIN public.tbl_person p ON (mm.person_id = p.person_id)
|
||||
LEFT JOIN public.tbl_benutzer b ON (mr.person_id = b.person_id)
|
||||
LEFT JOIN (
|
||||
SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = 'email'
|
||||
SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = \'email\'
|
||||
) ks ON (ks.person_id = mr.person_id)
|
||||
WHERE mr.message_id = ? AND mr.person_id = ?";
|
||||
WHERE mr.message_id = ? AND mr.person_id = ?';
|
||||
|
||||
$parametersArray = array($message_id, $person_id);
|
||||
|
||||
// Get data of the messages to sent
|
||||
$result = $this->db->query($query, $parametersArray);
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
return success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +59,15 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessageByToken($token)
|
||||
{
|
||||
// Check wrights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR);
|
||||
// Checks if the operation is permitted by the API caller
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_recipient', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_status', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
|
||||
$sql = "SELECT r.message_id,
|
||||
$sql = 'SELECT r.message_id,
|
||||
m.person_id as sender_id,
|
||||
r.person_id as receiver_id,
|
||||
m.subject,
|
||||
@@ -83,13 +83,13 @@ class Recipient_model extends DB_Model
|
||||
SELECT * FROM public.tbl_msg_status WHERE status < ? ORDER BY insertamum DESC, status DESC
|
||||
) s ON (r.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE r.token = ?
|
||||
LIMIT 1";
|
||||
LIMIT 1';
|
||||
|
||||
$result = $this->db->query($sql, array(MSG_STATUS_DELETED, $token));
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
return success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,17 +97,17 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessagesByPerson($person_id, $all)
|
||||
{
|
||||
// Check wrights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_person"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_person"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_status"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_status"), FHC_MODEL_ERROR);
|
||||
// Checks if the operation is permitted by the API caller
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_recipient', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_person', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_status', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
|
||||
$sql = "SELECT DISTINCT ON (r.message_id) r.message_id,
|
||||
$sql = 'SELECT DISTINCT ON (r.message_id) r.message_id,
|
||||
m.person_id,
|
||||
m.subject,
|
||||
m.body,
|
||||
@@ -133,25 +133,25 @@ class Recipient_model extends DB_Model
|
||||
ORDER BY insertamum DESC
|
||||
) s ON (m.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE r.person_id = ?
|
||||
ORDER BY r.message_id DESC, s.status DESC";
|
||||
ORDER BY r.message_id DESC, s.status DESC';
|
||||
|
||||
$parametersArray = array($person_id);
|
||||
|
||||
if ($all == "true")
|
||||
if ($all == 'true')
|
||||
{
|
||||
$sql = sprintf($sql, "");
|
||||
$sql = sprintf($sql, '');
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($parametersArray, $person_id, $person_id);
|
||||
$sql = sprintf($sql, "WHERE person_id = ? AND message_id NOT IN (SELECT message_id FROM public.tbl_msg_status WHERE status >= 3 AND person_id = ?)");
|
||||
$sql = sprintf($sql, 'WHERE person_id = ? AND message_id NOT IN (SELECT message_id FROM public.tbl_msg_status WHERE status >= 3 AND person_id = ?)');
|
||||
}
|
||||
|
||||
$result = $this->db->query($sql, $parametersArray);
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
return success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,23 +159,23 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessagesByUID($uid, $all)
|
||||
{
|
||||
// Check wrights
|
||||
// @ToDo: Define the special wright for reading own messages "basis/message:own"
|
||||
// Checks if the operation is permitted by the API caller
|
||||
// @ToDo: Define the special right for reading own messages 'basis/message:own'
|
||||
// if same user
|
||||
if ($uid === getAuthUID())
|
||||
{
|
||||
if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message", FHC_MODEL_ERROR);
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
}
|
||||
// if different user, for reading messages from other users
|
||||
else
|
||||
{
|
||||
if (! $this->fhc_db_acl->isBerechtigt("basis/message", "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> basis/message:all", FHC_MODEL_ERROR);
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
}
|
||||
|
||||
// get Data
|
||||
$sql = "SELECT b.uid,
|
||||
$sql = 'SELECT b.uid,
|
||||
m.person_id,
|
||||
m.message_id,
|
||||
m.subject,
|
||||
@@ -199,16 +199,16 @@ class Recipient_model extends DB_Model
|
||||
JOIN (
|
||||
SELECT * FROM public.tbl_msg_status ORDER BY insertamum DESC LIMIT 1
|
||||
) s ON (r.message_id = s.message_id AND r.person_id = s.person_id)
|
||||
WHERE b.uid = ?";
|
||||
WHERE b.uid = ?';
|
||||
|
||||
if (! $all)
|
||||
$sql .= " AND (status < 3 OR status IS NULL)";
|
||||
$sql .= ' AND (status < 3 OR status IS NULL)';
|
||||
|
||||
$result = $this->db->query($sql, array($uid));
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
return success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,15 +223,15 @@ class Recipient_model extends DB_Model
|
||||
*/
|
||||
public function getMessages($kontaktType, $sent, $limit = null, $message_id = null)
|
||||
{
|
||||
// Check rights
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_recipient"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_recipient"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_msg_message"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_msg_message"), FHC_MODEL_ERROR);
|
||||
if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz("public.tbl_kontakt"), "s"))
|
||||
return $this->_error(lang("fhc_".FHC_NORIGHT)." -> ".$this->getBerechtigungKurzbz("public.tbl_kontakt"), FHC_MODEL_ERROR);
|
||||
|
||||
$query = "SELECT mm.message_id,
|
||||
// Checks if the operation is permitted by the API caller
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_recipient', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_msg_message', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
if (($chkRights = $this->isEntitled('public.tbl_kontakt', PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
|
||||
return $chkRights;
|
||||
|
||||
$query = 'SELECT mm.message_id,
|
||||
ks.kontakt as sender,
|
||||
kr.kontakt as receiver,
|
||||
mr.person_id as receiver_id,
|
||||
@@ -245,39 +245,39 @@ class Recipient_model extends DB_Model
|
||||
) ks ON (ks.person_id = mm.person_id)
|
||||
LEFT JOIN (
|
||||
SELECT person_id, kontakt FROM public.tbl_kontakt WHERE kontakttyp = ?
|
||||
) kr ON (kr.person_id = mr.person_id)";
|
||||
) kr ON (kr.person_id = mr.person_id)';
|
||||
|
||||
$parametersArray = array($kontaktType, $kontaktType);
|
||||
|
||||
if (is_null($sent) || $sent == "")
|
||||
if (is_null($sent) || $sent == '')
|
||||
{
|
||||
$query .= " WHERE mr.sent IS NULL";
|
||||
$query .= ' WHERE mr.sent IS NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($parametersArray, $sent);
|
||||
$query .= " WHERE mr.sent = ?";
|
||||
$query .= ' WHERE mr.sent = ?';
|
||||
}
|
||||
|
||||
if (!is_null($message_id))
|
||||
{
|
||||
array_push($parametersArray, $message_id);
|
||||
$query .= " AND mm.message_id = ?";
|
||||
$query .= ' AND mm.message_id = ?';
|
||||
}
|
||||
|
||||
$query .= " ORDER BY mr.insertamum ASC";
|
||||
$query .= ' ORDER BY mr.insertamum ASC';
|
||||
|
||||
if (!is_null($limit))
|
||||
{
|
||||
$query .= " LIMIT ?";
|
||||
$query .= ' LIMIT ?';
|
||||
array_push($parametersArray, $limit);
|
||||
}
|
||||
|
||||
// Get data of the messages to sent
|
||||
$result = $this->db->query($query, $parametersArray);
|
||||
if (is_object($result))
|
||||
return $this->_success($result->result());
|
||||
return success($result->result());
|
||||
else
|
||||
return $this->_error($this->db->error(), FHC_DB_ERROR);
|
||||
return error($this->db->error(), FHC_DB_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user