chg: [clusterRelations:edit] Make edit works again and improved error

reporting
pull/6120/head
mokaddem 2020-05-25 16:10:00 +02:00
parent 9ba5bc186f
commit 79064d0eb8
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 48 additions and 23 deletions

View File

@ -178,11 +178,11 @@ class GalaxyClusterRelationsController extends AppController
$clusterSource = $clusters['clusterSource'];
$errors = array();
if (!$user['Role']['perm_galaxy_editor']) {
if (!$this->Auth->user()['Role']['perm_galaxy_editor']) {
$errors = array(__('Invalid permssions'));
}
if ($user['Role']['perm_site_admin'] || $clusterSource['GalaxyCluster']['org_id'] != $this->Auth->user()['org_id']) {
if ($this->Auth->user()['Role']['perm_site_admin'] || $clusterSource['GalaxyCluster']['org_id'] != $this->Auth->user()['org_id']) {
$errors = $this->GalaxyClusterRelation->editRelation($this->Auth->user(), $relation);
} else {
$errors = array(__('Only the owner organisation of the source cluster can use it as a source'));
@ -203,7 +203,7 @@ class GalaxyClusterRelationsController extends AppController
// $this->redirect(array('action' => 'index'));
$this->redirect($this->referer());
} else {
$message .= __(' Reason: %s', json_encode($this->GalaxyClusterRelation->validationErrors, true));
$message .= __(' Reason: %s', json_encode(array_merge($errors, $this->GalaxyClusterRelation->validationErrors), true));
$this->Flash->error($message);
}
}
@ -248,16 +248,16 @@ class GalaxyClusterRelationsController extends AppController
{
// Fetch cluster source and adapt IDs
$conditions = array();
$conditions['GalaxyCluster.uuid'] = $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'];
$clusterSource = $this->GalaxyClusterRelation->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => $conditions), false);
$conditions['uuid'] = $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'];
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => $conditions), false);
if (empty($clusterSource)) {
throw new NotFoundException('Source cluster not found.');
}
$clusterSource = $clusterSource[0];
// Fetch cluster target and adapt IDs
$conditions['GalaxyCluster.uuid'] = $relation['GalaxyClusterRelation']['referenced_galaxy_cluster_uuid'];
$clusterTarget = $this->GalaxyClusterRelation->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => $conditions), false);
$conditions['uuid'] = $relation['GalaxyClusterRelation']['referenced_galaxy_cluster_uuid'];
$clusterTarget = $this->GalaxyClusterRelation->TargetCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => $conditions), false);
if (empty($clusterTarget)) {
throw new NotFoundException('Target cluster not found.');
}

View File

@ -173,6 +173,7 @@ class Galaxy extends AppModel
$cluster_to_save['description'] = '';
}
$cluster_to_save['distribution'] = 3;
$cluster_to_save['default'] = true;
$result = $this->GalaxyCluster->save($cluster_to_save, false);
$galaxyClusterId = $this->GalaxyCluster->id;
if (isset($cluster['meta'])) {
@ -201,6 +202,7 @@ class Galaxy extends AppModel
'galaxy_cluster_uuid' => $cluster['uuid'],
'referenced_galaxy_cluster_uuid' => $relation['dest-uuid'],
'referenced_galaxy_cluster_type' => $relation['type'],
'default' => true,
'tags' => $relation['tags'],
);
}

View File

