chg: [objectTemplates] Removed model association with organisation and user + small UI and navigation fix

pull/9439/head
Sami Mokaddem 2023-12-05 09:07:44 +01:00
parent f7c6cf4d13
commit d4aa321813
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 32 additions and 56 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace App\Controller\Component\Navigation;
class ObjectTemplatesNavigation extends BaseNavigation
{
function addRoutes()
{
$this->bcf->addRoute('ObjectTemplates', 'update', [
'label' => __('Update ObjectTemplates'),
'url' => '/object-templates/update',
'icon' => 'circle-up',
'isPOST' => true,
]);
}
public function addActions()
{
$this->bcf->addAction('ObjectTemplates', 'index', 'ObjectTemplates', 'update');
}
}

View File

@ -22,9 +22,6 @@ class ObjectTemplatesController extends AppController
'order' => [
'Object.id' => 'desc'
],
'contain' => [
'Organisations' => ['fields' => ['Organisations.id', 'Organisations.name', 'Organisations.uuid']]
],
'recursive' => -1
];
@ -147,9 +144,6 @@ class ObjectTemplatesController extends AppController
if ($this->ParamHandler->isRest()) {
$params['contain'][] = 'ObjectTemplateElements';
}
if ($this->isSiteAdmin()) {
$params['contain']['Users'] = ['fields' => ['Users.id', 'Users.email']];
}
$objectTemplate = $this->ObjectTemplates->find('all', $params)->first();
if (empty($objectTemplate)) {
throw new NotFoundException('Invalid object template');
@ -197,14 +191,12 @@ class ObjectTemplatesController extends AppController
$conditions['ObjectTemplates.active'] = 1;
}
$this->CRUD->index(
[
$this->CRUD->index([
'filters' => $this->filterFields,
'quickFilters' => $this->quickFilterFields,
'quickFilterForMetaField' => ['enabled' => true, 'wildcard_search' => true],
'conditions' => $conditions
]
);
]);
$responsePayload = $this->CRUD->getResponsePayload();
@ -213,6 +205,11 @@ class ObjectTemplatesController extends AppController
}
}
public function filtering()
{
$this->CRUD->filtering();
}
public function update($type = false, $force = false)
{
if (!empty($this->request->getParam('type'))) {
@ -221,7 +218,7 @@ class ObjectTemplatesController extends AppController
if (!empty($this->request->getParam('force'))) {
$force = $this->request->getParam('force');
}
$result = $this->ObjectTemplates->update($this->ACL->getUser(), $type, $force);
$result = $this->ObjectTemplates->update($type, $force);
$ObjectRelationshipTable = $this->fetchTable('ObjectRelationships');
$ObjectRelationshipTable->update();
$this->Log = $this->fetchTable('Logs');

View File

@ -20,20 +20,6 @@ class ObjectTemplatesTable extends AppTable
'fields' => ['requirements' => []],
]
);
$this->belongsTo(
'Users',
[
'foreignKey' => 'user_id',
'propertyName' => 'User',
]
);
$this->belongsTo(
'Organisations',
[
'foreignKey' => 'org_id',
'propertyName' => 'Organisation',
]
);
$this->hasMany(
'ObjectTemplateElements',
[
@ -47,7 +33,7 @@ class ObjectTemplatesTable extends AppTable
const OBJECTS_DIR = APP . '../libraries/misp-objects/objects';
public function update($user = false, $type = false, $force = false)
public function update($type = false, $force = false)
{
$directories = $this->getTemplateDirectoryPaths();
$updated = [];
@ -76,7 +62,7 @@ class ObjectTemplatesTable extends AppTable
$current['version'] = $current['version'];
}
if ($force || empty($current) || $template['version'] > $current['version']) {
$result = $this->__updateObjectTemplate($template, $current, $user);
$result = $this->__updateObjectTemplate($template, $current);
if ($result === true) {
$temp = ['name' => $template['name'], 'new' => $template['version']];
if (!empty($current)) {
@ -91,7 +77,7 @@ class ObjectTemplatesTable extends AppTable
return $updated;
}
private function __updateObjectTemplate($template, $current, $user = false)
private function __updateObjectTemplate($template, $current)
{
$template['requirements'] = [];
$requirementFields = ['required', 'requiredOneOf'];
@ -100,13 +86,6 @@ class ObjectTemplatesTable extends AppTable
$template['requirements'][$field] = $template[$field];
}
}
if (!empty($user)) {
$template['user_id'] = $user['id'];
$template['org_id'] = $user['org_id'];
} else {
$template['user_id'] = 0;
$template['org_id'] = 0;
}
$template['fixed'] = 1;
$templateEntity = $this->newEntity($template);
$result = $this->save($templateEntity);

View File

@ -4,19 +4,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => $data,
'top_bar' => [
'children' => [
[
'type' => 'simple',
'children' => [
'data' => [
'type' => 'simple',
'text' => __('Update templates'),
'popover_url' => '/object-templates/update',
'button' => [
'icon' => 'refresh',
]
]
]
],
[
'type' => 'context_filters',
],
@ -30,7 +17,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
],
[
'type' => 'table_action',
'table_setting_id' => 'organisation_index',
'table_setting_id' => 'objecttemplates_index',
]
]
],
@ -53,13 +40,6 @@ echo $this->element('genericElements/IndexTable/index_table', [
'class' => 'short',
'data_path' => 'uuid',
],
[
'name' => __('Organisation'),
'sort' => 'Organisation.name',
'element' => 'org',
'data_path' => 'Organisation',
'class' => 'short',
],
[
'name' => __('Version'),
'data_path' => 'version',