mirror of https://github.com/MISP/MISP
chg: [galaxyCluster:fetchIfAuthorized] Renamed function
checkAuthorization into fetchIfAuthorizedpull/6120/head
parent
ac44422b04
commit
b235a9a825
|
@ -124,7 +124,7 @@ class GalaxyClusterRelationsController extends AppController
|
|||
$relation['GalaxyClusterRelation']['sharing_group_id'] = null;
|
||||
}
|
||||
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->checkAuthorization($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=false, $full=false);
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->fetchIfAuthorized($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=false, $full=false);
|
||||
if (isset($clusterSource['authorized']) && !$clusterSource['authorized']) {
|
||||
$errors = array($clusterSource['error']);
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ class GalaxyClusterRelationsController extends AppController
|
|||
$relation['GalaxyClusterRelation']['sharing_group_id'] = null;
|
||||
}
|
||||
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->checkAuthorization($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=false, $full=false);
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->fetchIfAuthorized($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=false, $full=false);
|
||||
if (isset($clusterSource['authorized']) && !$clusterSource['authorized']) {
|
||||
$errors = array($clusterSource['error']);
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ class GalaxyClusterRelationsController extends AppController
|
|||
throw new NotFoundException(__('Relation not found.'));
|
||||
}
|
||||
$relation = $relation[0];
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->checkAuthorization($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=true, $full=false);
|
||||
$clusterSource = $this->GalaxyClusterRelation->SourceCluster->fetchIfAuthorized($this->Auth->user(), $relation['GalaxyClusterRelation']['galaxy_cluster_uuid'], array('edit', 'publish'), $throwErrors=true, $full=false);
|
||||
$result = $this->GalaxyClusterRelation->delete($id, true);
|
||||
if ($result) {
|
||||
$this->GalaxyClusterRelation->SourceCluster->unpublish($clusterSource['SourceCluster']['id']);
|
||||
|
|
|
@ -350,7 +350,7 @@ class GalaxyClustersController extends AppController
|
|||
|
||||
public function edit($id)
|
||||
{
|
||||
$cluster = $this->GalaxyCluster->checkAuthorization($this->Auth->user(), $id, 'edit', $throwErrors=true, $full=true);
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $id, 'edit', $throwErrors=true, $full=true);
|
||||
if ($cluster['GalaxyCluster']['default']) {
|
||||
throw new MethodNotAllowedException('Default galaxy cluster cannot be edited');
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ class GalaxyClustersController extends AppController
|
|||
|
||||
public function publish($clusterId)
|
||||
{
|
||||
$cluster = $this->GalaxyCluster->checkAuthorization($this->Auth->user(), $clusterId, 'publish', $throwErrors=true, $full=false);
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $clusterId, 'publish', $throwErrors=true, $full=false);
|
||||
if ($cluster['GalaxyCluster']['published']) {
|
||||
throw new MethodNotAllowedException(__('You can\'t publish a galaxy cluster that is already published'));
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ class GalaxyClustersController extends AppController
|
|||
|
||||
public function unpublish($clusterId)
|
||||
{
|
||||
$cluster = $this->GalaxyCluster->checkAuthorization($this->Auth->user(), $clusterId, 'publish', $throwErrors=true, $full=false);
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $clusterId, 'publish', $throwErrors=true, $full=false);
|
||||
if (!$cluster['GalaxyCluster']['published']) {
|
||||
throw new MethodNotAllowedException(__('You can\'t unpublish a galaxy cluster that is not published'));
|
||||
}
|
||||
|
@ -706,7 +706,7 @@ class GalaxyClustersController extends AppController
|
|||
{
|
||||
if ($this->request->is('post')) {
|
||||
$result = false;
|
||||
$cluster = $this->GalaxyCluster->checkAuthorization($this->Auth->user(), $id, 'delete', $throwErrors=true, $full=false);
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $id, 'delete', $throwErrors=true, $full=false);
|
||||
if (!empty($cluster)) {
|
||||
$result = $this->GalaxyCluster->delete($id, true);
|
||||
$galaxy_id = $cluster['GalaxyCluster']['galaxy_id'];
|
||||
|
@ -863,7 +863,7 @@ class GalaxyClustersController extends AppController
|
|||
|
||||
public function updateCluster($clusterId)
|
||||
{
|
||||
$cluster = $this->GalaxyCluster->checkAuthorization($this->Auth->user(), $clusterId, 'edit', $throwErrors=true, $full=true);
|
||||
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $clusterId, 'edit', $throwErrors=true, $full=true);
|
||||
if ($cluster['GalaxyCluster']['default']) {
|
||||
throw new MethodNotAllowedException(__('Default galaxy cluster cannot be updated'));
|
||||
}
|
||||
|
|
|
@ -1121,12 +1121,12 @@ class GalaxyCluster extends AppModel
|
|||
throw new NotFoundException(__('Invalid galaxy cluster'));
|
||||
}
|
||||
$conditions = array('conditions' => array("${alias}.id" => $clusterId));
|
||||
$cluster = $this->fetchGalaxyClusters($user, $conditions, $full);
|
||||
$cluster = $this->fetchGalaxyClusters($user, $conditions, $full=$full);
|
||||
return $cluster;
|
||||
}
|
||||
|
||||
|
||||
public function checkAuthorization($user, $cluster, $authorizations, $throwErrors=true, $full=false)
|
||||
public function fetchIfAuthorized($user, $cluster, $authorizations, $throwErrors=true, $full=false)
|
||||
{
|
||||
$authorizations = is_array($authorizations) ? $authorizations : array($authorizations);
|
||||
$possibleAuthorizations = array('view', 'edit', 'delete', 'publish');
|
||||
|
|
Loading…
Reference in New Issue