mirror of https://github.com/MISP/MISP
[3.x-migration] Cerebrates (#9507)
* new: [Cerebrates] pullOrgs, pullSgs test * fix: [AppController] fix bug in harvestParameters() * fix: [Cerebrate] follow codingstyle * fix: [Cerebrate] more codingstyle * fix: [Cerebrates] strict types fixes * fix: [composer] slevomat coding-standard * fix: [Cerebrates] minor codestyle fix * fix: [codingstyle]pull/9540/head
parent
b076463bf4
commit
7a9c8f5989
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +50,9 @@ class AppController extends Controller
|
||||||
public $MetaTemplates = null;
|
public $MetaTemplates = null;
|
||||||
public $Users = null;
|
public $Users = null;
|
||||||
|
|
||||||
/** @var AuditLog|null */
|
/**
|
||||||
|
* @var \Model\Entity\AuditLog|null
|
||||||
|
*/
|
||||||
protected $AuditLogs = null;
|
protected $AuditLogs = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +74,7 @@ class AppController extends Controller
|
||||||
$this->loadComponent(
|
$this->loadComponent(
|
||||||
'ParamHandler',
|
'ParamHandler',
|
||||||
[
|
[
|
||||||
'request' => $this->request
|
'request' => $this->request,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->loadModel('MetaFields');
|
$this->loadModel('MetaFields');
|
||||||
|
@ -85,7 +86,7 @@ class AppController extends Controller
|
||||||
'request' => $this->request,
|
'request' => $this->request,
|
||||||
'table' => $table,
|
'table' => $table,
|
||||||
'MetaFields' => $this->MetaFields,
|
'MetaFields' => $this->MetaFields,
|
||||||
'MetaTemplates' => $this->MetaTemplates
|
'MetaTemplates' => $this->MetaTemplates,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->loadComponent('Authentication.Authentication');
|
$this->loadComponent('Authentication.Authentication');
|
||||||
|
@ -93,7 +94,7 @@ class AppController extends Controller
|
||||||
'ACL',
|
'ACL',
|
||||||
[
|
[
|
||||||
'request' => $this->request,
|
'request' => $this->request,
|
||||||
'Authentication' => $this->Authentication
|
'Authentication' => $this->Authentication,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->loadComponent(
|
$this->loadComponent(
|
||||||
|
@ -123,6 +124,12 @@ class AppController extends Controller
|
||||||
//$this->loadComponent('FormProtection');
|
//$this->loadComponent('FormProtection');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* beforeFilter
|
||||||
|
*
|
||||||
|
* @param \Cake\Event\EventInterface $event the event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function beforeFilter(EventInterface $event)
|
public function beforeFilter(EventInterface $event)
|
||||||
{
|
{
|
||||||
$this->loadModel('Users');
|
$this->loadModel('Users');
|
||||||
|
@ -137,13 +144,14 @@ class AppController extends Controller
|
||||||
$user = $this->Users->get(
|
$user = $this->Users->get(
|
||||||
$this->request->getAttribute('identity')->getIdentifier(),
|
$this->request->getAttribute('identity')->getIdentifier(),
|
||||||
[
|
[
|
||||||
'contain' => ['Roles', 'Organisations' /*'UserSettings'*/]
|
'contain' => ['Roles', 'Organisations' /*'UserSettings'*/],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->__accessMonitor($user->toArray());
|
$this->__accessMonitor($user->toArray());
|
||||||
if (!empty($user['disabled'])) {
|
if (!empty($user['disabled'])) {
|
||||||
$this->Authentication->logout();
|
$this->Authentication->logout();
|
||||||
$this->Flash->error(__('The user account is disabled.'));
|
$this->Flash->error(__('The user account is disabled.'));
|
||||||
|
|
||||||
return $this->redirect(\Cake\Routing\Router::url('/users/login'));
|
return $this->redirect(\Cake\Routing\Router::url('/users/login'));
|
||||||
}
|
}
|
||||||
unset($user['password']);
|
unset($user['password']);
|
||||||
|
@ -199,6 +207,12 @@ class AppController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* beforeRender
|
||||||
|
*
|
||||||
|
* @param \Cake\Event\EventInterface $event the event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function beforeRender(EventInterface $event)
|
public function beforeRender(EventInterface $event)
|
||||||
{
|
{
|
||||||
if (!empty($this->request->getAttribute('identity'))) {
|
if (!empty($this->request->getAttribute('identity'))) {
|
||||||
|
@ -210,6 +224,11 @@ class AppController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authApiUser
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
private function authApiUser(): void
|
private function authApiUser(): void
|
||||||
{
|
{
|
||||||
if (!empty($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION'])) {
|
if (!empty($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION'])) {
|
||||||
|
@ -225,7 +244,7 @@ class AppController extends Controller
|
||||||
'model' => 'Users',
|
'model' => 'Users',
|
||||||
'model_id' => $user['id'],
|
'model_id' => $user['id'],
|
||||||
'model_title' => $user['username'],
|
'model_title' => $user['username'],
|
||||||
'changed' => []
|
'changed' => [],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
if (!empty($user)) {
|
if (!empty($user)) {
|
||||||
|
@ -239,31 +258,50 @@ class AppController extends Controller
|
||||||
'model' => 'Users',
|
'model' => 'Users',
|
||||||
'model_id' => $user['id'],
|
'model_id' => $user['id'],
|
||||||
'model_title' => $user['name'],
|
'model_title' => $user['name'],
|
||||||
'changed' => []
|
'changed' => [],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generateUUID
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function generateUUID()
|
public function generateUUID()
|
||||||
{
|
{
|
||||||
$uuid = Text::uuid();
|
$uuid = Text::uuid();
|
||||||
|
|
||||||
return $this->RestResponse->viewData(['uuid' => $uuid], 'json');
|
return $this->RestResponse->viewData(['uuid' => $uuid], 'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* queryACL
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function queryACL()
|
public function queryACL()
|
||||||
{
|
{
|
||||||
return $this->RestResponse->viewData($this->ACL->findMissingFunctionNames());
|
return $this->RestResponse->viewData($this->ACL->findMissingFunctionNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getRoleAccess
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function getRoleAccess()
|
public function getRoleAccess()
|
||||||
{
|
{
|
||||||
return $this->RestResponse->viewData($this->ACL->getRoleAccess(false, false));
|
return $this->RestResponse->viewData($this->ACL->getRoleAccess(false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array to the same array but with the values also as index instead of an interface_exists
|
* arrayToValuesIndexArray - Convert an array to the same array but with the values also as index instead of an interface_exists
|
||||||
|
*
|
||||||
|
* @param array $oldArray the original array
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function arrayToValuesIndexArray(array $oldArray): array
|
protected function arrayToValuesIndexArray(array $oldArray): array
|
||||||
{
|
{
|
||||||
|
@ -271,10 +309,16 @@ class AppController extends Controller
|
||||||
foreach ($oldArray as $value) {
|
foreach ($oldArray as $value) {
|
||||||
$newArray[$value] = $value;
|
$newArray[$value] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newArray;
|
return $newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if the currently logged user is a site administrator (an admin that can manage any user or event on the instance and create / edit the roles).
|
/**
|
||||||
|
* isSiteAdmin
|
||||||
|
* checks if the currently logged user is a site administrator (an admin that can manage any user or event on the instance and create / edit the roles).
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
protected function isSiteAdmin()
|
protected function isSiteAdmin()
|
||||||
{
|
{
|
||||||
return $this->ACL->getUser()->Role->perm_site_admin;
|
return $this->ACL->getUser()->Role->perm_site_admin;
|
||||||
|
@ -282,34 +326,30 @@ class AppController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close session without writing changes to them and return current user.
|
* Close session without writing changes to them and return current user.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function closeSession()
|
protected function closeSession()
|
||||||
{
|
{
|
||||||
$user = $this->ACL->getUser();
|
$user = $this->ACL->getUser();
|
||||||
session_abort();
|
session_abort();
|
||||||
|
|
||||||
return $user->toArray();
|
return $user->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generic function to standardise on the collection of parameters. Accepts posted request objects, url params, named url params
|
* generic function to standardise on the collection of parameters. Accepts posted request objects, url params, named url params
|
||||||
* @param array $options
|
*
|
||||||
* @param CakeResponse $exception
|
* @param array $options options
|
||||||
* @param array $data
|
* @param mixed $exception exception
|
||||||
|
* @param array $data data
|
||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
protected function harvestParameters($options, &$exception = null, $data = [])
|
protected function harvestParameters($options, &$exception = null, $data = [])
|
||||||
{
|
{
|
||||||
$request = $options['request'] ?? $this->request;
|
$request = $options['request'] ?? $this->request;
|
||||||
if ($request->is('post')) {
|
if ($request->is('post')) {
|
||||||
if (empty($request->data)) {
|
if (!empty($request->data)) {
|
||||||
$exception = $this->RestResponse->throwException(
|
|
||||||
400,
|
|
||||||
__('Either specify the search terms in the url, or POST a json with the filter parameters.'),
|
|
||||||
'/' . $request->params['controller'] . '/' . $request->action
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (isset($request->data['request'])) {
|
if (isset($request->data['request'])) {
|
||||||
$temp = $request->data['request'];
|
$temp = $request->data['request'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -327,6 +367,14 @@ class AppController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif (empty($request->data) && !$this->ParamHandler->isRest()) {
|
||||||
|
$exception = $this->RestResponse->throwException(
|
||||||
|
400,
|
||||||
|
__('Either specify the search terms in the url, or POST a json with the filter parameters.'),
|
||||||
|
'/' . $request->params['controller'] . '/' . $request->action
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -385,21 +433,32 @@ class AppController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* captureParam
|
||||||
|
*
|
||||||
|
* @param mixed $data data
|
||||||
|
* @param mixed $param param
|
||||||
|
* @param mixed $value value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
private function captureParam($data, $param, $value)
|
private function captureParam($data, $param, $value)
|
||||||
{
|
{
|
||||||
$table = $this->getTableLocator()->get($this->defaultModel);
|
$table = $this->getTableLocator()->get($this->defaultModel);
|
||||||
if ($table->checkParam($param)) {
|
if ($table->checkParam($param)) {
|
||||||
$data[$param] = $value;
|
$data[$param] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode JSON with proper error handling.
|
* Decode JSON with proper error handling.
|
||||||
* @param string $dataToDecode
|
*
|
||||||
|
* @param string $dataToDecode data to decode
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function _jsonDecode($dataToDecode)
|
protected function _jsonDecode($dataToDecode)
|
||||||
|
@ -411,6 +470,11 @@ class AppController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setResponseType
|
||||||
|
*
|
||||||
|
* @return static|void
|
||||||
|
*/
|
||||||
private function setResponseType()
|
private function setResponseType()
|
||||||
{
|
{
|
||||||
foreach ($this->request->getHeader('Accept') as $accept) {
|
foreach ($this->request->getHeader('Accept') as $accept) {
|
||||||
|
@ -426,12 +490,13 @@ class AppController extends Controller
|
||||||
protected function _remoteIp()
|
protected function _remoteIp()
|
||||||
{
|
{
|
||||||
$ipHeader = Configure::read('MISP.log_client_ip_header') ?: 'REMOTE_ADDR';
|
$ipHeader = Configure::read('MISP.log_client_ip_header') ?: 'REMOTE_ADDR';
|
||||||
|
|
||||||
return isset($_SERVER[$ipHeader]) ? trim($_SERVER[$ipHeader]) : $_SERVER['REMOTE_ADDR'];
|
return isset($_SERVER[$ipHeader]) ? trim($_SERVER[$ipHeader]) : $_SERVER['REMOTE_ADDR'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $user
|
* @param array $user affected user
|
||||||
* @throws Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function __accessMonitor(array $user)
|
private function __accessMonitor(array $user)
|
||||||
{
|
{
|
||||||
|
@ -450,7 +515,7 @@ class AppController extends Controller
|
||||||
|
|
||||||
if ($shouldBeLogged) {
|
if ($shouldBeLogged) {
|
||||||
$includeRequestBody = !empty(Configure::read('MISP.log_paranoid_include_post_body')) || $userMonitoringEnabled;
|
$includeRequestBody = !empty(Configure::read('MISP.log_paranoid_include_post_body')) || $userMonitoringEnabled;
|
||||||
/** @var AccessLog $accessLog */
|
/** @var \App\Model\Entity\AccessLog $accessLog */
|
||||||
$accessLogsTable = $this->fetchTable('AccessLogs');
|
$accessLogsTable = $this->fetchTable('AccessLogs');
|
||||||
$accessLogsTable->logRequest($user, $this->_remoteIp(), $this->request, $includeRequestBody);
|
$accessLogsTable->logRequest($user, $this->_remoteIp(), $this->request, $includeRequestBody);
|
||||||
}
|
}
|
||||||
|
@ -460,7 +525,7 @@ class AppController extends Controller
|
||||||
$shouldBeLogged
|
$shouldBeLogged
|
||||||
) {
|
) {
|
||||||
$change = 'HTTP method: ' . $_SERVER['REQUEST_METHOD'] . PHP_EOL . 'Target: ' . $this->request->getAttribute('here');
|
$change = 'HTTP method: ' . $_SERVER['REQUEST_METHOD'] . PHP_EOL . 'Target: ' . $this->request->getAttribute('here');
|
||||||
;
|
|
||||||
if (
|
if (
|
||||||
(
|
(
|
||||||
$this->request->is('post') ||
|
$this->request->is('post') ||
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Controller\AppController;
|
|
||||||
use Cake\Core\Configure;
|
|
||||||
use Cake\Core\Exception\CakeException;
|
|
||||||
use Cake\Http\Exception\NotFoundException;
|
|
||||||
use App\Lib\Tools\CustomPaginationTool;
|
use App\Lib\Tools\CustomPaginationTool;
|
||||||
|
use Cake\Http\Exception\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cerebrates Controller
|
* Cerebrates Controller
|
||||||
|
@ -26,7 +24,7 @@ class CerebratesController extends AppController
|
||||||
$params = [
|
$params = [
|
||||||
'contain' => ['Organisations'],
|
'contain' => ['Organisations'],
|
||||||
'filters' => ['name', 'url', 'uuid'],
|
'filters' => ['name', 'url', 'uuid'],
|
||||||
'quickFilters' => ['name']
|
'quickFilters' => ['name'],
|
||||||
];
|
];
|
||||||
$this->CRUD->index($params);
|
$this->CRUD->index($params);
|
||||||
|
|
||||||
|
@ -39,13 +37,14 @@ class CerebratesController extends AppController
|
||||||
/**
|
/**
|
||||||
* View method
|
* View method
|
||||||
*
|
*
|
||||||
* @param string|null $id Cerebrate id.
|
* @param int|null $id Cerebrate id.
|
||||||
* @return \Cake\Http\Response|null|void Renders view
|
* @return \Cake\Http\Response|null|void Renders view
|
||||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||||
*/
|
*/
|
||||||
public function view($id = null)
|
public function view(int|null $id = null)
|
||||||
{
|
{
|
||||||
$this->CRUD->view($id,
|
$this->CRUD->view(
|
||||||
|
$id,
|
||||||
['contain' => ['Organisations']]
|
['contain' => ['Organisations']]
|
||||||
);
|
);
|
||||||
$responsePayload = $this->CRUD->getResponsePayload();
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
|
@ -70,13 +69,16 @@ class CerebratesController extends AppController
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orgs = $this->Cerebrates->Organisations->find('list', [
|
$orgs = $this->Cerebrates->Organisations->find(
|
||||||
|
'list',
|
||||||
|
[
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'fields' => ['id', 'name'],
|
'fields' => ['id', 'name'],
|
||||||
'order' => ['lower(name)' => 'ASC']
|
'order' => ['lower(name)' => 'ASC'],
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
$dropdownData = [
|
$dropdownData = [
|
||||||
'org_id' => $orgs
|
'org_id' => $orgs,
|
||||||
];
|
];
|
||||||
$this->set(compact('dropdownData'));
|
$this->set(compact('dropdownData'));
|
||||||
}
|
}
|
||||||
|
@ -84,11 +86,11 @@ class CerebratesController extends AppController
|
||||||
/**
|
/**
|
||||||
* Edit method
|
* Edit method
|
||||||
*
|
*
|
||||||
* @param string|null $id Cerebrate id.
|
* @param int|null $id Cerebrate id.
|
||||||
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
* @return \Cake\Http\Response|null|void Redirects on successful edit, renders view otherwise.
|
||||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||||
*/
|
*/
|
||||||
public function edit($id = null)
|
public function edit(int|null $id = null)
|
||||||
{
|
{
|
||||||
$params = [];
|
$params = [];
|
||||||
$this->CRUD->edit($id, $params);
|
$this->CRUD->edit($id, $params);
|
||||||
|
@ -97,13 +99,16 @@ class CerebratesController extends AppController
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
$orgs = $this->Cerebrates->Organisations->find('list', [
|
$orgs = $this->Cerebrates->Organisations->find(
|
||||||
|
'list',
|
||||||
|
[
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'fields' => ['id', 'name'],
|
'fields' => ['id', 'name'],
|
||||||
'order' => ['lower(name)' => 'ASC']
|
'order' => ['lower(name)' => 'ASC'],
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
$dropdownData = [
|
$dropdownData = [
|
||||||
'org_id' => $orgs
|
'org_id' => $orgs,
|
||||||
];
|
];
|
||||||
$this->set(compact('dropdownData'));
|
$this->set(compact('dropdownData'));
|
||||||
$this->render('add');
|
$this->render('add');
|
||||||
|
@ -112,11 +117,11 @@ class CerebratesController extends AppController
|
||||||
/**
|
/**
|
||||||
* Delete method
|
* Delete method
|
||||||
*
|
*
|
||||||
* @param string|null $id Cerebrate id.
|
* @param int|null $id Cerebrate id.
|
||||||
* @return \Cake\Http\Response|null|void Redirects to index.
|
* @return \Cake\Http\Response|null|void Redirects to index.
|
||||||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
|
||||||
*/
|
*/
|
||||||
public function delete($id = null)
|
public function delete(int|null $id = null)
|
||||||
{
|
{
|
||||||
$this->CRUD->delete($id);
|
$this->CRUD->delete($id);
|
||||||
$responsePayload = $this->CRUD->getResponsePayload();
|
$responsePayload = $this->CRUD->getResponsePayload();
|
||||||
|
@ -125,9 +130,13 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pullOrgs
|
||||||
public function pullOrgs($id)
|
*
|
||||||
|
* @param int $id of the org
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function pullOrgs(int $id)
|
||||||
{
|
{
|
||||||
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -137,15 +146,19 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
$orgs = $cerebrate->queryInstance([
|
$orgs = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/organisations/index',
|
'path' => '/organisations/index',
|
||||||
'params' => $this->harvestParameters([
|
'params' => $this->harvestParameters(
|
||||||
|
[
|
||||||
'name',
|
'name',
|
||||||
'uuid',
|
'uuid',
|
||||||
'quickFilter'
|
'quickFilter',
|
||||||
]),
|
]
|
||||||
'type' => 'GET'
|
),
|
||||||
]);
|
'type' => 'GET',
|
||||||
|
]
|
||||||
|
);
|
||||||
$result = $cerebrate->saveRemoteOrgs($orgs);
|
$result = $cerebrate->saveRemoteOrgs($orgs);
|
||||||
$message = __('Added {0} new organisations, updated {1} existing organisations, {2} failures.', $result['add'], $result['edit'], $result['fails']);
|
$message = __('Added {0} new organisations, updated {1} existing organisations, {2} failures.', $result['add'], $result['edit'], $result['fails']);
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
|
@ -165,7 +178,13 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pullSgs($id)
|
/**
|
||||||
|
* pullSgs
|
||||||
|
*
|
||||||
|
* @param int $id id of the Sharing Group
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function pullSgs(int $id)
|
||||||
{
|
{
|
||||||
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSgs']);
|
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSgs']);
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -175,15 +194,19 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
$sgs = $cerebrate->queryInstance([
|
$sgs = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/sharingGroups/index',
|
'path' => '/sharingGroups/index',
|
||||||
'params' => $this->harvestParameters([
|
'params' => $this->harvestParameters(
|
||||||
|
[
|
||||||
'name',
|
'name',
|
||||||
'uuid',
|
'uuid',
|
||||||
'quickFilter'
|
'quickFilter',
|
||||||
]),
|
]
|
||||||
'type' => 'GET'
|
),
|
||||||
]);
|
'type' => 'GET',
|
||||||
|
]
|
||||||
|
);
|
||||||
$result = $cerebrate->saveRemoteSgs($sgs, $this->ACL->getUser());
|
$result = $cerebrate->saveRemoteSgs($sgs, $this->ACL->getUser());
|
||||||
$message = __('Added {0} new sharing groups, updated {1} existing sharing groups, {2} failures.', $result['add'], $result['edit'], $result['fails']);
|
$message = __('Added {0} new sharing groups, updated {1} existing sharing groups, {2} failures.', $result['add'], $result['edit'], $result['fails']);
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
|
@ -203,7 +226,13 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function previewOrgs($id = null)
|
/**
|
||||||
|
* previewOrgs
|
||||||
|
*
|
||||||
|
* @param int $id id of the org
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function previewOrgs(int|null $id = null)
|
||||||
{
|
{
|
||||||
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -212,15 +241,19 @@ class CerebratesController extends AppController
|
||||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$orgs = $cerebrate->queryInstance([
|
$orgs = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/organisations/index',
|
'path' => '/organisations/index',
|
||||||
'params' => $this->harvestParameters([
|
'params' => $this->harvestParameters(
|
||||||
|
[
|
||||||
'name',
|
'name',
|
||||||
'uuid',
|
'uuid',
|
||||||
'quickFilter'
|
'quickFilter',
|
||||||
]),
|
]
|
||||||
'type' => 'GET'
|
),
|
||||||
]);
|
'type' => 'GET',
|
||||||
|
]
|
||||||
|
);
|
||||||
$result = $cerebrate->checkRemoteOrgs($orgs);
|
$result = $cerebrate->checkRemoteOrgs($orgs);
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
return $this->RestResponse->viewData($result, $this->response->getType());
|
return $this->RestResponse->viewData($result, $this->response->getType());
|
||||||
|
@ -234,7 +267,14 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadOrg($cerebrate_id, $org_id)
|
/**
|
||||||
|
* downloadOrg
|
||||||
|
*
|
||||||
|
* @param int $cerebrate_id id of the cerebrate instance
|
||||||
|
* @param int $org_id id of the org
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function downloadOrg(int $cerebrate_id, int $org_id)
|
||||||
{
|
{
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -242,10 +282,12 @@ class CerebratesController extends AppController
|
||||||
if (empty($cerebrate)) {
|
if (empty($cerebrate)) {
|
||||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||||
}
|
}
|
||||||
$result = $cerebrate->queryInstance([
|
$result = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/organisations/view/' . $org_id,
|
'path' => '/organisations/view/' . $org_id,
|
||||||
'type' => 'GET'
|
'type' => 'GET',
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
$saveResult = $cerebrate->captureOrg($result);
|
$saveResult = $cerebrate->captureOrg($result);
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
if (is_array($saveResult)) {
|
if (is_array($saveResult)) {
|
||||||
|
@ -272,7 +314,13 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function previewSharingGroups($id)
|
/**
|
||||||
|
* previewSharingGroups
|
||||||
|
*
|
||||||
|
* @param int $id id of the Sharing Group
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function previewSharingGroups(int $id)
|
||||||
{
|
{
|
||||||
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSGs']);
|
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSGs']);
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -280,18 +328,24 @@ class CerebratesController extends AppController
|
||||||
if (empty($cerebrate)) {
|
if (empty($cerebrate)) {
|
||||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||||
}
|
}
|
||||||
$sgs = $cerebrate->queryInstance([
|
$sgs = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/sharingGroups/index',
|
'path' => '/sharingGroups/index',
|
||||||
'params' => $this->harvestParameters([
|
'params' => $this->harvestParameters(
|
||||||
|
[
|
||||||
'name',
|
'name',
|
||||||
'uuid',
|
'uuid',
|
||||||
'quickFilter'
|
'quickFilter',
|
||||||
]),
|
]
|
||||||
'type' => 'GET'
|
),
|
||||||
]);
|
'type' => 'GET',
|
||||||
if (!empty($sgs))
|
]
|
||||||
|
);
|
||||||
|
if (!empty($sgs)) {
|
||||||
$result = $cerebrate->checkRemoteSharingGroups($sgs);
|
$result = $cerebrate->checkRemoteSharingGroups($sgs);
|
||||||
else $result = [];
|
} else {
|
||||||
|
$result = [];
|
||||||
|
}
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
return $this->RestResponse->viewData($result, $this->response->getType());
|
return $this->RestResponse->viewData($result, $this->response->getType());
|
||||||
} else {
|
} else {
|
||||||
|
@ -304,7 +358,14 @@ class CerebratesController extends AppController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadSg($cerebrate_id, $sg_id)
|
/**
|
||||||
|
* downloadSg
|
||||||
|
*
|
||||||
|
* @param int $cerebrate_id id of the cerebrate instance
|
||||||
|
* @param int $sg_id id of the Sharing Group
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function downloadSg(int $cerebrate_id, int $sg_id)
|
||||||
{
|
{
|
||||||
if ($this->request->is('post')) {
|
if ($this->request->is('post')) {
|
||||||
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
/** @var \App\Model\Entity\Cerebrate $cerebrate */
|
||||||
|
@ -312,10 +373,12 @@ class CerebratesController extends AppController
|
||||||
if (empty($cerebrate)) {
|
if (empty($cerebrate)) {
|
||||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||||
}
|
}
|
||||||
$result = $cerebrate->queryInstance([
|
$result = $cerebrate->queryInstance(
|
||||||
|
[
|
||||||
'path' => '/sharingGroups/view/' . $sg_id,
|
'path' => '/sharingGroups/view/' . $sg_id,
|
||||||
'type' => 'GET'
|
'type' => 'GET',
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
$saveResult = $cerebrate->captureSg($result, $this->ACL->getUser());
|
$saveResult = $cerebrate->captureSg($result, $this->ACL->getUser());
|
||||||
if ($this->ParamHandler->isRest()) {
|
if ($this->ParamHandler->isRest()) {
|
||||||
if (is_array($saveResult)) {
|
if (is_array($saveResult)) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Lib\Tools;
|
namespace App\Lib\Tools;
|
||||||
|
|
||||||
|
@ -10,12 +11,11 @@ use Psr\Http\Message\RequestInterface;
|
||||||
|
|
||||||
class CurlAdvanced extends Curl
|
class CurlAdvanced extends Curl
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getCertificateChain - returns the list of certificates offered by the server
|
* getCertificateChain - returns the list of certificates offered by the server
|
||||||
*
|
*
|
||||||
* @param mixed $request
|
* @param \Psr\Http\Message\RequestInterface $request the request interface
|
||||||
* @param mixed $options
|
* @param array $options options of curl
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getCertificateChain(RequestInterface $request, array $options): array
|
public function getCertificateChain(RequestInterface $request, array $options): array
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Model\Entity;
|
namespace App\Model\Entity;
|
||||||
|
|
||||||
use App\Lib\Tools\HttpTool;
|
use App\Lib\Tools\HttpTool;
|
||||||
use App\Model\Entity\AppModel;
|
use Cake\Database\Expression\QueryExpression;
|
||||||
use Cake\Core\Exception\CakeException;
|
use Cake\Database\Query;
|
||||||
use Cake\Http\Client\Exception\NetworkException;
|
use Cake\Http\Client\Exception\NetworkException;
|
||||||
use Cake\Http\Exception\BadRequestException;
|
use Cake\Http\Exception\BadRequestException;
|
||||||
use Cake\Http\Exception\ForbiddenException;
|
use Cake\Http\Exception\ForbiddenException;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use Cake\Utility\Hash;
|
use Cake\Utility\Hash;
|
||||||
use Cake\Database\Expression\QueryExpression;
|
|
||||||
use Cake\Database\Query;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cerebrate Entity
|
* Cerebrate Entity
|
||||||
|
@ -60,7 +57,6 @@ class Cerebrate extends AppModel
|
||||||
'description' => true,
|
'description' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* queryInstance - Query a remote Cerebrate instance for a specific path
|
* queryInstance - Query a remote Cerebrate instance for a specific path
|
||||||
*
|
*
|
||||||
|
@ -79,10 +75,11 @@ class Cerebrate extends AppModel
|
||||||
$response = $httpTool->get(
|
$response = $httpTool->get(
|
||||||
$url,
|
$url,
|
||||||
[],
|
[],
|
||||||
(isset($options['params']) ? $options['params'] : []));
|
($options['params'] ?? [])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ($response->isOk()) {
|
if ($response->isOk()) {
|
||||||
return json_decode($response->getBody(), true);
|
return json_decode($response->getBody()->__toString(), true);
|
||||||
}
|
}
|
||||||
} catch (NetworkException $e) {
|
} catch (NetworkException $e) {
|
||||||
throw new BadRequestException(__('Something went wrong. Error returned: {0}', $e->getMessage()));
|
throw new BadRequestException(__('Something went wrong. Error returned: {0}', $e->getMessage()));
|
||||||
|
@ -93,26 +90,32 @@ class Cerebrate extends AppModel
|
||||||
throw new BadRequestException(__('Something went wrong with the request or the remote side is having issues.'));
|
throw new BadRequestException(__('Something went wrong with the request or the remote side is having issues.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convertOrg
|
||||||
|
*
|
||||||
|
* @param mixed $org_data organisation data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function convertOrg($org_data)
|
public function convertOrg($org_data)
|
||||||
{
|
{
|
||||||
$mapping = [
|
$mapping = [
|
||||||
'name' => [
|
'name' => [
|
||||||
'field' => 'name',
|
'field' => 'name',
|
||||||
'required' => 1
|
'required' => 1,
|
||||||
],
|
],
|
||||||
'uuid' => [
|
'uuid' => [
|
||||||
'field' => 'uuid',
|
'field' => 'uuid',
|
||||||
'required' => 1
|
'required' => 1,
|
||||||
],
|
],
|
||||||
'nationality' => [
|
'nationality' => [
|
||||||
'field' => 'nationality'
|
'field' => 'nationality',
|
||||||
],
|
],
|
||||||
'sector' => [
|
'sector' => [
|
||||||
'field' => 'sector'
|
'field' => 'sector',
|
||||||
],
|
],
|
||||||
'type' => [
|
'type' => [
|
||||||
'field' => 'type'
|
'field' => 'type',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
$org = [];
|
$org = [];
|
||||||
foreach ($mapping as $cerebrate_field => $field_data) {
|
foreach ($mapping as $cerebrate_field => $field_data) {
|
||||||
|
@ -125,10 +128,10 @@ class Cerebrate extends AppModel
|
||||||
}
|
}
|
||||||
$org[$field_data['field']] = $org_data[$cerebrate_field];
|
$org[$field_data['field']] = $org_data[$cerebrate_field];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $org;
|
return $org;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saveRemoteOrgs -
|
* saveRemoteOrgs -
|
||||||
*
|
*
|
||||||
|
@ -140,7 +143,7 @@ class Cerebrate extends AppModel
|
||||||
$outcome = [
|
$outcome = [
|
||||||
'add' => 0,
|
'add' => 0,
|
||||||
'edit' => 0,
|
'edit' => 0,
|
||||||
'fails' => 0
|
'fails' => 0,
|
||||||
];
|
];
|
||||||
foreach ($orgs as $org) {
|
foreach ($orgs as $org) {
|
||||||
$isEdit = false;
|
$isEdit = false;
|
||||||
|
@ -158,14 +161,15 @@ class Cerebrate extends AppModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $outcome;
|
return $outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saveRemoteSgs
|
* saveRemoteSgs
|
||||||
*
|
*
|
||||||
* @param mixed $sgs
|
* @param mixed $sgs SharingGroups
|
||||||
* @param mixed $user
|
* @param mixed $user user
|
||||||
* @return array ['add'=> 0, 'edit' => 0, 'fails' => 0]
|
* @return array ['add'=> 0, 'edit' => 0, 'fails' => 0]
|
||||||
*/
|
*/
|
||||||
public function saveRemoteSgs($sgs, $user)
|
public function saveRemoteSgs($sgs, $user)
|
||||||
|
@ -173,7 +177,7 @@ class Cerebrate extends AppModel
|
||||||
$outcome = [
|
$outcome = [
|
||||||
'add' => 0,
|
'add' => 0,
|
||||||
'edit' => 0,
|
'edit' => 0,
|
||||||
'fails' => 0
|
'fails' => 0,
|
||||||
];
|
];
|
||||||
foreach ($sgs as $sg) {
|
foreach ($sgs as $sg) {
|
||||||
$isEdit = false;
|
$isEdit = false;
|
||||||
|
@ -191,6 +195,7 @@ class Cerebrate extends AppModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $outcome;
|
return $outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,10 +213,13 @@ class Cerebrate extends AppModel
|
||||||
if ($org) {
|
if ($org) {
|
||||||
/** @var \App\Model\Table\OrganisationsTable $organisationTable */
|
/** @var \App\Model\Table\OrganisationsTable $organisationTable */
|
||||||
$organisationTable = TableRegistry::getTableLocator()->get('Organisations');
|
$organisationTable = TableRegistry::getTableLocator()->get('Organisations');
|
||||||
$existingOrg = $organisationTable->find('all', [
|
$existingOrg = $organisationTable->find(
|
||||||
|
'all',
|
||||||
|
[
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => ['uuid' => $org['uuid']]
|
'conditions' => ['uuid' => $org['uuid']],
|
||||||
])->first();
|
]
|
||||||
|
)->first();
|
||||||
if (!empty($existingOrg)) {
|
if (!empty($existingOrg)) {
|
||||||
$fieldsToSave = ['name', 'sector', 'nationality', 'type'];
|
$fieldsToSave = ['name', 'sector', 'nationality', 'type'];
|
||||||
unset($org['uuid']);
|
unset($org['uuid']);
|
||||||
|
@ -243,36 +251,48 @@ class Cerebrate extends AppModel
|
||||||
}
|
}
|
||||||
if ($dirty) {
|
if ($dirty) {
|
||||||
// verify if the name exists, if so generate a new name
|
// verify if the name exists, if so generate a new name
|
||||||
$nameCheck = $organisationTable->find('all', [
|
$nameCheck = $organisationTable->find(
|
||||||
|
'all',
|
||||||
|
[
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => ['name' => $orgToSave->name],
|
'conditions' => ['name' => $orgToSave->name],
|
||||||
'fields' => ['id']
|
'fields' => ['id'],
|
||||||
])->first();
|
]
|
||||||
|
)->first();
|
||||||
if (!empty($nameCheck)) {
|
if (!empty($nameCheck)) {
|
||||||
$orgToSave['name'] = $orgToSave['name'] . '_' . mt_rand(0, 9999);
|
$orgToSave['name'] = $orgToSave['name'] . '_' . mt_rand(0, 9999);
|
||||||
}
|
}
|
||||||
// save the organisation
|
// save the organisation
|
||||||
$savedOrganisation = $organisationTable->save($orgToSave);
|
$savedOrganisation = $organisationTable->save($orgToSave);
|
||||||
if ($savedOrganisation) {
|
if ($savedOrganisation) {
|
||||||
return $organisationTable->find('all', [
|
return $organisationTable->find(
|
||||||
|
'all',
|
||||||
|
[
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => ['id' => $savedOrganisation->id]
|
'conditions' => ['id' => $savedOrganisation->id],
|
||||||
])->first()->toArray();
|
]
|
||||||
|
)->first()->toArray();
|
||||||
} else {
|
} else {
|
||||||
return __('The organisation could not be saved.');
|
return __('The organisation could not be saved.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$noChange = true;
|
$noChange = true;
|
||||||
|
|
||||||
return $existingOrg->toArray();
|
return $existingOrg->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return __('The retrieved data isn\'t a valid organisation.');
|
return __('The retrieved data isn\'t a valid organisation.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* checkRemoteOrgs
|
||||||
* Checks remote for the current status of each organisation
|
* Checks remote for the current status of each organisation
|
||||||
* Adds the exists_locally field with a boolean status
|
* Adds the exists_locally field with a boolean status
|
||||||
* If exists_loally is true, adds a list with the differences (keynames)
|
* If exists_loally is true, adds a list with the differences (keynames)
|
||||||
|
*
|
||||||
|
* @param array $orgs orgs
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function checkRemoteOrgs($orgs)
|
public function checkRemoteOrgs($orgs)
|
||||||
{
|
{
|
||||||
|
@ -281,9 +301,11 @@ class Cerebrate extends AppModel
|
||||||
$organisationTable = TableRegistry::getTableLocator()->get('Organisations');
|
$organisationTable = TableRegistry::getTableLocator()->get('Organisations');
|
||||||
$existingOrgs = $organisationTable->find('all')
|
$existingOrgs = $organisationTable->find('all')
|
||||||
->where(['uuid'])
|
->where(['uuid'])
|
||||||
->where(function (QueryExpression $exp, Query $q) use ($uuids) {
|
->where(
|
||||||
|
function (QueryExpression $exp, Query $q) use ($uuids) {
|
||||||
return $exp->in('uuid', array_values($uuids));
|
return $exp->in('uuid', array_values($uuids));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
$rearranged = [];
|
$rearranged = [];
|
||||||
foreach ($existingOrgs as $existingOrg) {
|
foreach ($existingOrgs as $existingOrg) {
|
||||||
$rearranged[$existingOrg->uuid] = $existingOrg->toArray();
|
$rearranged[$existingOrg->uuid] = $existingOrg->toArray();
|
||||||
|
@ -310,9 +332,17 @@ class Cerebrate extends AppModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $orgs;
|
return $orgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __compareNames
|
||||||
|
*
|
||||||
|
* @param string $name1 orgname
|
||||||
|
* @param string $name2 orgname
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function __compareNames($name1, $name2)
|
private function __compareNames($name1, $name2)
|
||||||
{
|
{
|
||||||
if (preg_match('/\_[0-9]{4}$/i', $name1)) {
|
if (preg_match('/\_[0-9]{4}$/i', $name1)) {
|
||||||
|
@ -322,9 +352,17 @@ class Cerebrate extends AppModel
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __compareMembers
|
||||||
|
*
|
||||||
|
* @param array $existingMembers members
|
||||||
|
* @param array $remoteMembers members
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private function __compareMembers($existingMembers, $remoteMembers)
|
private function __compareMembers($existingMembers, $remoteMembers)
|
||||||
{
|
{
|
||||||
$memberFound = [];
|
$memberFound = [];
|
||||||
|
@ -342,13 +380,18 @@ class Cerebrate extends AppModel
|
||||||
$memberNotFound[] = $remoteMember['uuid'];
|
$memberNotFound[] = $remoteMember['uuid'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return empty($memberNotFound);
|
return empty($memberNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
|
* checkRemoteSharingGroups
|
||||||
* Checks remote for the current status of each sharing groups
|
* Checks remote for the current status of each sharing groups
|
||||||
* Adds the exists_locally field with a boolean status
|
* Adds the exists_locally field with a boolean status
|
||||||
* If exists_loally is true, adds a list with the differences (keynames)
|
* If exists_loally is true, adds a list with the differences (keynames)
|
||||||
|
*
|
||||||
|
* @param array $sgs SharingGroups
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function checkRemoteSharingGroups($sgs)
|
public function checkRemoteSharingGroups($sgs)
|
||||||
{
|
{
|
||||||
|
@ -358,9 +401,11 @@ class Cerebrate extends AppModel
|
||||||
$existingSgs = $sharingGroupTable->find('all')
|
$existingSgs = $sharingGroupTable->find('all')
|
||||||
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
||||||
->where(['SharingGroups.uuid'])
|
->where(['SharingGroups.uuid'])
|
||||||
->where(function (QueryExpression $exp, Query $q) use ($uuids) {
|
->where(
|
||||||
|
function (QueryExpression $exp, Query $q) use ($uuids) {
|
||||||
return $exp->in('SharingGroups.uuid', array_values($uuids));
|
return $exp->in('SharingGroups.uuid', array_values($uuids));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
$rearranged = [];
|
$rearranged = [];
|
||||||
foreach ($existingSgs as $existingSg) {
|
foreach ($existingSgs as $existingSg) {
|
||||||
$existingSg = $existingSg->toArray();
|
$existingSg = $existingSg->toArray();
|
||||||
|
@ -375,9 +420,17 @@ class Cerebrate extends AppModel
|
||||||
$sgs[$k]['differences'] = $this->compareSgs($rearranged[$sg['uuid']], $sgs[$k]);
|
$sgs[$k]['differences'] = $this->compareSgs($rearranged[$sg['uuid']], $sgs[$k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $sgs;
|
return $sgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compareSgs
|
||||||
|
*
|
||||||
|
* @param array $existingSg existing SharingGroup
|
||||||
|
* @param array $remoteSg remote Sharing Group
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function compareSgs($existingSg, $remoteSg)
|
private function compareSgs($existingSg, $remoteSg)
|
||||||
{
|
{
|
||||||
$differences = [];
|
$differences = [];
|
||||||
|
@ -399,25 +452,32 @@ class Cerebrate extends AppModel
|
||||||
if (!$this->__compareMembers(Hash::extract($existingSg['SharingGroupOrg'], '{n}.Organisation'), $remoteSg['sharing_group_orgs'])) {
|
if (!$this->__compareMembers(Hash::extract($existingSg['SharingGroupOrg'], '{n}.Organisation'), $remoteSg['sharing_group_orgs'])) {
|
||||||
$differences[] = 'members';
|
$differences[] = 'members';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $differences;
|
return $differences;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convertSg
|
||||||
|
*
|
||||||
|
* @param array $sg_data Sharing Group data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function convertSg($sg_data)
|
private function convertSg($sg_data)
|
||||||
{
|
{
|
||||||
$mapping = [
|
$mapping = [
|
||||||
'name' => [
|
'name' => [
|
||||||
'field' => 'name',
|
'field' => 'name',
|
||||||
'required' => 1
|
'required' => 1,
|
||||||
],
|
],
|
||||||
'uuid' => [
|
'uuid' => [
|
||||||
'field' => 'uuid',
|
'field' => 'uuid',
|
||||||
'required' => 1
|
'required' => 1,
|
||||||
],
|
],
|
||||||
'releasability' => [
|
'releasability' => [
|
||||||
'field' => 'releasability'
|
'field' => 'releasability',
|
||||||
],
|
],
|
||||||
'description' => [
|
'description' => [
|
||||||
'field' => 'description'
|
'field' => 'description',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
$sg = [];
|
$sg = [];
|
||||||
|
@ -442,22 +502,24 @@ class Cerebrate extends AppModel
|
||||||
$sg['SharingGroupOrg'][$k]['extend'] = false;
|
$sg['SharingGroupOrg'][$k]['extend'] = false;
|
||||||
}
|
}
|
||||||
foreach ($org as $ok => $ov) {
|
foreach ($org as $ok => $ov) {
|
||||||
if ($ov === null) unset($sg['SharingGroupOrg'][$k][$ok]);
|
if ($ov === null) {
|
||||||
|
unset($sg['SharingGroupOrg'][$k][$ok]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $sg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $sg;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* captureSg
|
* captureSg
|
||||||
*
|
*
|
||||||
* @param array $sg_data
|
* @param array $sg_data Sharing Group data
|
||||||
* @param App\Model\Entity\User $user
|
* @param \App\Model\Entity\User $user user
|
||||||
* @param bool $edit
|
* @param bool $edit data was changed or not
|
||||||
* @param bool $noChange
|
* @param bool $noChange noChange
|
||||||
* @return mixed
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
public function captureSg($sg_data, $user, &$edit = false, &$noChange = false)
|
public function captureSg($sg_data, $user, &$edit = false, &$noChange = false)
|
||||||
{
|
{
|
||||||
|
@ -474,10 +536,13 @@ class Cerebrate extends AppModel
|
||||||
$savedSg = $sharingGroupTable->findById($captureResult)
|
$savedSg = $sharingGroupTable->findById($captureResult)
|
||||||
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return $savedSg->toArray();
|
return $savedSg->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
return __('The organisation could not be saved.');
|
return __('The organisation could not be saved.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return __('The retrieved data isn\'t a valid sharing group.');
|
return __('The retrieved data isn\'t a valid sharing group.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Model\Table;
|
namespace App\Model\Table;
|
||||||
|
|
||||||
use App\Model\Table\AppTable;
|
|
||||||
use ArrayObject;
|
|
||||||
use Cake\Datasource\EntityInterface;
|
|
||||||
use Cake\Event\Event;
|
|
||||||
use Cake\Event\EventInterface;
|
|
||||||
use Cake\ORM\Query;
|
|
||||||
use Cake\ORM\RulesChecker;
|
|
||||||
use Cake\Validation\Validator;
|
use Cake\Validation\Validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +43,7 @@ class CerebratesTable extends AppTable
|
||||||
'dependent' => false,
|
'dependent' => false,
|
||||||
'cascadeCallbacks' => false,
|
'cascadeCallbacks' => false,
|
||||||
'foreignKey' => 'org_id',
|
'foreignKey' => 'org_id',
|
||||||
'propertyName' => 'Organisation'
|
'propertyName' => 'Organisation',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -4,29 +4,29 @@ $edit = $this->request->getParam('action') === 'edit' ? true : false;
|
||||||
$fields = [
|
$fields = [
|
||||||
[
|
[
|
||||||
'field' => 'name',
|
'field' => 'name',
|
||||||
'class' => 'span6'
|
'class' => 'span6',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'url',
|
'field' => 'url',
|
||||||
'class' => 'span6'
|
'class' => 'span6',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'authkey',
|
'field' => 'authkey',
|
||||||
'class' => 'span6',
|
'class' => 'span6',
|
||||||
'autocomplete' => 'off',
|
'autocomplete' => 'off',
|
||||||
'type' => 'text'
|
'type' => 'text',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'org_id',
|
'field' => 'org_id',
|
||||||
'label' => 'Owner Organisation',
|
'label' => 'Owner Organisation',
|
||||||
'options' => $dropdownData['org_id'],
|
'options' => $dropdownData['org_id'],
|
||||||
'class' => 'span6',
|
'class' => 'span6',
|
||||||
'type' => 'dropdown'
|
'type' => 'dropdown',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'description',
|
'field' => 'description',
|
||||||
'type' => 'textarea',
|
'type' => 'textarea',
|
||||||
'class' => 'input span6'
|
'class' => 'input span6',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'field' => 'pull_orgs',
|
'field' => 'pull_orgs',
|
||||||
|
@ -37,9 +37,11 @@ $fields = [
|
||||||
'field' => 'pull_sharing_groups',
|
'field' => 'pull_sharing_groups',
|
||||||
'label' => __('Pull Sharing Groups'),
|
'label' => __('Pull Sharing Groups'),
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
echo $this->element('genericElements/Form/genericForm', [
|
echo $this->element(
|
||||||
|
'genericElements/Form/genericForm',
|
||||||
|
[
|
||||||
'data' => [
|
'data' => [
|
||||||
'description' => false,
|
'description' => false,
|
||||||
'model' => 'Cerebrate',
|
'model' => 'Cerebrate',
|
||||||
|
@ -47,7 +49,8 @@ echo $this->element('genericElements/Form/genericForm', [
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'submit' => [
|
'submit' => [
|
||||||
'action' => $this->request->getParam('action'),
|
'action' => $this->request->getParam('action'),
|
||||||
'ajaxSubmit' => 'submitGenericFormInPlace();'
|
'ajaxSubmit' => 'submitGenericFormInPlace();',
|
||||||
|
],
|
||||||
|
],
|
||||||
]
|
]
|
||||||
]
|
);
|
||||||
]);
|
|
||||||
|
|
|
@ -4,44 +4,46 @@
|
||||||
'name' => __('ID'),
|
'name' => __('ID'),
|
||||||
'sort' => 'id',
|
'sort' => 'id',
|
||||||
'class' => 'short',
|
'class' => 'short',
|
||||||
'data_path' => 'id'
|
'data_path' => 'id',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Owner Org'),
|
'name' => __('Owner Org'),
|
||||||
'sort' => 'Organisation',
|
'sort' => 'Organisation',
|
||||||
'data_path' => 'Organisation',
|
'data_path' => 'Organisation',
|
||||||
'element' => 'org'
|
'element' => 'org',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Name'),
|
'name' => __('Name'),
|
||||||
'sort' => 'name',
|
'sort' => 'name',
|
||||||
'data_path' => 'name'
|
'data_path' => 'name',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('URL'),
|
'name' => __('URL'),
|
||||||
'sort' => 'url',
|
'sort' => 'url',
|
||||||
'data_path' => 'url'
|
'data_path' => 'url',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Description'),
|
'name' => __('Description'),
|
||||||
'sort' => 'description',
|
'sort' => 'description',
|
||||||
'data_path' => 'description'
|
'data_path' => 'description',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Pull Orgs'),
|
'name' => __('Pull Orgs'),
|
||||||
'sort' => 'pull_orgs',
|
'sort' => 'pull_orgs',
|
||||||
'data_path' => 'pull_orgs',
|
'data_path' => 'pull_orgs',
|
||||||
'element' => 'boolean'
|
'element' => 'boolean',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Pull SGs'),
|
'name' => __('Pull SGs'),
|
||||||
'sort' => 'pull_sharing_groups',
|
'sort' => 'pull_sharing_groups',
|
||||||
'data_path' => 'pull_sharing_groups',
|
'data_path' => 'pull_sharing_groups',
|
||||||
'element' => 'boolean'
|
'element' => 'boolean',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
echo $this->element('genericElements/IndexTable/index_table', [
|
echo $this->element(
|
||||||
|
'genericElements/IndexTable/index_table',
|
||||||
|
[
|
||||||
'data' => [
|
'data' => [
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'top_bar' => [
|
'top_bar' => [
|
||||||
|
@ -57,9 +59,9 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'popover_url' => '/cerebrates/add',
|
'popover_url' => '/cerebrates/add',
|
||||||
'button' => [
|
'button' => [
|
||||||
'icon' => 'plus',
|
'icon' => 'plus',
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'type' => 'search',
|
'type' => 'search',
|
||||||
|
@ -67,12 +69,12 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'placeholder' => __('Enter value to search'),
|
'placeholder' => __('Enter value to search'),
|
||||||
'data' => '',
|
'data' => '',
|
||||||
'searchKey' => 'value',
|
'searchKey' => 'value',
|
||||||
'allowFilering' => true
|
'allowFilering' => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'type' => 'table_action',
|
'type' => 'table_action',
|
||||||
],
|
],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'title' => __('Linked Cerebrates'),
|
'title' => __('Linked Cerebrates'),
|
||||||
|
@ -81,31 +83,31 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
[
|
[
|
||||||
'url' => '/cerebrates/view',
|
'url' => '/cerebrates/view',
|
||||||
'url_params_data_paths' => ['id'],
|
'url_params_data_paths' => ['id'],
|
||||||
'icon' => 'eye'
|
'icon' => 'eye',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/cerebrates/pull_orgs/[onclick_params_data_path]',
|
'open_modal' => '/cerebrates/pull_orgs/[onclick_params_data_path]',
|
||||||
'onclick_params_data_path' => 'id',
|
'onclick_params_data_path' => 'id',
|
||||||
'title' => __('Pull all organisations'),
|
'title' => __('Pull all organisations'),
|
||||||
'icon' => 'arrow-circle-down'
|
'icon' => 'arrow-circle-down',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/cerebrates/pull_sgs/[onclick_params_data_path]',
|
'open_modal' => '/cerebrates/pull_sgs/[onclick_params_data_path]',
|
||||||
'onclick_params_data_path' => 'id',
|
'onclick_params_data_path' => 'id',
|
||||||
'title' => __('Pull all sharing groups'),
|
'title' => __('Pull all sharing groups'),
|
||||||
'icon' => 'arrow-circle-down'
|
'icon' => 'arrow-circle-down',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/cerebrates/edit/[onclick_params_data_path]',
|
'open_modal' => '/cerebrates/edit/[onclick_params_data_path]',
|
||||||
'modal_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
'icon' => 'edit'
|
'icon' => 'edit',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'open_modal' => '/cerebrates/delete/[onclick_params_data_path]',
|
'open_modal' => '/cerebrates/delete/[onclick_params_data_path]',
|
||||||
'modal_params_data_path' => 'id',
|
'modal_params_data_path' => 'id',
|
||||||
'icon' => 'trash'
|
'icon' => 'trash',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
]
|
]
|
||||||
]
|
);
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[
|
[
|
||||||
'name' => __('Id'),
|
'name' => __('Id'),
|
||||||
'sort' => 'id',
|
'sort' => 'id',
|
||||||
'data_path' => 'id'
|
'data_path' => 'id',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Known locally'),
|
'name' => __('Known locally'),
|
||||||
|
@ -13,26 +13,28 @@
|
||||||
[
|
[
|
||||||
'name' => __('UUID'),
|
'name' => __('UUID'),
|
||||||
'sort' => 'uuid',
|
'sort' => 'uuid',
|
||||||
'data_path' => 'uuid'
|
'data_path' => 'uuid',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Name'),
|
'name' => __('Name'),
|
||||||
'sort' => 'name',
|
'sort' => 'name',
|
||||||
'data_path' => 'name'
|
'data_path' => 'name',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Sector'),
|
'name' => __('Sector'),
|
||||||
'sort' => 'sector',
|
'sort' => 'sector',
|
||||||
'data_path' => 'sector'
|
'data_path' => 'sector',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Nationality'),
|
'name' => __('Nationality'),
|
||||||
'sort' => 'nationality',
|
'sort' => 'nationality',
|
||||||
'data_path' => 'nationality'
|
'data_path' => 'nationality',
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
echo $this->element('genericElements/IndexTable/index_table', [
|
echo $this->element(
|
||||||
|
'genericElements/IndexTable/index_table',
|
||||||
|
[
|
||||||
'data' => [
|
'data' => [
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'top_bar' => [
|
'top_bar' => [
|
||||||
|
@ -44,9 +46,9 @@
|
||||||
'placeholder' => __('Enter value to search'),
|
'placeholder' => __('Enter value to search'),
|
||||||
'data' => '',
|
'data' => '',
|
||||||
'preserve_url_params' => [$cerebrate['id']],
|
'preserve_url_params' => [$cerebrate['id']],
|
||||||
'searchKey' => 'quickFilter'
|
'searchKey' => 'quickFilter',
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'title' => empty($ajax) ? __(
|
'title' => empty($ajax) ? __(
|
||||||
|
@ -58,23 +60,24 @@
|
||||||
'actions' => [
|
'actions' => [
|
||||||
[
|
[
|
||||||
'onclick' => sprintf(
|
'onclick' => sprintf(
|
||||||
'openGenericModal(\'{0}/cerebrates/download_org/{1}/[onclick_params_data_path]\');',
|
'openGenericModal(\'%s/cerebrates/download_org/%d/[onclick_params_data_path]\');',
|
||||||
$baseurl,
|
$baseurl,
|
||||||
h($cerebrate['id'])
|
h($cerebrate['id'])
|
||||||
),
|
),
|
||||||
'onclick_params_data_path' => 'id',
|
'onclick_params_data_path' => 'id',
|
||||||
'icon' => 'download',
|
'icon' => 'download',
|
||||||
'title' => __('Fetch organisation object')
|
'title' => __('Fetch organisation object'),
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'paginatorOptions' => array_merge(
|
'paginatorOptions' => array_merge(
|
||||||
['url' => [$cerebrate['id']]],
|
['url' => [$cerebrate['id']]],
|
||||||
$passedParams
|
$passedParams
|
||||||
),
|
),
|
||||||
'persistUrlParams' => [0, 'quickFilter']
|
'persistUrlParams' => [0, 'quickFilter'],
|
||||||
],
|
],
|
||||||
'containerId' => 'preview_orgs_container'
|
'containerId' => 'preview_orgs_container',
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
||||||
|
|
|
@ -3,44 +3,46 @@
|
||||||
[
|
[
|
||||||
'name' => __('Id'),
|
'name' => __('Id'),
|
||||||
'sort' => 'id',
|
'sort' => 'id',
|
||||||
'data_path' => 'id'
|
'data_path' => 'id',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Status'),
|
'name' => __('Status'),
|
||||||
'sort' => 'exists_locally',
|
'sort' => 'exists_locally',
|
||||||
'element' => 'remote_status',
|
'element' => 'remote_status',
|
||||||
'data_path' => ''
|
'data_path' => '',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('UUID'),
|
'name' => __('UUID'),
|
||||||
'sort' => 'uuid',
|
'sort' => 'uuid',
|
||||||
'data_path' => 'uuid'
|
'data_path' => 'uuid',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Name'),
|
'name' => __('Name'),
|
||||||
'sort' => 'name',
|
'sort' => 'name',
|
||||||
'data_path' => 'name'
|
'data_path' => 'name',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Releasability'),
|
'name' => __('Releasability'),
|
||||||
'sort' => 'releasability',
|
'sort' => 'releasability',
|
||||||
'data_path' => 'releasability'
|
'data_path' => 'releasability',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('Description'),
|
'name' => __('Description'),
|
||||||
'sort' => 'description',
|
'sort' => 'description',
|
||||||
'data_path' => 'description'
|
'data_path' => 'description',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => __('# Member'),
|
'name' => __('# Member'),
|
||||||
'element' => 'custom',
|
'element' => 'custom',
|
||||||
'function' => function ($row) {
|
'function' => function ($row) {
|
||||||
return count($row['sharing_group_orgs']);
|
return count($row['sharing_group_orgs']);
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
echo $this->element('genericElements/IndexTable/index_table', [
|
echo $this->element(
|
||||||
|
'genericElements/IndexTable/index_table',
|
||||||
|
[
|
||||||
'data' => [
|
'data' => [
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'top_bar' => [
|
'top_bar' => [
|
||||||
|
@ -52,9 +54,9 @@
|
||||||
'placeholder' => __('Enter value to search'),
|
'placeholder' => __('Enter value to search'),
|
||||||
'data' => '',
|
'data' => '',
|
||||||
'preserve_url_params' => [$cerebrate['id']],
|
'preserve_url_params' => [$cerebrate['id']],
|
||||||
'searchKey' => 'quickFilter'
|
'searchKey' => 'quickFilter',
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'fields' => $fields,
|
'fields' => $fields,
|
||||||
'title' => empty($ajax) ? __(
|
'title' => empty($ajax) ? __(
|
||||||
|
@ -66,23 +68,24 @@
|
||||||
'actions' => [
|
'actions' => [
|
||||||
[
|
[
|
||||||
'onclick' => sprintf(
|
'onclick' => sprintf(
|
||||||
'openGenericModal(\'{0}/cerebrates/download_sg/{1}/[onclick_params_data_path]\');',
|
'openGenericModal(\'%s/cerebrates/download_sg/%d/[onclick_params_data_path]\');',
|
||||||
$baseurl,
|
$baseurl,
|
||||||
h($cerebrate['id'])
|
h($cerebrate['id'])
|
||||||
),
|
),
|
||||||
'onclick_params_data_path' => 'id',
|
'onclick_params_data_path' => 'id',
|
||||||
'icon' => 'download',
|
'icon' => 'download',
|
||||||
'title' => __('Fetch sharing group object')
|
'title' => __('Fetch sharing group object'),
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'paginatorOptions' => array_merge(
|
'paginatorOptions' => array_merge(
|
||||||
['url' => [$cerebrate['id']]],
|
['url' => [$cerebrate['id']]],
|
||||||
$passedParams
|
$passedParams
|
||||||
),
|
),
|
||||||
'persistUrlParams' => [0, 'quickFilter']
|
'persistUrlParams' => [0, 'quickFilter'],
|
||||||
],
|
],
|
||||||
'containerId' => 'preview_sgs_container'
|
'containerId' => 'preview_sgs_container',
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
||||||
|
|
|
@ -7,28 +7,28 @@ echo $this->element(
|
||||||
'fields' => [
|
'fields' => [
|
||||||
[
|
[
|
||||||
'key' => __('Id'),
|
'key' => __('Id'),
|
||||||
'path' => 'id'
|
'path' => 'id',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'key' => __('Name'),
|
'key' => __('Name'),
|
||||||
'path' => 'name'
|
'path' => 'name',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'key' => __('URL'),
|
'key' => __('URL'),
|
||||||
'path' => 'url',
|
'path' => 'url',
|
||||||
'url' => '{{0}}',
|
'url' => '{{0}}',
|
||||||
'url_vars' => ['url']
|
'url_vars' => ['url'],
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'key' => __('Owner Organisation'),
|
'key' => __('Owner Organisation'),
|
||||||
'path' => 'org_id',
|
'path' => 'org_id',
|
||||||
'pathName' => 'Organisation.name',
|
'pathName' => 'Organisation.name',
|
||||||
'type' => 'model',
|
'type' => 'model',
|
||||||
'model' => 'organisations'
|
'model' => 'organisations',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'key' => __('Description'),
|
'key' => __('Description'),
|
||||||
'path' => 'description'
|
'path' => 'description',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// 'side_panels' => [ // FIXME chri missing side-panel
|
// 'side_panels' => [ // FIXME chri missing side-panel
|
||||||
|
@ -63,6 +63,6 @@ echo $this->element(
|
||||||
'title' => __('Sharing Groups'),
|
'title' => __('Sharing Groups'),
|
||||||
// FIXME chri - 'elementId' => 'preview_sgs_container' FIXME chri
|
// FIXME chri - 'elementId' => 'preview_sgs_container' FIXME chri
|
||||||
],
|
],
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -19,7 +18,7 @@ class AddCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testAddCerebrate(): void
|
public function testAddCerebrate(): void
|
||||||
|
@ -43,7 +42,7 @@ class AddCerebrateApiTest extends TestCase
|
||||||
'client_cert_file' => false,
|
'client_cert_file' => false,
|
||||||
// 'internal' => 1,
|
// 'internal' => 1,
|
||||||
'skip_proxy' => false,
|
'skip_proxy' => false,
|
||||||
'description' => $faker->sentence()
|
'description' => $faker->sentence(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ class AddCerebrateApiTest extends TestCase
|
||||||
'client_cert_file' => false,
|
'client_cert_file' => false,
|
||||||
// 'internal' => 1,
|
// 'internal' => 1,
|
||||||
'skip_proxy' => false,
|
'skip_proxy' => false,
|
||||||
'description' => $faker->sentence()
|
'description' => $faker->sentence(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->assertResponseCode(405);
|
$this->assertResponseCode(405);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -20,7 +19,7 @@ class DeleteCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testDeleteCerebrate(): void
|
public function testDeleteCerebrate(): void
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
||||||
use Cake\Http\TestSuite\HttpClientTrait;
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
|
||||||
class DownloadOrgCerebrateApiTest extends TestCase
|
class DownloadOrgCerebrateApiTest extends TestCase
|
||||||
{
|
{
|
||||||
use ApiTestTrait;
|
use ApiTestTrait;
|
||||||
|
@ -23,7 +21,7 @@ class DownloadOrgCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testDownloadOrg(): void
|
public function testDownloadOrg(): void
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
||||||
use Cake\Http\TestSuite\HttpClientTrait;
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
|
||||||
class DownloadSharingGroupCerebrateApiTest extends TestCase
|
class DownloadSharingGroupCerebrateApiTest extends TestCase
|
||||||
{
|
{
|
||||||
use ApiTestTrait;
|
use ApiTestTrait;
|
||||||
|
@ -24,10 +22,9 @@ class DownloadSharingGroupCerebrateApiTest extends TestCase
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys',
|
'app.AuthKeys',
|
||||||
'app.SharingGroups'
|
'app.SharingGroups',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
public function testDownloadSharingGroup(): void
|
public function testDownloadSharingGroup(): void
|
||||||
{
|
{
|
||||||
$this->skipOpenApiValidations();
|
$this->skipOpenApiValidations();
|
||||||
|
@ -46,7 +43,6 @@ class DownloadSharingGroupCerebrateApiTest extends TestCase
|
||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
$this->assertResponseContains('"name": "' . CerebratesFixture::CEREBRATE_SG_LIST[0]['name'] . '"');
|
$this->assertResponseContains('"name": "' . CerebratesFixture::CEREBRATE_SG_LIST[0]['name'] . '"');
|
||||||
$this->assertDbRecordExists('SharingGroups', ['name' => CerebratesFixture::CEREBRATE_SG_LIST[0]['name'], 'uuid' => CerebratesFixture::CEREBRATE_SG_LIST[0]['uuid']]);
|
$this->assertDbRecordExists('SharingGroups', ['name' => CerebratesFixture::CEREBRATE_SG_LIST[0]['name'], 'uuid' => CerebratesFixture::CEREBRATE_SG_LIST[0]['uuid']]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add multiple tests to add new data to an existing SG (new metadata, new existing org, new new org, ...)
|
// TODO add multiple tests to add new data to an existing SG (new metadata, new existing org, new new org, ...)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -20,7 +19,7 @@ class EditCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testEditCerebrate(): void
|
public function testEditCerebrate(): void
|
||||||
|
@ -32,7 +31,7 @@ class EditCerebrateApiTest extends TestCase
|
||||||
$url,
|
$url,
|
||||||
[
|
[
|
||||||
'id' => CerebratesFixture::SERVER_A_ID,
|
'id' => CerebratesFixture::SERVER_A_ID,
|
||||||
'description' => 'new description'
|
'description' => 'new description',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ class EditCerebrateApiTest extends TestCase
|
||||||
'Cerebrates',
|
'Cerebrates',
|
||||||
[
|
[
|
||||||
'id' => CerebratesFixture::SERVER_A_ID,
|
'id' => CerebratesFixture::SERVER_A_ID,
|
||||||
'description' => 'new description'
|
'description' => 'new description',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +54,7 @@ class EditCerebrateApiTest extends TestCase
|
||||||
$url,
|
$url,
|
||||||
[
|
[
|
||||||
'id' => CerebratesFixture::SERVER_A_ID,
|
'id' => CerebratesFixture::SERVER_A_ID,
|
||||||
'description' => 'new description'
|
'description' => 'new description',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->assertResponseCode(405);
|
$this->assertResponseCode(405);
|
||||||
|
@ -63,7 +62,7 @@ class EditCerebrateApiTest extends TestCase
|
||||||
'Cerebrates',
|
'Cerebrates',
|
||||||
[
|
[
|
||||||
'id' => CerebratesFixture::SERVER_A_ID,
|
'id' => CerebratesFixture::SERVER_A_ID,
|
||||||
'description' => 'new description'
|
'description' => 'new description',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -20,7 +19,7 @@ class IndexCerebratesApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testIndexCerebrates(): void
|
public function testIndexCerebrates(): void
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
||||||
use Cake\Http\TestSuite\HttpClientTrait;
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
|
||||||
class PreviewOrgsCerebrateApiTest extends TestCase
|
class PreviewOrgsCerebrateApiTest extends TestCase
|
||||||
{
|
{
|
||||||
use ApiTestTrait;
|
use ApiTestTrait;
|
||||||
|
@ -23,10 +21,9 @@ class PreviewOrgsCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
public function testPreviewOrgs(): void
|
public function testPreviewOrgs(): void
|
||||||
{
|
{
|
||||||
$this->skipOpenApiValidations();
|
$this->skipOpenApiValidations();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
||||||
use Cake\Http\TestSuite\HttpClientTrait;
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
|
||||||
class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
||||||
{
|
{
|
||||||
use ApiTestTrait;
|
use ApiTestTrait;
|
||||||
|
@ -23,10 +21,9 @@ class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
public function testPreviewSharingGroups(): void
|
public function testPreviewSharingGroups(): void
|
||||||
{
|
{
|
||||||
$this->skipOpenApiValidations();
|
$this->skipOpenApiValidations();
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
|
||||||
|
use App\Test\Fixture\AuthKeysFixture;
|
||||||
|
use App\Test\Fixture\CerebratesFixture;
|
||||||
|
use App\Test\Helper\ApiTestTrait;
|
||||||
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
class PullOrgsCerebrateApiTest extends TestCase
|
||||||
|
{
|
||||||
|
use ApiTestTrait;
|
||||||
|
use HttpClientTrait;
|
||||||
|
|
||||||
|
protected const ENDPOINT = '/cerebrates/pull_orgs';
|
||||||
|
|
||||||
|
protected $fixtures = [
|
||||||
|
'app.Organisations',
|
||||||
|
'app.Cerebrates',
|
||||||
|
'app.Roles',
|
||||||
|
'app.Users',
|
||||||
|
'app.AuthKeys',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function testPullOrgs(): void
|
||||||
|
{
|
||||||
|
$this->skipOpenApiValidations();
|
||||||
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||||
|
$headers = [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Connection: close',
|
||||||
|
];
|
||||||
|
$response = json_encode(CerebratesFixture::CEREBRATE_ORG_LIST);
|
||||||
|
$this->mockClientGet(
|
||||||
|
CerebratesFixture::SERVER_A_URL . '/organisations/index',
|
||||||
|
$this->newClientResponse(200, $headers, $response)
|
||||||
|
);
|
||||||
|
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||||
|
$this->post($url);
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertResponseContains(' 0 failures');
|
||||||
|
foreach (CerebratesFixture::CEREBRATE_ORG_LIST as $org) {
|
||||||
|
$this->assertDbRecordExists('Organisations', ['name' => $org['name'], 'uuid' => $org['uuid']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO add more test cases where existing orgs are being pulled
|
||||||
|
|
||||||
|
public function testPullOrgsNotAllowedAsRegularUser(): void
|
||||||
|
{
|
||||||
|
$this->skipOpenApiValidations();
|
||||||
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
||||||
|
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||||
|
$this->get($url);
|
||||||
|
|
||||||
|
$this->assertResponseCode(405);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
|
||||||
|
use App\Test\Fixture\AuthKeysFixture;
|
||||||
|
use App\Test\Fixture\CerebratesFixture;
|
||||||
|
use App\Test\Helper\ApiTestTrait;
|
||||||
|
use Cake\Http\TestSuite\HttpClientTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
class PullSgsCerebrateApiTest extends TestCase
|
||||||
|
{
|
||||||
|
use ApiTestTrait;
|
||||||
|
use HttpClientTrait;
|
||||||
|
|
||||||
|
protected const ENDPOINT = '/cerebrates/pull_sgs';
|
||||||
|
|
||||||
|
protected $fixtures = [
|
||||||
|
'app.Organisations',
|
||||||
|
'app.Cerebrates',
|
||||||
|
'app.Roles',
|
||||||
|
'app.Users',
|
||||||
|
'app.AuthKeys',
|
||||||
|
'app.SharingGroups',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function testPullSharingGroups(): void
|
||||||
|
{
|
||||||
|
$this->skipOpenApiValidations();
|
||||||
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
||||||
|
$headers = [
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Connection: close',
|
||||||
|
];
|
||||||
|
$response = json_encode(CerebratesFixture::CEREBRATE_SG_LIST);
|
||||||
|
$this->mockClientGet(
|
||||||
|
CerebratesFixture::SERVER_A_URL . '/sharingGroups/index',
|
||||||
|
$this->newClientResponse(200, $headers, $response)
|
||||||
|
);
|
||||||
|
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||||
|
$this->post($url);
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertResponseContains(' 0 failures');
|
||||||
|
foreach (CerebratesFixture::CEREBRATE_SG_LIST as $sg) {
|
||||||
|
$this->assertDbRecordExists('SharingGroups', ['name' => $sg['name'], 'uuid' => $sg['uuid']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO add more use-cases where SGs already exist, contain new metadata and contain new orgs
|
||||||
|
|
||||||
|
public function testPullSharingGroupsNotAllowedAsRegularUser(): void
|
||||||
|
{
|
||||||
|
$this->skipOpenApiValidations();
|
||||||
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
||||||
|
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||||
|
$this->get($url);
|
||||||
|
|
||||||
|
$this->assertResponseCode(405);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Test\TestCase\Api\Cerebrates;
|
namespace App\Test\TestCase\Api\Cerebrates;
|
||||||
|
@ -20,7 +19,7 @@ class ViewCerebrateApiTest extends TestCase
|
||||||
'app.Cerebrates',
|
'app.Cerebrates',
|
||||||
'app.Roles',
|
'app.Roles',
|
||||||
'app.Users',
|
'app.Users',
|
||||||
'app.AuthKeys'
|
'app.AuthKeys',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function testViewCerebrateById(): void
|
public function testViewCerebrateById(): void
|
||||||
|
|
Loading…
Reference in New Issue