mirror of https://github.com/MISP/MISP
Added full text search to organisation index, fixes #803
- also some fixes and enhancements in general for thispull/865/head
parent
038d12a4c0
commit
b92c1c8db4
|
@ -3,12 +3,12 @@ App::uses('AppController', 'Controller');
|
|||
|
||||
class OrganisationsController extends AppController {
|
||||
public $components = array('Session', 'RequestHandler');
|
||||
|
||||
|
||||
public function beforeFilter() {
|
||||
parent::beforeFilter();
|
||||
if(!empty($this->request->params['admin']) && !$this->_isSiteAdmin()) $this->redirect('/');
|
||||
}
|
||||
|
||||
|
||||
public $paginate = array(
|
||||
'limit' => 60,
|
||||
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
|
||||
|
@ -16,12 +16,32 @@ class OrganisationsController extends AppController {
|
|||
'Organisation.name' => 'ASC'
|
||||
),
|
||||
);
|
||||
|
||||
public function index($local = true) {
|
||||
|
||||
public function index() {
|
||||
$conditions = array();
|
||||
// We can either index all of the organisations existing on this instance (default)
|
||||
// or we can pass the 'external' keyword in the URL to look at the added external organisations
|
||||
if ($local === 'external' || $local === 'remote') $local = false;
|
||||
$this->paginate['conditions'] = array('Organisation.local' => $local);
|
||||
$scope = isset($this->passedArgs['scope']) ? $this->passedArgs['scope'] : 'local';
|
||||
if ($scope !== 'all') $conditions['AND'][] = array('Organisation.local' => $scope === 'external' ? 0 : 1);
|
||||
$passedArgs = $this->passedArgs;
|
||||
|
||||
if (isset($this->request->data['searchall'])) $searchall = $this->request->data['searchall'];
|
||||
else if (isset($this->passedArgs['all'])) $searchall = $this->passedArgs['all'];
|
||||
else if (isset($this->passedArgs['searchall'])) $searchall = $this->passedArgs['searchall'];
|
||||
|
||||
|
||||
if (isset($searchall) && !empty($searchall)) {
|
||||
$passedArgs['searchall'] = $searchall;
|
||||
$allSearchFields = array('name', 'description', 'nationality', 'sector', 'type', 'contacts');
|
||||
foreach ($allSearchFields as $field) {
|
||||
$conditions['OR'][] = array('Organisation.' . $field . ' LIKE' => '%' . $passedArgs['searchall'] . '%');
|
||||
}
|
||||
}
|
||||
$this->set('passedArgs', json_encode($passedArgs));
|
||||
$this->paginate = array(
|
||||
'conditions' => $conditions,
|
||||
'recursive' => -1,
|
||||
);
|
||||
$orgs = $this->paginate();
|
||||
if ($this->_isSiteAdmin()) {
|
||||
$this->loadModel('User');
|
||||
|
@ -35,13 +55,13 @@ class OrganisationsController extends AppController {
|
|||
$org_creator_ids[$org['Organisation']['created_by']] = 'Unknown';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->set('org_creator_ids', $org_creator_ids);
|
||||
}
|
||||
$this->set('local', $local);
|
||||
$this->set('scope', $scope);
|
||||
$this->set('orgs', $orgs);
|
||||
}
|
||||
|
||||
|
||||
public function admin_add() {
|
||||
if($this->request->is('post')) {
|
||||
$this->Organisation->create();
|
||||
|
@ -56,7 +76,7 @@ class OrganisationsController extends AppController {
|
|||
}
|
||||
$this->set('countries', $this->_arrayToValuesIndexArray($this->Organisation->countries));
|
||||
}
|
||||
|
||||
|
||||
public function admin_edit($id) {
|
||||
$this->Organisation->id = $id;
|
||||
if (!$this->Organisation->exists()) throw new NotFoundException('Invalid organisation');
|
||||
|
@ -76,12 +96,12 @@ class OrganisationsController extends AppController {
|
|||
$this->request->data = $this->Organisation->data;
|
||||
$this->set('id', $id);
|
||||
}
|
||||
|
||||
|
||||
public function admin_delete($id) {
|
||||
if (!$this->request->is('post')) throw new MethodNotAllowedException('Action not allowed, post request expected.');
|
||||
$this->Organisation->id = $id;
|
||||
if (!$this->Organisation->exists()) throw new NotFoundException('Invalid organisation');
|
||||
|
||||
|
||||
$org = $this->Organisation->find('first', array(
|
||||
'conditions' => array('id' => $id),
|
||||
'recursive' => -1,
|
||||
|
@ -97,12 +117,12 @@ class OrganisationsController extends AppController {
|
|||
$this->redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function admin_generateuuid() {
|
||||
$this->set('uuid', $this->Organisation->generateUuid());
|
||||
$this->set('_serialize', array('uuid'));
|
||||
}
|
||||
|
||||
|
||||
public function view($id) {
|
||||
$this->Organisation->id = $id;
|
||||
if (!$this->Organisation->exists()) throw new NotFoundException('Invalid organisation');
|
||||
|
@ -116,9 +136,9 @@ class OrganisationsController extends AppController {
|
|||
'conditions' => array('id' => $id),
|
||||
'fields' => $fields
|
||||
));
|
||||
|
||||
|
||||
$this->set('local', $org['Organisation']['local']);
|
||||
|
||||
|
||||
if ($fullAccess) {
|
||||
$creator = $this->Organisation->User->find('first', array('conditions' => array('User.id' => $org['Organisation']['created_by'])));
|
||||
$this->set('creator', $creator);
|
||||
|
@ -127,7 +147,7 @@ class OrganisationsController extends AppController {
|
|||
$this->set('org', $org);
|
||||
$this->set('id', $id);
|
||||
}
|
||||
|
||||
|
||||
public function landingpage($id) {
|
||||
$this->Organisation->id = $id;
|
||||
if (!$this->Organisation->exists()) throw new NotFoundException('Invalid organisation');
|
||||
|
@ -138,7 +158,7 @@ class OrganisationsController extends AppController {
|
|||
$this->set('org', $org['Organisation']['name']);
|
||||
$this->render('ajax/landingpage');
|
||||
}
|
||||
|
||||
|
||||
public function fetchOrgsForSG($idList = '{}', $type) {
|
||||
if ($type === 'local') $local = 1;
|
||||
else $local = 0;
|
||||
|
@ -162,7 +182,7 @@ class OrganisationsController extends AppController {
|
|||
$this->set('orgs', $orgs);
|
||||
$this->render('ajax/fetch_orgs_for_sg');
|
||||
}
|
||||
|
||||
|
||||
public function fetchSGOrgRow($id, $removable = false, $extend = false) {
|
||||
$this->layout = false;
|
||||
$this->autoRender = false;
|
||||
|
@ -171,13 +191,13 @@ class OrganisationsController extends AppController {
|
|||
$this->set('extend', $extend);
|
||||
$this->render('ajax/sg_org_row_empty');
|
||||
}
|
||||
|
||||
|
||||
public function getUUIDs() {
|
||||
if (!$this->Auth->user('Role')['perm_sync']) throw new MethodNotAllowedException('This action is restricted to sync users');
|
||||
$temp = $this->Organisation->find('all', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('local' => 1),
|
||||
'fields' => array('Organisation.uuid')
|
||||
'recursive' => -1,
|
||||
'conditions' => array('local' => 1),
|
||||
'fields' => array('Organisation.uuid')
|
||||
));
|
||||
$orgs = array();
|
||||
foreach ($temp as $t) {
|
||||
|
@ -185,4 +205,8 @@ class OrganisationsController extends AppController {
|
|||
}
|
||||
return new CakeResponse(array('body'=> json_encode($orgs)));
|
||||
}
|
||||
|
||||
public function adminMerge() {
|
||||
|
||||
}
|
||||
}
|
|
@ -234,14 +234,13 @@ class UsersController extends AppController {
|
|||
$overrideAbleParams = array('all');
|
||||
$org = $this->User->Organisation->read(null, $id);
|
||||
if (!$this->User->Organisation->exists() || !($this->_isSiteAdmin() || $this->Auth->user('org_id') == $id)) {
|
||||
throw MethodNotAllowedException('Organisation not found or no authorisation to view it.');
|
||||
throw new MethodNotAllowedException('Organisation not found or no authorisation to view it.');
|
||||
}
|
||||
$user_fields = array('id', 'email', 'gpgkey', 'nids_sid');
|
||||
$conditions = array('org_id' => $id);
|
||||
if ($this->_isSiteAdmin() || ($this->_isAdmin() && $this->Auth->user('org_id') == $id)) {
|
||||
$user_fields = array_merge($user_fields, array('newsread', 'termsaccepted', 'change_pw', 'authkey'));
|
||||
}
|
||||
$passedArgs = $this->passedArgs;
|
||||
if (isset($this->request->data)) {
|
||||
if (isset($this->request->data['searchall'])) $this->request->data['all'] = $this->request->data['searchall'];
|
||||
if (isset($this->request->data['all']) && !empty($this->request->data['all'])) {
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
<div class="organisations index">
|
||||
<?php if ($local): ?>
|
||||
<h2>Local organisations on this instance</h2>
|
||||
<?php else: ?>
|
||||
<h2>Known remote organisations on other instances</h2>
|
||||
<?php endif;?>
|
||||
<?php
|
||||
$texts = array(
|
||||
'all' => array(
|
||||
'text' => 'All organisations',
|
||||
'extra' => ', both local and remote'
|
||||
),
|
||||
'external' => array(
|
||||
'text' => 'Known remote organisations',
|
||||
'extra' => ' on other instances'
|
||||
),
|
||||
'local' => array(
|
||||
'text' => 'Local organisations',
|
||||
'extra' => ' having a presence on this instance'
|
||||
),
|
||||
);
|
||||
if (!in_array($scope, array_keys($texts))) $scope = 'local';
|
||||
?>
|
||||
<h2><?php echo $texts[$scope]['text'] . $texts[$scope]['extra']; ?></h2>
|
||||
<div class="pagination">
|
||||
<ul>
|
||||
<?php
|
||||
$this->Paginator->options(array(
|
||||
'url' => $baseurl . '/organisations/index/' . $scope,
|
||||
'update' => '.span12',
|
||||
'evalScripts' => true,
|
||||
'before' => '$(".progress").show()',
|
||||
|
@ -20,9 +34,16 @@ echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escap
|
|||
?>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="tabMenuFixedContainer">
|
||||
<span class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php if ($local) echo 'tabMenuActive';?>" onClick="window.location='/organisations/index'">Local Organisations</span>
|
||||
<span class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php if (!$local) echo 'tabMenuActive';?>" onClick="window.location='/organisations/index/remote'">Known Remote Organisations</span>
|
||||
<div class="tabMenuFixedContainer" style="display:inline-block;">
|
||||
<?php
|
||||
foreach (array('local', 'external', 'all') as $scopeChoice):
|
||||
?>
|
||||
<span class="tabMenuFixed tabMenuFixedCenter tabMenuSides useCursorPointer <?php if ($scope === $scopeChoice) echo 'tabMenuActive';?>" onClick="window.location='/organisations/index/scope:<?php echo h($scopeChoice);?>'"><?php echo $texts[$scopeChoice]['text'];?></span>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<span id="quickFilterButton" class="tabMenuFilterFieldButton useCursorPointer" onClick="quickFilter(<?php echo h($passedArgs); ?>, '<?php echo $baseurl . '/organisations/index'; ?>');">Filter</span>
|
||||
<input class="tabMenuFilterField" type="text" id="quickFilterField"></input>
|
||||
</div>
|
||||
<table class="table table-striped table-hover table-condensed">
|
||||
<tr>
|
||||
|
@ -40,6 +61,7 @@ echo $this->Paginator->next(__('next') . ' »', array('tag' => 'li', 'escap
|
|||
<?php if ($isSiteAdmin): ?>
|
||||
<th>Added by</th>
|
||||
<?php endif; ?>
|
||||
<th><?php echo $this->Paginator->sort('local');?></th>
|
||||
<th class="actions">Actions</th>
|
||||
</tr>
|
||||
<?php
|
||||
|
@ -66,6 +88,7 @@ foreach ($orgs as $org): ?>
|
|||
<?php if ($isSiteAdmin): ?>
|
||||
<td class="short" ondblclick="document.location.href ='/organisations/view/<?php echo $org['Organisation']['id'];?>'"><?php echo h($org_creator_ids[$org['Organisation']['created_by']]); ?></td>
|
||||
<?php endif; ?>
|
||||
<td class="short <?php echo $org['Organisation']['local'] ? 'green' : 'red';?>" ondblclick="document.location.href ='/organisations/view/<?php echo $org['Organisation']['id'];?>'"><?php echo $org['Organisation']['local'] ? 'Yes' : 'No';?></td>
|
||||
<td class="short action-links">
|
||||
<?php if ($isSiteAdmin): ?>
|
||||
<a href='/admin/organisations/edit/<?php echo $org['Organisation']['id'];?>' class = "icon-edit" title = "Edit"></a>
|
||||
|
|
Loading…
Reference in New Issue