Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(View): 'manageTable' array key is not always set #1136

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Db/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
* @method setTitle(string $title)
* @method getTableId(): int
* @method setTableId(int $tableId)
* @method getColumns(): string
* @method setColumns(string $columns)
* @method getCreatedBy(): string
* @method setCreatedBy(string $createdBy)
* @method getCreatedAt(): string
* @method setCreatedAt(string $createdAt)
* @method getFilter(): string
* @method setFilter(string $filter)
* @method getLastEditBy(): string
* @method setLastEditBy(string $lastEditBy)
* @method getLastEditAt(): string
Expand All @@ -39,6 +43,8 @@
* @method setFavorite(bool $favorite)
* @method getRowsCount(): int
* @method setRowsCount(int $rowCount)
* @method getSort(): string
* @method setSort(string $sort)
* @method getOwnerDisplayName(): string
* @method setOwnerDisplayName(string $ownerDisplayName)
*/
Expand All @@ -62,7 +68,6 @@ class View extends Entity implements JsonSerializable {
protected ?string $ownership = null;
protected ?string $ownerDisplayName = null;


public function __construct() {
$this->addType('id', 'integer');
$this->addType('tableId', 'integer');
Expand Down
20 changes: 10 additions & 10 deletions lib/Service/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,22 +368,22 @@ private function enhanceView(View $view, string $userId): void {
$permissions = $this->permissionsService->getPermissionArrayForNodeFromContexts($view->getId(), 'view', $userId);
}
$view->setIsShared(true);
$canManageTable = false;
try {
try {
$manageTableShare = $this->shareService->getSharedPermissionsIfSharedWithMe($view->getTableId(), 'table', $userId);
} catch (NotFoundError) {
$manageTableShare = $this->permissionsService->getPermissionArrayForNodeFromContexts($view->getTableId(), 'table', $userId);
} finally {
$permissions['manageTable'] = $manageTableShare['manage'] ?? false;
}
$permissions['manageTable'] = $manageTableShare['manage'] ?? false;
} catch (NotFoundError $e) {
} catch (\Exception $e) {
throw new InternalError($e->getMessage());
}
$view->setOnSharePermissions($permissions);
} catch (NotFoundError $e) {
} catch (\Exception $e) {
$this->logger->warning('Exception occurred while setting shared permissions: '.$e->getMessage().' No permissions granted.');
$this->logger->warning('Exception occurred while setting shared permissions: ' . $e->getMessage() . ' No permissions granted.');
$view->setOnSharePermissions([
'read' => false,
'create' => false,
Expand Down Expand Up @@ -414,24 +414,24 @@ private function enhanceView(View $view, string $userId): void {
} catch (InternalError|PermissionError $e) {
}

if($view->getIsShared()) {
if ($view->getIsShared()) {
// Remove detailed view filtering and sorting information if necessary
if(!$view->getOnSharePermissions()['manageTable']) {
if (!$view->getOnSharePermissions()['manageTable']) {
$rawFilterArray = $view->getFilterArray();
if($rawFilterArray) {
if ($rawFilterArray) {
$view->setFilterArray(
array_map(function ($filterGroup) {
array_map(static function ($filterGroup) {
// Instead of filter just indicate that there is a filter, but hide details
return array_map(null, $filterGroup);
},
$rawFilterArray));
}
$rawSortArray = $view->getSortArray();
if($rawSortArray) {
if ($rawSortArray) {
$view->setSortArray(
array_map(function ($sortRule) use ($view) {
array_map(static function ($sortRule) use ($view) {
$columnsArray = $view->getColumnsArray();
if(isset($sortRule['columnId']) && $columnsArray && in_array($sortRule['columnId'], $columnsArray)) {
if (isset($sortRule['columnId']) && $columnsArray && in_array($sortRule['columnId'], $columnsArray, true)) {
return $sortRule;
}
// Instead of sort rule just indicate that there is a rule, but hide details
Expand Down
Loading