mirror of https://github.com/MISP/MISP
chg: [clusterRelations] Model linking and basic index
parent
c0150edfa7
commit
23d24c3c9e
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
App::uses('AppController', 'Controller');
|
||||
|
||||
class GalaxyClusterRelationsController extends AppController
|
||||
{
|
||||
public $components = array('Session', 'RequestHandler');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 60,
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
|
||||
'recursive' => -1,
|
||||
'order' => array(
|
||||
// 'GalaxyCluster.value' => 'ASC'
|
||||
),
|
||||
'contain' => array(
|
||||
)
|
||||
);
|
||||
|
||||
public function index()
|
||||
{
|
||||
$filters = $this->IndexFilter->harvestParameters(array('context', 'searchall'));
|
||||
$aclConditions = $this->GalaxyClusterRelation->buildConditions($this->Auth->user());
|
||||
$contextConditions = array();
|
||||
if (empty($filters['context'])) {
|
||||
$filters['context'] = 'all';
|
||||
} else {
|
||||
$contextConditions = array();
|
||||
if ($filters['context'] == 'default') {
|
||||
$contextConditions = array(
|
||||
'GalaxyClusterRelation.default' => true
|
||||
);
|
||||
} elseif ($filters['context'] == 'custom') {
|
||||
$contextConditions = array(
|
||||
'GalaxyClusterRelation.default' => false
|
||||
);
|
||||
} elseif ($filters['context'] == 'org') {
|
||||
$contextConditions = array(
|
||||
'GalaxyClusterRelation.org_id' => $this->Auth->user('org_id')
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->set('passedArgsArray', array('context' => $filters['context'], 'searchall' => isset($filters['searchall']) ? $filters['searchall'] : ''));
|
||||
$this->set('context', $filters['context']);
|
||||
$searchConditions = array();
|
||||
if (empty($filters['searchall'])) {
|
||||
$filters['searchall'] = '';
|
||||
}
|
||||
if (strlen($filters['searchall']) > 0) {
|
||||
$searchall = '%' . strtolower($filters['searchall']) . '%';
|
||||
$searchConditions = array(
|
||||
'OR' => array(
|
||||
'LOWER(GalaxyClusterRelation.referenced_galaxy_cluster_type) LIKE' => $searchall,
|
||||
'LOWER(GalaxyCluster.value) LIKE' => $searchall,
|
||||
'LOWER(ReferencedGalaxyCluster.value) LIKE' => $searchall,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->_isRest()) {
|
||||
$relations = $this->GalaxyClusterRelation->find('all',
|
||||
array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array(
|
||||
'AND' => array($contextConditions, $searchConditions, $aclConditions)
|
||||
),
|
||||
'contain' => array('Org', 'Orgc', 'SharingGroup', 'GalaxyCluster', 'ReferencedGalaxyCluster', 'GalaxyClusterRelationTag' => array('Tag'))
|
||||
)
|
||||
);
|
||||
return $this->RestResponse->viewData($relations, $this->response->type());
|
||||
} else {
|
||||
$this->paginate['conditions']['AND'][] = $contextConditions;
|
||||
$this->paginate['conditions']['AND'][] = $searchConditions;
|
||||
$this->paginate['conditions']['AND'][] = $aclConditions;
|
||||
$this->paginate['contain'] = array_merge($this->paginate['contain'], array('Org', 'Orgc', 'SharingGroup', 'GalaxyCluster', 'ReferencedGalaxyCluster', 'GalaxyClusterRelationTag' => array('Tag')));
|
||||
$relations = $this->paginate();
|
||||
$this->loadModel('SharingGroup');
|
||||
$sgs = $this->SharingGroup->fetchAllAuthorised($this->Auth->user());
|
||||
$this->loadModel('Attribute');
|
||||
$distributionLevels = $this->Attribute->distributionLevels;
|
||||
unset($distributionLevels[5]);
|
||||
$this->set('distributionLevels', $distributionLevels);
|
||||
$this->set('data', $relations);
|
||||
}
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1384,8 +1384,15 @@ class AppModel extends Model
|
|||
$sqlArray[] = "ALTER TABLE `galaxy_clusters` ADD `extends_version` int(11) DEFAULT 0;";
|
||||
$sqlArray[] = "ALTER TABLE `roles` ADD `perm_galaxy_editor` tinyint(1) NOT NULL DEFAULT 0;";
|
||||
$sqlArray[] = "UPDATE `roles` SET `perm_galaxy_editor`=1 WHERE `perm_tag_editor`=1;";
|
||||
$sqlArray[] = "UPDATE `galaxy_clusters` SET `distribution`=3, `default`=1;";
|
||||
$sqlArray[] = "UPDATE `galaxy_clusters` SET `distribution`=3, `default`=1 WHERE `org_id`=0;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_reference` RENAME `galaxy_cluster_relations`;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `distribution` tinyint(4) NOT NULL DEFAULT 0;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `sharing_group_id` int(11);";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `org_id` int(11) NOT NULL;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `orgc_id` int(11) NOT NULL;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `default` tinyint(1) NOT NULL DEFAULT 0;";
|
||||
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `locked` tinyint(1) NOT NULL DEFAULT 0;";
|
||||
$sqlArray[] = "UPDATE `galaxy_cluster_relations` SET `distribution`=3, `default`=1 WHERE `org_id`=0;";
|
||||
$sqlArray[] = "CREATE TABLE IF NOT EXISTS `galaxy_cluster_relation_tags` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`galaxy_cluster_relation_id` int(11) NOT NULL,
|
||||
|
|
|
@ -33,8 +33,8 @@ class GalaxyCluster extends AppModel
|
|||
)
|
||||
),
|
||||
'distribution' => array(
|
||||
'rule' => array('inList', array('0', '1', '2', '3', '4', '5')),
|
||||
'message' => 'Options: Your organisation only, This community only, Connected communities, All communities, Sharing group, Inherit event',
|
||||
'rule' => array('inList', array('0', '1', '2', '3', '4')),
|
||||
'message' => 'Options: Your organisation only, This community only, Connected communities, All communities, Sharing group',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
|
|
@ -12,12 +12,51 @@ class GalaxyClusterRelation extends AppModel
|
|||
);
|
||||
|
||||
public $validate = array(
|
||||
'referenced_galaxy_cluster_type' => array(
|
||||
'stringNotEmpty' => array(
|
||||
'rule' => array('stringNotEmpty')
|
||||
)
|
||||
),
|
||||
'referenced_galaxy_cluster_uuid' => array(
|
||||
'uuid' => array(
|
||||
'rule' => array('custom', '/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/'),
|
||||
'message' => 'Please provide a valid UUID'
|
||||
),
|
||||
'unique' => array(
|
||||
'rule' => 'isUnique',
|
||||
'message' => 'The UUID provided is not unique',
|
||||
'required' => 'create'
|
||||
)
|
||||
),
|
||||
'distribution' => array(
|
||||
'rule' => array('inList', array('0', '1', '2', '3', '4')),
|
||||
'message' => 'Options: Your organisation only, This community only, Connected communities, All communities, Sharing group',
|
||||
'required' => true
|
||||
)
|
||||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
'GalaxyCluster' => array(
|
||||
'className' => 'GalaxyCluster',
|
||||
'foreignKey' => 'galaxy_cluster_id',
|
||||
),
|
||||
'ReferencedGalaxyCluster' => array(
|
||||
'className' => 'GalaxyCluster',
|
||||
'foreignKey' => 'referenced_galaxy_cluster_id',
|
||||
),
|
||||
'Org' => array(
|
||||
'className' => 'Organisation',
|
||||
'foreignKey' => 'org_id',
|
||||
'conditions' => array('GalaxyClusterRelation.org_id !=' => 0),
|
||||
),
|
||||
'Orgc' => array(
|
||||
'className' => 'Organisation',
|
||||
'foreignKey' => 'orgc_id',
|
||||
'conditions' => array('GalaxyClusterRelation.orgc_id !=' => 0),
|
||||
),
|
||||
'SharingGroup' => array(
|
||||
'className' => 'SharingGroup',
|
||||
'foreignKey' => 'sharing_group_id'
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -31,6 +70,31 @@ class GalaxyClusterRelation extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
public function buildConditions($user)
|
||||
{
|
||||
$this->Event = ClassRegistry::init('Event');
|
||||
$conditions = array();
|
||||
if (!$user['Role']['perm_site_admin']) {
|
||||
$sgids = $this->Event->cacheSgids($user, true);
|
||||
$conditions['AND']['OR'] = array(
|
||||
'GalaxyClusterRelation.org_id' => $user['org_id'],
|
||||
array(
|
||||
'AND' => array(
|
||||
'GalaxyClusterRelation.distribution >' => 0,
|
||||
'GalaxyClusterRelation.distribution <' => 4
|
||||
),
|
||||
),
|
||||
array(
|
||||
'AND' => array(
|
||||
'GalaxyClusterRelation.sharing_group_id' => $sgids,
|
||||
'GalaxyClusterRelation.distribution' => 4
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
public function getExistingRelationships()
|
||||
{
|
||||
$existingRelationships = $this->find('list', array(
|
||||
|
|
|
@ -20,8 +20,12 @@ class GalaxyClusterRelationTag extends AppModel
|
|||
);
|
||||
|
||||
public $belongsTo = array(
|
||||
'GalaxyClusterRelation',
|
||||
'Tag'
|
||||
'GalaxyClusterRelation' => array(
|
||||
'className' => 'GalaxyClusterRelation',
|
||||
),
|
||||
'Tag' => array(
|
||||
'className' => 'Tag',
|
||||
),
|
||||
);
|
||||
|
||||
public function afterSave($created, $options = array())
|
||||
|
|
|
@ -1145,6 +1145,10 @@
|
|||
'url' => '/galaxies/index',
|
||||
'text' => __('List Galaxies')
|
||||
));
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'url' => '/galaxy_cluster_relations/index',
|
||||
'text' => __('List Relationships')
|
||||
));
|
||||
if ($isSiteAdmin) {
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_divider');
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_post_link', array(
|
||||
|
@ -1237,6 +1241,27 @@
|
|||
}
|
||||
break;
|
||||
|
||||
case 'galaxy_cluster_relations':
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'element_id' => 'galaxy_index',
|
||||
'url' => '/galaxies/index',
|
||||
'text' => __('List Galaxies')
|
||||
));
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'element_id' => 'index',
|
||||
'url' => '/galaxy_cluster_relations/index',
|
||||
'text' => __('List Relationships')
|
||||
));
|
||||
if ($hostOrgUser) {
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_divider');
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'element_id' => 'view',
|
||||
'url' => '/galaxy_cluster_relations/add/',
|
||||
'text' => __('Add Relationships')
|
||||
));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'objectTemplates':
|
||||
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
|
||||
'url' => '/objectTemplates/index',
|
||||
|
|
|
@ -97,7 +97,11 @@
|
|||
array(
|
||||
'text' => __('List Galaxies'),
|
||||
'url' => '/galaxies/index'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'text' => __('List Relationships'),
|
||||
'url' => '/galaxy_cluster_relations/index'
|
||||
),
|
||||
)
|
||||
),
|
||||
array(
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
array(
|
||||
'active' => $context === 'custom',
|
||||
'url' => sprintf('%s/galaxies/view/%s/context:custom', $baseurl, $galaxy_id),
|
||||
'text' => __('Custom Galaxy Clusters'),
|
||||
'text' => __('All Custom Galaxy Clusters'),
|
||||
),
|
||||
array(
|
||||
'active' => $context === 'org',
|
||||
|
|
Loading…
Reference in New Issue