add crud component noticelists index

pull/7357/head
Luciano Righetti 2021-04-19 15:46:27 +02:00
parent c36d9d8aa6
commit e491a9497f
6 changed files with 105 additions and 137 deletions

2
PyMISP

@ -1 +1 @@
Subproject commit 95e31bd2e3b4f14b55001a40cd51e44ec5cf7644
Subproject commit 62cd5173f087e88834e88472060181b681b0b4d2

View File

@ -6,31 +6,21 @@ class NoticelistsController extends AppController
public $components = array('Session', 'RequestHandler');
public $paginate = array(
'limit' => 60,
'maxLimit' => 9999,
'order' => array(
'Noticelist.id' => 'DESC'
),
'limit' => 60,
'maxLimit' => 9999,
'order' => array(
'Noticelist.id' => 'DESC'
),
);
public function index()
{
$this->paginate['recursive'] = -1;
if ($this->_isRest()) {
$noticelists = $this->Noticelist->find('all', $this->paginate);
foreach ($noticelists as $k => $v) {
$noticelists[$k]['Noticelist']['ref'] = json_decode($noticelists[$k]['Noticelist']['ref']);
$noticelists[$k]['Noticelist']['geographical_area'] = json_decode($noticelists[$k]['Noticelist']['geographical_area']);
}
return $this->RestResponse->viewData($noticelists, $this->response->type());
} else {
$noticelists = $this->paginate();
foreach ($noticelists as $k => $v) {
$noticelists[$k]['Noticelist']['ref'] = json_decode($noticelists[$k]['Noticelist']['ref']);
$noticelists[$k]['Noticelist']['geographical_area'] = json_decode($noticelists[$k]['Noticelist']['geographical_area']);
}
$this->set('noticelists', $noticelists);
$params = [];
$this->CRUD->index($params);
if ($this->IndexFilter->isRest()) {
return $this->restResponsePayload;
}
$this->set('menuData', array('menuList' => 'noticelist', 'menuItem' => 'list_noticelists'));
}
public function update()
@ -50,14 +40,14 @@ class NoticelistsController extends AppController
}
$this->Log->create();
$this->Log->save(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Notice list updated',
'change' => $change,
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Notice list updated',
'change' => $change,
));
$successes++;
}
@ -66,14 +56,14 @@ class NoticelistsController extends AppController
foreach ($result['fails'] as $id => $fail) {
$this->Log->create();
$this->Log->save(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Notice list failed to update',
'change' => $fail['name'] . ' could not be installed/updated. Error: ' . $fail['fail'],
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => $id,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Notice list failed to update',
'change' => $fail['name'] . ' could not be installed/updated. Error: ' . $fail['fail'],
));
$fails++;
}
@ -81,14 +71,14 @@ class NoticelistsController extends AppController
} else {
$this->Log->create();
$this->Log->save(array(
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => 0,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Noticelist update (nothing to update)',
'change' => 'Executed an update of the notice lists, but there was nothing to update.',
'org' => $this->Auth->user('Organisation')['name'],
'model' => 'Noticelist',
'model_id' => 0,
'email' => $this->Auth->user('email'),
'action' => 'update',
'user_id' => $this->Auth->user('id'),
'title' => 'Noticelist update (nothing to update)',
'change' => 'Executed an update of the notice lists, but there was nothing to update.',
));
}
if ($successes == 0 && $fails == 0) {
@ -116,11 +106,11 @@ class NoticelistsController extends AppController
{
$id = $this->request->data['Noticelist']['data'];
if (!is_numeric($id)) {
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Noticelist not found.')), 'status' => 200, 'type' => 'json'));
return new CakeResponse(array('body' => json_encode(array('saved' => false, 'errors' => 'Noticelist not found.')), 'status' => 200, 'type' => 'json'));
}
$currentState = $this->Noticelist->find('first', array('conditions' => array('id' => $id), 'recursive' => -1));
if (empty($currentState)) {
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Noticelist not found.')), 'status' => 200, 'type' => 'json'));
return new CakeResponse(array('body' => json_encode(array('saved' => false, 'errors' => 'Noticelist not found.')), 'status' => 200, 'type' => 'json'));
}
$currentState['Noticelist']['ref'] = json_decode($currentState['Noticelist']['ref']);
$currentState['Noticelist']['geographical_area'] = json_decode($currentState['Noticelist']['geographical_area']);
@ -132,9 +122,9 @@ class NoticelistsController extends AppController
$message = 'enabled';
}
if ($this->Noticelist->save($currentState)) {
return new CakeResponse(array('body'=> json_encode(array('saved' => true, 'success' => 'Noticelist ' . $message)), 'status' => 200, 'type' => 'json'));
return new CakeResponse(array('body' => json_encode(array('saved' => true, 'success' => 'Noticelist ' . $message)), 'status' => 200, 'type' => 'json'));
} else {
return new CakeResponse(array('body'=> json_encode(array('saved' => false, 'errors' => 'Noticelist could not be enabled.')), 'status' => 200, 'type' => 'json'));
return new CakeResponse(array('body' => json_encode(array('saved' => false, 'errors' => 'Noticelist could not be enabled.')), 'status' => 200, 'type' => 'json'));
}
}

View File

