chg: [galaxyCluster] Restored working behavior of `index` and `view` views

pull/6120/head
mokaddem 2020-04-15 08:46:21 +02:00
parent bde83fa39d
commit d3b837f947
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
6 changed files with 190 additions and 81 deletions

View File

@ -84,7 +84,7 @@ class GalaxiesController extends AppController
{
$id = $this->Toolbox->findIdByUuid($this->Galaxy, $id);
if (isset($this->params['named']['searchall']) && strlen($this->params['named']['searchall']) > 0) {
$this->set('passedArgsArray', array('all' => $this->params['named']['searchall']));
$this->set('passedArgsArray', array('context' => $this->params['named']['context'], 'searchall' => $this->params['named']['searchall']));
}
if ($this->_isRest()) {
$galaxy = $this->Galaxy->find('first', array(

View File

@ -34,88 +34,133 @@ class GalaxyClustersController extends AppController
public function index($id)
{
$filters = $this->IndexFilter->harvestParameters(array('context', 'searchall'));
$aclConditions = $this->GalaxyCluster->buildConditions($this->Auth->user());
$contextConditions = array();
if (empty($filters['context'])) {
$filters['context'] = 'all';
} else {
$contextConditions = array();
if ($filters['context'] == 'default') {
$contextConditions = array(
'Galaxy.default' => true
);
} elseif ($filters['context'] == 'org') {
$contextConditions = array(
'Galaxy.org_id' => $this->Auth->user('org_id')
);
} elseif ($filters['context'] == 'orgc') {
$contextConditions = array(
'Galaxy.orgc_id' => $this->Auth->user('org_id')
);
}
}
$this->set('passedArgsArray', array('context' => $filters['context'], 'searchall' => isset($filters['searchall']) ? $filters['searchall'] : ''));
$this->set('context', $filters['context']);
$this->set('searchall', isset($filters['searchall']) ? $filters['searchall'] : '');
$this->paginate['conditions'] = array('GalaxyCluster.galaxy_id' => $id);
if (isset($filters['searchall']) && strlen($filters['searchall']) > 0) {
$searchConditions = array();
if (empty($filters['searchall'])) {
$filters['searchall'] = '';
}
if (strlen($filters['searchall']) > 0) {
$searchall = '%' . strtolower($filters['searchall']) . '%';
$synonym_hits = $this->GalaxyCluster->GalaxyElement->find(
'list',
array(
'recursive' => -1,
'conditions' => array(
'LOWER(GalaxyElement.value) LIKE' => '%' . strtolower($filters['searchall']) . '%',
'LOWER(GalaxyElement.value) LIKE' => $searchall,
'GalaxyElement.key' => 'synonyms' ),
'fields' => array(
'GalaxyElement.galaxy_cluster_id')
)
);
$this->paginate['conditions'] =
array("AND" => array(
'OR' => array(
"LOWER(GalaxyCluster.value) LIKE" => '%'. strtolower($filters['searchall']) .'%',
"LOWER(GalaxyCluster.description) LIKE" => '%'. strtolower($filters['searchall']) .'%',
"GalaxyCluster.id" => array_values($synonym_hits)
$searchConditions = array(
'OR' => array(
'LOWER(GalaxyCluster.value) LIKE' => $searchall,
'LOWER(GalaxyCluster.description) LIKE' => $searchall,
'GalaxyCluster.uuid' => $filters['searchall'],
'GalaxyCluster.id' => array_values($synonym_hits),
),
);
}
$searchConditions['GalaxyCluster.galaxy_id'] = $id;
if ($this->_isRest()) {
$clusters = $this->Galaxy->find('all',
array(
// 'recursive' => -1,
'conditions' => array(
'AND' => array($contextConditions, $searchConditions, $aclConditions)
),
"GalaxyCluster.galaxy_id" => $id
));
$this->set('passedArgsArray', array('all'=>$filters['searchall']));
}
$clusters = $this->paginate();
$sgs = $this->GalaxyCluster->Tag->EventTag->Event->SharingGroup->fetchAllAuthorised($this->Auth->user());
foreach ($clusters as $k => $cluster) {
if (!empty($cluster['Tag']['id'])) {
$clusters[$k]['GalaxyCluster']['event_count'] = $this->GalaxyCluster->Tag->EventTag->countForTag($cluster['Tag']['id'], $this->Auth->user(), $sgs);
} else {
$clusters[$k]['GalaxyCluster']['event_count'] = 0;
// 'contain' => array('Org', 'Orgc')
)
);
return $this->RestResponse->viewData($galaxies, $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'));
$clusters = $this->paginate();
foreach ($clusters as $k => $cluster) {
// $clusters[$k] = $this->GalaxyCluster->attachExtendByInfo($this->Auth->user(), $clusters[$k]);
// $clusters[$k] = $this->GalaxyCluster->attachExtendFromInfo($this->Auth->user(), $clusters[$k]);
}
}
$tagIds = array();
$sightings = array();
if (!empty($clusters)) {
$galaxyType = $clusters[0]['GalaxyCluster']['type'];
foreach ($clusters as $k => $v) {
$clusters[$k]['event_ids'] = array();
if (!empty($v['Tag'])) {
$tagIds[] = $v['Tag']['id'];
$clusters[$k]['GalaxyCluster']['tag_id'] = $v['Tag']['id'];
}
$clusters[$k]['GalaxyCluster']['synonyms'] = array();
foreach ($v['GalaxyElement'] as $element) {
$clusters[$k]['GalaxyCluster']['synonyms'][] = $element['value'];
}
}
}
$this->loadModel('Sighting');
$sightings['tags'] = array();
foreach ($clusters as $k => $cluster) {
if (!empty($cluster['GalaxyCluster']['tag_id'])) {
$temp = $this->Sighting->getSightingsForTag($this->Auth->user(), $cluster['GalaxyCluster']['tag_id']);
$clusters[$k]['sightings'] = $temp;
}
}
$csv = array();
foreach ($clusters as $k => $cluster) {
$startDate = !empty($cluster['sightings']) ? min(array_keys($cluster['sightings'])) : date('Y-m-d');
$startDate = date('Y-m-d', strtotime("-3 days", strtotime($startDate)));
$to = date('Y-m-d', time());
for ($date = $startDate; strtotime($date) <= strtotime($to); $date = date('Y-m-d', strtotime("+1 day", strtotime($date)))) {
if (!isset($csv[$k])) {
$csv[$k] = 'Date,Close\n';
}
if (isset($cluster['sightings'][$date])) {
$csv[$k] .= $date . ',' . $cluster['sightings'][$date] . '\n';
$sgs = $this->GalaxyCluster->Tag->EventTag->Event->SharingGroup->fetchAllAuthorised($this->Auth->user());
foreach ($clusters as $k => $cluster) {
if (!empty($cluster['Tag']['id'])) {
$clusters[$k]['GalaxyCluster']['event_count'] = $this->GalaxyCluster->Tag->EventTag->countForTag($cluster['Tag']['id'], $this->Auth->user(), $sgs);
} else {
$csv[$k] .= $date . ',0\n';
$clusters[$k]['GalaxyCluster']['event_count'] = 0;
}
}
$tagIds = array();
$sightings = array();
if (!empty($clusters)) {
$galaxyType = $clusters[0]['GalaxyCluster']['type'];
foreach ($clusters as $k => $v) {
$clusters[$k]['event_ids'] = array();
if (!empty($v['Tag'])) {
$tagIds[] = $v['Tag']['id'];
$clusters[$k]['GalaxyCluster']['tag_id'] = $v['Tag']['id'];
}
$clusters[$k]['GalaxyCluster']['synonyms'] = array();
foreach ($v['GalaxyElement'] as $element) {
$clusters[$k]['GalaxyCluster']['synonyms'][] = $element['value'];
}
}
}
$this->loadModel('Sighting');
$sightings['tags'] = array();
foreach ($clusters as $k => $cluster) {
if (!empty($cluster['GalaxyCluster']['tag_id'])) {
$temp = $this->Sighting->getSightingsForTag($this->Auth->user(), $cluster['GalaxyCluster']['tag_id']);
$clusters[$k]['sightings'] = $temp;
}
}
$csv = array();
foreach ($clusters as $k => $cluster) {
$startDate = !empty($cluster['sightings']) ? min(array_keys($cluster['sightings'])) : date('Y-m-d');
$startDate = date('Y-m-d', strtotime("-3 days", strtotime($startDate)));
$to = date('Y-m-d', time());
for ($date = $startDate; strtotime($date) <= strtotime($to); $date = date('Y-m-d', strtotime("+1 day", strtotime($date)))) {
if (!isset($csv[$k])) {
$csv[$k] = 'Date,Close\n';
}
if (isset($cluster['sightings'][$date])) {
$csv[$k] .= $date . ',' . $cluster['sightings'][$date] . '\n';
} else {
$csv[$k] .= $date . ',0\n';
}
}
}
$this->loadModel('Attribute');
$distributionLevels = $this->Attribute->distributionLevels;
unset($distributionLevels[5]);
$this->set('distributionLevels', $distributionLevels);
$this->set('csv', $csv);
$this->set('list', $clusters);
$this->set('galaxy_id', $id);
}
$this->set('csv', $csv);
$this->set('list', $clusters);
$this->set('galaxy_id', $id);
if ($this->request->is('ajax')) {
$this->layout = 'ajax';
$this->render('ajax/index');
@ -130,10 +175,15 @@ class GalaxyClustersController extends AppController
} else {
$conditions['GalaxyCluster.id'] = $id;
}
$contain = array('Galaxy');
if ($this->_isRest()) {
$contain[] = 'GalaxyElement';
}
$options = array(
'conditions' => $conditions
'conditions' => $conditions,
'contain' => $contain
);
$cluster = $this->fetchGalaxyClusters($this->Auth->user(), $options, $full=true);
$cluster = $this->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), $options, $full=true);
if (!empty($cluster)) {
$cluster = $cluster[0];
$galaxyType = $cluster['GalaxyCluster']['type'];
@ -159,7 +209,7 @@ class GalaxyClustersController extends AppController
return $this->RestResponse->viewData(array('GalaxyCluster' => $cluster['GalaxyCluster']), $this->response->type());
} else {
$this->set('id', $id);
$this->set('galaxy_id', $cluster['Galaxy']['id']);
$this->set('galaxy_id', $cluster['GalaxyCluster']['galaxy_id']);
$this->set('cluster', $cluster);
}
}

View File

@ -11,6 +11,32 @@ class GalaxyCluster extends AppModel
);
public $validate = array(
'name' => array(
'stringNotEmpty' => array(
'rule' => array('stringNotEmpty')
)
),
'description' => array(
'stringNotEmpty' => array(
'rule' => array('stringNotEmpty')
)
),
'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', '5')),
'message' => 'Options: Your organisation only, This community only, Connected communities, All communities, Sharing group, Inherit event',
'required' => true
)
);
public $belongsTo = array(
@ -21,6 +47,14 @@ class GalaxyCluster extends AppModel
'Tag' => array(
'foreignKey' => false,
'conditions' => array('GalaxyCluster.tag_name = Tag.name')
),
'Org' => array(
'className' => 'Organisation',
'foreignKey' => 'org_id'
),
'Orgc' => array(
'className' => 'Organisation',
'foreignKey' => 'orgc_id'
)
);
@ -226,8 +260,9 @@ class GalaxyCluster extends AppModel
'conditions' => $this->buildConditions($user),
'recursive' => -1
);
if ($full) {
$params['contain'] = array('GalaxyClusterElement');
$params['contain'] = $options['contain'];
if ($full && !in_array('GalaxyElement', $params['contain'])) {
$params['contain'][] = 'GalaxyElement';
}
if (isset($options['fields'])) {
$params['fields'] = $options['fields'];

View File

@ -12,12 +12,7 @@
'active' => $context === 'all',
'url' => $baseurl . '/galaxies/index/context:all',
'text' => __('All'),
),
// array(
// 'active' => $context === 'altered',
// 'url' => $baseurl . '/galaxies/index/context:altered',
// 'text' => __('Altered Galaxies'),
// )
)
)
),
array(

View File

@ -33,8 +33,11 @@
$(document).ready(function () {
<?php
$uri = "/galaxy_clusters/index/" . $galaxy['Galaxy']['id'];
if (isset($passedArgsArray)) {
$uri .= '/searchall:' . $passedArgsArray['all'];
if (isset($passedArgsArray) && isset($passedArgsArray['context'])) {
$uri .= '/context:' . $passedArgsArray['context'];
}
if (isset($passedArgsArray) && isset($passedArgsArray['searchall'])) {
$uri .= '/searchall:' . $passedArgsArray['searchall'];
}
?>
$.get("<?php echo h($uri);?>", function(data) {

View File

@ -16,9 +16,9 @@
'text' => __('All'),
),
array(
'active' => $context === 'custom',
'url' => sprintf('%s/galaxies/view/%s/context:custom', $baseurl, $galaxy_id),
'text' => __('Custom Galaxy Clusters'),
'active' => $context === 'org',
'url' => sprintf('%s/galaxies/view/%s/context:org', $baseurl, $galaxy_id),
'text' => __('My Galaxy Clusters'),
)
)
),
@ -27,8 +27,6 @@
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'searchall',
'value' => $searchall
)
)
),
@ -45,9 +43,37 @@
array(
'name' => __('Synonyms'),
'sort' => 'name',
'class' => 'short',
'class' => '',
'data_path' => 'GalaxyCluster.synonyms',
),
array(
'name' => __('Owner Org'),
'class' => 'short',
'element' => 'org',
'data_path' => 'Org',
'fields' => array(
'allow_picture' => true,
'default_org' => 'MISP'
),
'requirement' => $isSiteAdmin || (Configure::read('MISP.showorgalternate') && Configure::read('MISP.showorg'))
),
array(
'name' => __('Creator Org'),
'class' => 'short',
'element' => 'org',
'data_path' => 'Orgc',
'fields' => array(
'allow_picture' => true,
'default_org' => 'MISP'
),
'requirement' => (Configure::read('MISP.showorg') || $isAdmin) || (Configure::read('MISP.showorgalternate') && Configure::read('MISP.showorg'))
),
array(
'name' => __('Default'),
'class' => 'short',
'element' => 'boolean',
'data_path' => 'GalaxyCluster.default',
),
array(
'name' => __('Activity'),
'class' => 'short',