From b6fbb8391d69e7d86432bc36dfcb363d752903cf Mon Sep 17 00:00:00 2001 From: Philipp Hempel Date: Thu, 3 Aug 2023 15:39:50 +0200 Subject: [PATCH] Fix: Create view repair, sharing shared elements possible now Signed-off-by: Philipp Hempel --- appinfo/info.xml | 2 +- lib/Db/ShareMapper.php | 1 - lib/Db/View.php | 2 - .../Version000600Date20230703000000.php | 4 - lib/Service/PermissionsService.php | 68 ++--- lib/Service/ShareService.php | 4 +- src/modules/main/modals/ViewSettings.vue | 81 ++---- .../editViewPartials/SelectedViewColumns.vue | 1 + .../editViewPartials/filter/FilterForm.vue | 4 +- .../editViewPartials/filter/FilterGroup.vue | 1 + .../editViewPartials/sort/SortForm.vue | 2 + .../partials/NavigationBaseViewItem_old.vue | 247 ------------------ src/modules/sidebar/mixins/shareAPI.js | 2 +- .../sidebar/sections/SidebarSharing.vue | 8 +- src/pages/DefaultWrapper.vue | 168 ------------ .../ncTable/mixins/permissionsMixin.js | 3 +- .../components/ncTileButton/NcTileButton.vue | 65 ----- 17 files changed, 73 insertions(+), 590 deletions(-) delete mode 100644 src/modules/navigation/partials/NavigationBaseViewItem_old.vue delete mode 100644 src/pages/DefaultWrapper.vue delete mode 100644 src/shared/components/ncTileButton/NcTileButton.vue diff --git a/appinfo/info.xml b/appinfo/info.xml index b1eb7e61c..197810305 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ Share your tables with users and groups within your cloud. Have a good time and manage whatever you want. ]]> - 0.6.0-dev0 + 0.6.0-dev1 agpl Florian Steffens Tables diff --git a/lib/Db/ShareMapper.php b/lib/Db/ShareMapper.php index a76c8f5c1..a5aa08ef9 100644 --- a/lib/Db/ShareMapper.php +++ b/lib/Db/ShareMapper.php @@ -104,7 +104,6 @@ public function findAllSharesForNode(string $nodeType, int $nodeId, string $send $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->table) - ->where($qb->expr()->eq('sender', $qb->createNamedParameter($sender, IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('node_type', $qb->createNamedParameter($nodeType, IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT))); return $this->findEntities($qb); diff --git a/lib/Db/View.php b/lib/Db/View.php index b27f6b545..e2eff3dd6 100644 --- a/lib/Db/View.php +++ b/lib/Db/View.php @@ -49,8 +49,6 @@ class View extends Entity implements JsonSerializable { protected ?string $columns = null; // json protected ?string $sort = null; // json protected ?string $filter = null; // json - - protected ?bool $isBaseView = false; //TODO: Delete protected ?bool $isShared = null; protected ?array $onSharePermissions = null; protected ?bool $hasShares = false; diff --git a/lib/Migration/Version000600Date20230703000000.php b/lib/Migration/Version000600Date20230703000000.php index a4640b3e4..a68929827 100644 --- a/lib/Migration/Version000600Date20230703000000.php +++ b/lib/Migration/Version000600Date20230703000000.php @@ -48,10 +48,6 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->addColumn('description', Types::TEXT, [ 'notnull' => true, ]); - $table->addColumn('is_base_view', Types::BOOLEAN, [ - 'notnull' => true, - 'default' => false, - ]); $table->addColumn('created_by', Types::STRING, [ 'notnull' => true, 'length' => 64, diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index ece2f86d3..ef205800b 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -84,6 +84,19 @@ public function canAccessView($view, ?string $userId = null): bool { return false; } + /** + * @param int $elementId + * @param string $nodeType + * @param string|null $userId + * @return bool + * @throws InternalError + */ + public function canManageElementById(int $elementId, string $nodeType = 'table', ?string $userId = null): bool { + if ($nodeType === 'table') return $this->canManageTableById($elementId, $userId); + else if ($nodeType === 'view') return $this->canManageViewById($elementId, $userId); + else throw new InternalError('Cannot read permission for node type '.$nodeType); + } + /** * @param View $view * @param string|null $userId @@ -113,6 +126,22 @@ public function canManageTableById(int $tableId, ?string $userId = null): bool { return $this->canManageTable($table, $userId); } + public function canManageViewById(int $viewId, ?string $userId = null): bool { + try { + $view = $this->viewMapper->find($viewId); + } catch (MultipleObjectsReturnedException $e) { + $this->logger->warning('Multiple tables were found for this id'); + return false; + } catch (DoesNotExistException $e) { + $this->logger->warning('No table was found for this id'); + return false; + } catch (InternalError | Exception $e) { + $this->logger->warning('Error occurred: '.$e->getMessage()); + return false; + } + return $this->canManageView($view, $userId); + } + // ***** COLUMNS permissions ***** @@ -237,6 +266,15 @@ public function canReadShare(Share $share, ?string $userId = null): bool { if ($userId === '') { return true; } + try { + if ($this->canManageElementById($share->getNodeId(), $share->getNodeType())){ + return true; + } + } catch (InternalError $e) { + $this->logger->warning('Cannot check manage permissions, permission denied'); + return false; + } + if ($share->getSender() === $userId) { return true; @@ -263,36 +301,6 @@ public function canReadShare(Share $share, ?string $userId = null): bool { return false; } - public function canUpdateShare(Share $item, ?string $userId = null): bool { - try { - $userId = $this->preCheckUserId($userId); - } catch (InternalError $e) { - $this->logger->warning('Cannot pre check the user id, permission denied'); - return false; - } - - if ($userId === '') { - return true; - } - - return $item->getSender() === $userId; - } - - public function canDeleteShare(Share $item, ?string $userId = null): bool { - try { - $userId = $this->preCheckUserId($userId); - } catch (InternalError $e) { - $this->logger->warning('Cannot pre check the user id, permission denied'); - return false; - } - - if ($userId === '') { - return true; - } - - return $item->getSender() === $userId; - } - /** * @param int $elementId * @param string|null $elementType diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index 2c76fe971..2f4834acb 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -226,7 +226,7 @@ public function updatePermission(int $id, string $permission, bool $value): Shar $item = $this->mapper->find($id); // security - if (!$this->permissionsService->canUpdateShare($item)) { + if (!$this->permissionsService->canManageElementById($item->getNodeId(), $item->getNodeType())) { throw new PermissionError('PermissionError: can not update share with id '.$id); } @@ -272,7 +272,7 @@ public function delete(int $id): Share { $item = $this->mapper->find($id); // security - if (!$this->permissionsService->canDeleteShare($item)) { + if (!$this->permissionsService->canManageElementById($item->getNodeId(), $item->getNodeType())) { throw new PermissionError('PermissionError: can not delete share with id '.$id); } diff --git a/src/modules/main/modals/ViewSettings.vue b/src/modules/main/modals/ViewSettings.vue index 4e28fe1bc..26f4a9f7a 100644 --- a/src/modules/main/modals/ViewSettings.vue +++ b/src/modules/main/modals/ViewSettings.vue @@ -1,5 +1,5 @@