From d09455f640197f56879cce89d9b06c2387110329 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sat, 15 Oct 2022 09:30:03 +0200 Subject: [PATCH] fix: [UI] Cleanup for reference bulk add --- app/Controller/ObjectReferencesController.php | 30 ++++++++----------- app/View/ObjectReferences/ajax/bulkAdd.ctp | 13 +++----- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/app/Controller/ObjectReferencesController.php b/app/Controller/ObjectReferencesController.php index 58c573def..8e757492a 100644 --- a/app/Controller/ObjectReferencesController.php +++ b/app/Controller/ObjectReferencesController.php @@ -217,11 +217,6 @@ class ObjectReferencesController extends AppController } $selectedAttributeIDs = $this->_jsonDecode($selectedAttributes); - $event = $this->ObjectReference->Object->Event->find('first', array( - 'recursive' => -1, - 'fields' => array('Event.id', 'Event.uuid', 'Event.orgc_id', 'Event.user_id', 'Event.publish_timestamp'), - 'conditions' => array('Event.id' => $eventId) - )); $event = $this->ObjectReference->Object->Event->fetchEvent($this->Auth->user(), [ 'eventid' => $eventId, ]); @@ -233,33 +228,28 @@ class ObjectReferencesController extends AppController throw new ForbiddenException(__('You do not have permission to do that.')); } - $eventObjects = []; - $validSourceUuid = []; - foreach ($event['Object'] as $object) { - $validSourceUuid[$object['uuid']] = sprintf('[%s] %s ', $object['id'], $object['name']); - $eventObjects[$object['uuid']] = $object; - } $selectedAttributes = []; foreach ($event['Attribute'] as $attribute) { if (in_array($attribute['id'], $selectedAttributeIDs)) { $selectedAttributes[$attribute['id']] = $attribute; } } + + if (empty($selectedAttributes)) { + throw new BadRequestException(__('No attribute selected.')); + } + if ($this->request->is('post')) { $conditions = [ 'Object.deleted' => 0, + 'Object.event_id' => $eventId, 'Object.uuid' => $this->data['ObjectReference']['source_uuid'], ]; $object = $this->ObjectReference->Object->find('first', array( 'conditions' => $conditions, 'recursive' => -1, - 'contain' => array( - 'Event' => array( - 'fields' => array('Event.id', 'Event.orgc_id', 'Event.user_id', 'Event.extends_uuid') - ) - ) )); - if (empty($object) || !$this->__canModifyEvent($object)) { + if (empty($object)) { throw new NotFoundException('Invalid object.'); } @@ -310,6 +300,12 @@ class ObjectReferencesController extends AppController } } + $eventObjects = []; + $validSourceUuid = []; + foreach ($event['Object'] as $object) { + $validSourceUuid[$object['uuid']] = sprintf('[%s] %s ', $object['id'], $object['name']); + $eventObjects[$object['uuid']] = $object; + } $this->loadModel('ObjectRelationship'); $relationships = $this->ObjectRelationship->find('column', array( diff --git a/app/View/ObjectReferences/ajax/bulkAdd.ctp b/app/View/ObjectReferences/ajax/bulkAdd.ctp index 33245f0f5..56c2b2284 100644 --- a/app/View/ObjectReferences/ajax/bulkAdd.ctp +++ b/app/View/ObjectReferences/ajax/bulkAdd.ctp @@ -13,6 +13,7 @@ $fields = [ [ 'field' => 'relationship_type_select', 'type' => 'dropdown', + 'title' => __('Relationship type'), 'class' => 'span6', 'options' => $relationships, 'picker' => true, @@ -41,9 +42,9 @@ $fields = [ [ 'field' => 'comment', 'type' => 'textarea', - 'class' => 'input span6' + 'class' => 'input span6', + 'rows' => 3, ], - ]; echo $this->element('genericElements/Form/genericForm', [ 'data' => [ @@ -57,16 +58,10 @@ echo $this->element('genericElements/Form/genericForm', [ ] ] ]); - -if (!$ajax) { - echo $this->element('/genericElements/SideMenu/side_menu', $menuData); -} - ?> -