mirror of https://github.com/MISP/MISP
chg: [decaying:model] First batch of fix from the PR review - WiP (not tested)
parent
60edb198a7
commit
a990727db2
|
@ -86,7 +86,7 @@ class DecayingModelController extends AppController
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
$this->Flash->success(__('The model has been imported.'));
|
$this->Flash->success(__('The model has been imported.'));
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('The model has been but mapping. However importing mapping failed.'));
|
$this->Flash->error(__('The model has been imported. However importing mapping failed.'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('Error while importing model.'));
|
$this->Flash->error(__('Error while importing model.'));
|
||||||
|
@ -180,14 +180,25 @@ class DecayingModelController extends AppController
|
||||||
if ($this->request->data === false) {
|
if ($this->request->data === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$attribute_types = array();
|
||||||
|
if (!empty($this->request->data['attribute_types'])) {
|
||||||
|
$attribute_types = $this->request->data['attribute_types'];
|
||||||
|
unset($this->request->data['attribute_types']);
|
||||||
|
}
|
||||||
if ($this->DecayingModel->save($this->request->data)) {
|
if ($this->DecayingModel->save($this->request->data)) {
|
||||||
|
$success_message = __('The model has been saved.');
|
||||||
|
if (!empty($saved_model['attribute_types'])) {
|
||||||
|
if (!$this->DecayingModel->DecayingModelMapping->resetMappingForModel($saved_model, $this->Auth->user())) {
|
||||||
|
$success_message = __('The model has been saved. However importing mapping failed.');
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($this->request->is('ajax') || $this->_isRest()) {
|
if ($this->request->is('ajax') || $this->_isRest()) {
|
||||||
$saved = $this->DecayingModel->fetchModel($this->Auth->user(), $this->DecayingModel->id);
|
$saved = $this->DecayingModel->fetchModel($this->Auth->user(), $this->DecayingModel->id);
|
||||||
$saved = $this->DecayingModel->attachIsEditableByCurrentUser($this->Auth->user(), $saved);
|
$saved = $this->DecayingModel->attachIsEditableByCurrentUser($this->Auth->user(), $saved);
|
||||||
$response = array('data' => $saved, 'action' => 'add');
|
$response = array('data' => $saved, 'action' => 'add');
|
||||||
return $this->RestResponse->viewData($response, $this->response->type());
|
return $this->RestResponse->viewData($response, $this->response->type());
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->success(__('The model has been saved.'));
|
$this->Flash->success($sucess_messaqge);
|
||||||
$this->redirect(array('action' => 'index'));
|
$this->redirect(array('action' => 'index'));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -16,7 +16,7 @@ class DecayingModel extends AppModel
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
private $__registered_model_classes = array(); // Proxy for already instanciated classes
|
private $__registered_model_classes = array(); // Proxy for already instantiated classes
|
||||||
public $allowed_overrides = array('threshold' => 1, 'lifetime' => 1, 'decay_speed' => 1);
|
public $allowed_overrides = array('threshold' => 1, 'lifetime' => 1, 'decay_speed' => 1);
|
||||||
|
|
||||||
public function afterFind($results, $primary = false) {
|
public function afterFind($results, $primary = false) {
|
||||||
|
@ -66,30 +66,28 @@ class DecayingModel extends AppModel
|
||||||
$this->data['DecayingModel']['parameters']['settings'] = '{}';
|
$this->data['DecayingModel']['parameters']['settings'] = '{}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->data['DecayingModel']['attribute_types']) && !is_array($this->data['DecayingModel']['attribute_types'])) {
|
||||||
|
$encoded = json_decode($this->data['DecayingModel']['attribute_types'], true);
|
||||||
|
if ($encoded === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isset($this->data['DecayingModel']['parameters']) &&
|
isset($this->data['DecayingModel']['parameters']) &&
|
||||||
!empty($this->data['DecayingModel']['parameters']) &&
|
!empty($this->data['DecayingModel']['parameters']) &&
|
||||||
!is_array($this->data['DecayingModel']['parameters'])
|
!is_array($this->data['DecayingModel']['parameters'])
|
||||||
) {
|
) {
|
||||||
$encoded = json_decode($this->data['DecayingModel']['parameters'], true);
|
$encoded = json_decode($this->data['DecayingModel']['parameters'], true);
|
||||||
if ($encoded !== null) {
|
if ($encoded === null) {
|
||||||
$validation = $this->__adjustParameters($encoded);
|
return false;
|
||||||
if ($validation !== false) {
|
|
||||||
$this->data['DecayingModel']['parameters'] = json_encode($encoded);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
$encoded = $this->__adjustParameters($encoded);
|
||||||
|
$this->data['DecayingModel']['parameters'] = json_encode($encoded);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$validation = $this->__adjustParameters($this->data['DecayingModel']['parameters']);
|
$this->data['DecayingModel']['parameters'] = $this->__adjustParameters($this->data['DecayingModel']['parameters']);
|
||||||
return $validation;
|
return $this->data['DecayingModel']['parameters'];
|
||||||
}
|
|
||||||
if (!empty($this->data['DecayingModel']['attribute_types']) && !is_array($this->data['DecayingModel']['attribute_types'])) {
|
|
||||||
$encoded = json_decode($this->data['DecayingModel']['attribute_types'], true);
|
|
||||||
if ($encoded !== null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +118,7 @@ class DecayingModel extends AppModel
|
||||||
* May be improved at some point.
|
* May be improved at some point.
|
||||||
* For now, limit the number of digits for the parameters
|
* For now, limit the number of digits for the parameters
|
||||||
*/
|
*/
|
||||||
private function __adjustParameters(&$parameters)
|
private function __adjustParameters($parameters)
|
||||||
{
|
{
|
||||||
foreach ($parameters as $name => $value) {
|
foreach ($parameters as $name => $value) {
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
|
@ -133,7 +131,7 @@ class DecayingModel extends AppModel
|
||||||
$parameters[$name] = 0;
|
$parameters[$name] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return $parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function __load_models($force = false)
|
private function __load_models($force = false)
|
||||||
|
@ -181,7 +179,12 @@ class DecayingModel extends AppModel
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
$user['Role']['perm_site_admin'] ||
|
$user['Role']['perm_site_admin'] ||
|
||||||
($user['Role']['perm_decaying'] && !$decaying_model['DecayingModel']['default'] && $decaying_model['DecayingModel']['org_id'] == $user['org_id']));
|
(
|
||||||
|
$user['Role']['perm_decaying'] &&
|
||||||
|
!$decaying_model['DecayingModel']['default'] &&
|
||||||
|
$decaying_model['DecayingModel']['org_id'] == $user['org_id']
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attachIsEditableByCurrentUser($user, $decaying_model)
|
public function attachIsEditableByCurrentUser($user, $decaying_model)
|
||||||
|
|
Loading…
Reference in New Issue