2020-05-29 13:41:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Controller\AppController;
|
|
|
|
use Cake\Utility\Hash;
|
|
|
|
use Cake\Utility\Text;
|
|
|
|
use \Cake\Database\Expression\QueryExpression;
|
|
|
|
use Cake\Http\Exception\NotFoundException;
|
|
|
|
use Cake\Http\Exception\MethodNotAllowedException;
|
|
|
|
use Cake\Http\Exception\ForbiddenException;
|
|
|
|
use Cake\Http\Exception\NotAcceptableException;
|
|
|
|
use Cake\Error\Debugger;
|
|
|
|
|
|
|
|
class EncryptionKeysController extends AppController
|
|
|
|
{
|
2021-09-10 11:55:54 +02:00
|
|
|
public $filterFields = ['owner_model', 'organisation_id', 'individual_id', 'encryption_key'];
|
|
|
|
public $quickFilterFields = ['encryption_key'];
|
|
|
|
public $containFields = ['Individuals', 'Organisations'];
|
|
|
|
|
2020-06-04 10:05:45 +02:00
|
|
|
public function index()
|
2020-05-29 13:41:58 +02:00
|
|
|
{
|
2020-06-19 00:40:58 +02:00
|
|
|
$this->CRUD->index([
|
2021-09-10 11:55:54 +02:00
|
|
|
'quickFilters' => $this->quickFilterFields,
|
|
|
|
'filters' => $this->filterFields,
|
2021-01-11 16:28:07 +01:00
|
|
|
'contextFilters' => [
|
|
|
|
'fields' => [
|
|
|
|
'type'
|
|
|
|
]
|
|
|
|
],
|
2021-09-10 11:55:54 +02:00
|
|
|
'contain' => $this->containFields
|
2020-06-19 00:40:58 +02:00
|
|
|
]);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
2020-06-19 00:40:58 +02:00
|
|
|
$this->set('metaGroup', 'ContactDB');
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete($id)
|
|
|
|
{
|
2020-06-19 00:40:58 +02:00
|
|
|
$this->CRUD->delete($id);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
|
|
|
$this->set('metaGroup', 'ContactDB');
|
|
|
|
}
|
|
|
|
|
2020-06-04 10:05:45 +02:00
|
|
|
public function add()
|
2020-05-29 13:41:58 +02:00
|
|
|
{
|
2021-11-24 01:32:05 +01:00
|
|
|
$orgConditions = [];
|
|
|
|
$currentUser = $this->ACL->getUser();
|
|
|
|
$params = ['redirect' => $this->referer()];
|
|
|
|
if (empty($currentUser['role']['perm_admin'])) {
|
|
|
|
$params['beforeSave'] = function($entity) {
|
|
|
|
if ($entity['owner_model'] === 'organisation') {
|
|
|
|
$entity['owner_id'] = $currentUser['organisation_id'];
|
|
|
|
} else {
|
|
|
|
if ($currentUser['role']['perm_org_admin']) {
|
|
|
|
$validIndividuals = $this->Organisations->Alignments->find('list', [
|
|
|
|
'fields' => ['distinct(individual_id)'],
|
|
|
|
'conditions' => ['organisation_id' => $currentUser['organisation_id']]
|
|
|
|
]);
|
|
|
|
if (!in_array($entity['owner_id'], $validIndividuals)) {
|
|
|
|
throw new MethodNotAllowedException(__('Selected individual cannot be linked by the current user.'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($entity['owner_id'] !== $currentUser['id']) {
|
|
|
|
throw new MethodNotAllowedException(__('Selected individual cannot be linked by the current user.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
$this->CRUD->add($params);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
2020-06-04 10:05:45 +02:00
|
|
|
$this->loadModel('Organisations');
|
|
|
|
$this->loadModel('Individuals');
|
|
|
|
$dropdownData = [
|
|
|
|
'organisation' => $this->Organisations->find('list', [
|
2021-11-24 01:32:05 +01:00
|
|
|
'sort' => ['name' => 'asc'],
|
|
|
|
'conditions' => $orgConditions
|
2020-06-04 10:05:45 +02:00
|
|
|
]),
|
|
|
|
'individual' => $this->Individuals->find('list', [
|
|
|
|
'sort' => ['email' => 'asc']
|
|
|
|
])
|
|
|
|
];
|
|
|
|
$this->set(compact('dropdownData'));
|
2020-05-29 13:41:58 +02:00
|
|
|
$this->set('metaGroup', 'ContactDB');
|
|
|
|
}
|
2020-11-06 10:45:00 +01:00
|
|
|
|
|
|
|
public function edit($id = false)
|
|
|
|
{
|
2021-11-24 01:32:05 +01:00
|
|
|
$conditions = [];
|
|
|
|
$currentUser = $this->ACL->getUser();
|
2020-11-06 10:45:00 +01:00
|
|
|
$params = [
|
|
|
|
'fields' => [
|
|
|
|
'type', 'encryption_key', 'revoked'
|
|
|
|
],
|
|
|
|
'redirect' => $this->referer()
|
|
|
|
];
|
2021-11-24 01:32:05 +01:00
|
|
|
if (empty($currentUser['role']['perm_admin'])) {
|
|
|
|
if (empty($currentUser['role']['perm_org_admin'])) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 10:45:00 +01:00
|
|
|
$this->CRUD->edit($id, $params);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-11-06 10:45:00 +01:00
|
|
|
}
|
|
|
|
$this->set('dropdownData', []);
|
|
|
|
$this->set('metaGroup', 'ContactDB');
|
|
|
|
$this->render('add');
|
|
|
|
}
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|