fix: [galaxyCluster] Recursive conditions on grandparent model

pull/6120/head
mokaddem 2020-09-25 11:13:26 +02:00
parent 7d3748f403
commit 780957518d
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 28 additions and 11 deletions

View File

@ -206,7 +206,7 @@ class GalaxyClustersController extends AppController
$this->loadModel('Attribute');
$distributionLevels = $this->Attribute->distributionLevels;
$this->set('distributionLevels', $distributionLevels);
if (!$cluster['GalaxyCluster']['default'] && !$cluster['GalaxyCluster']['published']) {
if (!$cluster['GalaxyCluster']['default'] && !$cluster['GalaxyCluster']['published'] && $cluster['GalaxyCluster']['orgc_id'] == $this->Auth->user()['org_id']) {
$this->Flash->warning(__('This cluster is not published. Users will not be able to use it'));
}
}
@ -987,7 +987,7 @@ class GalaxyClustersController extends AppController
'conditions' => array(
'GalaxyClusterRelation.galaxy_cluster_uuid' => $cluster['GalaxyCluster']['uuid']
),
'contain' => array('SharingGroup', 'TargetCluster', 'GalaxyClusterRelationTag' => array('Tag'))
'contain' => array('SharingGroup', 'SourceCluster', 'TargetCluster', 'GalaxyClusterRelationTag' => array('Tag'))
));
$this->set('relations', $relations);
$this->set('tree', $tree);

View File

@ -930,14 +930,9 @@ class GalaxyCluster extends AppModel
'Galaxy',
'GalaxyElement',
'GalaxyClusterRelation' => array(
'conditions' => $this->GalaxyClusterRelation->buildConditions($user),
'conditions' => $this->GalaxyClusterRelation->buildConditions($user, false),
'GalaxyClusterRelationTag' => array('Tag'),
'SharingGroup'
),
'TargetingClusterRelation' => array(
'conditions' => $this->TargetingClusterRelation->buildConditions($user),
'GalaxyClusterRelationTag' => array('Tag'),
'SharingGroup'
'SharingGroup',
),
'Orgc',
'Org',
@ -987,6 +982,28 @@ class GalaxyCluster extends AppModel
}
}
}
if (isset($cluster['GalaxyCluster'])) {
$targetingClusterRelations = $this->TargetingClusterRelation->fetchRelations($user, array(
'contain' => array(
'GalaxyClusterRelationTag' => array('Tag'),
'SharingGroup',
'SourceCluster',
),
'conditions' => array(
'TargetingClusterRelation.referenced_galaxy_cluster_id' => $cluster['GalaxyCluster']['id']
)
));
foreach ($targetingClusterRelations as $k => $targetingClusterRelation) {
if (!empty($targetingClusterRelation['GalaxyClusterRelationTag'])) {
$targetingClusterRelation['TargetingClusterRelation']['Tag'] = Hash::extract($targetingClusterRelation['GalaxyClusterRelationTag'], '{n}.Tag');
}
if (!empty($targetingClusterRelation['SharingGroup']['id'])) {
$targetingClusterRelation['TargetingClusterRelation']['SharingGroup'] = $TargetingClusterRelation['SharingGroup'];
}
$targetingClusterRelations[$k] = $targetingClusterRelation['TargetingClusterRelation'];
}
$clusters[$i]['TargetingClusterRelation'] = $targetingClusterRelations;
}
$clusters[$i] = $this->arrangeData($clusters[$i]);
$clusters[$i] = $this->GalaxyClusterRelation->massageRelationTag($clusters[$i]);
$clusters[$i] = $this->TargetingClusterRelation->massageRelationTag($clusters[$i]);

View File

@ -74,7 +74,7 @@ class GalaxyClusterRelation extends AppModel
return $results;
}
public function buildConditions($user)
public function buildConditions($user, $clusterConditions = true)
{
$this->Event = ClassRegistry::init('Event');
$conditions = [];
@ -95,7 +95,7 @@ class GalaxyClusterRelation extends AppModel
]
]
];
$conditionsSourceCluster = $this->SourceCluster->buildConditions($user);
$conditionsSourceCluster = $clusterConditions ? $this->SourceCluster->buildConditions($user) : [];
$conditions = [
'AND' => [
$conditionsRelations,