diff --git a/lib/Db/ContextMapper.php b/lib/Db/ContextMapper.php index 8669b85d1..e60301a9e 100644 --- a/lib/Db/ContextMapper.php +++ b/lib/Db/ContextMapper.php @@ -96,6 +96,9 @@ protected function formatResultRows(array $rows, ?string $userId) { 'display_mode_default' => (int)$item['display_mode_default'], ]; if ($userId !== null) { + if ($item['display_mode'] === null) { + $item['display_mode'] = $item['display_mode_default']; + } $carry[$item['share_id']]['display_mode'] = (int)$item['display_mode']; } return $carry; diff --git a/lib/Db/ContextNavigationMapper.php b/lib/Db/ContextNavigationMapper.php index f32a53f59..be304fb05 100644 --- a/lib/Db/ContextNavigationMapper.php +++ b/lib/Db/ContextNavigationMapper.php @@ -7,6 +7,7 @@ */ namespace OCA\Tables\Db; +use OCP\AppFramework\Db\Entity; use OCP\AppFramework\Db\QBMapper; use OCP\DB\Exception; use OCP\DB\QueryBuilder\IQueryBuilder; @@ -41,4 +42,63 @@ public function setDisplayModeByShareId(int $shareId, int $displayMode, string $ return $this->insertOrUpdate($entity); } + + // we have to overwrite QBMapper`s insert() because we do not have + // an id column in this table. Sad. + public function insert(Entity $entity): Entity { + // get updated fields to save, fields have to be set using a setter to + // be saved + $properties = $entity->getUpdatedFields(); + + $qb = $this->db->getQueryBuilder(); + $qb->insert($this->tableName); + + // build the fields + foreach ($properties as $property => $updated) { + $column = $entity->propertyToColumn($property); + $getter = 'get' . ucfirst($property); + $value = $entity->$getter(); + + $type = $this->getParameterTypeForProperty($entity, $property); + $qb->setValue($column, $qb->createNamedParameter($value, $type)); + } + + $qb->executeStatement(); + + return $entity; + } + + // we have to overwrite QBMapper`s update() because we do not have + // an id column in this table. Sad. + public function update(Entity $entity): ContextNavigation { + if (!$entity instanceof ContextNavigation) { + throw new \LogicException('Can only update context navigation entities'); + } + + // if entity wasn't changed it makes no sense to run a db query + $properties = $entity->getUpdatedFields(); + if (\count($properties) === 0) { + return $entity; + } + + $qb = $this->db->getQueryBuilder(); + $qb->update($this->tableName); + + // build the fields + foreach ($properties as $property => $updated) { + $column = $entity->propertyToColumn($property); + $getter = 'get' . ucfirst($property); + $value = $entity->$getter(); + + $type = $this->getParameterTypeForProperty($entity, $property); + $qb->set($column, $qb->createNamedParameter($value, $type)); + } + + $qb->where($qb->expr()->eq('share_id', $qb->createNamedParameter($entity->getShareId(), IQueryBuilder::PARAM_INT))) + ->andWhere($qb->expr()->eq('user_id', $qb->createNamedParameter($entity->getUserId(), IQueryBuilder::PARAM_STR))); + + $qb->executeStatement(); + + return $entity; + } } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index d4780fd24..1555bd981 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -339,7 +339,8 @@ public function updateDisplayMode(int $shareId, int $displayMode, string $userId } } else { // setting user display mode override only requires access - if (!$this->permissionsService->canAccessContextById($item->getId())) { + // this does not seem to work + if (!$this->permissionsService->canAccessContextById($item->getNodeId(), $userId)) { throw new PermissionError(sprintf('PermissionError: can not update share with id %d', $shareId)); } } diff --git a/src/modules/modals/CreateContext.vue b/src/modules/modals/CreateContext.vue index 04df5de6a..db1959036 100644 --- a/src/modules/modals/CreateContext.vue +++ b/src/modules/modals/CreateContext.vue @@ -42,6 +42,14 @@ +
+ + Show in app list + + +
@@ -54,13 +62,15 @@