@ -110,7 +110,6 @@ class GalaxyClusterRelation extends AppModel
if ($relation['GalaxyClusterRelation']['distribution'] != 4) {
unset($relation[$i]['SharingGroup']);
}
$clusters[$i] = $this->GalaxyClusterRelation->massageRelationTag($clusters[$i]);
}
return $relations;
}
@ -136,21 +135,30 @@ class GalaxyClusterRelation extends AppModel
'galaxy_cluster_uuid',
'referenced_galaxy_cluster_uuid',
'referenced_galaxy_cluster_type',
'default',
'distribution',
'sharing_group_id',
);
foreach ($relations as $k => $relation) {
$sourceCluster = $this->SourceCluster->fetchGalaxyClusters($user, array('conditions' => array('uuid' => $relation['galaxy_cluster_uuid'])));
if (empty($sourceCluster)) {
throw new NotFoundException(__('Invalid galaxy cluster'));
}
$relation['galaxy_cluster_id'] = $sourceCluster['GalaxyCluster']['id'];
if (!isset($relation['referenced_galaxy_cluster_uuid'])) {
$referencedCluster = $this->TargetCluster->fetchGalaxyClusters($user, array('conditions' => array('uuid' => $relation['referenced_galaxy_cluster_uuid'])));
if (!empty($referencedCluster)) { // do not save the relation if referenced cluster does not exists
$referencedCluster = $referencedCluster[0];
$relation['referenced_galaxy_cluster_uuid'] = $referencedCluster['GalaxyCluster']['uuid'];
$targetCluster = $this->TargetCluster->fetchGalaxyClusters($user, array('conditions' => array('uuid' => $relation['referenced_galaxy_cluster_uuid'])));
if (!empty($targetCluster)) { // do not save the relation if referenced cluster does not exists
$targetCluster = $targetCluster[0];
$relation['referenced_galaxy_cluster_uuid'] = $targetCluster['GalaxyCluster']['uuid'];
$relation['referenced_galaxy_cluster_id'] = $targetCluster['GalaxyCluster']['id'];
$this->create();
$saveResult = $this->save($relation, array('fieldList' => $fieldList));
if ($saveResult) {
$savedId = $this->id;
$this->GalaxyClusterRelationTag->attachTags($user, $savedId, $relation['tags']);
}
} else {
throw new NotFoundException(__('Invalid referenced galaxy cluster'));
}
}
}
@ -217,28 +225,43 @@ class GalaxyClusterRelation extends AppModel
$errors[] = __('Unkown ID');
} else {
$options = array('conditions' => array(
'GalaxyCluster.uuid' => $relations['GalaxyClusterRelation']['galaxy_cluster_uuid']
'uuid' => $relation['GalaxyClusterRelation']['galaxy_cluster_uuid']
));
$cluster = $this->SourceCluster->fetchGalaxyClusters($user, $options);
if (empty($cluster)) {
$errors[] = __('Source cluster not found');
$errors[] = __('Invalid source galaxy cluster');
}
$cluster = $cluster[0];
$relation['GalaxyClusterRelation']['id'] = $existingRelation['GalaxyClusterRelation']['id'];
$relation['GalaxyClusterRelation']['galaxy_cluster_id'] = $cluster['SourceCluster']['id'];
$relation['GalaxyClusterRelation']['galaxy_cluster_uuid'] = $cluster['SourceCluster']['uuid'];
if (isset($relation['GalaxyClusterRelation']['distribution']) && $relation['GalaxyClusterRelation']['distribution'] == 4 && !$this->SharingGroup->checkIfAuthorised($user, $relation['GalaxyClusterRelation']['sharing_group_id'])) {
$errors[] = array(__('Galaxy Cluster Relation could not be saved: The user has to have access to the sharing group in order to be able to edit it.'));
}
if ($cluster['SourceCluster']['org_id'] != $user['org_id'] && !$user['Role']['perm_site_admin']) {
$errors[] = array(__('Relations can only be created by cluster\'s owner organisation'));
}
if (empty($errors)) {
$relation['GalaxyClusterRelation']['default'] = false;
if (empty($fieldList)) {
$fieldList = array('galaxy_cluster_uuid', 'referenced_galaxy_cluster_uuid', 'referenced_galaxy_cluster_type', 'distribution', 'sharing_group_id');
}
$saveSuccess = $this->save($relation, array('fieldList' => $fieldList));
if (!$saveSuccess) {
foreach($this->validationErrors as $validationError) {
$errors[] = $validationError[0];
$targetCluster = $this->TargetCluster->fetchGalaxyClusters($user, array('conditions' => array('uuid' => $relation['GalaxyClusterRelation']['referenced_galaxy_cluster_uuid'])));
if (empty($targetCluster)) { // do not save the relation if referenced cluster does not exists
$errors[] = array(__('Invalid referenced galaxy cluster'));
} else {
$targetCluster = $targetCluster[0];
$relation['GalaxyClusterRelation']['referenced_galaxy_cluster_id'] = $targetCluster['TargetCluster']['id'];
$relation['GalaxyClusterRelation']['referenced_galaxy_cluster_uuid'] = $targetCluster['TargetCluster']['uuid'];
$relation['GalaxyClusterRelation']['default'] = false;
if (empty($fieldList)) {
$fieldList = array('galaxy_cluster_id', 'galaxy_cluster_uuid', 'referenced_galaxy_cluster_id', 'referenced_galaxy_cluster_uuid', 'referenced_galaxy_cluster_type', 'distribution', 'sharing_group_id', 'default');
}
$saveSuccess = $this->save($relation, array('fieldList' => $fieldList));
if (!$saveSuccess) {
foreach($this->validationErrors as $validationError) {
$errors[] = $validationError[0];
}
}
}
}