fix: [sharinggroups] Possibility to remove/add org from sharinggroup

pull/37/head
mokaddem 2021-01-18 17:26:35 +01:00
parent 2288e8f66f
commit 41948044cd
3 changed files with 47 additions and 7 deletions

View File

@ -2,6 +2,7 @@
namespace App\Controller;
use App\Controller\AppController;
use Cake\Utility\Inflector;
use Cake\Utility\Hash;
use Cake\Utility\Text;
use \Cake\Database\Expression\QueryExpression;
@ -115,9 +116,12 @@ class SharingGroupsController extends AppController
}
if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) {
if ($result) {
$this->RestResponse->saveSuccessResponse('SharingGroups', 'addOrg', $id, 'json', $message);
$savedData = $this->SharingGroups->get($id, [
'contain' => 'SharingGroupOrgs'
]);
return $this->RestResponse->ajaxSuccessResponse(Inflector::singularize($this->SharingGroups->getAlias()), 'addOrg', $savedData, $message);
} else {
$this->RestResponse->saveFailResponse('SharingGroups', 'addOrg', $id, $message, 'json');
return $this->RestResponse->ajaxFailResponse(Inflector::singularize($this->SharingGroups->getAlias()), 'addOrg', $sharingGroup, $message);;
}
} else {
if ($result) {
@ -131,9 +135,45 @@ class SharingGroupsController extends AppController
$this->set(compact('dropdownData'));
}
public function removeOrg($id)
public function removeOrg($id, $org_id)
{
$sharingGroup = $this->SharingGroups->get($id, [
'contain' => 'SharingGroupOrgs'
]);
if ($this->request->is('post')) {
$org = $this->SharingGroups->SharingGroupOrgs->get($org_id);
$result = (bool)$this->SharingGroups->SharingGroupOrgs->unlink($sharingGroup, [$org]);
if ($result) {
$message = __('Organisation(s) removed from the sharing group.');
} else {
$message = __('Organisation(s) could not be removed to the sharing group.');
}
if ($this->ParamHandler->isRest() || $this->ParamHandler->isAjax()) {
if ($result) {
$savedData = $this->SharingGroups->get($id, [
'contain' => 'SharingGroupOrgs'
]);
return $this->RestResponse->ajaxSuccessResponse(Inflector::singularize($this->SharingGroups->getAlias()), 'removeOrg', $savedData, $message);
} else {
return $this->RestResponse->ajaxFailResponse(Inflector::singularize($this->SharingGroups->getAlias()), 'removeOrg', $sharingGroup, $message);
;
}
} else {
if ($result) {
$this->Flash->success($message);
} else {
$this->Flash->error($message);
}
$this->redirect(['action' => 'view', $id]);
}
}
$this->set('scope', 'sharing_groups');
$this->set('id', $org_id);
$this->set('sharingGroup', $sharingGroup);
$this->set('deletionText', __('Are you sure you want to remove Organisation #{0} from Sharing group #{1}?', $org_id, $sharingGroup['id']));
$this->set('postLinkParameters', ['action' => 'removeOrg', $id, $org_id]);
$this->viewBuilder()->setLayout('ajax');
$this->render('/genericTemplates/delete');
}
public function listOrgs($id)

View File

@ -10,7 +10,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'type' => 'simple',
'text' => __('Add sharing group'),
'class' => 'btn btn-primary',
'popover_url' => '/SharingGroups/add'
]
]

View File

@ -11,8 +11,8 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => [
'type' => 'simple',
'text' => __('Add member'),
'class' => 'btn btn-primary',
'popover_url' => '/sharingGroups/addOrg/' . h($sharing_group_id)
'popover_url' => '/sharingGroups/addOrg/' . h($sharing_group_id),
'reload_url' => '/sharingGroups/listOrgs/' . h($sharing_group_id)
]
]
],
@ -54,6 +54,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
[
'open_modal' => '/sharingGroups/removeOrg/' . h($sharing_group_id) . '/[onclick_params_data_path]',
'modal_params_data_path' => 'id',
'reload_url' => '/sharingGroups/listOrgs/' . h($sharing_group_id),
'icon' => 'trash'
],
]