fix: [encryption] keys could not be added due to invalid marshaling, fixes #15

remotes/origin/main
iglocska 2020-06-23 14:42:53 +02:00
parent 3c0bee7848
commit 1a50e2ded1
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 8 additions and 3 deletions

View File

@ -5,6 +5,8 @@ namespace App\Model\Table;
use App\Model\Table\AppTable; use App\Model\Table\AppTable;
use Cake\ORM\Table; use Cake\ORM\Table;
use Cake\Validation\Validator; use Cake\Validation\Validator;
use Cake\Event\EventInterface;
use ArrayObject;
class EncryptionKeysTable extends AppTable class EncryptionKeysTable extends AppTable
{ {
@ -31,11 +33,14 @@ class EncryptionKeysTable extends AppTable
public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options) public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObject $options)
{ {
if (isset($data['owner_id'])) { if (empty($data['owner_id'])) {
if (empty($data['owner_type']) || !in_array(['individual', 'organisation'], $data['owner_type'])) { if (empty($data['owner_type'])) {
return false; return false;
} }
$data[$data['owner_type'] . '_id'] = $data['owner_id']; if (empty($data[$data['owner_type'] . '_id'])) {
return false;
}
$data['owner_id'] = $data[$data['owner_type'] . '_id'];
} }
} }