Merge pull request #34 from mokaddem/fix-sharing-group

fix: [sharingGroup] Various fixes for sharing groups
pull/35/head
Andras Iklody 2020-11-25 16:54:20 +01:00 committed by GitHub
commit 396c5bcfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 15 deletions

View File

@ -8,6 +8,8 @@ DROP TABLE IF EXISTS encryption_keys;
DROP TABLE IF EXISTS organisation_encryption_keys;
DROP TABLE IF EXISTS organisations;
DROP TABLE IF EXISTS roles;
DROP TABLE IF EXISTS sharing_groups;
DROP TABLE IF EXISTS sgo;
DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS user_keys;
DROP TABLE IF EXISTS users;

View File

@ -309,7 +309,7 @@ CREATE TABLE `sharing_groups` (
KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `sharing_group_orgs` (
CREATE TABLE `sgo` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`sharing_group_id` int(10) unsigned NOT NULL,
`organisation_id` int(10) unsigned NOT NULL,

View File

@ -29,12 +29,7 @@ class SharingGroupsController extends AppController
]
]);
$dropdownData = [
'organisation' => $this->SharingGroups->Organisations->find('list', [
'sort' => ['name' => 'asc'],
'conditions' => [
'id IN' => array_values(\Cake\Utility\Hash::extract($this->ACL->getUser(), 'individual.organisations.{n}.id'))
]
])
'organisation' => $this->getAvailableOrgForSg($this->ACL->getUser())
];
if ($this->ParamHandler->isRest()) {
return $this->restResponsePayload;
@ -61,12 +56,7 @@ class SharingGroupsController extends AppController
return $this->restResponsePayload;
}
$dropdownData = [
'organisation' => $this->SharingGroups->Organisations->find('list', [
'sort' => ['name' => 'asc'],
'conditions' => [
'id IN' => array_values(\Cake\Utility\Hash::extract($this->ACL->getUser(), 'individual.organisations.{n}.id'))
]
])
'organisation' => $this->getAvailableOrgForSg($this->ACL->getUser())
];
$this->set(compact('dropdownData'));
$this->set('metaGroup', 'Trust Circles');
@ -160,4 +150,20 @@ class SharingGroupsController extends AppController
$this->set('sharing_group_id', $id);
$this->set('sharing_group_orgs', $sharingGroup['sharing_group_orgs']);
}
private function getAvailableOrgForSg($user)
{
$organisations = [];
if (!empty($user['role']['perm_admin'])) {
$organisations = $this->SharingGroups->Organisations->find('list')->order(['name' => 'ASC'])->toArray();
} else if (!empty($user['individual']['organisations'])) {
$organisations = $this->SharingGroups->Organisations->find('list', [
'sort' => ['name' => 'asc'],
'conditions' => [
'id IN' => array_values(\Cake\Utility\Hash::extract($user, 'individual.organisations.{n}.id'))
]
]);
}
return $organisations;
}
}

View File

@ -24,8 +24,8 @@ class SharingGroupsTable extends AppTable
'SharingGroupOrgs',
[
'className' => 'Organisations',
'joinTable' => 'sgo',
'foreignKey' => 'sharing_group_id',
'joinTable' => 'sgo',
'targetForeignKey' => 'organisation_id'
]
);

View File

@ -12,7 +12,7 @@
],
'submit' => [
'action' => $this->request->getParam('action')
]
],
]
]);
?>

View File

@ -15,6 +15,7 @@
$modelForForm = empty($data['model']) ?
h(\Cake\Utility\Inflector::singularize(\Cake\Utility\Inflector::classify($this->request->getParam('controller')))) :
h($data['model']);
$entity = isset($entity) ? $entity : null;
$fieldsString = '';
$simpleFieldWhitelist = [
'default', 'type', 'placeholder', 'label', 'empty', 'rows', 'div', 'required'