Skip to content

Commit

Permalink
Merge pull request #1136 from nextcloud/fix/1131/undefined-manageTable
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Jun 11, 2024
2 parents d525bcd + 9564f3c commit 75d5ddf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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

0 comments on commit 75d5ddf

Please sign in to comment.