chg: [attribute:restSearch] New paramter `includeFullModel` to attach

full model information
pull/5032/head
mokaddem 2019-09-06 11:32:54 +02:00
parent 519ec416ea
commit 893dd617c8
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 11 additions and 5 deletions

View File

@ -1892,7 +1892,7 @@ class AttributesController extends AppController
'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id', 'includeEventTags',
'includeProposals', 'returnFormat', 'published', 'limit', 'page', 'requested_attributes', 'includeContext', 'headerless',
'includeWarninglistHits', 'attackGalaxy', 'object_relation', 'includeSightings', 'includeCorrelations', 'includeDecayScore',
'decayingModel', 'excludeDecayed', 'modelOverrides'
'decayingModel', 'excludeDecayed', 'modelOverrides', 'includeFullModel'
);
$filterData = array(
'request' => $this->request,

View File

@ -3279,7 +3279,8 @@ class Attribute extends AppModel
}
if ($options['includeDecayScore']) {
$this->DecayingModel = ClassRegistry::init('DecayingModel');
$this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel'], $options['modelOverrides']);
$include_full_model = isset($options['includeFullModel']) && $options['includeFullModel'] ? 1 : 0;
$this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel'], $options['modelOverrides'], $include_full_model);
if ($options['excludeDecayed']) { // filter out decayed attribute
$decayed_flag = true;
foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) { // remove attribute if ALL score results in a decay
@ -4263,7 +4264,8 @@ class Attribute extends AppModel
'includeContext' => !empty($filters['includeContext']) ? $filters['includeContext'] : 0,
'includeSightings' => !empty($filters['includeSightings']) ? $filters['includeSightings'] : 0,
'includeCorrelations' => !empty($filters['includeCorrelations']) ? $filters['includeCorrelations'] : 0,
'includeDecayScore' => !empty($filters['includeDecayScore']) ? $filters['includeDecayScore'] : 0
'includeDecayScore' => !empty($filters['includeDecayScore']) ? $filters['includeDecayScore'] : 0,
'includeFullModel' => !empty($filters['includeFullModel']) ? $filters['includeFullModel'] : 0
);
if (!empty($filters['attackGalaxy'])) {
$params['attackGalaxy'] = $filters['attackGalaxy'];

View File

@ -510,7 +510,7 @@ class DecayingModel extends AppModel
}
}
public function attachScoresToAttribute($user, &$attribute, $model_id=false, $model_overrides=array())
public function attachScoresToAttribute($user, &$attribute, $model_id=false, $model_overrides=array(), $include_full_model=0)
{
$models = array();
if ($model_id === false) { // fetch all allowed and associated models
@ -530,7 +530,11 @@ class DecayingModel extends AppModel
}
$score = $this->getScore($attribute, $model, $user);
$decayed = $this->isDecayed($attribute, $model, $score);
$attribute['decay_score'][] = array('DecayingModel' => $model['DecayingModel'], 'score' => $score, 'decayed' => $decayed);
$to_attach = array('score' => $score, 'decayed' => $decayed, 'DecayingModel' => array('id' => $model['DecayingModel']['id']));
if ($include_full_model) {
$to_attach['DecayingModel'] = $model['DecayingModel'];
}
$attribute['decay_score'][] = $to_attach;
}
}