@ -519,17 +519,18 @@ $divider = $this->element('/genericElements/SideMenu/side_menu_divider');
case 'noticelist':
if ($menuItem === 'view') {
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'view',
'element_id' => 'view_noticelist',
'text' => __('View Noticelist')
));
}
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'index',
'element_id' => 'list_noticelists',
'url' => $baseurl . '/noticelists/index',
'text' => __('List Noticelist')
));
if ($canAccess('noticelists', 'update')) {
echo $this->element('/genericElements/SideMenu/side_menu_post_link', array(
'element_id' => 'update_noticelists',
'url' => $baseurl . '/noticelists/update',
'text' => __('Update Noticelists'),
'message' => __('Do you wish to continue and update all noticelists?')

View File

@ -1,85 +1,62 @@
<div class="taxonomies index">
<h2><?php echo __('Noticelists');?></h2>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev('&laquo; ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
echo $this->Paginator->next(__('next') . ' &raquo;', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
?>
</ul>
</div>
<div id="hiddenFormDiv">
<?php
if ($isSiteAdmin) {
echo $this->Form->create('Noticelist', array('url' => $baseurl . '/noticelists/toggleEnable'));
echo $this->Form->input('data', array('label' => false, 'style' => 'display:none;'));
echo $this->Form->end();
}
?>
</div>
<table class="table table-striped table-hover table-condensed">
<tr>
<th><?php echo $this->Paginator->sort('id'); ?></th>
<th><?php echo $this->Paginator->sort('name'); ?></th>
<th><?php echo $this->Paginator->sort('expanded_name', __('Expanded name')); ?></th>
<th><?php echo __('ref');?></th>
<th><?php echo __('geographical_area');?></th>
<th><?php echo __('version');?></th>
<th><?php echo __('enabled');?></th>
<th class="actions"><?php echo __('Actions');?></th>
</tr>
<?php
foreach ($noticelists as $k => $item) {
echo '<tr>';
echo sprintf('<td ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), h($item['Noticelist']['id']));
echo sprintf('<td ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), h($item['Noticelist']['name']));
echo sprintf('<td ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), h($item['Noticelist']['expanded_name']));
$references = array();
foreach ($item['Noticelist']['ref'] as $ref) {
$references[] = sprintf('<a href="%s">%s</a>', h($ref), h($ref));
}
$references = implode(PHP_EOL, $references);
echo sprintf('<td ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), $references);
$geo = array();
foreach ($item['Noticelist']['geographical_area'] as $geo_area) {
$geo[] = h($geo_area);
}
$geo = implode(PHP_EOL, $geo);
echo sprintf('<td class="short" ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), $geo);
echo sprintf('<td class="short" ondblclick="document.location.href =%s">%s&nbsp;</td>', $baseurl . "/noticeists/view/" . h($item['Noticelist']['id']), h($item['Noticelist']['version']));
if ($isSiteAdmin) {
$onClick = 'onClick="toggleSetting(event, \'noticelist_enable\', \'' . h($item['Noticelist']['id']) . '\'); ' . '"';
} else {
$onClick = 'disabled';
}
$input = '<input id="checkBox_' . h($item['Noticelist']['id']) . '" type="checkbox" aria-label="' . __('Enabled') . '" ' . $onClick . ' ' . ($item['Noticelist']['enabled'] ? 'checked' : '') . ' />';
echo '<td class="short" id="checkbox_row_' . h($item['Noticelist']['id']) . '">' . $input . '</td>';
$actions = '';
$actions .= '<a href="' . $baseurl . "/noticelists/view/" . h($item['Noticelist']['id']) . '" class="fa fa-eye" title="' . __('View') . '" aria-label="' . __('View') . '"></a>';
echo '<td class="short action-links">' . $actions . '</td>';
echo '</tr>';
}
?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?>
</p>
<div class="pagination">
<ul>
<?php
echo $this->Paginator->prev('&laquo; ' . __('previous'), array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'prev disabled', 'escape' => false, 'disabledTag' => 'span'));
echo $this->Paginator->numbers(array('modulus' => 20, 'separator' => '', 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'span'));
echo $this->Paginator->next(__('next') . ' &raquo;', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
?>
</ul>
</div>
</div>
<?php
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'noticelist', 'menuItem' => 'index'));
?>
$fields = [
[
'name' => __('Id'),
'sort' => 'Noticelist.id',
'data_path' => 'Noticelist.id'
],
[
'name' => __('Name'),
'sort' => 'Noticelist.name',
'data_path' => 'Noticelist.name'
],
[
'name' => __('Expanded Name'),
'sort' => 'Noticelist.expanded_name',
'data_path' => 'Noticelist.expanded_name'
],
[
'name' => __('ref'),
'data_path' => 'Noticelist.ref',
'element' => 'links'
],
[
'name' => __('geographical_area'),
'data_path' => 'Noticelist.geographical_area',
'element' => 'list'
],
[
'name' => __('version'),
'data_path' => 'Noticelist.version',
],
[
'name' => __('enabled'),
'data_path' => 'Noticelist.enabled',
'element' => 'toggle',
'url' => '/admin/noticelists/enableNoticelist',
'url_params_data_paths' => ['Noticelist.id'],
'requirement' => $isSiteAdmin
]
];
echo $this->element('genericElements/IndexTable/scaffold', [
'scaffold_data' => [
'data' => [
'data' => $data,
'top_bar' => [
'pull' => 'right',
],
'fields' => $fields,
'title' => empty($ajax) ? __('Noticelists') : false,
// 'description' => empty($ajax) ? __('You can connect your MISP to one or several Cerebrate instances to act as lookup directories for organisation and sharing group information.') : false,
'actions' => [
[
'url' => $baseurl . '/noticelists/view',
'url_params_data_paths' => ['Noticelist.id'],
'icon' => 'eye'
],
]
]
]
]);

@ -1 +1 @@
Subproject commit 5cdad926716caad5fec6049431cc6ae42a8d3bf7
Subproject commit eba33a1c91c59b41dd9bc58d80ed3a1e54cdb2e1

@ -1 +1 @@
Subproject commit 5e6f887fa131437089eaa8cdb9078b6a6371d121
Subproject commit e1f01f674fbaeb5f5af13b15f9b87ede9bcc1291