select manager changes
This commit is contained in:
@@ -337,34 +337,88 @@ class Base
|
||||
|
||||
protected function accessOnlyOwn(&$result)
|
||||
{
|
||||
if ($this->getSeed()->hasField('assignedUserId')) {
|
||||
if ($this->hasAssignedUsersField()) {
|
||||
$this->setDistinct(true, $result);
|
||||
$this->addLeftJoin('assignedUsers', $result);
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUsers.id' => $this->getUser()->id
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->hasAssignedUserField()) {
|
||||
$result['whereClause'][] = array(
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getSeed()->hasField('createdById')) {
|
||||
if ($this->hasCreatedByField()) {
|
||||
$result['whereClause'][] = array(
|
||||
'createdById' => $this->getUser()->id
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected function accessOnlyTeam(&$result)
|
||||
{
|
||||
if (!$this->getSeed()->hasField('teamsIds')) {
|
||||
if (!$this->hasTeamsField()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setDistinct(true, $result);
|
||||
$this->addLeftJoin('teams', $result);
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => array(
|
||||
'teams.id' => $this->user->get('teamsIds'),
|
||||
'assignedUserId' => $this->getUser()->id
|
||||
)
|
||||
$this->addLeftJoin(['teams', 'teamsAccess'], $result);
|
||||
|
||||
if ($this->hasAssignedUsersField()) {
|
||||
$this->addLeftJoin(['assignedUsers', 'assignedUsersAccess'], $result);
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => array(
|
||||
'teamsAccess.id' => $this->getUser()->getLinkMultipleIdList('teams'),
|
||||
'assignedUsersAccess.id' => $this->getUser()->id
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$d = array(
|
||||
'teamsAccess.id' => $this->getUser()->getLinkMultipleIdList('teams')
|
||||
);
|
||||
if ($this->hasAssignedUserField()) {
|
||||
$d['assignedUserId'] = $this->getUser()->id;
|
||||
} else if ($this->hasCreatedByField()) {
|
||||
$d['createdById'] = $this->getUser()->id;
|
||||
}
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => $d
|
||||
);
|
||||
}
|
||||
|
||||
protected function hasAssignedUsersField()
|
||||
{
|
||||
if ($this->getSeed()->hasRelation('assignedUsers') && $this->getSeed()->hasField('assignedUsersIds')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasAssignedUserField()
|
||||
{
|
||||
if ($this->getSeed()->hasField('assignedUserId')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasCreatedByField()
|
||||
{
|
||||
if ($this->getSeed()->hasField('createdById')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function hasTeamsField()
|
||||
{
|
||||
if ($this->getSeed()->hasRelation('teams') && $this->getSeed()->hasField('teamsIds')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getAclParams()
|
||||
@@ -798,13 +852,23 @@ class Base
|
||||
$this->textFilter($textFilter, $result);
|
||||
}
|
||||
|
||||
public function hasJoin($join, &$result)
|
||||
{
|
||||
return in_array($join, $result['joins']);
|
||||
}
|
||||
|
||||
public function hasLeftJoin($leftJoin, &$result)
|
||||
{
|
||||
return in_array($leftJoin, $result['leftJoin']);
|
||||
}
|
||||
|
||||
public function addJoin($join, &$result)
|
||||
{
|
||||
if (empty($result['joins'])) {
|
||||
$result['joins'] = [];
|
||||
}
|
||||
|
||||
if (!in_array($join, $result['joins'])) {
|
||||
if (is_array($join) || !in_array($join, $result['joins'])) {
|
||||
$result['joins'][] = $join;
|
||||
}
|
||||
}
|
||||
@@ -815,11 +879,16 @@ class Base
|
||||
$result['leftJoins'] = [];
|
||||
}
|
||||
|
||||
if (!in_array($leftJoin, $result['leftJoins'])) {
|
||||
if (!is_array($leftJoin) || !in_array($leftJoin, $result['leftJoins'])) {
|
||||
$result['leftJoins'][] = $leftJoin;
|
||||
}
|
||||
}
|
||||
|
||||
public function setJoinCondition($join, $condition, &$result)
|
||||
{
|
||||
$result['joinConditions'][$join] = $condition;
|
||||
}
|
||||
|
||||
public function setDistinct($distinct, &$result)
|
||||
{
|
||||
$result['distinct'] = (bool) $distinct;
|
||||
|
||||
@@ -150,7 +150,7 @@ abstract class Base
|
||||
}
|
||||
|
||||
if (!empty($params['joins']) && is_array($params['joins'])) {
|
||||
$params['joins'] = array_unique($params['joins']);
|
||||
// TODO array unique
|
||||
$joinsRelated = $this->getJoins($entity, $params['joins'], false, $params['joinConditions']);
|
||||
if (!empty($joinsRelated)) {
|
||||
if (!empty($joinsPart)) {
|
||||
@@ -161,7 +161,7 @@ abstract class Base
|
||||
}
|
||||
|
||||
if (!empty($params['leftJoins']) && is_array($params['leftJoins'])) {
|
||||
$params['leftJoins'] = array_unique($params['leftJoins']);
|
||||
// TODO array unique
|
||||
$joinsRelated = $this->getJoins($entity, $params['leftJoins'], true, $params['joinConditions']);
|
||||
if (!empty($joinsRelated)) {
|
||||
if (!empty($joinsPart)) {
|
||||
|
||||
@@ -35,31 +35,30 @@ class Email extends \Espo\Core\SelectManagers\Base
|
||||
{
|
||||
$result = parent::getSelectParams($params, $withAcl);
|
||||
|
||||
if (!in_array('users', $result['joins']) && !in_array('users', $result['leftJoins'])) {
|
||||
$result['leftJoins'][] = 'users';
|
||||
$result['joinConditions']['users'] = array(
|
||||
if (!$this->hasJoin('users', $result) && !$this->hasLeftJoin('users', $result)) {
|
||||
$this->addLeftJoin('users', $result);
|
||||
$this->setJoinCondition('users', array(
|
||||
'userId' => $this->getUser()->id
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
if (!isset($result['select'])) {
|
||||
$result['additionalSelectColumns']['usersMiddle.is_read'] = 'isRead';
|
||||
$result['additionalSelectColumns']['usersMiddle.is_important'] = 'isImportant';
|
||||
$result['additionalSelectColumns']['usersMiddle.in_trash'] = 'inTrash';
|
||||
}
|
||||
$this->addUsersColumns($result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function boolFilterOnlyMy(&$result)
|
||||
{
|
||||
if (!in_array('users', $result['joins'])) {
|
||||
$result['joins'][] = 'users';
|
||||
}
|
||||
$this->addJoin('users', $result);
|
||||
$result['whereClause'][] = array(
|
||||
'usersMiddle.userId' => $this->getUser()->id
|
||||
);
|
||||
|
||||
$this->addUsersColumns($result);
|
||||
}
|
||||
|
||||
protected function addUsersColumns(&$result)
|
||||
{
|
||||
if (!isset($result['select'])) {
|
||||
$result['additionalSelectColumns']['usersMiddle.is_read'] = 'isRead';
|
||||
$result['additionalSelectColumns']['usersMiddle.is_important'] = 'isImportant';
|
||||
@@ -122,6 +121,20 @@ class Email extends \Espo\Core\SelectManagers\Base
|
||||
$this->boolFilterOnlyMy($result);
|
||||
}
|
||||
|
||||
protected function accessOnlyTeam(&$result)
|
||||
{
|
||||
$this->setDistinct(true, $result);
|
||||
$this->addLeftJoin(['teams', 'teamsAccess'], $result);
|
||||
$this->addLeftJoin(['users', 'usersAccess'], $result);
|
||||
|
||||
$result['whereClause'][] = array(
|
||||
'OR' => array(
|
||||
'teamsAccess.id' => $this->getUser()->getLinkMultipleIdList('teams'),
|
||||
'usersAccess.id' => $this->getUser()->id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function textFilter($textFilter, &$result)
|
||||
{
|
||||
$d = array();
|
||||
|
||||
Reference in New Issue
Block a user