Skip to content

Commit

Permalink
Validate that the patched entities are all part of the patched collec…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
carlobeltrame committed Mar 30, 2021
1 parent 9b36f39 commit f0d7a33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ final public function patch($id, $data): BaseEntity {
/**
* Patches a list of entities.
*
* @param mixed $data Expected in the form
* @param \ArrayObject $data Expected in the form
* {
* id: { ***patch paylod*** },
* id2: { ***patch payload*** }
* }
*
* @throws EntityNotFoundException
* @throws EntityValidationException
* @throws NoAccessException
* @throws ORMException
* @throws OptimisticLockException
Expand All @@ -176,9 +177,16 @@ final public function patchList($data) {
$request = $this->getEvent()->getRequest();
$queryParams = $request->getQuery();

// TODO validate that the patched entities are all part of the patched collection URI
// /** @var ContentNodeCollection $allowedEntities */
// $allowedEntities = $this->fetchAll($queryParams);
// validate that the patched entities are all part of the patched collection URI
$ids = array_keys($data->getArrayCopy());
$q = $this->fetchAllQueryBuilder($queryParams)
->andWhere('row.id IN (:ids)')->setParameter('ids', $ids);
$numEntities = intval($q->select('count(row.id)')->getQuery()->getSingleScalarResult());
if ($numEntities !== count($ids)) {
throw (new EntityValidationException())->setMessages([
'' => ['invalidIds' => 'Not all of the ids in the payload are part of the patched collection.']
]);
}

foreach ($data as $key => $value) {
$entity = $this->patch($key, $value);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/activity/content/ColumnLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export default {
let position = 0
return columnContents.map(contentNode => {
return [contentNode.id, {
parentId: this.contentNode.id,
slot: slot,
position: position++
}]
Expand Down

0 comments on commit f0d7a33

Please sign in to comment.