chg: [instance:searchAll] Sharinggroup filter on org membership in addition to owner

pull/93/head
Sami Mokaddem 2022-02-28 14:35:06 +01:00
parent bc04fd0336
commit ad6362eed4
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 16 additions and 7 deletions

View File

@ -35,14 +35,23 @@ class InstanceTable extends AppTable
'Individuals' => ['conditions' => false, 'afterFind' => false],
'Organisations' => ['conditions' => false, 'afterFind' => false],
'SharingGroups' => [
'conditions' => function($user) {
$conditions = [];
if (empty($user['role']['perm_admin'])) {
$conditions['SharingGroups.organisation_id'] = $user['organisation_id'];
}
return $conditions;
},
'conditions' => false,
'afterFind' => function($result, $user) {
foreach ($result as $i => $row) {
if (empty($user['role']['perm_admin'])) {
$orgFound = false;
if (!empty($row['sharing_group_orgs'])) {
foreach ($row['sharing_group_orgs'] as $org) {
if ($org['id'] === $user['organisation_id']) {
$orgFound = true;
}
}
}
if ($row['organisation_id'] !== $user['organisation_id'] && !$orgFound) {
unset($result[$i]);
}
}
}
return $result;
},
],