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)); throw new NotFoundException(__('Invalid %s.', $modelName));
} }
$this->Controller->{$modelName}->includeAnalystData = true; $this->Controller->{$modelName}->includeAnalystData = true;
$this->Controller->{$modelName}->includeAnalystDataRecursive = true;
$query = [ $query = [
'recursive' => -1, 'recursive' => -1,
'conditions' => [$modelName . '.id' => $id], 'conditions' => [$modelName . '.id' => $id],

View File

@ -62,6 +62,7 @@ class EventReportsController extends AppController
public function view($reportId, $ajax=false) public function view($reportId, $ajax=false)
{ {
$this->EventReport->includeAnalystData = true; $this->EventReport->includeAnalystData = true;
$this->EventReport->includeAnalystDataRecursive = true;
$report = $this->EventReport->simpleFetchById($this->Auth->user(), $reportId); $report = $this->EventReport->simpleFetchById($this->Auth->user(), $reportId);
if ($this->_isRest()) { if ($this->_isRest()) {
return $this->RestResponse->viewData($report, $this->response->type()); 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->includeAnalystData = true;
$this->Event->Attribute->includeAnalystDataRecursive = true;
if (isset($filters['focus'])) { if (isset($filters['focus'])) {
$this->set('focus', $filters['focus']); $this->set('focus', $filters['focus']);

View File

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

View File

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

View File

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

View File

@ -22,8 +22,6 @@ class AnalystDataBehavior extends ModelBehavior
]; ];
$type = $Model->current_type; $type = $Model->current_type;
if (empty($user['Role']['perm_site_admin'])) { if (empty($user['Role']['perm_site_admin'])) {
// $this->SharingGroup = ClassRegistry::init('SharingGroup');
// $validSharingGroups = $this->SharingGroup->authorizedIds($user, true);
$validSharingGroups = $Model->SharingGroup->authorizedIds($user, true); $validSharingGroups = $Model->SharingGroup->authorizedIds($user, true);
$conditions['AND'][] = [ $conditions['AND'][] = [
'OR' => [ '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 // No uuid, nothing to attach
if (empty($object['uuid'])) { if (empty($object['uuid'])) {
@ -27,7 +27,9 @@ class AnalystDataParentBehavior extends ModelBehavior
$data = []; $data = [];
foreach ($types as $type) { foreach ($types as $type) {
$this->{$type} = ClassRegistry::init($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); $temp = $this->{$type}->fetchForUuid($object['uuid'], $this->__currentUser);
if (!empty($temp)) { if (!empty($temp)) {
foreach ($temp as $k => $temp_element) { foreach ($temp as $k => $temp_element) {

View File

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