diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 3679992a9..05047f29a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -26,6 +26,9 @@ class Application extends App implements IBootstrap { public const APP_ID = 'tables'; + public const NODE_TYPE_TABLE = 0; + public const NODE_TYPE_VIEW = 1; + public function __construct() { parent::__construct(self::APP_ID); } diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index 8b3c851de..390011a3b 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -2,6 +2,7 @@ namespace OCA\Tables\Service; +use OCA\Tables\AppInfo\Application; use OCA\Tables\Db\Share; use OCA\Tables\Db\ShareMapper; use OCA\Tables\Db\Table; @@ -95,6 +96,28 @@ public function canUpdateTable(Table $table, ?string $userId = null): bool { return $this->canManageTable($table, $userId); } + public function canAccessNodeById(int $nodeType, int $nodeId, ?string $userId = null): bool { + if ($nodeType === Application::NODE_TYPE_TABLE) { + return $this->canReadColumnsByTableId($nodeId, $this->userId); + } + if ($nodeType === Application::NODE_TYPE_VIEW) { + return $this->canReadColumnsByViewId($nodeId, $this->userId); + } + + return false; + } + + public function canManageNodeById(int $nodeType, int $nodeId, ?string $userId = null): bool { + if ($nodeType === Application::NODE_TYPE_TABLE) { + return $this->canManageTableById($nodeId, $this->userId); + } + if ($nodeType === Application::NODE_TYPE_VIEW) { + return $this->canManageViewById($nodeId, $this->userId); + } + + return false; + } + public function canAccessView(View $view, ?string $userId = null): bool { if($this->basisCheck($view, 'view', $userId)) { return true; @@ -118,6 +141,7 @@ public function canAccessView(View $view, ?string $userId = null): bool { * @param string|null $userId * @return bool * @throws InternalError + * @note prefer canManageNodeById() */ public function canManageElementById(int $elementId, string $nodeType = 'table', ?string $userId = null): bool { if ($nodeType === 'table') {