new: [Sharing groups] added (wip)
- CRUD - attach organisation still missing: - remove organisationpull/17/head
parent
12a83352a4
commit
ecc81bdb00
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Utility\Hash;
|
||||
use Cake\Utility\Text;
|
||||
use \Cake\Database\Expression\QueryExpression;
|
||||
use Cake\Error\Debugger;
|
||||
|
||||
class SharingGroupsController extends AppController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->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']);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model\Table;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\Validation\Validator;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
class SharingGroupsTable extends AppTable
|
||||
{
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
$this->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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
echo $this->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')
|
||||
)
|
||||
)
|
||||
));
|
||||
?>
|
||||
</div>
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
echo $this->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')
|
||||
]
|
||||
]
|
||||
]);
|
||||
?>
|
||||
</div>
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
echo $this->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 '</div>';
|
||||
?>
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
echo $this->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 '</div>';
|
||||
?>
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
echo $this->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')
|
||||
]
|
||||
]
|
||||
]
|
||||
);
|
Loading…
Reference in New Issue