Skip to content

Commit

Permalink
Merge pull request #878 from nextcloud/feat/noid/node-types
Browse files Browse the repository at this point in the history
node type constants and convenience methods to check access and manage permissions
  • Loading branch information
juliushaertl committed Feb 28, 2024
2 parents 9f3c2b5 + 26096d5 commit 6c1220d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 24 additions & 0 deletions lib/Service/PermissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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') {
Expand Down

0 comments on commit 6c1220d

Please sign in to comment.