mirror of https://github.com/MISP/MISP
chg: migrate /templates/index view, use CRUD compoenent in TemplatesController::delete()
parent
760227c8cd
commit
e7ae9df6a3
|
@ -6,7 +6,7 @@ App::uses('File', 'Utility');
|
|||
|
||||
class TemplatesController extends AppController
|
||||
{
|
||||
public $components = array('Security' ,'RequestHandler');
|
||||
public $components = array('Security' ,'RequestHandler', 'CRUD');
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 50,
|
||||
|
@ -231,23 +231,20 @@ class TemplatesController extends AppController
|
|||
|
||||
public function delete($id)
|
||||
{
|
||||
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
|
||||
if (!$this->request->is('post')) {
|
||||
throw new MethodNotAllowedException('This action can only be invoked via a post request.');
|
||||
}
|
||||
if (!$this->_isSiteAdmin() && !$template) {
|
||||
throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
|
||||
}
|
||||
if ($this->Template->delete($id, true)) {
|
||||
$this->Flash->success('Template deleted.');
|
||||
$this->redirect(array('action' => 'index'));
|
||||
} else {
|
||||
$this->Flash->error('The template could not be deleted.');
|
||||
$this->redirect(array('action' => 'index'));
|
||||
$this->CRUD->delete($id, [
|
||||
'validate' => function () use ($id) {
|
||||
$template = $this->Template->checkAuthorisation($id, $this->Auth->user(), true);
|
||||
|
||||
if (!$this->_isSiteAdmin() && !$template) {
|
||||
throw new MethodNotAllowedException('No template with the provided ID exists, or you are not authorised to edit it.');
|
||||
}
|
||||
}
|
||||
]);
|
||||
if ($this->IndexFilter->isRest()) {
|
||||
return $this->restResponsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function templateChoices($id)
|
||||
{
|
||||
$this->loadModel('Event');
|
||||
|
|
|
@ -1,63 +1,68 @@
|
|||
<div class="templates index">
|
||||
<h2><?php echo __('Templates');?></h2>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
echo $this->Paginator->prev('« ' . __('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') . ' »', array('tag' => 'li', 'escape' => false), null, array('tag' => 'li', 'class' => 'next disabled', 'escape' => false, 'disabledTag' => 'span'));
|
||||
?>
|
||||
</ul>
|
||||
</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('org');?></th>
|
||||
<th><?php echo $this->Paginator->sort('share');?></th>
|
||||
<th><?php echo $this->Paginator->sort('name');?></th>
|
||||
<th><?php echo $this->Paginator->sort('description');?></th>
|
||||
<?php if ($isAclTemplate): ?>
|
||||
<th class="actions"><?php echo __('Actions');?></th>
|
||||
<?php endif; ?>
|
||||
</tr><?php
|
||||
foreach ($list as $item): ?>
|
||||
<tr>
|
||||
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['id']); ?> </td>
|
||||
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'">
|
||||
<?php
|
||||
echo $this->OrgImg->getOrgImg(array('name' => $item['Template']['org'], 'size' => 24));
|
||||
?>
|
||||
|
||||
</td>
|
||||
<td class="short" onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php if ($item['Template']['share']) echo 'Yes'; else echo 'No'; ?> </td>
|
||||
<td onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['name']); ?> </td>
|
||||
<td onclick="document.location.href ='<?php echo $baseurl."/templates/view/".$item['Template']['id']; ?>'"><?php echo h($item['Template']['description']); ?> </td>
|
||||
<?php if ($isAclTemplate): ?>
|
||||
<td class="short action-links">
|
||||
<?php echo $this->Html->link('', array('action' => 'edit', $item['Template']['id']), array('class' => 'fa fa-edit', 'title' => 'Edit', 'aria-label' => 'Edit'));?>
|
||||
<?php echo $this->Form->postLink('', array('action' => 'delete', $item['Template']['id']), array('class' => 'fa fa-trash', 'title' => 'Delete', 'aria-label' => 'Delete'), __('Are you sure you want to delete Template #' . $item['Template']['id'] . '?'));?>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
</tr><?php
|
||||
endforeach; ?>
|
||||
</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('« ' . __('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') . ' »', 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' => 'templates', 'menuItem' => 'index'));
|
||||
|
||||
$this->set('menuData', ['menuList' => 'templates', 'menuItem' => 'index']);
|
||||
|
||||
foreach ($list as &$item) {
|
||||
$item['Organisation'] = ['name' => $item['Template']['org']];
|
||||
}
|
||||
|
||||
echo $this->element('genericElements/IndexTable/scaffold', [
|
||||
'scaffold_data' => [
|
||||
'data' => [
|
||||
'title' => empty($ajax) ? __('Templates') : false,
|
||||
'data' => $list,
|
||||
'fields' => [
|
||||
[
|
||||
'name' => 'Id',
|
||||
'sort' => 'Template.id',
|
||||
'data_path' => 'Template.id',
|
||||
'class' => 'short'
|
||||
],
|
||||
[
|
||||
'name' => 'Org',
|
||||
'sort' => 'Organisation.name',
|
||||
'data_path' => 'Organisation',
|
||||
'element' => 'org',
|
||||
'class' => 'short'
|
||||
],
|
||||
[
|
||||
'name' => 'Share',
|
||||
'sort' => 'Template.share',
|
||||
'data_path' => 'Template.share',
|
||||
'element' => 'boolean',
|
||||
'class' => 'short'
|
||||
],
|
||||
[
|
||||
'name' => 'Name',
|
||||
'sort' => 'Template.org',
|
||||
'data_path' => 'Template.org',
|
||||
'class' => 'short'
|
||||
],
|
||||
[
|
||||
'name' => 'Description',
|
||||
'sort' => 'Template.description',
|
||||
'data_path' => 'Template.description',
|
||||
'class' => 'bitwider'
|
||||
]
|
||||
],
|
||||
'actions' => [
|
||||
[
|
||||
'url' => $baseurl . '/templates/edit',
|
||||
'url_params_data_paths' => [
|
||||
'Template.id'
|
||||
],
|
||||
'icon' => 'edit',
|
||||
'title' => 'Edit',
|
||||
],
|
||||
[
|
||||
'onclick' => sprintf(
|
||||
'openGenericModal(\'%s/templates/delete/[onclick_params_data_path]\');',
|
||||
$baseurl
|
||||
),
|
||||
'onclick_params_data_path' => 'Template.id',
|
||||
'icon' => 'trash',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
|
Loading…
Reference in New Issue