fix: [objects:edit] Restored behavior of upgrading object to newer template

pull/9370/head
Sami Mokaddem 2023-10-24 09:26:41 +02:00
parent e406f48965
commit c952fcad4b
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 10 additions and 3 deletions

View File

@ -27,7 +27,7 @@ class ObjectsController extends AppController
}
}
public function revise_object($action, $event_id, $template_id, $object_id = false, $similar_objects_display_threshold=15)
public function revise_object($action, $event_id, $template_id, $object_id = false, $update_template_available = false, $similar_objects_display_threshold=15)
{
if (!$this->request->is('post') && !$this->request->is('put')) {
throw new MethodNotAllowedException(__('This action can only be reached via POST requests'));
@ -79,6 +79,7 @@ class ObjectsController extends AppController
$this->set('object_id', $object_id);
$this->set('event', $event);
$this->set('data', $this->request->data);
$this->set('update_template_available', !empty($update_template_available));
// Make sure the data stored in the session applies to this object. User might be prompted to perform a merge with another object if the session's data is somehow not cleaned
$curObjectTmpUuid = CakeText::uuid();
$this->set('cur_object_tmp_uuid', $curObjectTmpUuid);
@ -368,7 +369,7 @@ class ObjectsController extends AppController
$this->Flash->error('Object cannot be edited, no valid template found. ', ['params' => ['url' => sprintf('/objects/edit/%s/1/0', $id), 'urlName' => __('Force update anyway')]]);
$this->redirect(array('controller' => 'events', 'action' => 'view', $object['Object']['event_id']));
}
if (!empty($template)) {
if (!empty($template) || $update_template_available) {
$templateData = $this->MispObject->resolveUpdatedTemplate($template, $object, $update_template_available);
$this->set('updateable_attribute', $templateData['updateable_attribute']);
$this->set('not_updateable_attribute', $templateData['not_updateable_attribute']);

View File

@ -1398,7 +1398,7 @@ class MispObject extends AppModel
));
$template_difference = array();
if (!empty($newer_template)) {
$toReturn['newer_template_version'] = !$newer_template['ObjectTemplate']['version'];
$toReturn['newer_template_version'] = $newer_template['ObjectTemplate']['version'];
$newer_template_temp = Hash::remove(Hash::remove($newer_template['ObjectTemplateElement'], '{n}.id'), '{n}.object_template_id');
if (!empty($template)) {
// ignore IDs for comparison

View File

@ -5,6 +5,9 @@
$url = $baseurl . '/objects/revise_object/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'];
} else {
$url = $baseurl . '/objects/revise_object/edit/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'] . '/' . h($object['Object']['id']);
if ($update_template_available) {
$url .= '/1';
}
}
echo $this->Form->create('Object', array('id', 'url' => $url, 'enctype' => 'multipart/form-data'));
?>

View File

@ -22,6 +22,9 @@ $tableData = [
$url = $baseurl . '/objects/add/' . $event['Event']['id'] . '/' . $template['ObjectTemplate']['id'];
} else {
$url = $baseurl . '/objects/edit/' . $object_id;
if (!empty($update_template_available)) {
$url .= '/1';
}
}
echo $this->Form->create('Object', array('id', 'url' => $url));
$formSettings = array(