add: migrate view sg

pull/9143/head
Luciano Righetti 2023-06-13 16:45:44 +02:00
parent 78dd5d3e83
commit 267e870d0e
9 changed files with 195 additions and 181 deletions

View File

@ -153,7 +153,7 @@ class SharingGroupsController extends AppController
// check if the user is eligible to edit the SG (original creator or extend)
$sharingGroup = $this->SharingGroups->find(
'first',
'all',
[
'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id],
'recursive' => -1,
@ -171,12 +171,12 @@ class SharingGroupsController extends AppController
],
],
]
);
)->disableHydration()->first();
if (empty($sharingGroup)) {
throw new NotFoundException('Invalid sharing group.');
}
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser(), $sharingGroup['SharingGroup']['id'])) {
if (!$this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser(), $sharingGroup['id'])) {
throw new MethodNotAllowedException('Action not allowed.');
}
if ($this->request->is('post')) {
@ -184,7 +184,7 @@ class SharingGroupsController extends AppController
if (!empty($this->request->getData('SharingGroup'))) {
$data = $this->request->getData('SharingGroup');
}
$data['uuid'] = $sharingGroup['SharingGroup']['uuid'];
$data['uuid'] = $sharingGroup['uuid'];
$id = $this->SharingGroups->captureSG($data, $this->ACL->getUser());
if ($id) {
$sg = $this->SharingGroups->fetchAllAuthorised($this->ACL->getUser(), 'simplified', false, $id);
@ -195,17 +195,17 @@ class SharingGroupsController extends AppController
} else {
$json = json_decode($this->request->getData('json'), true);
$sg = $json['sharingGroup'];
$sg['id'] = $sharingGroup['SharingGroup']['id'];
$sg['id'] = $sharingGroup['id'];
$fields = ['name', 'releasability', 'description', 'active', 'roaming'];
$existingSG = $this->SharingGroups->find('first', ['recursive' => -1, 'conditions' => ['SharingGroup.id' => $sharingGroup['SharingGroup']['id']]]);
$existingSG = $this->SharingGroups->find('all', ['recursive' => -1, 'conditions' => ['SharingGroup.id' => $sharingGroup['id']]])->disableHydration()->first();
foreach ($fields as $field) {
$existingSG['SharingGroup'][$field] = $sg[$field];
$existingSG[$field] = $sg[$field];
}
unset($existingSG['SharingGroup']['modified']);
unset($existingSG['modified']);
if ($this->SharingGroups->save($existingSG)) {
$this->SharingGroups->SharingGroupOrgs->updateOrgsForSG($sharingGroup['SharingGroup']['id'], $json['organisations'], $sharingGroup['SharingGroupOrg'], $this->ACL->getUser());
$this->SharingGroups->SharingGroupServers->updateServersForSG($sharingGroup['SharingGroup']['id'], $json['servers'], $sharingGroup['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->ACL->getUser());
$this->redirect('/SharingGroups/view/' . $sharingGroup['SharingGroup']['id']);
$this->SharingGroups->SharingGroupOrgs->updateOrgsForSG($sharingGroup['id'], $json['organisations'], $sharingGroup['SharingGroupOrg'], $this->ACL->getUser());
$this->SharingGroups->SharingGroupServers->updateServersForSG($sharingGroup['id'], $json['servers'], $sharingGroup['SharingGroupServer'], $json['sharingGroup']['roaming'], $this->ACL->getUser());
$this->redirect('/SharingGroups/view/' . $sharingGroup['id']);
} else {
$validationReplacements = [
'notempty' => 'This field cannot be left empty.',
@ -233,7 +233,7 @@ class SharingGroupsController extends AppController
]
);
$this->set('sharingGroup', $sharingGroup);
$this->set('id', $sharingGroup['SharingGroup']['id']);
$this->set('id', $sharingGroup['id']);
$this->set('orgs', $orgs);
$this->set('localInstance', empty(Configure::read('MISP.external_baseurl')) ? Configure::read('MISP.baseurl') : Configure::read('MISP.external_baseurl'));
// We just pass true and allow the user to edit, since he/she is just about to create the SG. This is needed to reuse the view for the edit
@ -245,17 +245,17 @@ class SharingGroupsController extends AppController
$this->request->allowMethod(['post', 'delete']);
$deletedSg = $this->SharingGroups->find(
'first',
'all',
[
'conditions' => Validation::uuid($id) ? ['uuid' => $id] : ['id' => $id],
'recursive' => -1,
'fields' => ['id', 'active'],
]
);
if (empty($deletedSg) || !$this->SharingGroups->checkIfOwner($this->ACL->getUser(), $deletedSg['SharingGroup']['id'])) {
)->disableHydration()->first();
if (empty($deletedSg) || !$this->SharingGroups->checkIfOwner($this->ACL->getUser(), $deletedSg['id'])) {
throw new MethodNotAllowedException('Action not allowed.');
}
if ($this->SharingGroups->delete($deletedSg['SharingGroup']['id'])) {
if ($this->SharingGroups->delete($deletedSg['id'])) {
if ($this->ParamHandler->isRest()) {
return $this->RestResponse->saveSuccessResponse('SharingGroups', 'delete', $id, $this->response->getType());
}
@ -267,7 +267,7 @@ class SharingGroupsController extends AppController
$this->Flash->error(__('Sharing Group could not be deleted. Make sure that there are no events, attributes or threads belonging to this sharing group.'));
}
if ($deletedSg['SharingGroup']['active']) {
if ($deletedSg['active']) {
$this->redirect('/SharingGroups/index');
} else {
$this->redirect('/SharingGroups/index/true');
@ -399,31 +399,31 @@ class SharingGroupsController extends AppController
}
$contain = [
'Organisation',
'SharingGroupOrg' => [
'Organisation' => [
'Organisations',
'SharingGroupOrgs' => [
'Organisations' => [
'fields' => ['id', 'name', 'uuid', 'local']
]
],
'SharingGroupServer' => [
'Server' => [
'SharingGroupServers' => [
'Servers' => [
'fields' => ['id', 'name', 'url']
]
]
];
if (!$this->__showOrgs()) {
unset($contain['SharingGroupOrg']);
unset($contain['SharingGroupServer']);
unset($contain['SharingGroupOrgs']);
unset($contain['SharingGroupServers']);
}
$sg = $this->SharingGroups->find(
'first',
'all',
[
'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id],
'conditions' => Validation::uuid($id) ? ['SharingGroups.uuid' => $id] : ['SharingGroups.id' => $id],
'contain' => $contain,
]
);
)->disableHydration()->first();
if (isset($sg['SharingGroupServer'])) {
foreach ($sg['SharingGroupServer'] as $key => $sgs) {
if ($sgs['server_id'] == 0) {
@ -435,24 +435,24 @@ class SharingGroupsController extends AppController
}
}
}
if ($sg['SharingGroup']['sync_user_id']) {
if ($sg['sync_user_id']) {
$UserTable = $this->fetchTable('Users');
$syncUser = $UserTable->find(
'all',
[
'conditions' => ['User.id' => $sg['SharingGroup']['sync_user_id']],
'conditions' => ['Users.id' => $sg['sync_user_id']],
'recursive' => -1,
'fields' => ['User.id'],
'contain' => ['Organisation' => [
'fields' => ['Organisations.id', 'Organisation.name', 'Organisation.uuid'],
'fields' => ['Users.id'],
'contain' => ['Organisations' => [
'fields' => ['Organisations.id', 'Organisations.name', 'Organisations.uuid'],
]]
]
)->first();
)->disableHydration()->first();
if (empty($syncUser)) {
$sg['SharingGroup']['sync_org_name'] = 'N/A';
$sg['sync_org_name'] = 'N/A';
} else {
$sg['SharingGroup']['sync_org_name'] = $syncUser['Organisation']['name'];
$sg['SharingGroup']['sync_org'] = $syncUser['Organisation'];
$sg['sync_org_name'] = $syncUser['Organisation']['name'];
$sg['sync_org'] = $syncUser['Organisation'];
}
}
if ($this->ParamHandler->isRest()) {
@ -460,20 +460,20 @@ class SharingGroupsController extends AppController
}
$EventsTable = $this->fetchTable('Events');
$conditions = $EventsTable->createEventConditions($this->ACL->getUser());
$conditions['AND']['sharing_group_id'] = $sg['SharingGroup']['id'];
$sg['SharingGroup']['event_count'] = $EventsTable->find(
'count',
$conditions = $EventsTable->createEventConditions($this->ACL->getUser()->toArray());
$conditions['AND']['sharing_group_id'] = $sg['id'];
$sg['event_count'] = $EventsTable->find(
'all',
[
'conditions' => $conditions,
'recursive' => -1,
'callbacks' => false,
]
);
)->count();
$this->set('mayModify', $this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser(), $sg['SharingGroup']['id']));
$this->set('id', $sg['SharingGroup']['id']);
$this->set('sg', $sg);
$this->set('mayModify', $this->SharingGroups->checkIfAuthorisedExtend($this->ACL->getUser()->toArray(), $sg['id']));
$this->set('id', $sg['id']);
$this->set('entity', $sg);
$this->set('menuData', ['menuList' => 'globalActions', 'menuItem' => 'viewSG']);
}
@ -558,7 +558,7 @@ class SharingGroupsController extends AppController
$sgo = [
'SharingGroupOrg' => [
'org_id' => $org['id'],
'sharing_group_id' => $sg['SharingGroup']['id'],
'sharing_group_id' => $sg['id'],
'extend' => $extend ? 1 : 0
]
];
@ -617,7 +617,7 @@ class SharingGroupsController extends AppController
$sgs = [
'SharingGroupServer' => [
'server_id' => $server['Server']['id'],
'sharing_group_id' => $sg['SharingGroup']['id'],
'sharing_group_id' => $sg['id'],
'all_orgs' => $all ? 1 : 0
]
];

View File

@ -0,0 +1,9 @@
<?php
namespace App\Model\Entity;
use App\Model\Entity\AppModel;
class Event extends AppModel
{
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Model\Table;
use App\Model\Table\AppTable;
use Cake\Core\Configure;
class EventsTable extends AppTable
{
public function createEventConditions($user)
{
$conditions = array();
if (!$user['Role']['perm_site_admin']) {
$sgids = $this->SharingGroup->authorizedIds($user);
$unpublishedPrivate = Configure::read('MISP.unpublishedprivate');
$conditions['AND']['OR'] = [
'Event.org_id' => $user['org_id'],
[
'AND' => [
'Event.distribution >' => 0,
'Event.distribution <' => 4,
$unpublishedPrivate ? array('Event.published' => 1) : [],
],
],
[
'AND' => [
'Event.sharing_group_id' => $sgids,
'Event.distribution' => 4,
$unpublishedPrivate ? array('Event.published' => 1) : [],
]
]
];
}
return $conditions;
}
}

View File

@ -2,20 +2,7 @@
namespace App\Model\Table;
use App\Model\Entity\SharingGroup;
use App\Model\Table\AppTable;
use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\RulesChecker;
use Cake\Utility\Text;
use Cake\Validation\Validation;
use Cake\Validation\Validator;
use InvalidArgumentException;
use App\Model\Entity\Log;
class ServersTable extends AppTable
{

View File

@ -2,20 +2,7 @@
namespace App\Model\Table;
use App\Model\Entity\SharingGroup;
use App\Model\Table\AppTable;
use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\RulesChecker;
use Cake\Utility\Text;
use Cake\Validation\Validation;
use Cake\Validation\Validator;
use InvalidArgumentException;
use App\Model\Entity\Log;
class SharingGroupOrgsTable extends AppTable
{

View File

@ -2,20 +2,7 @@
namespace App\Model\Table;
use App\Model\Entity\SharingGroup;
use App\Model\Table\AppTable;
use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\ORM\Locator\LocatorAwareTrait;
use Cake\ORM\RulesChecker;
use Cake\Utility\Text;
use Cake\Validation\Validation;
use Cake\Validation\Validator;
use InvalidArgumentException;
use App\Model\Entity\Log;
class SharingGroupServersTable extends AppTable
{

View File

@ -2,6 +2,7 @@
namespace App\Model\Table;
use App\Model\Entity\Log;
use App\Model\Entity\SharingGroup;
use App\Model\Table\AppTable;
use ArrayObject;
@ -15,7 +16,6 @@ use Cake\Utility\Text;
use Cake\Validation\Validation;
use Cake\Validation\Validator;
use InvalidArgumentException;
use App\Model\Entity\Log;
class SharingGroupsTable extends AppTable
{
@ -38,14 +38,14 @@ class SharingGroupsTable extends AppTable
'SharingGroupOrgs',
[
'dependent' => true,
'propertyName' => 'SharingGroupOrgs'
'propertyName' => 'SharingGroupOrg'
],
);
$this->hasMany(
'SharingGroupServers',
[
'dependent' => true,
'propertyName' => 'SharingGroupServers'
'propertyName' => 'SharingGroupServer'
],
);
// $this->hasMany('Event');
@ -221,7 +221,7 @@ class SharingGroupsTable extends AppTable
return $this->appendOrgsAndServers($sgs, ['id', 'name'], []);
}
foreach ($sgs as &$sg) {
$sg['SharingGroupOrgs'] = [];
$sg['SharingGroupOrg'] = [];
}
return $sgs;
} elseif ($scope === 'name') {
@ -263,8 +263,8 @@ class SharingGroupsTable extends AppTable
if (isset($sg['SharingGroup']['org_id'])) {
$orgsToFetch[$sg['SharingGroup']['org_id']] = true;
}
if (isset($sg['SharingGroupOrgs'])) {
foreach ($sg['SharingGroupOrgs'] as $sgo) {
if (isset($sg['SharingGroupOrg'])) {
foreach ($sg['SharingGroupOrg'] as $sgo) {
$orgsToFetch[$sgo['org_id']] = true;
}
}
@ -309,8 +309,8 @@ class SharingGroupsTable extends AppTable
$sg['Organisation'] = $orgsById[$sg['SharingGroup']['org_id']];
}
if (isset($sg['SharingGroupOrgs'])) {
foreach ($sg['SharingGroupOrgs'] as &$sgo) {
if (isset($sg['SharingGroupOrg'])) {
foreach ($sg['SharingGroupOrg'] as &$sgo) {
if (isset($orgsById[$sgo['org_id']])) {
$sgo['Organisation'] = $orgsById[$sgo['org_id']];
}
@ -353,18 +353,18 @@ class SharingGroupsTable extends AppTable
}
// First let us find out if we already have the SG
$local = $this->find(
'first',
'all',
[
'recursive' => -1,
'conditions' => ['uuid' => $sg['uuid']],
'fields' => ['id'],
]
);
)->disableHydration()->first();
if (empty($local)) {
$orgCheck = false;
$serverCheck = false;
if (isset($sg['SharingGroupOrgs'])) {
foreach ($sg['SharingGroupOrgs'] as $org) {
if (isset($sg['SharingGroupOrg'])) {
foreach ($sg['SharingGroupOrg'] as $org) {
if (isset($org['Organisation'][0])) {
$org['Organisation'] = $org['Organisation'][0];
}
@ -425,7 +425,7 @@ class SharingGroupsTable extends AppTable
}
if ($user['Role']['perm_sync']) {
$sg = $this->find(
'first',
'all',
[
'conditions' => [
'id' => $id,
@ -433,7 +433,7 @@ class SharingGroupsTable extends AppTable
],
'recursive' => -1,
]
);
)->disableHydration()->first();
if (!empty($sg)) {
return true;
}
@ -468,13 +468,13 @@ class SharingGroupsTable extends AppTable
}
if (Validation::uuid($id)) {
$sgid = $this->find(
'first',
'all',
[
'conditions' => ['SharingGroup.uuid' => $id],
'conditions' => ['uuid' => $id],
'recursive' => -1,
'fields' => ['SharingGroup.id']
'fields' => ['id']
]
);
)->disableHydration()->first();
if (empty($sgid)) {
return false;
}
@ -489,13 +489,13 @@ class SharingGroupsTable extends AppTable
throw new MethodNotAllowedException('Invalid user.');
}
$sg_org_id = $this->find(
'first',
'all',
[
'recursive' => -1,
'fields' => ['SharingGroup.org_id'],
'conditions' => ['SharingGroup.id' => $id]
'fields' => ['org_id'],
'conditions' => ['id' => $id]
]
);
)->disableHydration()->first();
$authorized = ($adminCheck && $user['Role']['perm_site_admin']) ||
$user['org_id'] === $sg_org_id['SharingGroup']['org_id'] ||
$this->SharingGroupServer->checkIfAuthorised($id) ||
@ -558,13 +558,13 @@ class SharingGroupsTable extends AppTable
throw new MethodNotAllowedException('Invalid user.');
}
$sg = $this->find(
'first',
'all',
[
'conditions' => Validation::uuid($id) ? ['SharingGroup.uuid' => $id] : ['SharingGroup.id' => $id],
'recursive' => -1,
'fields' => ['org_id'],
]
);
)->disableHydration()->first();
if (empty($sg)) {
return false;
}
@ -582,7 +582,7 @@ class SharingGroupsTable extends AppTable
public function getOrgsWithAccess($id)
{
$sg = $this->find(
'first',
'all',
[
'conditions' => ['SharingGroup.id' => $id],
'recursive' => -1,
@ -592,7 +592,7 @@ class SharingGroupsTable extends AppTable
'SharingGroupServer' => ['fields' => ['id', 'server_id', 'all_orgs']],
]
]
);
)->disableHydration()->first();
if (empty($sg)) {
return [];
}
@ -605,7 +605,7 @@ class SharingGroupsTable extends AppTable
}
}
// return a list of arrays with all organisations tied to the SG.
return array_column($sg['SharingGroupOrgs'], 'org_id');
return array_column($sg['SharingGroupOrg'], 'org_id');
}
public function checkIfServerInSG($sg, $server)
@ -625,8 +625,8 @@ class SharingGroupsTable extends AppTable
return false;
}
}
if (isset($sg['SharingGroupOrgs']) && !empty($sg['SharingGroupOrgs'])) {
foreach ($sg['SharingGroupOrgs'] as $org) {
if (isset($sg['SharingGroupOrg']) && !empty($sg['SharingGroupOrg'])) {
foreach ($sg['SharingGroupOrg'] as $org) {
if (isset($org['Organisation']) && $org['Organisation']['uuid'] === $server['RemoteOrg']['uuid']) {
return true;
}
@ -652,7 +652,7 @@ class SharingGroupsTable extends AppTable
$syncLocal = true;
}
$existingSG = !isset($sg['uuid']) ? null : $this->find(
'first',
'all',
[
'recursive' => -1,
'conditions' => ['SharingGroup.uuid' => $sg['uuid']],
@ -662,7 +662,7 @@ class SharingGroupsTable extends AppTable
'SharingGroupOrgs' => ['Organisation']
]
]
);
)->disableHydration()->first();
$forceUpdate = false;
if (empty($existingSG)) {
if (!$user['Role']['perm_sharing_group']) {
@ -767,7 +767,8 @@ class SharingGroupsTable extends AppTable
}
$this->create();
$date = date('Y-m-d H:i:s');
$newSG = new SharingGroup([
$newSG = new SharingGroup(
[
'name' => $sg['name'],
'releasability' => !isset($sg['releasability']) ? '' : $sg['releasability'],
'description' => !isset($sg['description']) ? '' : $sg['description'],
@ -780,7 +781,8 @@ class SharingGroupsTable extends AppTable
'local' => 0,
'sync_user_id' => $user['id'],
'org_id' => $user['Role']['perm_sync'] ? $this->__retrieveOrgIdFromCapturedSG($user, $sg) : $user['org_id']
]);
]
);
if (empty($newSG->org_id)) {
return false;
}
@ -801,15 +803,15 @@ class SharingGroupsTable extends AppTable
private function __retrieveOrgIdFromCapturedSG($user, $sg)
{
if (!isset($sg['Organisation'])) {
if (!isset($sg['SharingGroupOrgs'])) {
$sg['SharingGroupOrgs'] = [[
if (!isset($sg['SharingGroupOrg'])) {
$sg['SharingGroupOrg'] = [[
'extend' => 1,
'uuid' => $user['Organisation']['uuid'],
'name' => $user['Organisation']['name'],
]];
return $user['org_id'];
} else {
foreach ($sg['SharingGroupOrgs'] as $k => $org) {
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (!isset($org['Organisation'])) {
$org['Organisation'] = $org;
}
@ -865,48 +867,48 @@ class SharingGroupsTable extends AppTable
public function captureSGOrgs(array $user, array $sg, int $sg_id, bool $force)
{
$creatorOrgFound = false;
if (!empty($sg['SharingGroupOrgs'])) {
if (isset($sg['SharingGroupOrgs']['id'])) {
$temp = $sg['SharingGroupOrgs'];
unset($sg['SharingGroupOrgs']);
$sg['SharingGroupOrgs'][0] = $temp;
if (!empty($sg['SharingGroupOrg'])) {
if (isset($sg['SharingGroupOrg']['id'])) {
$temp = $sg['SharingGroupOrg'];
unset($sg['SharingGroupOrg']);
$sg['SharingGroupOrg'][0] = $temp;
}
foreach ($sg['SharingGroupOrgs'] as $k => $org) {
foreach ($sg['SharingGroupOrg'] as $k => $org) {
if (empty($org['Organisation'])) {
$org['Organisation'] = $org;
}
if (isset($org['Organisation'][0])) {
$org['Organisation'] = $org['Organisation'][0];
}
$sg['SharingGroupOrgs'][$k]['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user, $force);
if ($sg['SharingGroupOrgs'][$k]['org_id'] == $user['org_id']) {
$sg['SharingGroupOrg'][$k]['org_id'] = $this->Organisation->captureOrg($org['Organisation'], $user, $force);
if ($sg['SharingGroupOrg'][$k]['org_id'] == $user['org_id']) {
$creatorOrgFound = true;
}
unset($sg['SharingGroupOrgs'][$k]['Organisation']);
unset($sg['SharingGroupOrg'][$k]['Organisation']);
if ($force) {
// we are editing not creating here
$temp = $this->SharingGroupOrgs->find(
'first',
'all',
[
'recursive' => -1,
'conditions' => [
'sharing_group_id' => $sg_id,
'org_id' => $sg['SharingGroupOrgs'][$k]['org_id']
'org_id' => $sg['SharingGroupOrg'][$k]['org_id']
],
]
);
)->disableHydration()->first();
if (empty($temp)) {
$this->SharingGroupOrgs->create();
$this->SharingGroupOrgs->save(['sharing_group_id' => $sg_id, 'org_id' => $sg['SharingGroupOrgs'][$k]['org_id'], 'extend' => $org['extend']]);
$this->SharingGroupOrgs->save(['sharing_group_id' => $sg_id, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']]);
} else {
if ($temp['SharingGroupOrgs']['extend'] != $sg['SharingGroupOrgs'][$k]['extend']) {
$temp['SharingGroupOrgs']['extend'] = $sg['SharingGroupOrgs'][$k]['extend'];
$this->SharingGroupOrgs->save($temp['SharingGroupOrgs']);
if ($temp['SharingGroupOrg']['extend'] != $sg['SharingGroupOrg'][$k]['extend']) {
$temp['SharingGroupOrg']['extend'] = $sg['SharingGroupOrg'][$k]['extend'];
$this->SharingGroupOrgs->save($temp['SharingGroupOrg']);
}
}
} else {
$this->SharingGroupOrgs->create();
$this->SharingGroupOrgs->save(['sharing_group_id' => $sg_id, 'org_id' => $sg['SharingGroupOrgs'][$k]['org_id'], 'extend' => $org['extend']]);
$this->SharingGroupOrgs->save(['sharing_group_id' => $sg_id, 'org_id' => $sg['SharingGroupOrg'][$k]['org_id'], 'extend' => $org['extend']]);
}
}
}
@ -942,7 +944,7 @@ class SharingGroupsTable extends AppTable
if ($force) {
// we are editing not creating here
$temp = $this->SharingGroupServer->find(
'first',
'all',
[
'recursive' => -1,
'conditions' => [
@ -950,7 +952,7 @@ class SharingGroupsTable extends AppTable
'server_id' => $sg['SharingGroupServer'][$k]['server_id']
],
]
);
)->disableHydration()->first();
if (empty($temp)) {
$this->SharingGroupServer->create();
$this->SharingGroupServer->save(['sharing_group_id' => $sg_id, 'server_id' => $sg['SharingGroupServer'][$k]['server_id'], 'all_orgs' => empty($server['all_orgs']) ? 0 : $server['all_orgs']]);
@ -991,7 +993,8 @@ class SharingGroupsTable extends AppTable
$syncUsers[$sg['SharingGroup']['sync_user_id']] = $UsersTable->getAuthUser($sg['SharingGroup']['sync_user_id']);
if (empty($syncUsers[$sg['SharingGroup']['sync_user_id']])) {
$LogsTable->create();
$entry = new Log([
$entry = new Log(
[
'org' => 'SYSTEM',
'model' => 'SharingGroup',
'model_id' => $sg['SharingGroup']['id'],
@ -999,7 +1002,8 @@ class SharingGroupsTable extends AppTable
'action' => 'error',
'user_id' => 0,
'title' => 'Tried to update a sharing group as part of the 2.4.49 update, but the user used for creating the sharing group locally doesn\'t exist any longer.'
]);
]
);
$LogsTable->save($entry);
unset($syncUsers[$sg['SharingGroup']['sync_user_id']]);
continue;
@ -1009,7 +1013,8 @@ class SharingGroupsTable extends AppTable
$sharingGroupOrg = ['sharing_group_id' => $sg['SharingGroup']['id'], 'org_id' => $syncUsers[$sg['SharingGroup']['sync_user_id']]['org_id'], 'extend' => 0];
$result = $this->SharingGroupOrgs->save($sharingGroupOrg);
if (!$result) {
$entry = new Log([
$entry = new Log(
[
'org' => 'SYSTEM',
'model' => 'SharingGroup',
'model_id' => $sg['SharingGroup']['id'],
@ -1017,7 +1022,8 @@ class SharingGroupsTable extends AppTable
'action' => 'error',
'user_id' => 0,
'title' => 'Tried to update a sharing group as part of the 2.4.49 update, but saving the changes has resulted in the following error: ' . json_encode($this->SharingGroupOrgs->validationErrors)
]);
]
);
$LogsTable->save($entry);
}
}
@ -1050,13 +1056,13 @@ class SharingGroupsTable extends AppTable
}
if (Validation::uuid($id)) {
$id = $this->find(
'first',
'all',
[
'conditions' => ['SharingGroup.uuid' => $id],
'recursive' => -1,
'fields' => ['SharingGroup.id']
]
);
)->disableHydration()->first();
if (empty($id)) {
return false;
} else {

View File

@ -1,4 +1,4 @@
<div class="sharing_groups<?php if (!$ajax) echo ' index' ?>">
<div class="sharingGroups<?php if (!$ajax) echo ' index' ?>">
<?= $this->element(
'/genericElements/IndexTable/index_table',
[
@ -13,8 +13,8 @@
[
'text' => __('Add'),
'fa-icon' => 'plus',
'url' => $baseurl . '/sharing_groups/add',
'requirement' => $this->Acl->checkAccess('sharing_groups', 'add'),
'url' => '/sharingGroups/add',
'requirement' => $this->Acl->checkAccess('sharingGroups', 'add'),
]
]
],
@ -22,12 +22,12 @@
'type' => 'simple',
'children' => [
[
'url' => $baseurl . '/sharing_groups/index',
'url' => '/sharingGroups/index',
'text' => __('Active Sharing Groups'),
'active' => !$passive,
],
[
'url' => $baseurl . '/sharing_groups/index/true',
'url' => '/sharingGroups/index/true',
'text' => __('Passive Sharing Groups'),
'active' => $passive,
]
@ -52,7 +52,7 @@
'sort' => 'id',
'class' => 'short',
'data_path' => 'id',
'url' => '/sharing_groups/view/{{id}}',
'url' => '/sharingGroups/view/{{id}}',
'url_vars' => ['id' => 'id']
],
[
@ -87,14 +87,14 @@
[
'name' => __('Releasable to'),
'element' => 'custom',
'function' => function (array $sharingGroup) use ($baseurl) {
'function' => function (array $sharingGroup) {
$combined = __("Organisations:");
if (empty($sharingGroup['SharingGroupOrg'])) {
$combined .= "<br>N/A";
} else {
foreach ($sharingGroup['SharingGroupOrg'] as $sge) {
if (!empty($sge['Organisation'])) {
$combined .= "<br><a href='" . $baseurl . "/organisation/view/" . h($sge['Organisation']['id']) . "'>" . h($sge['Organisation']['name']) . "</a>";
$combined .= "<br><a href='/organisation/view/" . h($sge['Organisation']['id']) . "'>" . h($sge['Organisation']['name']) . "</a>";
if ($sge['extend']) {
$combined .= ' (can extend)';
}
@ -107,7 +107,7 @@
} else {
foreach ($sharingGroup['SharingGroupServer'] as $sgs) {
if ($sgs['server_id'] != 0) {
$combined .= "<br><a href='" . $baseurl . "/server/view/" . h($sgs['Server']['id']) . "'>" . h($sgs['Server']['name']) . "</a>";
$combined .= "<br><a href='/server/view/" . h($sgs['Server']['id']) . "'>" . h($sgs['Server']['name']) . "</a>";
} else {
$combined .= "<br>This instance";
}
@ -130,13 +130,13 @@
],
'actions' => [
[
'url' => $baseurl . '/sharing_groups/view',
'url' => '/sharingGroups/view',
'url_params_data_paths' => ['id'],
'icon' => 'eye',
'title' => __('View Sharing Group'),
],
[
'url' => '/sharing_groups/edit',
'url' => '/sharingGroups/edit',
'url_params_data_paths' => ['id'],
'icon' => 'edit',
'complex_requirement' => [
@ -147,7 +147,7 @@
'title' => __('Edit Sharing Group'),
],
[
'url' => '/sharing_groups/delete',
'url' => '/sharingGroups/delete',
'url_params_data_paths' => ['id'],
'postLinkConfirm' => __('Are you sure you want to delete the sharing group?'),
'icon' => 'trash',

View File

@ -1,56 +1,57 @@
<?php
echo $this->element(
'genericElements/SingleViews/single_view',
[
'title' => __('Sharing Group %s', $sg['SharingGroup']['name']),
'data' => $sg,
'title' => __('Sharing Group %s', $entity['name']),
'data' => $entity,
'fields' => [
[
'key' => __('ID'),
'path' => 'SharingGroup.id'
'path' => 'id'
],
[
'key' => __('UUID'),
'path' => 'SharingGroup.uuid'
'path' => 'uuid'
],
[
'key' => __('Name'),
'path' => 'SharingGroup.name'
'path' => 'name'
],
[
'key' => __('Releasability'),
'path' => 'SharingGroup.releasability'
'path' => 'releasability'
],
[
'key' => __('Description'),
'path' => 'SharingGroup.description'
'path' => 'description'
],
[
'key' => __('Selectable'),
'path' => 'SharingGroup.active',
'path' => 'active',
'type' => 'boolean'
],
[
'key' => __('Created by'),
'path' => 'Organisation',
'type' => 'org'
'element' => 'org',
'path' => 'Organisation.name',
'data_path' => 'Organisation'
],
[
'key' => __('Synced by'),
'path' => 'SharingGroup.sync_org',
'type' => 'org',
'requirement' => isset($sg['SharingGroup']['sync_org'])
'element' => 'org',
'path' => 'sync_org.name',
'data_path' => 'sync_org',
'requirement' => isset($entity['sync_org'])
],
[
'key' => __('Events'),
'raw' => __n('%s event', '%s events', $sg['SharingGroup']['event_count'], $sg['SharingGroup']['event_count']),
'url' => sprintf('/events/index/searchsharinggroup:%s', h($sg['SharingGroup']['id']))
'raw' => __n('{0} event', '{0} events', $entity['event_count'], $entity['event_count']),
'url' => sprintf('/events/index/searchsharinggroup:%s', h($entity['id']))
],
[
'key' => __('Organisations'),
'type' => 'custom',
'requirement' => isset($sg['SharingGroupOrg']),
'requirement' => isset($entity['SharingGroupOrg']),
'function' => function (array $sharingGroup) {
echo sprintf(
'<div class="span6">
@ -66,7 +67,8 @@ echo $this->element(
);
foreach ($sharingGroup['SharingGroupOrg'] as $sgo) {
echo '<tr>';
echo sprintf('<td>%s</td>', $this->OrgImg->getNameWithImg($sgo));
// TODO: [3.x-MIGRATION]
// echo sprintf('<td>%s</td>', $this->OrgImg->getNameWithImg($sgo));
echo sprintf('<td><span class="%s"></span></td>', $sgo['Organisation']['local'] ? 'fas fa-check' : 'fas fa-times');
echo sprintf('<td><span class="%s"></span></td>', $sgo['extend'] ? 'fas fa-check' : 'fas fa-times');
echo '</tr>';
@ -78,7 +80,7 @@ echo $this->element(
[
'key' => __('Instances'),
'type' => 'custom',
'requirement' => isset($sg['SharingGroupServer']),
'requirement' => isset($entity['SharingGroupServer']),
'function' => function (array $sharingGroup) {
echo sprintf(
'<div class="span6">
@ -92,11 +94,11 @@ echo $this->element(
__('URL'),
__('All orgs')
);
foreach ($sharingGroup['SharingGroupServer'] as $sgs) {
foreach ($sharingGroup['SharingGroupServer'] as $entitys) {
echo '<tr>';
echo sprintf('<td>%s</td>', h($sgs['Server']['name']));
echo sprintf('<td>%s</td>', h($sgs['Server']['url']));
echo sprintf('<td><span class="%s"></span></td>', $sgs['all_orgs'] ? 'fas fa-check' : 'fas fa-times');
echo sprintf('<td>%s</td>', h($entitys['Server']['name']));
echo sprintf('<td>%s</td>', h($entitys['Server']['url']));
echo sprintf('<td><span class="%s"></span></td>', $entitys['all_orgs'] ? 'fas fa-check' : 'fas fa-times');
echo '</tr>';
}
echo '</table>