new: [encryption keys] controller/model/template added
parent
1fde2d7a8e
commit
21ad2e8b5e
|
@ -16,62 +16,30 @@ class EncryptionKeysController extends AppController
|
|||
{
|
||||
public function index()
|
||||
{
|
||||
$params = $this->_harvestParams($this->request, ['owner_type', 'owner_id']);
|
||||
$query = $this->EncryptionKeys->find();
|
||||
if (!empty($params['owner_type'])) {
|
||||
$query->where(['owner_type' => $params['owner_type']]);
|
||||
$this->CRUD->index([
|
||||
'filters' => ['owner_type', 'organisation_id', 'individual_id'],
|
||||
'contain' => ['Individuals', 'Organisations']
|
||||
]);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
if (!empty($params['owner_id'])) {
|
||||
$query->where(['owner_id' => $params['owner_id']]);
|
||||
}
|
||||
$query->contain(['Individuals', 'Organisations']);
|
||||
if ($this->_isRest()) {
|
||||
$alignments = $query->all();
|
||||
return $this->RestResponse->viewData($alignments, 'json');
|
||||
} else {
|
||||
$this->loadComponent('Paginator');
|
||||
$encrpyion_keys = $this->Paginator->paginate($query);
|
||||
$this->set('data', $encrpyion_keys);
|
||||
$this->set('metaGroup', 'ContactDB');
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
throw new NotFoundException(__('Invalid encryption key.'));
|
||||
}
|
||||
$key = $this->EncryptionKeys->get($id);
|
||||
if ($this->request->is('post') || $this->request->is('delete')) {
|
||||
if ($this->EncryptionKey->delete($individual)) {
|
||||
$message = __('Encryption key deleted.');
|
||||
if ($this->_isRest()) {
|
||||
$individual = $this->EncryptionKeys->get($id);
|
||||
return $this->RestResponse->saveSuccessResponse('EncryptionKeys', 'delete', $id, 'json', $message);
|
||||
} else {
|
||||
$this->Flash->success($message);
|
||||
return $this->redirect($this->referer());
|
||||
}
|
||||
}
|
||||
$this->CRUD->delete($id);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->set('metaGroup', 'ContactDB');
|
||||
$this->set('scope', 'encryptionKeys');
|
||||
$this->set('id', $key['id']);
|
||||
$this->set('key', $key);
|
||||
$this->viewBuilder()->setLayout('ajax');
|
||||
$this->render('/genericTemplates/delete');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = $this->_harvestParams($this->request, ['owner_type', 'owner_id', 'organisation_id', 'individual_id', 'encryption_key', 'expires', 'uuid', 'revoked', 'type']);
|
||||
$input = $this->request->getData();
|
||||
$encryptionKey = $this->EncryptionKeys->newEmptyEntity();
|
||||
if (!empty($params['owner_type'])) {
|
||||
if (!empty($params[$params['owner_type'] . '_id'])) {
|
||||
$params['owner_id'] = $params[$params['owner_type'] . '_id'];
|
||||
}
|
||||
$params[$params['owner_type'] . '_id'] = $params['owner_id'];
|
||||
$this->CRUD->add();
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
$this->loadModel('Organisations');
|
||||
$this->loadModel('Individuals');
|
||||
|
@ -83,42 +51,6 @@ class EncryptionKeysController extends AppController
|
|||
'sort' => ['email' => 'asc']
|
||||
])
|
||||
];
|
||||
if ($this->request->is('post')) {
|
||||
if (empty($params['owner_type']) || empty($params['owner_id'])) {
|
||||
throw new NotAcceptableException(__('Invalid input. owner_type and owner_id expected as parameters in the format /encryption_keys/add/[owner_type]/[owner_id] or passed as a JSON.'));
|
||||
}
|
||||
if ($params['owner_type'] === 'individual') {
|
||||
$owner = $this->Individuals->find()->where(['id' => $params['owner_id']])->first();
|
||||
if (empty($owner)) {
|
||||
throw new NotFoundException(__('Invalid owner individual.'));
|
||||
}
|
||||
} else {
|
||||
$owner = $this->Organisations->find()->where(['id' => $params['owner_id']])->first();
|
||||
if (empty($owner)) {
|
||||
throw new NotFoundException(__('Invalid owner organisation.'));
|
||||
}
|
||||
}
|
||||
$encryptionKey = $this->EncryptionKeys->patchEntity($encryptionKey, $params);
|
||||
if ($this->EncryptionKeys->save($encryptionKey)) {
|
||||
$message = __('EncryptionKey added.');
|
||||
if ($this->_isRest()) {
|
||||
$encryptionKey = $this->EncryptionKeys->get($this->EncryptionKeys->id);
|
||||
return $this->RestResponse->viewData($encryptionKey, 'json');
|
||||
} else {
|
||||
$this->Flash->success($message);
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
} else {
|
||||
$message = __('EncryptionKey could not be added.');
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->saveFailResponse('EncryptionKeys', 'add', false, $message);
|
||||
} else {
|
||||
$this->Flash->error($message);
|
||||
$this->redirect($this->referer());
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set('encryptionKey', $encryptionKey);
|
||||
$this->set(compact('dropdownData'));
|
||||
$this->set('metaGroup', 'ContactDB');
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ class EncryptionKeysTable extends AppTable
|
|||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
$this->addBehavior('UUID');
|
||||
$this->belongsTo(
|
||||
'Individuals',
|
||||
[
|
||||
|
@ -28,15 +29,24 @@ class EncryptionKeysTable extends AppTable
|
|||
$this->setDisplayField('encryption_key');
|
||||
}
|
||||
|
||||
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
|
||||
{
|
||||
if (isset($data['owner_id'])) {
|
||||
if (empty($data['owner_type']) || !in_array(['individual', 'organisation'], $data['owner_type'])) {
|
||||
return false;
|
||||
}
|
||||
$data[$data['owner_type'] . '_id'] = $data['owner_id'];
|
||||
}
|
||||
}
|
||||
|
||||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->notEmptyString('type')
|
||||
->notEmptyString('encryption_key')
|
||||
->notEmptyString('uuid')
|
||||
->notEmptyString('owner_id')
|
||||
->notEmptyString('owner_type')
|
||||
->requirePresence(['type', 'encryption_key', 'uuid', 'owner_id', 'owner_type'], 'create');
|
||||
->requirePresence(['type', 'encryption_key', 'owner_id', 'owner_type'], 'create');
|
||||
return $validator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
<?php
|
||||
$primaryIdentifiers = ['individual' => 'email', 'organisation' => 'name'];
|
||||
echo $this->element('genericElements/Form/genericForm', array(
|
||||
'form' => $this->Form,
|
||||
'data' => array(
|
||||
'entity' => $encryptionKey,
|
||||
'title' => __('Add new encryption key'),
|
||||
'description' => __('Alignments indicate that an individual belongs to an organisation in one way or another. The type of relationship is defined by the type field.'),
|
||||
'model' => 'Organisations',
|
||||
|
|
Loading…
Reference in New Issue