mirror of https://github.com/MISP/MISP
chg: [decaying] Added default models to selection when fetching
associated modelspull/5032/head
parent
c39c168962
commit
9baafffc7a
|
@ -189,6 +189,17 @@ class DecayingModel extends AppModel
|
||||||
$decaying_model['DecayingModel']['isEditable'] = $this->isEditableByCurrentUser($user, $decaying_model);
|
$decaying_model['DecayingModel']['isEditable'] = $this->isEditableByCurrentUser($user, $decaying_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fetchAllDefaultModel($user)
|
||||||
|
{
|
||||||
|
$default_models = $this->fetchAllAllowedModels($user, false);
|
||||||
|
foreach ($default_models as $i => $model) {
|
||||||
|
if (!$default_models[$i]['DecayingModel']['isDefault']) {
|
||||||
|
unset($default_models[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $default_models;
|
||||||
|
}
|
||||||
|
|
||||||
public function fetchAllAllowedModels($user, $full=true, $filters=array())
|
public function fetchAllAllowedModels($user, $full=true, $filters=array())
|
||||||
{
|
{
|
||||||
$conditions = array();
|
$conditions = array();
|
||||||
|
@ -521,7 +532,6 @@ class DecayingModel extends AppModel
|
||||||
} else {
|
} else {
|
||||||
$models[] = $this->fetchModel($user, $model_id, false, array());
|
$models[] = $this->fetchModel($user, $model_id, false, array());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($models as $i => $model) {
|
foreach ($models as $i => $model) {
|
||||||
if (!empty($model_overrides)) {
|
if (!empty($model_overrides)) {
|
||||||
$this->overrideModelParameters($model, $model_overrides);
|
$this->overrideModelParameters($model, $model_overrides);
|
||||||
|
|
|
@ -69,14 +69,14 @@ class DecayingModelMapping extends AppModel
|
||||||
return $associated_types;
|
return $associated_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAssociatedModels($user, $attribute_type = array()) {
|
public function getAssociatedModels($user, $attribute_type = false) {
|
||||||
$conditions = array(
|
$conditions = array(
|
||||||
'OR' => array(
|
'OR' => array(
|
||||||
'DecayingModel.org_id' => $user['org_id'],
|
'DecayingModel.org_id' => $user['org_id'],
|
||||||
'DecayingModel.all_orgs' => true
|
'DecayingModel.all_orgs' => true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (!empty($attribute_type)) {
|
if ($attribute_type !== false) {
|
||||||
$conditions['attribute_type'] = $attribute_type;
|
$conditions['attribute_type'] = $attribute_type;
|
||||||
}
|
}
|
||||||
$associated_models = $this->find('all', array(
|
$associated_models = $this->find('all', array(
|
||||||
|
@ -94,8 +94,18 @@ class DecayingModelMapping extends AppModel
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
// Also add default models to selection
|
||||||
|
$default_models = $this->DecayingModel->fetchAllDefaultModel($user);
|
||||||
|
$associated_default_models = array();
|
||||||
|
foreach ($default_models as $i => $model) {
|
||||||
|
$intersection = array_intersect($model['DecayingModel']['attribute_types'], array($attribute_type));
|
||||||
|
if (count($intersection) > 0) {
|
||||||
|
$associated_default_models[$attribute_type][] = $model['DecayingModel']['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
$associated_models = Hash::combine($associated_models, '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.attribute_type');
|
$associated_models = Hash::combine($associated_models, '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.attribute_type');
|
||||||
return $associated_models;
|
$models = array_merge_recursive($associated_default_models, $associated_models);
|
||||||
|
return $models;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue