fix: [UI] Communities

pull/8613/head
Jakub Onderka 2022-09-23 17:37:32 +02:00
parent a7bdb3e1f5
commit 4d625f87eb
5 changed files with 46 additions and 71 deletions

View File

@ -1,15 +1,13 @@
<?php
App::uses('AppController', 'Controller');
/**
* @property Community $Community
*/
class CommunitiesController extends AppController
{
public $components = array('Session', 'RequestHandler');
public function beforeFilter()
{
parent::beforeFilter();
}
public $paginate = array(
'limit' => 60,
'maxLimit' => 9999

View File

@ -4,37 +4,20 @@ class Community extends AppModel
{
public $useTable = false;
public $recursive = -1;
public $actsAs = array(
'Containable',
);
public $validate = array(
);
public function beforeValidate($options = array())
{
parent::beforeValidate();
return true;
}
/**
* @param string $context
* @param string|null $value
* @return array
*/
public function getCommunityList($context, $value)
{
$community_file = new File(APP . 'files/community-metadata/defaults.json');
if (!$community_file->exists()) {
throw new NotFoundException(__('Default community list not found.'));
}
$community_list = $community_file->read();
if (empty($community_list)) {
throw new NotFoundException(__('Default community list empty.'));
}
try {
$community_list = json_decode($community_list, true);
$community_list = FileAccessTool::readJsonFromFile(APP . 'files/community-metadata/defaults.json');
} catch (Exception $e) {
throw new NotFoundException(__('Default community list not in the expected format.'));
}
$fieldsToCheck = array('name', 'uuid', 'description', 'url', 'sector', 'nationality', 'type', 'org_uuid', 'org_name');
$fieldsToCheck = ['name', 'uuid', 'description', 'url', 'sector', 'nationality', 'type', 'org_uuid', 'org_name'];
foreach ($community_list as $k => $v) {
if ($v['misp_project_vetted'] === ($context === 'vetted')) {
$community_list[$k]['id'] = $k + 1;
@ -44,11 +27,12 @@ class Community extends AppModel
continue;
}
if (!empty($value)) {
$value = mb_strtolower($value);
$found = false;
foreach ($fieldsToCheck as $field) {
if (strpos(strtolower($v[$field]), $value) !== false) {
if (strpos(mb_strtolower($v[$field]), $value) !== false) {
$found = true;
continue;
break;
}
}
if (!$found) {
@ -56,42 +40,32 @@ class Community extends AppModel
}
}
}
$community_list = array_values($community_list);
return $community_list;
return array_values($community_list);
}
/**
* @param int|string $id Community ID or UUID
* @return array
*/
public function getCommunity($id)
{
$community_file = new File(APP . 'files/community-metadata/defaults.json');
if (!$community_file->exists()) {
throw new NotFoundException(__('Default community list not found.'));
}
$community_list = $community_file->read();
if (empty($community_list)) {
throw new NotFoundException(__('Default community list empty.'));
}
try {
$community_list = json_decode($community_list, true);
$community_list = FileAccessTool::readJsonFromFile(APP . 'files/community-metadata/defaults.json');
} catch (Exception $e) {
throw new NotFoundException(__('Default community list not in the expected format.'));
}
foreach ($community_list as $k => $v) {
$community_list[$k]['id'] = $k + 1;
$community_list[$k]['Org'] = array('uuid' => $v['org_uuid'], 'name' => $v['org_name']);
}
$community = false;
$lookupField = 'id';
if (Validation::uuid($id)) {
$lookupField = 'uuid';
}
$lookupField = Validation::uuid($id) ? 'uuid' : 'id';
foreach ($community_list as $s) {
if ($s[$lookupField === 'uuid' ? 'uuid' : 'id'] === $id) {
$community = $s;
if ($s[$lookupField === 'uuid' ? 'uuid' : 'id'] == $id) {
return $s;
}
}
if (empty($community)) {
throw new NotFoundException(__('Community not found.'));
}
return $community;
throw new NotFoundException(__('Community not found.'));
}
}

View File

@ -31,7 +31,7 @@
),
'fields' => array(
array(
'name' => __('Id'),
'name' => __('ID'),
'sort' => 'id',
'class' => 'short',
'data_path' => 'id',
@ -76,14 +76,16 @@
'url_params_data_paths' => array(
'uuid'
),
'icon' => 'eye'
'icon' => 'eye',
'title' => __('View'),
),
array(
'url' => $baseurl . '/communities/requestAccess',
'url_params_data_paths' => array(
'uuid'
),
'icon' => 'comments'
'icon' => 'comments',
'title' => __('Request access'),
)
)
)
@ -91,12 +93,12 @@
echo '</div>';
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'sync', 'menuItem' => 'list_communities'));
?>
<script type="text/javascript">
<script>
var passedArgsArray = <?php echo $passedArgs; ?>;
if (passedArgsArray['context'] === undefined) {
passedArgsArray['context'] = 'vetted';
}
$(document).ready(function() {
$(function() {
$('#quickFilterButton').click(function() {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
});

View File

@ -1,10 +1,10 @@
<div class="communities view">
<?php
$table_data = array();
$table_data[] = array('key' => __('Id'), 'value' => $community['id']);
$table_data[] = array('key' => __('ID'), 'value' => $community['id']);
$table_data[] = array('key' => __('UUID'), 'value' => $community['uuid']);
$table_data[] = array('key' => __('Name'), 'value' => $community['name']);
$table_data[] = array('key' => __('Url'), 'url' => $community['url']);
$table_data[] = array('key' => __('URL'), 'url' => $community['url']);
$table_data[] = array('key' => __('Host organisation'), 'value' => $community['org_name'] . ' (' . $community['org_uuid'] . ')');
$table_data[] = array(
'key' => __('Vetted by MISP-project'),
@ -24,7 +24,7 @@
}
if (!empty($community['pgp_key'])) {
$table_data[] = array(
'key' => __('GnuPG key'),
'key' => __('PGP key'),
'element' => 'genericElements/key',
'element_params' => array('key' => $community['pgp_key']),
);
@ -34,12 +34,13 @@
sprintf(
'%s<h2>%s</h2>%s',
sprintf(
'<img src="https://misp-project.org/org-logos/%s.png" title="%s" aria-label="%s" style="max-height: 100px;"/>',
'<img src="https://misp-project.org/org-logos/%s.png" title="%s" alt="%s" aria-label="%s" style="max-height: 100px;">',
h($community['org_uuid']),
h($community['org_name']),
h($community['org_name']),
h($community['org_name'])
),
__('Community ') . h($community['name']),
__('Community %s', h($community['name'])),
$this->element('genericElements/viewMetaTable', array('table_data' => $table_data))
)
);

View File

@ -121,7 +121,7 @@
"nationality": "International",
"type": "Vetted Information Sharing Community",
"email": "undefined",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": true,
"scope_of_data_to_be_shared": "Any relevant security information for IXPs and GRXs",
"self_registration": true
@ -138,7 +138,7 @@
"nationality": "International",
"type": "Vetted Information Sharing Community",
"email": "undefined",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": true,
"scope_of_data_to_be_shared": "",
"self_registration": false
@ -155,7 +155,7 @@
"nationality": "Germany",
"type": "Vetted Information Sharing Community",
"email": "undefined",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": false,
"scope_of_data_to_be_shared": "",
"self_registration": false
@ -172,7 +172,7 @@
"nationality": "International",
"type": "Vetted Information Sharing Community",
"email": "undefined",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": true,
"scope_of_data_to_be_shared": "",
"self_registration": false
@ -189,14 +189,14 @@
"nationality": "International",
"type": "Vetted Information Sharing Community",
"email": "mispsupport@ncia.nato.int",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": true,
"scope_of_data_to_be_shared": "",
"self_registration": false
},
{
"name": "BEAM SOC MISP Community",
"logo": " https://www.beamteknoloji.com/wp-content/uploads/2020/01/beamlogo.png",
"logo": "https://www.beamteknoloji.com/wp-content/uploads/2020/01/beamlogo.png",
"uuid": "45819403-49b9-438f-95bc-e0abb50ba03b",
"org_uuid": "",
"org_name": "",
@ -206,7 +206,7 @@
"nationality": "Turkey",
"type": "Vetted Information Sharing Community",
"email": "contact@beamteknoloji.com",
"pgp_key": "undefined",
"pgp_key": null,
"misp_project_vetted": true,
"scope_of_data_to_be_shared": "",
"self_registration": false