fix: [analyst-data] Various fixes regarding ACL and recursive fetching

notes
Sami Mokaddem 2024-02-06 10:04:20 +01:00
parent 744a1124fd
commit 9d18007b2e
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
9 changed files with 23 additions and 13 deletions

View File

@ -235,6 +235,7 @@ class CRUDComponent extends Component
throw new NotFoundException(__('Invalid %s.', $modelName));
}
$this->Controller->{$modelName}->includeAnalystData = true;
$this->Controller->{$modelName}->includeAnalystDataRecursive = true;
$query = [
'recursive' => -1,
'conditions' => [$modelName . '.id' => $id],

View File

@ -62,6 +62,7 @@ class EventReportsController extends AppController
public function view($reportId, $ajax=false)
{
$this->EventReport->includeAnalystData = true;
$this->EventReport->includeAnalystDataRecursive = true;
$report = $this->EventReport->simpleFetchById($this->Auth->user(), $reportId);
if ($this->_isRest()) {
return $this->RestResponse->viewData($report, $this->response->type());

View File

@ -1234,6 +1234,7 @@ class EventsController extends AppController
}
$this->Event->Attribute->includeAnalystData = true;
$this->Event->Attribute->includeAnalystDataRecursive = true;
if (isset($filters['focus'])) {
$this->set('focus', $filters['focus']);

View File

@ -174,6 +174,7 @@ class GalaxyClustersController extends AppController
public function view($id)
{
$this->GalaxyCluster->includeAnalystData = true;
$this->GalaxyCluster->includeAnalystDataRecursive = true;
$cluster = $this->GalaxyCluster->fetchIfAuthorized($this->Auth->user(), $id, 'view', $throwErrors=true, $full=true);
$tag = $this->GalaxyCluster->Tag->find('first', array(
'conditions' => array(

View File

@ -256,14 +256,15 @@ class AnalystData extends AppModel
{
$this->Note = ClassRegistry::init('Note');
$this->Opinion = ClassRegistry::init('Opinion');
$paramsNote = [
'recursive' => -1,
'contain' => ['Org', 'Orgc'],
'conditions' => [
'AND' => [
$this->buildConditions($user)
$this->Note->buildConditions($user)
],
'object_type' => $this->current_type,
'object_type' => $analystData['note_type_name'],
'object_uuid' => $analystData['uuid'],
]
];
@ -272,28 +273,28 @@ class AnalystData extends AppModel
'contain' => ['Org', 'Orgc'],
'conditions' => [
'AND' => [
$this->buildConditions($user)
$this->Opinion->buildConditions($user)
],
'object_type' => $this->current_type,
'object_type' => $analystData['note_type_name'],
'object_uuid' => $analystData['uuid'],
]
];
// recursively fetch and include nested notes and opinions
$childNotes = array_map(function ($item) use ($user) {
$expandedNotes = $this->fetchChildNotesAndOpinions($user, $item[$this->Note->current_type]);
$expandedNotes = $this->fetchChildNotesAndOpinions($user, $item['Note']);
return $expandedNotes;
}, $this->Note->find('all', $paramsNote));
$childOpinions = array_map(function ($item) use ($user) {
$expandedNotes = $this->fetchChildNotesAndOpinions($user, $item[$this->Opinion->current_type]);
$expandedNotes = $this->fetchChildNotesAndOpinions($user, $item['Opinion']);
return $expandedNotes;
}, $this->Opinion->find('all', $paramsOpinion));
if (!empty($childNotes)) {
$analystData[$this->Note->current_type] = $childNotes;
$analystData['Note'] = $childNotes;
}
if (!empty($childOpinions)) {
$analystData[$this->Opinion->current_type] = $childOpinions;
$analystData['Opinion'] = $childOpinions;
}
return $analystData;
}

View File

@ -48,6 +48,7 @@ class AppModel extends Model
private $Workflow;
public $includeAnalystData;
public $includeAnalystDataRecursive;
// deprecated, use $db_changes
// major -> minor -> hotfix -> requires_logout

View File

@ -22,8 +22,6 @@ class AnalystDataBehavior extends ModelBehavior
];
$type = $Model->current_type;
if (empty($user['Role']['perm_site_admin'])) {
// $this->SharingGroup = ClassRegistry::init('SharingGroup');
// $validSharingGroups = $this->SharingGroup->authorizedIds($user, true);
$validSharingGroups = $Model->SharingGroup->authorizedIds($user, true);
$conditions['AND'][] = [
'OR' => [

View File

@ -11,7 +11,7 @@ class AnalystDataParentBehavior extends ModelBehavior
public function attachAnalystData(Model $Model, array $object, array $types = ['Note', 'Opinion', 'Relationship'])
public function attachAnalystData(Model $model, array $object, array $types = ['Note', 'Opinion', 'Relationship'])
{
// No uuid, nothing to attach
if (empty($object['uuid'])) {
@ -27,7 +27,9 @@ class AnalystDataParentBehavior extends ModelBehavior
$data = [];
foreach ($types as $type) {
$this->{$type} = ClassRegistry::init($type);
$this->{$type}->fetchRecursive = true;
if ($model->includeAnalystDataRecursive) {
$this->{$type}->fetchRecursive = true;
}
$temp = $this->{$type}->fetchForUuid($object['uuid'], $this->__currentUser);
if (!empty($temp)) {
foreach ($temp as $k => $temp_element) {

View File

@ -2040,7 +2040,9 @@ class Event extends AppModel
$params['page'] = $options['page'];
}
if (!empty($options['includeAnalystData'])) {
$params['includeAnalystData'] = $options['includeAnalystData'];
// $params['includeAnalystData'] = $options['includeAnalystData'];
$this->includeAnalystData = true;
$this->includeAnalystDataRecursive = true;
}
if (!empty($options['order'])) {
$params['order'] = $this->findOrder(
@ -2204,6 +2206,7 @@ class Event extends AppModel
}
if (!empty($options['includeAnalystData'])) {
foreach ($event['Attribute'] as $k => $attribute) {
$this->Attribute->includeAnalystDataRecursive = true;
$analyst_data = $this->Attribute->attachAnalystData($attribute);
$event['Attribute'][$k] = array_merge($event['Attribute'][$k], $analyst_data);
}
@ -2263,6 +2266,7 @@ class Event extends AppModel
$objectValue['Attribute'] = $tempObjectAttributeContainer[$objectValue['id']];
}
if (!empty($options['includeAnalystData'])) {
$this->Object->includeAnalystDataRecursive = true;
$analyst_data = $this->Object->attachAnalystData($objectValue);
$objectValue = array_merge($objectValue, $analyst_data);
}