diff --git a/src/Controller/SharingGroupsController.php b/src/Controller/SharingGroupsController.php new file mode 100644 index 0000000..4b89034 --- /dev/null +++ b/src/Controller/SharingGroupsController.php @@ -0,0 +1,163 @@ +CRUD->index([ + 'contain' => ['SharingGroupOrgs', 'Organisations', 'Users'], + 'filters' => ['uuid', 'description', 'releasability', 'Organisations.name', 'Organisations.uuid'] + ]); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Trust Circles'); + } + + public function add() + { + $this->CRUD->add([ + 'override' => [ + 'user_id' => $this->ACL->getUser()['id'] + ] + ]); + $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')) + ] + ]) + ]; + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set(compact('dropdownData')); + $this->set('metaGroup', 'Trust Circles'); + } + + public function view($id) + { + $this->CRUD->view($id, [ + 'contain' => ['SharingGroupOrgs', 'Organisations', 'Users'] + ]); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Trust Circles'); + } + + public function edit($id = false) + { + $this->CRUD->edit($id); + if ($this->ParamHandler->isRest()) { + 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')) + ] + ]) + ]; + $this->set(compact('dropdownData')); + $this->set('metaGroup', 'Trust Circles'); + $this->render('add'); + } + + public function delete($id) + { + $this->CRUD->delete($id); + if ($this->ParamHandler->isRest()) { + return $this->restResponsePayload; + } + $this->set('metaGroup', 'Trust Circles'); + } + + public function addOrg($id) + { + $sharingGroup = $this->SharingGroups->get($id, [ + 'contain' => 'SharingGroupOrgs' + ]); + $conditions = []; + $containedOrgIds = array_values(\Cake\Utility\Hash::extract($sharingGroup, 'sharing_group_orgs.{n}.id')); + if (!empty($containedOrgIds)) { + $conditions = [ + 'NOT' => [ + 'id IN' => $containedOrgIds + ] + ]; + } + $dropdownData = [ + 'organisation' => $this->SharingGroups->Organisations->find('list', [ + 'sort' => ['name' => 'asc'], + 'conditions' => $conditions + ]) + ]; + if ($this->request->is('post')) { + $input = $this->request->getData(); + if (empty($input['organisation_id'])) { + throw new InvalidArgumentException(__('No organisation IDs passed.')); + } + if (!is_array($input['organisation_id'])) { + $input['organisation_id'] = [$input['organisation_id']]; + } + $result = true; + foreach ($input['organisation_id'] as $org_id) { + $org = $this->SharingGroups->SharingGroupOrgs->get($org_id); + $result &= (bool)$this->SharingGroups->SharingGroupOrgs->link($sharingGroup, [$org]); + } + if ($result) { + $message = __('Organisation(s) added to the sharing group.'); + } else { + $message = __('Organisation(s) could not be added to the sharing group.'); + } + if ($this->ParamHandler->isRest()) { + if ($result) { + $this->RestResponse->saveSuccessResponse('SharingGroups', 'addOrg', $id, 'json', $message); + } else { + $this->RestResponse->saveFailResponse('SharingGroups', 'addOrg', $id, $message, 'json'); + } + } else { + if ($result) { + $this->Flash->success($message); + } else { + $this->Flash->error($message); + } + $this->redirect(['action' => 'view', $id]); + } + } + $this->set(compact('dropdownData')); + } + + public function removeOrg($id) + { + + } + + public function listOrgs($id) + { + $sharingGroup = $this->SharingGroups->get($id, [ + 'contain' => 'SharingGroupOrgs' + ]); + $params = $this->ParamHandler->harvestParams(['quickFilter']); + if (!empty($params['quickFilter'])) { + foreach ($sharingGroup['sharing_group_orgs'] as $k => $org) { + if (strpos($org['name'], $params['quickFilter']) === false) { + unset($sharingGroup['sharing_group_orgs'][$k]); + } + } + $sharingGroup['sharing_group_orgs'] = array_values($sharingGroup['sharing_group_orgs']); + } + $this->set('sharing_group_id', $id); + $this->set('sharing_group_orgs', $sharingGroup['sharing_group_orgs']); + } +} diff --git a/src/Model/Entity/SharingGroup.php b/src/Model/Entity/SharingGroup.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Model/Table/SharingGroupsTable.php b/src/Model/Table/SharingGroupsTable.php new file mode 100644 index 0000000..7204dec --- /dev/null +++ b/src/Model/Table/SharingGroupsTable.php @@ -0,0 +1,46 @@ +addBehavior('UUID'); + $this->belongsTo( + 'Users' + ); + $this->belongsTo( + 'Organisations' + ); + $this->belongsToMany( + 'SharingGroupOrgs', + [ + 'className' => 'Organisations', + 'joinTable' => 'sgo', + 'foreignKey' => 'sharing_group_id', + 'targetForeignKey' => 'organisation_id' + ] + ); + $this->setDisplayField('name'); + } + + public function validationDefault(Validator $validator): Validator + { + $validator + ->requirePresence(['name', 'releasability'], 'create'); + return $validator; + } + + public function buildRules(RulesChecker $rules): RulesChecker + { + return $rules; + } +} diff --git a/templates/SharingGroups/add.php b/templates/SharingGroups/add.php new file mode 100644 index 0000000..5b3e413 --- /dev/null +++ b/templates/SharingGroups/add.php @@ -0,0 +1,41 @@ +element('genericElements/Form/genericForm', array( + 'data' => array( + 'description' => __('Sharing groups are distribution lists usable by tools that can exchange information with a list of trusted partners. Create recurring or ad hoc sharing groups and share them with the members of the sharing group.'), + 'model' => 'Organisations', + 'fields' => array( + array( + 'field' => 'name' + ), + [ + 'field' => 'organisation_id', + 'type' => 'dropdown', + 'label' => __('Owner organisation'), + 'options' => $dropdownData['organisation'] + ], + array( + 'field' => 'releasability', + 'type' => 'textarea' + ), + array( + 'field' => 'description', + 'type' => 'textarea' + ), + array( + 'field' => 'uuid', + 'label' => 'UUID', + 'type' => 'uuid' + ), + array( + 'field' => 'active', + 'type' => 'checkbox', + 'default' => 1 + ) + ), + 'submit' => array( + 'action' => $this->request->getParam('action') + ) + ) + )); +?> + diff --git a/templates/SharingGroups/add_org.php b/templates/SharingGroups/add_org.php new file mode 100644 index 0000000..24b89c2 --- /dev/null +++ b/templates/SharingGroups/add_org.php @@ -0,0 +1,19 @@ +element('genericElements/Form/genericForm', [ + 'data' => [ + 'model' => 'SharingGroups', + 'fields' => [ + [ + 'field' => 'organisation_id', + 'type' => 'dropdown', + 'label' => __('Owner organisation'), + 'options' => $dropdownData['organisation'] + ], + ], + 'submit' => [ + 'action' => $this->request->getParam('action') + ] + ] + ]); +?> + diff --git a/templates/SharingGroups/index.php b/templates/SharingGroups/index.php new file mode 100644 index 0000000..f862aff --- /dev/null +++ b/templates/SharingGroups/index.php @@ -0,0 +1,77 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $data, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'simple', + 'children' => [ + 'data' => [ + 'type' => 'simple', + 'text' => __('Add sharing group'), + 'class' => 'btn btn-primary', + 'popover_url' => '/SharingGroups/add' + ] + ] + ], + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'class' => 'short', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'class' => 'short', + 'data_path' => 'name', + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'class' => 'short', + 'data_path' => 'uuid', + ], + [ + 'name' => __('Members'), + 'data_path' => 'alignments', + 'element' => 'count_summary', + 'url' => '/sharingGroups/view/{{id}}', + 'url_data_path' => 'id' + ] + ], + 'title' => __('Sharing Groups Index'), + 'description' => __('Sharing groups are distribution lists usable by tools that can exchange information with a list of trusted partners. Create recurring or ad hoc sharing groups and share them with the members of the sharing group.'), + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/sharingGroups/view', + 'url_params_data_paths' => ['id'], + 'icon' => 'eye' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/sharingGroups/edit/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'edit' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/sharingGroups/delete/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'trash' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/SharingGroups/list_orgs.php b/templates/SharingGroups/list_orgs.php new file mode 100644 index 0000000..0862276 --- /dev/null +++ b/templates/SharingGroups/list_orgs.php @@ -0,0 +1,64 @@ +element('genericElements/IndexTable/index_table', [ + 'data' => [ + 'data' => $sharing_group_orgs, + 'skip_pagination' => 1, + 'top_bar' => [ + 'pull' => 'right', + 'children' => [ + [ + 'type' => 'simple', + 'children' => [ + 'data' => [ + 'type' => 'simple', + 'text' => __('Add member'), + 'class' => 'btn btn-primary', + 'popover_url' => '/sharingGroups/addOrg/' . h($sharing_group_id) + ] + ] + ], + [ + 'type' => 'search', + 'button' => __('Filter'), + 'placeholder' => __('Enter value to search'), + 'data' => '', + 'searchKey' => 'value' + ] + ] + ], + 'fields' => [ + [ + 'name' => '#', + 'sort' => 'id', + 'class' => 'short', + 'data_path' => 'id', + ], + [ + 'name' => __('Name'), + 'class' => 'short', + 'data_path' => 'name', + ], + [ + 'name' => __('UUID'), + 'sort' => 'uuid', + 'class' => 'short', + 'data_path' => 'uuid', + ] + ], + 'pull' => 'right', + 'actions' => [ + [ + 'url' => '/organisations/view', + 'url_params_data_paths' => ['id'], + 'icon' => 'eye' + ], + [ + 'onclick' => 'populateAndLoadModal(\'/sharingGroups/removeOrg/' . h($sharing_group_id) . '/[onclick_params_data_path]\');', + 'onclick_params_data_path' => 'id', + 'icon' => 'trash' + ] + ] + ] +]); +echo ''; +?> diff --git a/templates/SharingGroups/view.php b/templates/SharingGroups/view.php new file mode 100644 index 0000000..84ab096 --- /dev/null +++ b/templates/SharingGroups/view.php @@ -0,0 +1,52 @@ +element( + '/genericElements/SingleViews/single_view', + [ + 'data' => $entity, + 'fields' => [ + [ + 'key' => __('ID'), + 'path' => 'id' + ], + [ + 'key' => __('UUID'), + 'path' => 'uuid' + ], + [ + 'key' => __('Name'), + 'path' => 'name' + ], + [ + 'key' => __('Organisation'), + 'path' => 'organisation.name', + 'url' => '/organisations/view/{{0}}', + 'url_vars' => 'organisation.id' + ], + [ + 'key' => __('Releasability'), + 'path' => 'releasability' + ], + [ + 'key' => __('Description'), + 'path' => 'description' + ], + [ + 'key' => __('Active'), + 'path' => 'active', + 'type' => 'boolean' + ], + [ + 'key' => __('local'), + 'path' => 'local', + 'type' => 'boolean' + ] + ], + 'children' => [ + [ + 'url' => '/sharingGroups/listOrgs/{{0}}', + 'url_params' => ['id'], + 'title' => __('Organisations') + ] + ] + ] +);