From a666b09c8c8a8eb05ce7177262cd6e394f3d84b9 Mon Sep 17 00:00:00 2001 From: Philipp Hempel Date: Fri, 21 Jul 2023 14:05:51 +0200 Subject: [PATCH] Second step of cleanup, Format code, linting Signed-off-by: Philipp Hempel --- lib/Controller/RowController.php | 2 +- lib/Db/ColumnTypes/DatetimeColumnQB.php | 1 - lib/Db/ColumnTypes/NumberColumnQB.php | 1 - lib/Db/ColumnTypes/SelectionColumnQB.php | 2 - lib/Db/ColumnTypes/SuperColumnQB.php | 8 +- lib/Db/ColumnTypes/TextColumnQB.php | 2 - lib/Db/RowMapper.php | 17 +- lib/Db/View.php | 2 +- lib/Db/ViewMapper.php | 6 +- lib/Search/SearchTablesProvider.php | 2 +- lib/Service/ColumnService.php | 9 +- lib/Service/PermissionsService.php | 256 +++++++++--------- lib/Service/RowService.php | 6 +- lib/Service/ShareService.php | 2 +- lib/Service/TableService.php | 4 +- lib/Service/TableTemplateService.php | 2 +- lib/Service/ViewService.php | 30 +- src/App.vue | 1 - src/modules/main/modals/EditColumn.vue | 75 ++--- src/modules/main/modals/ViewSettings.vue | 2 +- .../editViewPartials/SelectedViewColumns.vue | 11 +- .../editViewPartials/filter/FilterEntry.vue | 1 + .../editViewPartials/filter/FilterForm.vue | 3 +- .../editViewPartials/filter/FilterGroup.vue | 3 +- .../editViewPartials/sort/SortEntry.vue | 3 + .../editViewPartials/sort/SortForm.vue | 3 - src/modules/navigation/modals/CreateTable.vue | 1 - src/modules/navigation/modals/CreateView.vue | 1 - .../partials/NavigationViewItem.vue | 5 - .../navigation/sections/Navigation.vue | 2 +- src/modules/sidebar/mixins/shareAPI.js | 1 - src/modules/sidebar/partials/ShareForm.vue | 2 +- src/modules/sidebar/partials/ShareList.vue | 2 +- src/modules/sidebar/sections/Sidebar.vue | 1 - .../sidebar/sections/SidebarSharing.vue | 2 - src/pages/Startpage.vue | 1 - .../ncTable/partials/TableHeader.vue | 1 + .../partials/TableHeaderColumnOptions.vue | 2 + .../columnTypePartials/forms/MainForm.vue | 1 - src/store/data.js | 1 - src/store/store.js | 2 - src/views/TableReferenceWidget.vue | 3 - 42 files changed, 227 insertions(+), 255 deletions(-) diff --git a/lib/Controller/RowController.php b/lib/Controller/RowController.php index 53e7f6598..46bec735e 100644 --- a/lib/Controller/RowController.php +++ b/lib/Controller/RowController.php @@ -130,7 +130,7 @@ public function updateSet( */ public function destroy(int $id, int $viewId): DataResponse { return $this->handleError(function () use ($id, $viewId) { - return $this->service->delete($id, $viewId, $this->userId); + return $this->service->delete($id, $viewId, $this->userId); }); } } diff --git a/lib/Db/ColumnTypes/DatetimeColumnQB.php b/lib/Db/ColumnTypes/DatetimeColumnQB.php index 12689e0fd..fc5db0bf6 100644 --- a/lib/Db/ColumnTypes/DatetimeColumnQB.php +++ b/lib/Db/ColumnTypes/DatetimeColumnQB.php @@ -2,7 +2,6 @@ namespace OCA\Tables\Db\ColumnTypes; -use OCA\Tables\Db\View; use OCP\DB\QueryBuilder\IQueryBuilder; use Psr\Log\LoggerInterface; diff --git a/lib/Db/ColumnTypes/NumberColumnQB.php b/lib/Db/ColumnTypes/NumberColumnQB.php index f418bfb2c..baedb9b11 100644 --- a/lib/Db/ColumnTypes/NumberColumnQB.php +++ b/lib/Db/ColumnTypes/NumberColumnQB.php @@ -2,7 +2,6 @@ namespace OCA\Tables\Db\ColumnTypes; -use OCA\Tables\Db\View; use OCP\DB\QueryBuilder\IQueryBuilder; use Psr\Log\LoggerInterface; diff --git a/lib/Db/ColumnTypes/SelectionColumnQB.php b/lib/Db/ColumnTypes/SelectionColumnQB.php index 1b9314621..029f3561b 100644 --- a/lib/Db/ColumnTypes/SelectionColumnQB.php +++ b/lib/Db/ColumnTypes/SelectionColumnQB.php @@ -2,8 +2,6 @@ namespace OCA\Tables\Db\ColumnTypes; -use OCA\Tables\Db\View; -use OCP\DB\QueryBuilder\IQueryBuilder; use Psr\Log\LoggerInterface; class SelectionColumnQB extends SuperColumnQB implements IColumnTypeQB { diff --git a/lib/Db/ColumnTypes/SuperColumnQB.php b/lib/Db/ColumnTypes/SuperColumnQB.php index 4fb1dd846..62e4a74ba 100644 --- a/lib/Db/ColumnTypes/SuperColumnQB.php +++ b/lib/Db/ColumnTypes/SuperColumnQB.php @@ -22,17 +22,17 @@ public function setPlatform(int $platform) { public function formatCellValue(string $unformattedValue): string { return 'JSON_UNQUOTE(LOWER('.$unformattedValue.'))'; } - public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void { + public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void { $lowerCaseSearchValue = strtolower($unformattedSearchValue); switch ($operator) { case 'begins-with': $lowerCaseSearchValue = $lowerCaseSearchValue . '%'; break; case 'ends-with': - $lowerCaseSearchValue = '%' . $lowerCaseSearchValue; + $lowerCaseSearchValue = '%' . $lowerCaseSearchValue; break; case 'contains': - $lowerCaseSearchValue = '%' . $lowerCaseSearchValue . '%'; + $lowerCaseSearchValue = '%' . $lowerCaseSearchValue . '%'; break; default: break; @@ -45,7 +45,7 @@ public function passSearchValue(IQueryBuilder &$qb, string $unformattedSearchVal * @return string * @throws InternalError */ - private function buildSQLString(string $operator, string $formattedCellValue, string $searchValuePlaceHolder) : string{ + private function buildSQLString(string $operator, string $formattedCellValue, string $searchValuePlaceHolder) : string { if ($this->platform === self::DB_PLATFORM_PGSQL) { return ''; } elseif ($this->platform === self::DB_PLATFORM_SQLITE) { diff --git a/lib/Db/ColumnTypes/TextColumnQB.php b/lib/Db/ColumnTypes/TextColumnQB.php index 21b5b6f83..7275f7ee8 100644 --- a/lib/Db/ColumnTypes/TextColumnQB.php +++ b/lib/Db/ColumnTypes/TextColumnQB.php @@ -2,8 +2,6 @@ namespace OCA\Tables\Db\ColumnTypes; -use OCA\Tables\Db\View; -use OCP\DB\QueryBuilder\IQueryBuilder; use Psr\Log\LoggerInterface; class TextColumnQB extends SuperColumnQB implements IColumnTypeQB { diff --git a/lib/Db/RowMapper.php b/lib/Db/RowMapper.php index 91bd5d7eb..428d9c968 100644 --- a/lib/Db/RowMapper.php +++ b/lib/Db/RowMapper.php @@ -9,7 +9,6 @@ use OCA\Tables\Db\ColumnTypes\SuperColumnQB; use OCA\Tables\Db\ColumnTypes\TextColumnQB; use OCA\Tables\Helper\UserHelper; -use OCA\Tables\Service\ColumnTypes\TextLineBusiness; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; @@ -39,7 +38,7 @@ public function __construct(IDBConnection $db, LoggerInterface $logger, TextColu $this->textColumnQB = $textColumnQB; $this->numberColumnQB = $numberColumnQB; $this->selectionColumnQB = $selectionColumnQB; - $this->datetimeColumnQB= $datetimeColumnQB; + $this->datetimeColumnQB = $datetimeColumnQB; $this->genericColumnQB = $columnQB; $this->columnMapper = $columnMapper; $this->userHelper = $userHelper; @@ -101,15 +100,15 @@ private function buildFilterByColumnType(&$qb, array $filter, string $filterId): private function getInnerFilterExpressions(&$qb, $filterGroup, int $groupIndex): array { $innerFilterExpressions = []; - foreach ($filterGroup as $index=>$filter) { - $innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex.$index); + foreach ($filterGroup as $index => $filter) { + $innerFilterExpressions[] = $this->buildFilterByColumnType($qb, $filter, $groupIndex.$index); } return $innerFilterExpressions; } private function getFilterGroups(&$qb, $filters): array { $filterGroups = []; - foreach ($filters as $groupIndex=>$filterGroup) { + foreach ($filters as $groupIndex => $filterGroup) { $filterGroups[] = $qb->expr()->andX(...$this->getInnerFilterExpressions($qb, $filterGroup, $groupIndex)); } return $filterGroups; @@ -140,18 +139,18 @@ private function resolveSearchValue(string $unresolvedSearchValue, string $userI } private function addOrderByRules(IQueryBuilder &$qb, $sortArray) { - foreach ($sortArray as $index=>$sortRule) { + foreach ($sortArray as $index => $sortRule) { $sortMode = $sortRule['mode']; if (!in_array($sortMode, ['ASC', 'DESC'])) { continue; } $sortColumnPlaceholder = 'sortColumn'.$index; $orderString = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$sortColumnPlaceholder.')), \'.value\'))'; - if (str_starts_with($sortRule['columnType'],'number')) { + if (str_starts_with($sortRule['columnType'], 'number')) { $orderString = 'CAST('.$orderString.' as int)'; } - $qb->addOrderBy($qb->createFunction($orderString),$sortMode); - $qb->setParameter($sortColumnPlaceholder,$sortRule['columnId'], $qb::PARAM_INT); + $qb->addOrderBy($qb->createFunction($orderString), $sortMode); + $qb->setParameter($sortColumnPlaceholder, $sortRule['columnId'], $qb::PARAM_INT); } } diff --git a/lib/Db/View.php b/lib/Db/View.php index ba38b9e8f..7f9c1b9d6 100644 --- a/lib/Db/View.php +++ b/lib/Db/View.php @@ -88,7 +88,7 @@ public function jsonSerialize(): array { 'lastEditAt' => $this->lastEditAt, 'columns' => $this->getColumnsArray(), 'sort' => $this->getSortArray(), - 'isBaseView'=> $this->isBaseView, + 'isBaseView' => $this->isBaseView, 'isShared' => !!$this->isShared, 'onSharePermissions' => $this->onSharePermissions, 'hasShares' => $this->hasShares, diff --git a/lib/Db/ViewMapper.php b/lib/Db/ViewMapper.php index fc77e3776..6a0b04276 100644 --- a/lib/Db/ViewMapper.php +++ b/lib/Db/ViewMapper.php @@ -34,7 +34,9 @@ public function find(int $id, bool $skipEnhancement = false): View { ->from($this->table) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $view = $this->findEntity($qb); - if(!$skipEnhancement) $this->enhanceByOwnership($view); + if(!$skipEnhancement) { + $this->enhanceByOwnership($view); + } return $view; } @@ -112,7 +114,7 @@ public function search(string $term = null, ?string $userId = null, ?int $limit $qb->select('v.*') ->from($this->table, 'v') - ->leftJoin('v','tables_tables', 't','t.id = v.table_id'); + ->leftJoin('v', 'tables_tables', 't', 't.id = v.table_id'); if ($userId !== null && $userId !== '') { $qb->andWhere($qb->expr()->eq('ownership', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) diff --git a/lib/Search/SearchTablesProvider.php b/lib/Search/SearchTablesProvider.php index 9bce86007..0fa53109f 100644 --- a/lib/Search/SearchTablesProvider.php +++ b/lib/Search/SearchTablesProvider.php @@ -44,7 +44,7 @@ class SearchTablesProvider implements IProvider { public function __construct(IAppManager $appManager, IL10N $l10n, - ViewService $viewService, + ViewService $viewService, IURLGenerator $urlGenerator) { $this->appManager = $appManager; $this->l10n = $l10n; diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index 6d4215944..de1784dec 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -7,7 +7,6 @@ use OCA\Tables\Db\Column; use OCA\Tables\Db\ColumnMapper; use OCA\Tables\Db\TableMapper; -use OCA\Tables\Db\ViewMapper; use OCA\Tables\Errors\InternalError; use OCA\Tables\Errors\NotFoundError; use OCA\Tables\Errors\PermissionError; @@ -79,12 +78,14 @@ public function findAllByView(int $viewId, ?string $userId = null): array { $viewColumnIds = $view->getColumnsArray(); $viewColumns = []; foreach ($viewColumnIds as $viewColumnId) { - if ($viewColumnId < 0) continue; + if ($viewColumnId < 0) { + continue; + } try { $viewColumns[] = $this->mapper->find($viewColumnId); } catch (DoesNotExistException $e) { - $this->logger->warning($e->getMessage()); - throw new NotFoundError($e->getMessage()); + $this->logger->warning($e->getMessage()); + throw new NotFoundError($e->getMessage()); } catch (MultipleObjectsReturnedException $e) { $this->logger->error($e->getMessage()); throw new InternalError($e->getMessage()); diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index bde551022..7ca392aed 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -69,13 +69,15 @@ public function preCheckUserId(string $userId = null, bool $canBeEmpty = true): public function canAccessView($view, ?string $userId = null): bool { try { - if($this->basisCheck($view, 'view', $userId)) return true; + if($this->basisCheck($view, 'view', $userId)) { + return true; + } } catch (InternalError $e) { return false; } try { - $this->getSharedPermissionsIfSharedWithMe($view->getId(), 'view', $userId); + $this->getSharedPermissionsIfSharedWithMe($view->getId(), 'view', $userId); return true; } catch (InternalError|NotFoundError $e) { } @@ -89,7 +91,7 @@ public function canAccessView($view, ?string $userId = null): bool { * @return bool */ public function canManageView(View $view, ?string $userId = null): bool { - return $this->checkPermission($view, 'view', 'manage', $userId); + return $this->checkPermission($view, 'view', 'manage', $userId); } public function canManageTable(Table $table, ?string $userId = null): bool { @@ -149,7 +151,7 @@ public function canDeleteColumnsByTableId(int $tableId, ?string $userId = null): * @return bool */ public function canReadRowsByElementId(int $elementId, string $nodeType, ?string $userId = null): bool { - return $this->checkPermissionById($elementId, $nodeType, 'read', $userId); + return $this->checkPermissionById($elementId, $nodeType, 'read', $userId); } public function canReadRowsByElement($element, string $nodeType, ?string $userId = null): bool { @@ -162,7 +164,7 @@ public function canReadRowsByElement($element, string $nodeType, ?string $userId * @return bool */ public function canCreateRowsByViewId(int $viewId, ?string $userId = null): bool { - return $this->checkPermissionById($viewId, 'view', 'create', $userId); + return $this->checkPermissionById($viewId, 'view', 'create', $userId); } /** @@ -171,7 +173,7 @@ public function canCreateRowsByViewId(int $viewId, ?string $userId = null): bool * @return bool */ public function canUpdateRowsByViewId(int $viewId, ?string $userId = null): bool { - return $this->checkPermissionById($viewId, 'view', 'update', $userId); + return $this->checkPermissionById($viewId, 'view', 'update', $userId); } /** @@ -180,7 +182,7 @@ public function canUpdateRowsByViewId(int $viewId, ?string $userId = null): bool * @return bool */ public function canDeleteRowsByViewId(int $viewId, ?string $userId = null): bool { - return $this->checkPermissionById($viewId, 'view', 'delete', $userId); + return $this->checkPermissionById($viewId, 'view', 'delete', $userId); } @@ -252,124 +254,128 @@ public function canDeleteShare(Share $item, ?string $userId = null): bool { return $item->getSender() === $userId; } - public function getSharedPermissionsIfSharedWithMe(int $elementId, ?string $elementType = 'table', string $userId = null): array { - $shares = $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userId, 'user'); - $userGroups = $this->userHelper->getGroupsForUser($userId); - foreach ($userGroups as $userGroup) { - $shares = array_merge($shares, $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userGroup->getGid(), 'group')); - } - if (count($shares) > 0) { - $read = array_reduce($shares, function ($carry, $share) { - return $carry || ($share->getPermissionRead()); - }, false); - $create = array_reduce($shares, function ($carry, $share) { - return $carry || ($share->getPermissionCreate()); - }, false); - $update = array_reduce($shares, function ($carry, $share) { - return $carry || ($share->getPermissionUpdate()); - }, false); - $delete = array_reduce($shares, function ($carry, $share) { - return $carry || ($share->getPermissionDelete()); - }, false); - $manage = array_reduce($shares, function ($carry, $share) { - return $carry || ($share->getPermissionManage()); - }, false); - - return [ - 'read' => $read || $update || $delete || $manage, - 'create' => $create || $manage, - 'update' => $update || $manage, - 'delete' => $delete || $manage, - 'manage' => $manage, - ]; - } - throw new NotFoundError('No share for '.$elementType.' and given user ID found.'); - } - - // private methods ========================================================================== - - private function checkPermission($element, string $nodeType, string $permission, ?string $userId = null): bool { - try { - if($this->basisCheck($element, $nodeType, $userId)) return true; - } catch (InternalError $e) { - return false; - } - - try { - return $this->getSharedPermissionsIfSharedWithMe($element->getId(), $nodeType, $userId)[$permission]; - } catch (NotFoundError $e) { - } - return false; - } - - private function checkPermissionById(int $elementId, string $nodeType, string $permission, ?string $userId = null): bool { - try { - if($this->basisCheckById($elementId, $nodeType, $userId)) return true; - } catch (InternalError $e) { - return false; - } - - try { - return $this->getSharedPermissionsIfSharedWithMe($elementId, $nodeType, $userId)[$permission]; - } catch (NotFoundError $e) { - } - return false; - } - - /** - * @param $element - * @param string $nodeType - * @param string|null $userId - * @return bool - * @throws InternalError - */ - private function basisCheck($element, string $nodeType, ?string &$userId) { - $userId = $this->preCheckUserId($userId); - - if ($userId === '') { - return true; - } - - if ($this->userIsElementOwner($userId, $element)) { - return true; - } - try { - $permissions = $this->getSharedPermissionsIfSharedWithMe($nodeType === 'view' ? $element->getTableId() : $element->getId(), 'table', $userId); - if($permissions['manage']) { - return true; - } - } catch (InternalError | NotFoundError $e) { - } - return false; - } - - /** - * @param int $elementId - * @param string $nodeType - * @param string|null $userId - * @return bool - * @throws DoesNotExistException - * @throws Exception - * @throws InternalError - * @throws MultipleObjectsReturnedException - * @throws NotFoundError - */ - private function basisCheckById(int $elementId, string $nodeType, ?string &$userId) { - $userId = $this->preCheckUserId($userId); - - if ($userId === '') { - return true; - } - - try { - $element = $nodeType === 'table' ? $this->tableMapper->find($elementId) : $this->viewMapper->find($elementId); - return $this->basisCheck($element, $nodeType, $userId); - } catch (DoesNotExistException|MultipleObjectsReturnedException|\Exception $e) { - } - return false; - } - - /** @noinspection PhpUndefinedMethodInspection */ + public function getSharedPermissionsIfSharedWithMe(int $elementId, ?string $elementType = 'table', string $userId = null): array { + $shares = $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userId, 'user'); + $userGroups = $this->userHelper->getGroupsForUser($userId); + foreach ($userGroups as $userGroup) { + $shares = array_merge($shares, $this->shareMapper->findAllSharesForNodeFor($elementType, $elementId, $userGroup->getGid(), 'group')); + } + if (count($shares) > 0) { + $read = array_reduce($shares, function ($carry, $share) { + return $carry || ($share->getPermissionRead()); + }, false); + $create = array_reduce($shares, function ($carry, $share) { + return $carry || ($share->getPermissionCreate()); + }, false); + $update = array_reduce($shares, function ($carry, $share) { + return $carry || ($share->getPermissionUpdate()); + }, false); + $delete = array_reduce($shares, function ($carry, $share) { + return $carry || ($share->getPermissionDelete()); + }, false); + $manage = array_reduce($shares, function ($carry, $share) { + return $carry || ($share->getPermissionManage()); + }, false); + + return [ + 'read' => $read || $update || $delete || $manage, + 'create' => $create || $manage, + 'update' => $update || $manage, + 'delete' => $delete || $manage, + 'manage' => $manage, + ]; + } + throw new NotFoundError('No share for '.$elementType.' and given user ID found.'); + } + + // private methods ========================================================================== + + private function checkPermission($element, string $nodeType, string $permission, ?string $userId = null): bool { + try { + if($this->basisCheck($element, $nodeType, $userId)) { + return true; + } + } catch (InternalError $e) { + return false; + } + + try { + return $this->getSharedPermissionsIfSharedWithMe($element->getId(), $nodeType, $userId)[$permission]; + } catch (NotFoundError $e) { + } + return false; + } + + private function checkPermissionById(int $elementId, string $nodeType, string $permission, ?string $userId = null): bool { + try { + if($this->basisCheckById($elementId, $nodeType, $userId)) { + return true; + } + } catch (InternalError $e) { + return false; + } + + try { + return $this->getSharedPermissionsIfSharedWithMe($elementId, $nodeType, $userId)[$permission]; + } catch (NotFoundError $e) { + } + return false; + } + + /** + * @param $element + * @param string $nodeType + * @param string|null $userId + * @return bool + * @throws InternalError + */ + private function basisCheck($element, string $nodeType, ?string &$userId) { + $userId = $this->preCheckUserId($userId); + + if ($userId === '') { + return true; + } + + if ($this->userIsElementOwner($userId, $element)) { + return true; + } + try { + $permissions = $this->getSharedPermissionsIfSharedWithMe($nodeType === 'view' ? $element->getTableId() : $element->getId(), 'table', $userId); + if($permissions['manage']) { + return true; + } + } catch (InternalError | NotFoundError $e) { + } + return false; + } + + /** + * @param int $elementId + * @param string $nodeType + * @param string|null $userId + * @return bool + * @throws DoesNotExistException + * @throws Exception + * @throws InternalError + * @throws MultipleObjectsReturnedException + * @throws NotFoundError + */ + private function basisCheckById(int $elementId, string $nodeType, ?string &$userId) { + $userId = $this->preCheckUserId($userId); + + if ($userId === '') { + return true; + } + + try { + $element = $nodeType === 'table' ? $this->tableMapper->find($elementId) : $this->viewMapper->find($elementId); + return $this->basisCheck($element, $nodeType, $userId); + } catch (DoesNotExistException|MultipleObjectsReturnedException|\Exception $e) { + } + return false; + } + + /** @noinspection PhpUndefinedMethodInspection */ private function userIsElementOwner(string $userId, $element): bool { return $element->getOwnership() === $userId; } diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index a2b141706..6b1426dc3 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -169,7 +169,7 @@ public function update( } $view = $this->viewMapper->find($viewId); $rowIds = $this->mapper->getRowIdsOfView($view, $userId); - if(!in_array( $id, $rowIds)) { + if(!in_array($id, $rowIds)) { throw new PermissionError('update row id = '.$item->getId().' is not allowed.'); } @@ -224,7 +224,7 @@ public function updateSet( } $view = $this->viewMapper->find($viewId); $rowIds = $this->mapper->getRowIdsOfView($view, $userId); - if(!in_array( $id, $rowIds)) { + if(!in_array($id, $rowIds)) { throw new PermissionError('User should not be able to access row with id = '.$item->getId()); } @@ -283,7 +283,7 @@ public function delete(int $id, int $viewId, string $userId): Row { } $view = $this->viewMapper->find($viewId); $rowIds = $this->mapper->getRowIdsOfView($view, $userId); - if(!in_array( $id, $rowIds)) { + if(!in_array($id, $rowIds)) { throw new PermissionError('User should not be able to access row with id = '.$item->getId()); } diff --git a/lib/Service/ShareService.php b/lib/Service/ShareService.php index f99a305f9..e6b7c2950 100644 --- a/lib/Service/ShareService.php +++ b/lib/Service/ShareService.php @@ -132,7 +132,7 @@ private function findElementsSharedWithMe(?string $elementType = 'table', ?strin try { if ($elementType === 'table') { $element = $this->tableMapper->find($share->getNodeId()); - } else if ($elementType === 'view') { + } elseif ($elementType === 'view') { $element = $this->viewMapper->find($share->getNodeId()); } else { throw new InternalError('Cannot find element of type '.$elementType); diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index ac0a80ad5..10465a7bf 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -168,7 +168,7 @@ private function enhanceTable(Table &$table, string $userId): void { } catch (DoesNotExistException $e) { // Create new base view if none exists $view = $this->viewService->create($table->getTitle(), $table->getEmoji(), $table, true); - $view = $this->viewService->update($view->getId(), ["columns" => json_encode(array_column($this->columnService->findAllByTable($table->getId()),'id'))]); + $view = $this->viewService->update($view->getId(), ["columns" => json_encode(array_column($this->columnService->findAllByTable($table->getId()), 'id'))]); $table->setBaseView($view); } $table->setViews($this->viewService->findAllNotBaseViews($table)); @@ -342,7 +342,7 @@ public function delete(int $id, ?string $userId = null): Table { } // delete all views for that table - $this->viewService->deleteAllByTable($item,$userId); + $this->viewService->deleteAllByTable($item, $userId); // delete all shares for that table $this->shareService->deleteAllForTable($item); diff --git a/lib/Service/TableTemplateService.php b/lib/Service/TableTemplateService.php index a3c23521f..20a77148c 100644 --- a/lib/Service/TableTemplateService.php +++ b/lib/Service/TableTemplateService.php @@ -76,7 +76,7 @@ public function getTemplateList(): array { public function makeTemplate(Table $table, string $template, int $baseViewId): Table { $createColumn = function ($params) use ($table, $baseViewId) {return $this->createColumn($table->getId(), $params, $baseViewId);}; $createRow = function ($data) use ($table, $baseViewId) {$this->createRow($table, $baseViewId, $data);}; - $createView = function ($data) use ($table) {$this->createView($table,$data);}; + $createView = function ($data) use ($table) {$this->createView($table, $data);}; if ($template === 'todo') { $this->makeTodo($createColumn, $createRow); } elseif ($template === 'members') { diff --git a/lib/Service/ViewService.php b/lib/Service/ViewService.php index 3802dcc0d..0f6967215 100644 --- a/lib/Service/ViewService.php +++ b/lib/Service/ViewService.php @@ -94,7 +94,9 @@ public function findBaseView(Table $table, bool $skipTableEnhancement = false, ? throw new PermissionError('PermissionError: can not read views for tableId '.$table->getId()); } $baseView = $this->mapper->findBaseView($table->getId()); - if(!$skipTableEnhancement) $this->enhanceView($baseView, $userId); + if(!$skipTableEnhancement) { + $this->enhanceView($baseView, $userId); + } return $baseView; } catch (\OCP\DB\Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); @@ -129,7 +131,9 @@ public function find(int $id, bool $skipEnhancement = false, ?string $userId = n if (!$this->permissionsService->canAccessView($view, $userId)) { throw new PermissionError('PermissionError: can not read view with id '.$id); } - if(!$skipEnhancement) $this->enhanceView($view, $userId); + if(!$skipEnhancement) { + $this->enhanceView($view, $userId); + } return $view; } @@ -232,7 +236,9 @@ public function update(int $id, array $data, ?string $userId = null, bool $skipT $view->setLastEditBy($userId); $view->setLastEditAt($time->format('Y-m-d H:i:s')); $view = $this->mapper->update($view); - if(!$skipTableEnhancement) $this->enhanceView($view, $userId); + if(!$skipTableEnhancement) { + $this->enhanceView($view, $userId); + } return $view; } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); @@ -312,7 +318,7 @@ private function enhanceView(View &$view, string $userId): void { // (senseless if we have no user in context) if ($userId !== '') { try { - $permissions = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getId(),'view', $userId); + $permissions = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getId(), 'view', $userId); /** @noinspection PhpUndefinedMethodInspection */ $view->setIsShared(true); $canManageTable = false; @@ -334,14 +340,18 @@ private function enhanceView(View &$view, string $userId): void { } } - if (!$this->permissionsService->canReadRowsByElement($view, 'view', $userId)) return; + if (!$this->permissionsService->canReadRowsByElement($view, 'view', $userId)) { + return; + } // add the rows count try { $view->setRowsCount($this->rowService->getViewRowsCount($view, $userId)); } catch (InternalError|PermissionError $e) { } - if (!$this->permissionsService->canManageTableById($view->getTableId(), $userId)) return; + if (!$this->permissionsService->canManageTableById($view->getTableId(), $userId)) { + return; + } // set hasShares if this table is shared by you (you share it with somebody else) // (senseless if we have no user in context) @@ -369,7 +379,7 @@ public function deleteAllByTable(Table $table, ?string $userId = null): View { if (!$this->permissionsService->canManageTable($table, $userId)) { throw new PermissionError('delete all rows for table id = '.$table->getId().' is not allowed.'); } - $views = $this->findAll($table,$userId); + $views = $this->findAll($table, $userId); foreach ($views as $view) { if($view->getIsBaseView()) { $baseView = $view; @@ -383,12 +393,12 @@ public function deleteAllByTable(Table $table, ?string $userId = null): View { public function deleteColumnDataFromViews(int $columnId, Table $table) { $views = $this->mapper->findAll($table->getId()); foreach ($views as $view) { - $filteredSortingRules = array_filter($view->getSortArray(), function($sort) use ($columnId){ + $filteredSortingRules = array_filter($view->getSortArray(), function ($sort) use ($columnId) { return $sort['columnId'] !== $columnId; }); $filteredSortingRules = array_values($filteredSortingRules); - $filteredFilters = array_filter($view->getFilterArray(), function($filterGroup) use ($columnId){ - array_filter($filterGroup, function($filter) use ($columnId){ + $filteredFilters = array_filter($view->getFilterArray(), function ($filterGroup) use ($columnId) { + array_filter($filterGroup, function ($filter) use ($columnId) { return $filter['columnId'] !== $columnId; }); }); diff --git a/src/App.vue b/src/App.vue index 586a43530..7a51ac126 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,7 +49,6 @@ export default { this.$store.commit('setActiveViewId', parseInt(to.params.viewId)) this.$store.commit('setActiveRowId', parseInt(to.params.rowId)) } - // console.debug("Setting table ID to value",to.params.tableId, to) }, }, async created() { diff --git a/src/modules/main/modals/EditColumn.vue b/src/modules/main/modals/EditColumn.vue index 98de0c5b4..bc74f7fcd 100644 --- a/src/modules/main/modals/EditColumn.vue +++ b/src/modules/main/modals/EditColumn.vue @@ -21,20 +21,14 @@
- -
- + +
+ {{ t('tables', 'Last edit') + ': ' }} + {{ updateTime }} + +
@@ -46,47 +40,14 @@
- - - -
- - diff --git a/src/modules/navigation/modals/CreateTable.vue b/src/modules/navigation/modals/CreateTable.vue index 7e604c9d5..2e34f1ed7 100644 --- a/src/modules/navigation/modals/CreateTable.vue +++ b/src/modules/navigation/modals/CreateTable.vue @@ -149,7 +149,6 @@ export default { } else { const newBaseViewId = await this.sendNewTableToBE(this.templateChoice) if (newBaseViewId) { - // showSuccess(t('tables', 'The table "{emoji} {table}" is ready to use.', { emoji: this.icon, table: this.title })) await this.$router.push('/view/' + newBaseViewId) this.actionCancel() } diff --git a/src/modules/navigation/modals/CreateView.vue b/src/modules/navigation/modals/CreateView.vue index b1e09c128..1b3998054 100644 --- a/src/modules/navigation/modals/CreateView.vue +++ b/src/modules/navigation/modals/CreateView.vue @@ -92,7 +92,6 @@ export default { actionCancel() { this.reset() this.$emit('close') - console.debug('Closed') }, async actionConfirm() { if (this.title === '') { diff --git a/src/modules/navigation/partials/NavigationViewItem.vue b/src/modules/navigation/partials/NavigationViewItem.vue index 4996ca6c7..31a94f7a2 100644 --- a/src/modules/navigation/partials/NavigationViewItem.vue +++ b/src/modules/navigation/partials/NavigationViewItem.vue @@ -78,7 +78,6 @@ import Table from 'vue-material-design-icons/Table.vue' import permissionsMixin from '../../../shared/components/ncTable/mixins/permissionsMixin.js' import DialogConfirmation from '../../../shared/modals/DialogConfirmation.vue' import Creation from 'vue-material-design-icons/Creation.vue' -import Import from 'vue-material-design-icons/Import.vue' import TableMultiple from 'vue-material-design-icons/TableMultiple.vue' import { emit } from '@nextcloud/event-bus' @@ -94,7 +93,6 @@ export default { NcActionButton, Creation, NcAvatar, - Import, TableMultiple, }, @@ -137,9 +135,6 @@ export default { emit('tables:sidebar:sharing', { open: true, tab: 'sharing' }) await this.$router.push('/view/' + parseInt(this.view.id)).catch(err => err) }, - // async actionShowImport(table) { - // emit('tables:modal:import', table) - // }, async actionShowIntegration() { emit('tables:sidebar:integration', { open: true, tab: 'integration' }) await this.$router.push('/view/' + parseInt(this.view.id)).catch(err => err) diff --git a/src/modules/navigation/sections/Navigation.vue b/src/modules/navigation/sections/Navigation.vue index 74b2c990a..b7faf2abd 100644 --- a/src/modules/navigation/sections/Navigation.vue +++ b/src/modules/navigation/sections/Navigation.vue @@ -71,7 +71,7 @@ import CreateTable from '../modals/CreateTable.vue' import ViewSettings from '../../main/modals/ViewSettings.vue' import NavigationViewItem from '../partials/NavigationViewItem.vue' import NavigationBaseViewItem from '../partials/NavigationBaseViewItem.vue' -import { mapState, mapGetters } from 'vuex' +import { mapState } from 'vuex' import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus' import Magnify from 'vue-material-design-icons/Magnify.vue' import { getCurrentUser } from '@nextcloud/auth' diff --git a/src/modules/sidebar/mixins/shareAPI.js b/src/modules/sidebar/mixins/shareAPI.js index dd49c2398..66e7edc68 100644 --- a/src/modules/sidebar/mixins/shareAPI.js +++ b/src/modules/sidebar/mixins/shareAPI.js @@ -18,7 +18,6 @@ export default { }, async sendNewTableShareToBE(share) { - console.debug(share) const data = { nodeType: 'table', nodeId: this.activeView.tableId, diff --git a/src/modules/sidebar/partials/ShareForm.vue b/src/modules/sidebar/partials/ShareForm.vue index 78f8e7e3f..82986182a 100644 --- a/src/modules/sidebar/partials/ShareForm.vue +++ b/src/modules/sidebar/partials/ShareForm.vue @@ -57,7 +57,7 @@ import { getCurrentUser } from '@nextcloud/auth' import axios from '@nextcloud/axios' import debounce from 'debounce' import { NcSelect } from '@nextcloud/vue' -import { mapGetters, mapState } from 'vuex' +import { mapState } from 'vuex' import formatting from '../../../shared/mixins/formatting.js' import ShareTypes from '../mixins/shareTypesMixin.js' diff --git a/src/modules/sidebar/partials/ShareList.vue b/src/modules/sidebar/partials/ShareList.vue index bd3721a2c..ca387101f 100644 --- a/src/modules/sidebar/partials/ShareList.vue +++ b/src/modules/sidebar/partials/ShareList.vue @@ -125,7 +125,6 @@ import moment from '@nextcloud/moment' export default { components: { - // UserBubble, NcAvatar, NcActionButton, NcActions, @@ -224,6 +223,7 @@ export default { .high-line-height { line-height: 35px; } + .manage-button { display: flex; justify-content: center; diff --git a/src/modules/sidebar/sections/Sidebar.vue b/src/modules/sidebar/sections/Sidebar.vue index bd1095820..46f46beda 100644 --- a/src/modules/sidebar/sections/Sidebar.vue +++ b/src/modules/sidebar/sections/Sidebar.vue @@ -79,7 +79,6 @@ export default { }, methods: { handleToggleSidebar(data) { - console.debug('toggle sidebar in nav', data) this.showSidebar = data.open ? data.open : false this.activeSidebarTab = data.tab ? data.tab : '' }, diff --git a/src/modules/sidebar/sections/SidebarSharing.vue b/src/modules/sidebar/sections/SidebarSharing.vue index 5f33bd3b9..b07d9261f 100644 --- a/src/modules/sidebar/sections/SidebarSharing.vue +++ b/src/modules/sidebar/sections/SidebarSharing.vue @@ -67,12 +67,10 @@ export default { } }, async addShare(share) { - console.debug('add share triggered', share) await this.sendNewShareToBE(share) await this.loadSharesFromBE() }, async updateShare(data) { - console.debug('update share triggered', data) const shareId = data.id delete data.id await this.updateShareToBE(shareId, data) diff --git a/src/pages/Startpage.vue b/src/pages/Startpage.vue index b0e712734..5983e5814 100644 --- a/src/pages/Startpage.vue +++ b/src/pages/Startpage.vue @@ -15,7 +15,6 @@