mirror of https://github.com/MISP/MISP
fix: [galaxyCluster] Make sure we correctly update cluster relations and few QoL fixes
parent
c664a32478
commit
543dcca00a
|
@ -312,10 +312,10 @@ class GalaxyClustersController extends AppController
|
|||
$cluster['GalaxyCluster']['extends_version'] = $extendedCluster[0]['GalaxyCluster']['version'];
|
||||
}
|
||||
} else {
|
||||
$cluster['GalaxyCluster']['extends_uuid'] = '';
|
||||
$cluster['GalaxyCluster']['extends_uuid'] = null;
|
||||
}
|
||||
} else {
|
||||
$cluster['GalaxyCluster']['extends_uuid'] = '';
|
||||
$cluster['GalaxyCluster']['extends_uuid'] = null;
|
||||
}
|
||||
if ($cluster['GalaxyCluster']['distribution'] != 4) {
|
||||
$cluster['GalaxyCluster']['sharing_group_id'] = null;
|
||||
|
|
|
@ -70,6 +70,7 @@ class GalaxyCluster extends AppModel
|
|||
);
|
||||
|
||||
private $__clusterCache = array();
|
||||
private $deleteClusterUUID;
|
||||
|
||||
public $hasMany = array(
|
||||
'GalaxyElement' => array('dependent' => true),
|
||||
|
@ -154,24 +155,32 @@ class GalaxyCluster extends AppModel
|
|||
public function afterDelete()
|
||||
{
|
||||
// Remove all relations IDs now that the cluster is unkown
|
||||
parent::afterDelete();
|
||||
$cluster = $this->data[$this->alias];
|
||||
$cluster = $this->fetchAndSetUUID($cluster);
|
||||
$this->GalaxyClusterRelation->updateAll(
|
||||
array('GalaxyClusterRelation.referenced_galaxy_cluster_id' => 0),
|
||||
array('GalaxyClusterRelation.referenced_galaxy_cluster_uuid' => $cluster['uuid'])
|
||||
);
|
||||
if (!empty($this->deletedClusterUUID)) {
|
||||
$this->GalaxyClusterRelation->updateAll(
|
||||
array('GalaxyClusterRelation.referenced_galaxy_cluster_id' => 0),
|
||||
array('GalaxyClusterRelation.referenced_galaxy_cluster_uuid' => $this->deletedClusterUUID)
|
||||
);
|
||||
$this->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $this->id));
|
||||
$this->GalaxyClusterRelation->deleteAll(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $this->deletedClusterUUID));
|
||||
}
|
||||
}
|
||||
|
||||
public function beforeDelete($cascade = true)
|
||||
{
|
||||
$this->GalaxyElement->deleteAll(array('GalaxyElement.galaxy_cluster_id' => $this->id));
|
||||
$this->GalaxyClusterRelation->deleteAll(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $this->uuid));
|
||||
$cluster = $this->find('first', array(
|
||||
'conditions' => array('id' => $this->id),
|
||||
'fields' => array('uuid'),
|
||||
));
|
||||
if (!empty($cluster)) {
|
||||
$this->deletedClusterUUID = $cluster[$this->alias]['uuid'];
|
||||
} else {
|
||||
$this->deletedClusterUUID = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function arrangeData($cluster)
|
||||
{
|
||||
$models = array('Galaxy', 'GalaxyElement', 'GalaxyClusterRelation', 'Org', 'Orgc', 'TargetingClusterRelation');
|
||||
$models = array('Galaxy', 'SharingGroup', 'GalaxyElement', 'GalaxyClusterRelation', 'Org', 'Orgc', 'TargetingClusterRelation');
|
||||
foreach ($models as $model) {
|
||||
if (isset($cluster[$model])) {
|
||||
$cluster['GalaxyCluster'][$model] = $cluster[$model];
|
||||
|
@ -239,10 +248,15 @@ class GalaxyCluster extends AppModel
|
|||
if (!isset($cluster['GalaxyCluster']['published'])) {
|
||||
$cluster['GalaxyCluster']['published'] = false;
|
||||
}
|
||||
$forkedCluster = $this->find('first', array('conditions' => array('GalaxyCluster.uuid' => $cluster['GalaxyCluster']['extends_uuid'])));
|
||||
if (!empty($forkedCluster) && $forkedCluster['GalaxyCluster']['galaxy_id'] != $galaxy['id']) {
|
||||
$errors[] = __('Cluster forks always have to belong to the same galaxy as the parent');
|
||||
return $errors;
|
||||
if (!empty($cluster['GalaxyCluster']['extends_uuid'])) {
|
||||
|
||||
$forkedCluster = $this->find('first', array('conditions' => array('GalaxyCluster.uuid' => $cluster['GalaxyCluster']['extends_uuid'])));
|
||||
if (!empty($forkedCluster) && $forkedCluster['GalaxyCluster']['galaxy_id'] != $galaxy['id']) {
|
||||
$errors[] = __('Cluster forks always have to belong to the same galaxy as the parent');
|
||||
return $errors;
|
||||
}
|
||||
} else {
|
||||
$cluster['GalaxyCluster']['extends_version'] = null;
|
||||
}
|
||||
$cluster['GalaxyCluster']['org_id'] = $user['Organisation']['id'];
|
||||
$cluster['GalaxyCluster']['orgc_id'] = $user['Organisation']['id'];
|
||||
|
|
|
@ -47,7 +47,10 @@
|
|||
$table_data[] = array('key' => __('Collection UUID'), 'value' => $cluster['GalaxyCluster']['collection_uuid']);
|
||||
$table_data[] = array('key' => __('Source'), 'value' => $cluster['GalaxyCluster']['source']);
|
||||
$table_data[] = array('key' => __('Authors'), 'value' => !empty($cluster['GalaxyCluster']['authors']) ? implode(', ', $cluster['GalaxyCluster']['authors']) : __('N/A'));
|
||||
$table_data[] = array('key' => __('Distribution'), 'element' => 'genericElements/IndexTable/Fields/distribution_levels', 'element_params' => array('row' => $cluster['GalaxyCluster'], 'field' => array('data_path' => 'distribution')));
|
||||
$table_data[] = array('key' => __('Distribution'), 'element' => 'genericElements/IndexTable/Fields/distribution_levels', 'element_params' => array(
|
||||
'row' => $cluster['GalaxyCluster'],
|
||||
'field' => array('data_path' => 'distribution')
|
||||
));
|
||||
$table_data[] = array(
|
||||
'key' => __('Owner Organisation'),
|
||||
'html' => $this->OrgImg->getOrgImg(array('name' => $cluster['GalaxyCluster']['Org']['name'], 'id' => $cluster['GalaxyCluster']['Org']['id'], 'size' => 18), true),
|
||||
|
|
Loading…
Reference in New Issue