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

node type constants and convenience methods to check access and manage permissions #878

Merged
merged 2 commits into from
Feb 28, 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
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
Loading