mirror of https://github.com/MISP/MISP
fix: [Cerebrate] follow codingstyle
parent
bfa9cae9b3
commit
4d393573a5
|
@ -144,7 +144,7 @@ class AppController extends Controller
|
|||
$user = $this->Users->get(
|
||||
$this->request->getAttribute('identity')->getIdentifier(),
|
||||
[
|
||||
'contain' => ['Roles', 'Organisations' /*'UserSettings'*/],
|
||||
'contain' => ['Roles', 'Organisations' /*'UserSettings'*/],
|
||||
]
|
||||
);
|
||||
$this->__accessMonitor($user->toArray());
|
||||
|
@ -443,7 +443,7 @@ class AppController extends Controller
|
|||
* @param mixed $data data
|
||||
* @param mixed $param param
|
||||
* @param mixed $value value
|
||||
* @return void
|
||||
* @return mixed
|
||||
*/
|
||||
private function captureParam($data, $param, $value)
|
||||
{
|
||||
|
@ -473,7 +473,7 @@ class AppController extends Controller
|
|||
/**
|
||||
* setResponseType
|
||||
*
|
||||
* @return void
|
||||
* @return static|void
|
||||
*/
|
||||
private function setResponseType()
|
||||
{
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
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 Cake\Http\Exception\NotFoundException;
|
||||
|
||||
/**
|
||||
* Cerebrates Controller
|
||||
|
@ -26,7 +24,7 @@ class CerebratesController extends AppController
|
|||
$params = [
|
||||
'contain' => ['Organisations'],
|
||||
'filters' => ['name', 'url', 'uuid'],
|
||||
'quickFilters' => ['name']
|
||||
'quickFilters' => ['name'],
|
||||
];
|
||||
$this->CRUD->index($params);
|
||||
|
||||
|
@ -45,7 +43,8 @@ class CerebratesController extends AppController
|
|||
*/
|
||||
public function view($id = null)
|
||||
{
|
||||
$this->CRUD->view($id,
|
||||
$this->CRUD->view(
|
||||
$id,
|
||||
['contain' => ['Organisations']]
|
||||
);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
|
@ -70,13 +69,16 @@ class CerebratesController extends AppController
|
|||
return $responsePayload;
|
||||
}
|
||||
|
||||
$orgs = $this->Cerebrates->Organisations->find('list', [
|
||||
'recursive' => -1,
|
||||
'fields' => ['id', 'name'],
|
||||
'order' => ['lower(name)' => 'ASC']
|
||||
]);
|
||||
$orgs = $this->Cerebrates->Organisations->find(
|
||||
'list',
|
||||
[
|
||||
'recursive' => -1,
|
||||
'fields' => ['id', 'name'],
|
||||
'order' => ['lower(name)' => 'ASC'],
|
||||
]
|
||||
);
|
||||
$dropdownData = [
|
||||
'org_id' => $orgs
|
||||
'org_id' => $orgs,
|
||||
];
|
||||
$this->set(compact('dropdownData'));
|
||||
}
|
||||
|
@ -97,13 +99,16 @@ class CerebratesController extends AppController
|
|||
return $responsePayload;
|
||||
}
|
||||
|
||||
$orgs = $this->Cerebrates->Organisations->find('list', [
|
||||
'recursive' => -1,
|
||||
'fields' => ['id', 'name'],
|
||||
'order' => ['lower(name)' => 'ASC']
|
||||
]);
|
||||
$orgs = $this->Cerebrates->Organisations->find(
|
||||
'list',
|
||||
[
|
||||
'recursive' => -1,
|
||||
'fields' => ['id', 'name'],
|
||||
'order' => ['lower(name)' => 'ASC'],
|
||||
]
|
||||
);
|
||||
$dropdownData = [
|
||||
'org_id' => $orgs
|
||||
'org_id' => $orgs,
|
||||
];
|
||||
$this->set(compact('dropdownData'));
|
||||
$this->render('add');
|
||||
|
@ -125,8 +130,12 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* pullOrgs
|
||||
*
|
||||
* @param mixed $id of the org
|
||||
* @return void
|
||||
*/
|
||||
public function pullOrgs($id)
|
||||
{
|
||||
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
||||
|
@ -135,17 +144,21 @@ class CerebratesController extends AppController
|
|||
if (empty($cerebrate)) {
|
||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||
}
|
||||
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$orgs = $cerebrate->queryInstance([
|
||||
'path' => '/organisations/index',
|
||||
'params' => $this->harvestParameters([
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter'
|
||||
]),
|
||||
'type' => 'GET'
|
||||
]);
|
||||
$orgs = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/organisations/index',
|
||||
'params' => $this->harvestParameters(
|
||||
[
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter',
|
||||
]
|
||||
),
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
$result = $cerebrate->saveRemoteOrgs($orgs);
|
||||
$message = __('Added {0} new organisations, updated {1} existing organisations, {2} failures.', $result['add'], $result['edit'], $result['fails']);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
|
@ -165,6 +178,12 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pullSgs
|
||||
*
|
||||
* @param mixed $id id of the Sharing Group
|
||||
* @return void
|
||||
*/
|
||||
public function pullSgs($id)
|
||||
{
|
||||
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSgs']);
|
||||
|
@ -175,15 +194,19 @@ class CerebratesController extends AppController
|
|||
}
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$sgs = $cerebrate->queryInstance([
|
||||
'path' => '/sharingGroups/index',
|
||||
'params' => $this->harvestParameters([
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter'
|
||||
]),
|
||||
'type' => 'GET'
|
||||
]);
|
||||
$sgs = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/sharingGroups/index',
|
||||
'params' => $this->harvestParameters(
|
||||
[
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter',
|
||||
]
|
||||
),
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
$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']);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
|
@ -203,6 +226,12 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* previewOrgs
|
||||
*
|
||||
* @param mixed $id id of the org
|
||||
* @return void
|
||||
*/
|
||||
public function previewOrgs($id = null)
|
||||
{
|
||||
// FIXME chri - $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateOrgs']);
|
||||
|
@ -212,15 +241,19 @@ class CerebratesController extends AppController
|
|||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||
}
|
||||
|
||||
$orgs = $cerebrate->queryInstance([
|
||||
'path' => '/organisations/index',
|
||||
'params' => $this->harvestParameters([
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter'
|
||||
]),
|
||||
'type' => 'GET'
|
||||
]);
|
||||
$orgs = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/organisations/index',
|
||||
'params' => $this->harvestParameters(
|
||||
[
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter',
|
||||
]
|
||||
),
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
$result = $cerebrate->checkRemoteOrgs($orgs);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->RestResponse->viewData($result, $this->response->getType());
|
||||
|
@ -234,6 +267,13 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadOrg
|
||||
*
|
||||
* @param mixed $cerebrate_id id of the cerebrate instance
|
||||
* @param mixed $org_id id of the org
|
||||
* @return void
|
||||
*/
|
||||
public function downloadOrg($cerebrate_id, $org_id)
|
||||
{
|
||||
if ($this->request->is('post')) {
|
||||
|
@ -242,10 +282,12 @@ class CerebratesController extends AppController
|
|||
if (empty($cerebrate)) {
|
||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||
}
|
||||
$result = $cerebrate->queryInstance([
|
||||
'path' => '/organisations/view/' . $org_id,
|
||||
'type' => 'GET'
|
||||
]);
|
||||
$result = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/organisations/view/' . $org_id,
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
$saveResult = $cerebrate->captureOrg($result);
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
if (is_array($saveResult)) {
|
||||
|
@ -272,6 +314,12 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* previewSharingGroups
|
||||
*
|
||||
* @param mixed $id id of the Sharing Group
|
||||
* @return void
|
||||
*/
|
||||
public function previewSharingGroups($id)
|
||||
{
|
||||
// $this->set('menuData', ['menuList' => 'sync', 'menuItem' => 'previewCerebrateSGs']);
|
||||
|
@ -280,18 +328,24 @@ class CerebratesController extends AppController
|
|||
if (empty($cerebrate)) {
|
||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||
}
|
||||
$sgs = $cerebrate->queryInstance([
|
||||
'path' => '/sharingGroups/index',
|
||||
'params' => $this->harvestParameters([
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter'
|
||||
]),
|
||||
'type' => 'GET'
|
||||
]);
|
||||
if (!empty($sgs))
|
||||
$sgs = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/sharingGroups/index',
|
||||
'params' => $this->harvestParameters(
|
||||
[
|
||||
'name',
|
||||
'uuid',
|
||||
'quickFilter',
|
||||
]
|
||||
),
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
if (!empty($sgs)) {
|
||||
$result = $cerebrate->checkRemoteSharingGroups($sgs);
|
||||
else $result = [];
|
||||
} else {
|
||||
$result = [];
|
||||
}
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
return $this->RestResponse->viewData($result, $this->response->getType());
|
||||
} else {
|
||||
|
@ -304,6 +358,13 @@ class CerebratesController extends AppController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadSg
|
||||
*
|
||||
* @param mixed $cerebrate_id id of the cerebrate instance
|
||||
* @param mixed $sg_id id of the Sharing Group
|
||||
* @return void
|
||||
*/
|
||||
public function downloadSg($cerebrate_id, $sg_id)
|
||||
{
|
||||
if ($this->request->is('post')) {
|
||||
|
@ -312,10 +373,12 @@ class CerebratesController extends AppController
|
|||
if (empty($cerebrate)) {
|
||||
throw new NotFoundException(__('Invalid Cerebrate instance ID provided.'));
|
||||
}
|
||||
$result = $cerebrate->queryInstance([
|
||||
'path' => '/sharingGroups/view/' . $sg_id,
|
||||
'type' => 'GET'
|
||||
]);
|
||||
$result = $cerebrate->queryInstance(
|
||||
[
|
||||
'path' => '/sharingGroups/view/' . $sg_id,
|
||||
'type' => 'GET',
|
||||
]
|
||||
);
|
||||
$saveResult = $cerebrate->captureSg($result, $this->ACL->getUser());
|
||||
if ($this->ParamHandler->isRest()) {
|
||||
if (is_array($saveResult)) {
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use App\Lib\Tools\HttpTool;
|
||||
use App\Model\Entity\AppModel;
|
||||
use Cake\Core\Exception\CakeException;
|
||||
use Cake\Database\Expression\QueryExpression;
|
||||
use Cake\Database\Query;
|
||||
use Cake\Http\Client\Exception\NetworkException;
|
||||
use Cake\Http\Exception\BadRequestException;
|
||||
use Cake\Http\Exception\ForbiddenException;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\Utility\Hash;
|
||||
use Cake\Database\Expression\QueryExpression;
|
||||
use Cake\Database\Query;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Cerebrate Entity
|
||||
|
@ -60,7 +57,6 @@ class Cerebrate extends AppModel
|
|||
'description' => true,
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* queryInstance - Query a remote Cerebrate instance for a specific path
|
||||
*
|
||||
|
@ -79,7 +75,8 @@ class Cerebrate extends AppModel
|
|||
$response = $httpTool->get(
|
||||
$url,
|
||||
[],
|
||||
(isset($options['params']) ? $options['params'] : []));
|
||||
(isset($options['params']) ? $options['params'] : [])
|
||||
);
|
||||
}
|
||||
if ($response->isOk()) {
|
||||
return json_decode($response->getBody(), true);
|
||||
|
@ -93,26 +90,32 @@ class Cerebrate extends AppModel
|
|||
throw new BadRequestException(__('Something went wrong with the request or the remote side is having issues.'));
|
||||
}
|
||||
|
||||
public function convertOrg($org_data)
|
||||
/**
|
||||
* convertOrg
|
||||
*
|
||||
* @param mixed $org_data organisation data
|
||||
* @return array
|
||||
*/
|
||||
public function convertOrg($org_data)
|
||||
{
|
||||
$mapping = [
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'required' => 1
|
||||
'required' => 1,
|
||||
],
|
||||
'uuid' => [
|
||||
'field' => 'uuid',
|
||||
'required' => 1
|
||||
'required' => 1,
|
||||
],
|
||||
'nationality' => [
|
||||
'field' => 'nationality'
|
||||
'field' => 'nationality',
|
||||
],
|
||||
'sector' => [
|
||||
'field' => 'sector'
|
||||
'field' => 'sector',
|
||||
],
|
||||
'type' => [
|
||||
'field' => 'type'
|
||||
]
|
||||
'field' => 'type',
|
||||
],
|
||||
];
|
||||
$org = [];
|
||||
foreach ($mapping as $cerebrate_field => $field_data) {
|
||||
|
@ -125,12 +128,12 @@ class Cerebrate extends AppModel
|
|||
}
|
||||
$org[$field_data['field']] = $org_data[$cerebrate_field];
|
||||
}
|
||||
|
||||
return $org;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* saveRemoteOrgs -
|
||||
* saveRemoteOrgs -
|
||||
*
|
||||
* @param array $orgs An array of organisations with name, uuid, sector, nationality, type
|
||||
* @return array {'add': int, 'edit': int, 'fails': int}
|
||||
|
@ -140,7 +143,7 @@ class Cerebrate extends AppModel
|
|||
$outcome = [
|
||||
'add' => 0,
|
||||
'edit' => 0,
|
||||
'fails' => 0
|
||||
'fails' => 0,
|
||||
];
|
||||
foreach ($orgs as $org) {
|
||||
$isEdit = false;
|
||||
|
@ -158,14 +161,15 @@ class Cerebrate extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $outcome;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* saveRemoteSgs
|
||||
*
|
||||
* @param mixed $sgs
|
||||
* @param mixed $user
|
||||
* @param mixed $sgs SharingGroups
|
||||
* @param mixed $user user
|
||||
* @return array ['add'=> 0, 'edit' => 0, 'fails' => 0]
|
||||
*/
|
||||
public function saveRemoteSgs($sgs, $user)
|
||||
|
@ -173,7 +177,7 @@ class Cerebrate extends AppModel
|
|||
$outcome = [
|
||||
'add' => 0,
|
||||
'edit' => 0,
|
||||
'fails' => 0
|
||||
'fails' => 0,
|
||||
];
|
||||
foreach ($sgs as $sg) {
|
||||
$isEdit = false;
|
||||
|
@ -191,18 +195,19 @@ class Cerebrate extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $outcome;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* captureOrg - save or update an Org locally that comes from a Remote Cerebrate server
|
||||
*
|
||||
* @param array $org_data The Org array from the remote Cerebrate server
|
||||
* @param bool $edit Returns if the org was edited or not
|
||||
* @param bool $noChange Returns
|
||||
* @param bool $noChange Returns
|
||||
* @return string|array Error message or Organisation array
|
||||
*/
|
||||
public function captureOrg($org_data, &$edit=false, &$noChange=false)
|
||||
public function captureOrg($org_data, &$edit = false, &$noChange = false)
|
||||
{
|
||||
$org = $this->convertOrg($org_data);
|
||||
if ($org) {
|
||||
|
@ -210,7 +215,7 @@ class Cerebrate extends AppModel
|
|||
$organisationTable = TableRegistry::getTableLocator()->get('Organisations');
|
||||
$existingOrg = $organisationTable->find('all', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['uuid' => $org['uuid']]
|
||||
'conditions' => ['uuid' => $org['uuid']],
|
||||
])->first();
|
||||
if (!empty($existingOrg)) {
|
||||
$fieldsToSave = ['name', 'sector', 'nationality', 'type'];
|
||||
|
@ -246,7 +251,7 @@ class Cerebrate extends AppModel
|
|||
$nameCheck = $organisationTable->find('all', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['name' => $orgToSave->name],
|
||||
'fields' => ['id']
|
||||
'fields' => ['id'],
|
||||
])->first();
|
||||
if (!empty($nameCheck)) {
|
||||
$orgToSave['name'] = $orgToSave['name'] . '_' . mt_rand(0, 9999);
|
||||
|
@ -256,23 +261,29 @@ class Cerebrate extends AppModel
|
|||
if ($savedOrganisation) {
|
||||
return $organisationTable->find('all', [
|
||||
'recursive' => -1,
|
||||
'conditions' => ['id' => $savedOrganisation->id]
|
||||
'conditions' => ['id' => $savedOrganisation->id],
|
||||
])->first()->toArray();
|
||||
} else {
|
||||
return __('The organisation could not be saved.');
|
||||
}
|
||||
} else {
|
||||
$noChange = true;
|
||||
|
||||
return $existingOrg->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
return __('The retrieved data isn\'t a valid organisation.');
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* checkRemoteOrgs
|
||||
* Checks remote for the current status of each organisation
|
||||
* Adds the exists_locally field with a boolean status
|
||||
* If exists_loally is true, adds a list with the differences (keynames)
|
||||
*
|
||||
* @param array $orgs orgs
|
||||
* @return array
|
||||
*/
|
||||
public function checkRemoteOrgs($orgs)
|
||||
{
|
||||
|
@ -310,9 +321,17 @@ class Cerebrate extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $orgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* __compareNames
|
||||
*
|
||||
* @param string $name1 orgname
|
||||
* @param string $name2 orgname
|
||||
* @return bool
|
||||
*/
|
||||
private function __compareNames($name1, $name2)
|
||||
{
|
||||
if (preg_match('/\_[0-9]{4}$/i', $name1)) {
|
||||
|
@ -322,9 +341,17 @@ class Cerebrate extends AppModel
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* __compareMembers
|
||||
*
|
||||
* @param array $existingMembers members
|
||||
* @param array $remoteMembers members
|
||||
* @return bool
|
||||
*/
|
||||
private function __compareMembers($existingMembers, $remoteMembers)
|
||||
{
|
||||
$memberFound = [];
|
||||
|
@ -342,13 +369,18 @@ class Cerebrate extends AppModel
|
|||
$memberNotFound[] = $remoteMember['uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
return empty($memberNotFound);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks remote for the current status of each sharing groups
|
||||
* Adds the exists_locally field with a boolean status
|
||||
* If exists_loally is true, adds a list with the differences (keynames)
|
||||
/**
|
||||
* checkRemoteSharingGroups
|
||||
* Checks remote for the current status of each sharing groups
|
||||
* Adds the exists_locally field with a boolean status
|
||||
* If exists_loally is true, adds a list with the differences (keynames)
|
||||
*
|
||||
* @param array $sgs SharingGroups
|
||||
* @return array
|
||||
*/
|
||||
public function checkRemoteSharingGroups($sgs)
|
||||
{
|
||||
|
@ -356,7 +388,7 @@ class Cerebrate extends AppModel
|
|||
$sharingGroupTable = TableRegistry::getTableLocator()->get('SharingGroups');
|
||||
$uuids = Hash::extract($sgs, '{n}.uuid');
|
||||
$existingSgs = $sharingGroupTable->find('all')
|
||||
->contain(['SharingGroupOrgs'=> 'Organisations', 'Organisations'])
|
||||
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
||||
->where(['SharingGroups.uuid'])
|
||||
->where(function (QueryExpression $exp, Query $q) use ($uuids) {
|
||||
return $exp->in('SharingGroups.uuid', array_values($uuids));
|
||||
|
@ -375,9 +407,17 @@ class Cerebrate extends AppModel
|
|||
$sgs[$k]['differences'] = $this->compareSgs($rearranged[$sg['uuid']], $sgs[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* compareSgs
|
||||
*
|
||||
* @param array $existingSg existing SharingGroup
|
||||
* @param array $remoteSg remote Sharing Group
|
||||
* @return array
|
||||
*/
|
||||
private function compareSgs($existingSg, $remoteSg)
|
||||
{
|
||||
$differences = [];
|
||||
|
@ -399,25 +439,32 @@ class Cerebrate extends AppModel
|
|||
if (!$this->__compareMembers(Hash::extract($existingSg['SharingGroupOrg'], '{n}.Organisation'), $remoteSg['sharing_group_orgs'])) {
|
||||
$differences[] = 'members';
|
||||
}
|
||||
|
||||
return $differences;
|
||||
}
|
||||
|
||||
/**
|
||||
* convertSg
|
||||
*
|
||||
* @param array $sg_data Sharing Group data
|
||||
* @return array
|
||||
*/
|
||||
private function convertSg($sg_data)
|
||||
{
|
||||
$mapping = [
|
||||
'name' => [
|
||||
'field' => 'name',
|
||||
'required' => 1
|
||||
'required' => 1,
|
||||
],
|
||||
'uuid' => [
|
||||
'field' => 'uuid',
|
||||
'required' => 1
|
||||
'required' => 1,
|
||||
],
|
||||
'releasability' => [
|
||||
'field' => 'releasability'
|
||||
'field' => 'releasability',
|
||||
],
|
||||
'description' => [
|
||||
'field' => 'description'
|
||||
'field' => 'description',
|
||||
],
|
||||
];
|
||||
$sg = [];
|
||||
|
@ -442,24 +489,26 @@ class Cerebrate extends AppModel
|
|||
$sg['SharingGroupOrg'][$k]['extend'] = false;
|
||||
}
|
||||
foreach ($org as $ok => $ov) {
|
||||
if ($ov === null) unset($sg['SharingGroupOrg'][$k][$ok]);
|
||||
if ($ov === null) {
|
||||
unset($sg['SharingGroupOrg'][$k][$ok]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $sg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* captureSg
|
||||
*
|
||||
* @param array $sg_data
|
||||
* @param App\Model\Entity\User $user
|
||||
* @param bool $edit
|
||||
* @param bool $noChange
|
||||
* @return mixed
|
||||
* @param array $sg_data Sharing Group data
|
||||
* @param \App\Model\Entity\User $user user
|
||||
* @param bool $edit data was changed or not
|
||||
* @param bool $noChange noChange
|
||||
* @return string|array
|
||||
*/
|
||||
public function captureSg($sg_data, $user, &$edit=false, &$noChange=false)
|
||||
public function captureSg($sg_data, $user, &$edit = false, &$noChange = false)
|
||||
{
|
||||
/** @var \App\Model\Table\SharingGroupsTable $sharingGroupTable */
|
||||
$sharingGroupTable = TableRegistry::getTableLocator()->get('SharingGroups');
|
||||
|
@ -472,12 +521,15 @@ class Cerebrate extends AppModel
|
|||
$captureResult = $sharingGroupTable->captureSG($sg, $user->toArray(), false);
|
||||
if (!empty($captureResult)) {
|
||||
$savedSg = $sharingGroupTable->findById($captureResult)
|
||||
->contain(['SharingGroupOrgs'=> 'Organisations', 'Organisations'])
|
||||
->contain(['SharingGroupOrgs' => 'Organisations', 'Organisations'])
|
||||
->first();
|
||||
|
||||
return $savedSg->toArray();
|
||||
}
|
||||
|
||||
return __('The organisation could not be saved.');
|
||||
}
|
||||
|
||||
return __('The retrieved data isn\'t a valid sharing group.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,29 +4,29 @@ $edit = $this->request->getParam('action') === 'edit' ? true : false;
|
|||
$fields = [
|
||||
[
|
||||
'field' => 'name',
|
||||
'class' => 'span6'
|
||||
'class' => 'span6',
|
||||
],
|
||||
[
|
||||
'field' => 'url',
|
||||
'class' => 'span6'
|
||||
'class' => 'span6',
|
||||
],
|
||||
[
|
||||
'field' => 'authkey',
|
||||
'class' => 'span6',
|
||||
'autocomplete' => 'off',
|
||||
'type' => 'text'
|
||||
'type' => 'text',
|
||||
],
|
||||
[
|
||||
'field' => 'org_id',
|
||||
'label' => 'Owner Organisation',
|
||||
'options' => $dropdownData['org_id'],
|
||||
'class' => 'span6',
|
||||
'type' => 'dropdown'
|
||||
'type' => 'dropdown',
|
||||
],
|
||||
[
|
||||
'field' => 'description',
|
||||
'type' => 'textarea',
|
||||
'class' => 'input span6'
|
||||
'class' => 'input span6',
|
||||
],
|
||||
[
|
||||
'field' => 'pull_orgs',
|
||||
|
@ -37,17 +37,20 @@ $fields = [
|
|||
'field' => 'pull_sharing_groups',
|
||||
'label' => __('Pull Sharing Groups'),
|
||||
'type' => 'checkbox',
|
||||
]
|
||||
],
|
||||
];
|
||||
echo $this->element('genericElements/Form/genericForm', [
|
||||
'data' => [
|
||||
'description' => false,
|
||||
'model' => 'Cerebrate',
|
||||
'title' => $edit ? __('Edit Cerebrate connection') : __('Add Cerebrate connection'),
|
||||
'fields' => $fields,
|
||||
'submit' => [
|
||||
'action' => $this->request->getParam('action'),
|
||||
'ajaxSubmit' => 'submitGenericFormInPlace();'
|
||||
]
|
||||
echo $this->element(
|
||||
'genericElements/Form/genericForm',
|
||||
[
|
||||
'data' => [
|
||||
'description' => false,
|
||||
'model' => 'Cerebrate',
|
||||
'title' => $edit ? __('Edit Cerebrate connection') : __('Add Cerebrate connection'),
|
||||
'fields' => $fields,
|
||||
'submit' => [
|
||||
'action' => $this->request->getParam('action'),
|
||||
'ajaxSubmit' => 'submitGenericFormInPlace();',
|
||||
],
|
||||
],
|
||||
]
|
||||
]);
|
||||
);
|
||||
|
|
|
@ -1,111 +1,113 @@
|
|||
<?php
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('ID'),
|
||||
'sort' => 'id',
|
||||
'class' => 'short',
|
||||
'data_path' => 'id'
|
||||
],
|
||||
[
|
||||
'name' => __('Owner Org'),
|
||||
'sort' => 'Organisation',
|
||||
'data_path' => 'Organisation',
|
||||
'element' => 'org'
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name'
|
||||
],
|
||||
[
|
||||
'name' => __('URL'),
|
||||
'sort' => 'url',
|
||||
'data_path' => 'url'
|
||||
],
|
||||
[
|
||||
'name' => __('Description'),
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description'
|
||||
],
|
||||
[
|
||||
'name' => __('Pull Orgs'),
|
||||
'sort' => 'pull_orgs',
|
||||
'data_path' => 'pull_orgs',
|
||||
'element' => 'boolean'
|
||||
],
|
||||
[
|
||||
'name' => __('Pull SGs'),
|
||||
'sort' => 'pull_sharing_groups',
|
||||
'data_path' => 'pull_sharing_groups',
|
||||
'element' => 'boolean'
|
||||
]
|
||||
];
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('ID'),
|
||||
'sort' => 'id',
|
||||
'class' => 'short',
|
||||
'data_path' => 'id',
|
||||
],
|
||||
[
|
||||
'name' => __('Owner Org'),
|
||||
'sort' => 'Organisation',
|
||||
'data_path' => 'Organisation',
|
||||
'element' => 'org',
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name',
|
||||
],
|
||||
[
|
||||
'name' => __('URL'),
|
||||
'sort' => 'url',
|
||||
'data_path' => 'url',
|
||||
],
|
||||
[
|
||||
'name' => __('Description'),
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description',
|
||||
],
|
||||
[
|
||||
'name' => __('Pull Orgs'),
|
||||
'sort' => 'pull_orgs',
|
||||
'data_path' => 'pull_orgs',
|
||||
'element' => 'boolean',
|
||||
],
|
||||
[
|
||||
'name' => __('Pull SGs'),
|
||||
'sort' => 'pull_sharing_groups',
|
||||
'data_path' => 'pull_sharing_groups',
|
||||
'element' => 'boolean',
|
||||
],
|
||||
];
|
||||
|
||||
echo $this->element('genericElements/IndexTable/index_table', [
|
||||
'data' => [
|
||||
'data' => $data,
|
||||
'top_bar' => [
|
||||
'children' => [
|
||||
[
|
||||
'type' => 'simple',
|
||||
'children' => [
|
||||
'data' => [
|
||||
'type' => 'simple',
|
||||
'icon' => 'plus',
|
||||
'text' => __('Add Cerebrate'),
|
||||
'class' => 'btn btn-primary',
|
||||
'popover_url' => '/cerebrates/add',
|
||||
'button' => [
|
||||
echo $this->element(
|
||||
'genericElements/IndexTable/index_table',
|
||||
[
|
||||
'data' => [
|
||||
'data' => $data,
|
||||
'top_bar' => [
|
||||
'children' => [
|
||||
[
|
||||
'type' => 'simple',
|
||||
'children' => [
|
||||
'data' => [
|
||||
'type' => 'simple',
|
||||
'icon' => 'plus',
|
||||
]
|
||||
]
|
||||
]
|
||||
'text' => __('Add Cerebrate'),
|
||||
'class' => 'btn btn-primary',
|
||||
'popover_url' => '/cerebrates/add',
|
||||
'button' => [
|
||||
'icon' => 'plus',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'search',
|
||||
'button' => __('Search'),
|
||||
'placeholder' => __('Enter value to search'),
|
||||
'data' => '',
|
||||
'searchKey' => 'value',
|
||||
'allowFilering' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'table_action',
|
||||
],
|
||||
],
|
||||
],
|
||||
'fields' => $fields,
|
||||
'title' => __('Linked Cerebrates'),
|
||||
'description' => __('You can connect your MISP to one or several Cerebrate instances to act as lookup directories for organisation and sharing group information.'),
|
||||
'actions' => [
|
||||
[
|
||||
'url' => '/cerebrates/view',
|
||||
'url_params_data_paths' => ['id'],
|
||||
'icon' => 'eye',
|
||||
],
|
||||
[
|
||||
'type' => 'search',
|
||||
'button' => __('Search'),
|
||||
'placeholder' => __('Enter value to search'),
|
||||
'data' => '',
|
||||
'searchKey' => 'value',
|
||||
'allowFilering' => true
|
||||
'open_modal' => '/cerebrates/pull_orgs/[onclick_params_data_path]',
|
||||
'onclick_params_data_path' => 'id',
|
||||
'title' => __('Pull all organisations'),
|
||||
'icon' => 'arrow-circle-down',
|
||||
],
|
||||
[
|
||||
'type' => 'table_action',
|
||||
'open_modal' => '/cerebrates/pull_sgs/[onclick_params_data_path]',
|
||||
'onclick_params_data_path' => 'id',
|
||||
'title' => __('Pull all sharing groups'),
|
||||
'icon' => 'arrow-circle-down',
|
||||
],
|
||||
]
|
||||
[
|
||||
'open_modal' => '/cerebrates/edit/[onclick_params_data_path]',
|
||||
'modal_params_data_path' => 'id',
|
||||
'icon' => 'edit',
|
||||
],
|
||||
[
|
||||
'open_modal' => '/cerebrates/delete/[onclick_params_data_path]',
|
||||
'modal_params_data_path' => 'id',
|
||||
'icon' => 'trash',
|
||||
],
|
||||
],
|
||||
],
|
||||
'fields' => $fields,
|
||||
'title' => __('Linked Cerebrates'),
|
||||
'description' => __('You can connect your MISP to one or several Cerebrate instances to act as lookup directories for organisation and sharing group information.'),
|
||||
'actions' => [
|
||||
[
|
||||
'url' => '/cerebrates/view',
|
||||
'url_params_data_paths' => ['id'],
|
||||
'icon' => 'eye'
|
||||
],
|
||||
[
|
||||
'open_modal' => '/cerebrates/pull_orgs/[onclick_params_data_path]',
|
||||
'onclick_params_data_path' => 'id',
|
||||
'title' => __('Pull all organisations'),
|
||||
'icon' => 'arrow-circle-down'
|
||||
],
|
||||
[
|
||||
'open_modal' => '/cerebrates/pull_sgs/[onclick_params_data_path]',
|
||||
'onclick_params_data_path' => 'id',
|
||||
'title' => __('Pull all sharing groups'),
|
||||
'icon' => 'arrow-circle-down'
|
||||
],
|
||||
[
|
||||
'open_modal' => '/cerebrates/edit/[onclick_params_data_path]',
|
||||
'modal_params_data_path' => 'id',
|
||||
'icon' => 'edit'
|
||||
],
|
||||
[
|
||||
'open_modal' => '/cerebrates/delete/[onclick_params_data_path]',
|
||||
'modal_params_data_path' => 'id',
|
||||
'icon' => 'trash'
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
);
|
||||
|
|
|
@ -1,38 +1,40 @@
|
|||
<?php
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('Id'),
|
||||
'sort' => 'id',
|
||||
'data_path' => 'id'
|
||||
],
|
||||
[
|
||||
'name' => __('Known locally'),
|
||||
'sort' => 'exists_locally',
|
||||
'element' => 'remote_status',
|
||||
],
|
||||
[
|
||||
'name' => __('UUID'),
|
||||
'sort' => 'uuid',
|
||||
'data_path' => 'uuid'
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name'
|
||||
],
|
||||
[
|
||||
'name' => __('Sector'),
|
||||
'sort' => 'sector',
|
||||
'data_path' => 'sector'
|
||||
],
|
||||
[
|
||||
'name' => __('Nationality'),
|
||||
'sort' => 'nationality',
|
||||
'data_path' => 'nationality'
|
||||
]
|
||||
];
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('Id'),
|
||||
'sort' => 'id',
|
||||
'data_path' => 'id',
|
||||
],
|
||||
[
|
||||
'name' => __('Known locally'),
|
||||
'sort' => 'exists_locally',
|
||||
'element' => 'remote_status',
|
||||
],
|
||||
[
|
||||
'name' => __('UUID'),
|
||||
'sort' => 'uuid',
|
||||
'data_path' => 'uuid',
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name',
|
||||
],
|
||||
[
|
||||
'name' => __('Sector'),
|
||||
'sort' => 'sector',
|
||||
'data_path' => 'sector',
|
||||
],
|
||||
[
|
||||
'name' => __('Nationality'),
|
||||
'sort' => 'nationality',
|
||||
'data_path' => 'nationality',
|
||||
],
|
||||
];
|
||||
|
||||
echo $this->element('genericElements/IndexTable/index_table', [
|
||||
echo $this->element(
|
||||
'genericElements/IndexTable/index_table',
|
||||
[
|
||||
'data' => [
|
||||
'data' => $data,
|
||||
'top_bar' => [
|
||||
|
@ -44,37 +46,38 @@
|
|||
'placeholder' => __('Enter value to search'),
|
||||
'data' => '',
|
||||
'preserve_url_params' => [$cerebrate['id']],
|
||||
'searchKey' => 'quickFilter'
|
||||
]
|
||||
]
|
||||
'searchKey' => 'quickFilter',
|
||||
],
|
||||
],
|
||||
],
|
||||
'fields' => $fields,
|
||||
'title' => empty($ajax) ? __(
|
||||
'Organisations list via Cerebrate {0} ({1})',
|
||||
h($cerebrate['id']),
|
||||
h($cerebrate['name'])
|
||||
) : false,
|
||||
'Organisations list via Cerebrate {0} ({1})',
|
||||
h($cerebrate['id']),
|
||||
h($cerebrate['name'])
|
||||
) : false,
|
||||
'description' => empty($ajax) ? __('Preview of the organisations known to the remote Cerebrate instance.') : false,
|
||||
'actions' => [
|
||||
[
|
||||
'onclick' => sprintf(
|
||||
'openGenericModal(\'{0}/cerebrates/download_org/{1}/[onclick_params_data_path]\');',
|
||||
'openGenericModal(\'%s/cerebrates/download_org/%d/[onclick_params_data_path]\');',
|
||||
$baseurl,
|
||||
h($cerebrate['id'])
|
||||
),
|
||||
'onclick_params_data_path' => 'id',
|
||||
'icon' => 'download',
|
||||
'title' => __('Fetch organisation object')
|
||||
]
|
||||
'title' => __('Fetch organisation object'),
|
||||
],
|
||||
],
|
||||
'paginatorOptions' => array_merge(
|
||||
['url' => [$cerebrate['id']]],
|
||||
$passedParams
|
||||
),
|
||||
'persistUrlParams' => [0, 'quickFilter']
|
||||
'persistUrlParams' => [0, 'quickFilter'],
|
||||
],
|
||||
'containerId' => 'preview_orgs_container'
|
||||
]);
|
||||
'containerId' => 'preview_orgs_container',
|
||||
]
|
||||
);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
||||
|
|
|
@ -1,46 +1,48 @@
|
|||
<?php
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('Id'),
|
||||
'sort' => 'id',
|
||||
'data_path' => 'id'
|
||||
],
|
||||
[
|
||||
'name' => __('Status'),
|
||||
'sort' => 'exists_locally',
|
||||
'element' => 'remote_status',
|
||||
'data_path' => ''
|
||||
],
|
||||
[
|
||||
'name' => __('UUID'),
|
||||
'sort' => 'uuid',
|
||||
'data_path' => 'uuid'
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name'
|
||||
],
|
||||
[
|
||||
'name' => __('Releasability'),
|
||||
'sort' => 'releasability',
|
||||
'data_path' => 'releasability'
|
||||
],
|
||||
[
|
||||
'name' => __('Description'),
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description'
|
||||
],
|
||||
[
|
||||
'name' => __('# Member'),
|
||||
'element' => 'custom',
|
||||
'function' => function($row) {
|
||||
return count($row['sharing_group_orgs']);
|
||||
}
|
||||
],
|
||||
];
|
||||
$fields = [
|
||||
[
|
||||
'name' => __('Id'),
|
||||
'sort' => 'id',
|
||||
'data_path' => 'id',
|
||||
],
|
||||
[
|
||||
'name' => __('Status'),
|
||||
'sort' => 'exists_locally',
|
||||
'element' => 'remote_status',
|
||||
'data_path' => '',
|
||||
],
|
||||
[
|
||||
'name' => __('UUID'),
|
||||
'sort' => 'uuid',
|
||||
'data_path' => 'uuid',
|
||||
],
|
||||
[
|
||||
'name' => __('Name'),
|
||||
'sort' => 'name',
|
||||
'data_path' => 'name',
|
||||
],
|
||||
[
|
||||
'name' => __('Releasability'),
|
||||
'sort' => 'releasability',
|
||||
'data_path' => 'releasability',
|
||||
],
|
||||
[
|
||||
'name' => __('Description'),
|
||||
'sort' => 'description',
|
||||
'data_path' => 'description',
|
||||
],
|
||||
[
|
||||
'name' => __('# Member'),
|
||||
'element' => 'custom',
|
||||
'function' => function ($row) {
|
||||
return count($row['sharing_group_orgs']);
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
echo $this->element('genericElements/IndexTable/index_table', [
|
||||
echo $this->element(
|
||||
'genericElements/IndexTable/index_table',
|
||||
[
|
||||
'data' => [
|
||||
'data' => $data,
|
||||
'top_bar' => [
|
||||
|
@ -52,37 +54,38 @@
|
|||
'placeholder' => __('Enter value to search'),
|
||||
'data' => '',
|
||||
'preserve_url_params' => [$cerebrate['id']],
|
||||
'searchKey' => 'quickFilter'
|
||||
]
|
||||
]
|
||||
'searchKey' => 'quickFilter',
|
||||
],
|
||||
],
|
||||
],
|
||||
'fields' => $fields,
|
||||
'title' => empty($ajax) ? __(
|
||||
'Sharing group list via Cerebrate {0} ({1})',
|
||||
h($cerebrate['id']),
|
||||
h($cerebrate['name'])
|
||||
) : false,
|
||||
'Sharing group list via Cerebrate {0} ({1})',
|
||||
h($cerebrate['id']),
|
||||
h($cerebrate['name'])
|
||||
) : false,
|
||||
'description' => empty($ajax) ? __('Preview of the sharing group known to the remote Cerebrate instance.') : false,
|
||||
'actions' => [
|
||||
[
|
||||
'onclick' => sprintf(
|
||||
'openGenericModal(\'{0}/cerebrates/download_sg/{1}/[onclick_params_data_path]\');',
|
||||
'openGenericModal(\'%s/cerebrates/download_sg/%d/[onclick_params_data_path]\');',
|
||||
$baseurl,
|
||||
h($cerebrate['id'])
|
||||
),
|
||||
'onclick_params_data_path' => 'id',
|
||||
'icon' => 'download',
|
||||
'title' => __('Fetch sharing group object')
|
||||
]
|
||||
'title' => __('Fetch sharing group object'),
|
||||
],
|
||||
],
|
||||
'paginatorOptions' => array_merge(
|
||||
['url' => [$cerebrate['id']]],
|
||||
$passedParams
|
||||
),
|
||||
'persistUrlParams' => [0, 'quickFilter']
|
||||
'persistUrlParams' => [0, 'quickFilter'],
|
||||
],
|
||||
'containerId' => 'preview_sgs_container'
|
||||
]);
|
||||
'containerId' => 'preview_sgs_container',
|
||||
]
|
||||
);
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var passedArgsArray = <?= json_encode([h($cerebrate['id'])]) ?>;
|
||||
|
|
|
@ -7,28 +7,28 @@ echo $this->element(
|
|||
'fields' => [
|
||||
[
|
||||
'key' => __('Id'),
|
||||
'path' => 'id'
|
||||
'path' => 'id',
|
||||
],
|
||||
[
|
||||
'key' => __('Name'),
|
||||
'path' => 'name'
|
||||
'path' => 'name',
|
||||
],
|
||||
[
|
||||
'key' => __('URL'),
|
||||
'path' => 'url',
|
||||
'url' => '{{0}}',
|
||||
'url_vars' => ['url']
|
||||
'url_vars' => ['url'],
|
||||
],
|
||||
[
|
||||
'key' => __('Owner Organisation'),
|
||||
'path' => 'org_id',
|
||||
'pathName' => 'Organisation.name',
|
||||
'type' => 'model',
|
||||
'model' => 'organisations'
|
||||
'model' => 'organisations',
|
||||
],
|
||||
[
|
||||
'key' => __('Description'),
|
||||
'path' => 'description'
|
||||
'path' => 'description',
|
||||
],
|
||||
],
|
||||
// 'side_panels' => [ // FIXME chri missing side-panel
|
||||
|
@ -63,6 +63,6 @@ echo $this->element(
|
|||
'title' => __('Sharing Groups'),
|
||||
// FIXME chri - 'elementId' => 'preview_sgs_container' FIXME chri
|
||||
],
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -19,7 +18,7 @@ class AddCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testAddCerebrate(): void
|
||||
|
@ -43,7 +42,7 @@ class AddCerebrateApiTest extends TestCase
|
|||
'client_cert_file' => false,
|
||||
// 'internal' => 1,
|
||||
'skip_proxy' => false,
|
||||
'description' => $faker->sentence()
|
||||
'description' => $faker->sentence(),
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -73,7 +72,7 @@ class AddCerebrateApiTest extends TestCase
|
|||
'client_cert_file' => false,
|
||||
// 'internal' => 1,
|
||||
'skip_proxy' => false,
|
||||
'description' => $faker->sentence()
|
||||
'description' => $faker->sentence(),
|
||||
]
|
||||
);
|
||||
$this->assertResponseCode(405);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -20,7 +19,7 @@ class DeleteCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testDeleteCerebrate(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class DownloadOrgCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
@ -23,7 +21,7 @@ class DownloadOrgCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testDownloadOrg(): void
|
||||
|
@ -36,20 +34,20 @@ class DownloadOrgCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_ORG_LIST[0]);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/organisations/view/'.CerebratesFixture::CEREBRATE_ORG_LIST[0]['id'],
|
||||
CerebratesFixture::SERVER_A_URL . '/organisations/view/' . CerebratesFixture::CEREBRATE_ORG_LIST[0]['id'],
|
||||
$this->newClientResponse(200, $headers, $response)
|
||||
);
|
||||
$url = sprintf('%s/%d/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID, CerebratesFixture::CEREBRATE_ORG_LIST[0]['id']);
|
||||
$this->post($url);
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('"name": "'.CerebratesFixture::CEREBRATE_ORG_LIST[0]['name'].'"');
|
||||
$this->assertResponseContains('"name": "' . CerebratesFixture::CEREBRATE_ORG_LIST[0]['name'] . '"');
|
||||
$this->assertDbRecordExists('Organisations', ['name' => CerebratesFixture::CEREBRATE_ORG_LIST[0]['name']]);
|
||||
}
|
||||
|
||||
// TODO add a test to add new data to an existing organisation
|
||||
// public function testDownloadOrgUpdateExisting(): void
|
||||
// {
|
||||
|
||||
|
||||
// }
|
||||
|
||||
public function testDownloadOrgNotAllowedAsRegularUser(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class DownloadSharingGroupCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
@ -24,10 +22,9 @@ class DownloadSharingGroupCerebrateApiTest extends TestCase
|
|||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.SharingGroups'
|
||||
'app.SharingGroups',
|
||||
];
|
||||
|
||||
|
||||
public function testDownloadSharingGroup(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
|
@ -38,21 +35,20 @@ class DownloadSharingGroupCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_SG_LIST[0]);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/sharingGroups/view/'.CerebratesFixture::CEREBRATE_SG_LIST[0]['id'],
|
||||
CerebratesFixture::SERVER_A_URL . '/sharingGroups/view/' . CerebratesFixture::CEREBRATE_SG_LIST[0]['id'],
|
||||
$this->newClientResponse(200, $headers, $response)
|
||||
);
|
||||
$url = sprintf('%s/%d/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID, CerebratesFixture::CEREBRATE_SG_LIST[0]['id']);
|
||||
$this->post($url);
|
||||
$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']]);
|
||||
|
||||
}
|
||||
|
||||
// TODO add multiple tests to add new data to an existing SG (new metadata, new existing org, new new org, ...)
|
||||
// public function testDownloadSharingGroupUpdateExisting(): void
|
||||
// {
|
||||
|
||||
|
||||
// }
|
||||
|
||||
public function testDownloadSharingGroupNotAllowedAsRegularUser(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -20,7 +19,7 @@ class EditCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testEditCerebrate(): void
|
||||
|
@ -32,7 +31,7 @@ class EditCerebrateApiTest extends TestCase
|
|||
$url,
|
||||
[
|
||||
'id' => CerebratesFixture::SERVER_A_ID,
|
||||
'description' => 'new description'
|
||||
'description' => 'new description',
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -41,7 +40,7 @@ class EditCerebrateApiTest extends TestCase
|
|||
'Cerebrates',
|
||||
[
|
||||
'id' => CerebratesFixture::SERVER_A_ID,
|
||||
'description' => 'new description'
|
||||
'description' => 'new description',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -55,7 +54,7 @@ class EditCerebrateApiTest extends TestCase
|
|||
$url,
|
||||
[
|
||||
'id' => CerebratesFixture::SERVER_A_ID,
|
||||
'description' => 'new description'
|
||||
'description' => 'new description',
|
||||
]
|
||||
);
|
||||
$this->assertResponseCode(405);
|
||||
|
@ -63,7 +62,7 @@ class EditCerebrateApiTest extends TestCase
|
|||
'Cerebrates',
|
||||
[
|
||||
'id' => CerebratesFixture::SERVER_A_ID,
|
||||
'description' => 'new description'
|
||||
'description' => 'new description',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -20,7 +19,7 @@ class IndexCerebratesApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testIndexCerebrates(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class PreviewOrgsCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
@ -23,10 +21,9 @@ class PreviewOrgsCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
|
||||
public function testPreviewOrgs(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
|
@ -37,13 +34,13 @@ class PreviewOrgsCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_ORG_LIST);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/organisations/index',
|
||||
CerebratesFixture::SERVER_A_URL . '/organisations/index',
|
||||
$this->newClientResponse(200, $headers, $response)
|
||||
);
|
||||
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||
$this->get($url);
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('"name": "'.CerebratesFixture::CEREBRATE_ORG_LIST[0]['name'].'"');
|
||||
$this->assertResponseContains('"name": "' . CerebratesFixture::CEREBRATE_ORG_LIST[0]['name'] . '"');
|
||||
}
|
||||
|
||||
public function testPreviewOrgsNotAllowedAsRegularUser(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
@ -23,10 +21,9 @@ class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
|
||||
public function testPreviewSharingGroups(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
|
@ -37,13 +34,13 @@ class PreviewSharingGroupsCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_SG_LIST);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/sharingGroups/index',
|
||||
CerebratesFixture::SERVER_A_URL . '/sharingGroups/index',
|
||||
$this->newClientResponse(200, $headers, $response)
|
||||
);
|
||||
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||
$this->get($url);
|
||||
$this->assertResponseOk();
|
||||
$this->assertResponseContains('"name": "'.CerebratesFixture::CEREBRATE_SG_LIST[0]['name'].'"');
|
||||
$this->assertResponseContains('"name": "' . CerebratesFixture::CEREBRATE_SG_LIST[0]['name'] . '"');
|
||||
}
|
||||
|
||||
public function testPreviewSharingGroupsNotAllowedAsRegularUser(): void
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,7 +9,6 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class PullOrgsCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
|
@ -23,10 +21,9 @@ class PullOrgsCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
|
||||
public function testPullOrgs(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
|
@ -37,14 +34,14 @@ class PullOrgsCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_ORG_LIST);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/organisations/index',
|
||||
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) {
|
||||
foreach (CerebratesFixture::CEREBRATE_ORG_LIST as $org) {
|
||||
$this->assertDbRecordExists('Organisations', ['name' => $org['name'], 'uuid' => $org['uuid']]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -10,8 +9,7 @@ use App\Test\Helper\ApiTestTrait;
|
|||
use Cake\Http\TestSuite\HttpClientTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
|
||||
class PullSGsCerebrateApiTest extends TestCase
|
||||
class PullSgsCerebrateApiTest extends TestCase
|
||||
{
|
||||
use ApiTestTrait;
|
||||
use HttpClientTrait;
|
||||
|
@ -24,10 +22,9 @@ class PullSGsCerebrateApiTest extends TestCase
|
|||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys',
|
||||
'app.SharingGroups'
|
||||
'app.SharingGroups',
|
||||
];
|
||||
|
||||
|
||||
public function testPullSharingGroups(): void
|
||||
{
|
||||
$this->skipOpenApiValidations();
|
||||
|
@ -38,7 +35,7 @@ class PullSGsCerebrateApiTest extends TestCase
|
|||
];
|
||||
$response = json_encode(CerebratesFixture::CEREBRATE_SG_LIST);
|
||||
$this->mockClientGet(
|
||||
CerebratesFixture::SERVER_A_URL.'/sharingGroups/index',
|
||||
CerebratesFixture::SERVER_A_URL . '/sharingGroups/index',
|
||||
$this->newClientResponse(200, $headers, $response)
|
||||
);
|
||||
$url = sprintf('%s/%d', self::ENDPOINT, CerebratesFixture::SERVER_A_ID);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Api\Cerebrates;
|
||||
|
@ -20,7 +19,7 @@ class ViewCerebrateApiTest extends TestCase
|
|||
'app.Cerebrates',
|
||||
'app.Roles',
|
||||
'app.Users',
|
||||
'app.AuthKeys'
|
||||
'app.AuthKeys',
|
||||
];
|
||||
|
||||
public function testViewCerebrateById(): void
|
||||
|
|
Loading…
Reference in New Issue