Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Introduce the first version of server side validators

Hakan Shehu374a01e240f7
diff --git a/server/src/data/migrations.ts b/server/src/data/migrations.ts
index 709ffc0f..38de4a5b 100644
--- a/server/src/data/migrations.ts
+++ b/server/src/data/migrations.ts
@@ -205,82 +205,6 @@ const createNodePathsTable: Migration = {
},
};
-const createNodeCollaboratorsTable: Migration = {
- up: async (db) => {
- await db.schema
- .createTable('node_collaborators')
- .addColumn('node_id', 'varchar(30)', (col) =>
- col.notNull().references('nodes.id').onDelete('cascade'),
- )
- .addColumn('collaborator_id', 'varchar(30)', (col) =>
- col.notNull().references('nodes.id').onDelete('cascade'),
- )
- .addColumn('role', 'varchar(30)', (col) => col.notNull())
- .addColumn('created_at', 'timestamptz', (col) => col.notNull())
- .addPrimaryKeyConstraint('node_collaborators_pkey', [
- 'node_id',
- 'collaborator_id',
- ])
- .execute();
-
- await sql`
- CREATE OR REPLACE FUNCTION fn_insert_node_collaborators() RETURNS TRIGGER AS $$
- DECLARE
- collaborator_key text;
- collaborator_role text;
- BEGIN
- FOR collaborator_key, collaborator_role IN
- SELECT * FROM jsonb_each_text(NEW.attributes->'collaborators')
- LOOP
- INSERT INTO node_collaborators (node_id, collaborator_id, role, created_at)
- VALUES (NEW.id, collaborator_key, collaborator_role, NOW());
- END LOOP;
-
- RETURN NEW;
- END;
- $$ LANGUAGE plpgsql;
-
- CREATE TRIGGER trg_insert_node_collaborators
- AFTER INSERT ON nodes
- FOR EACH ROW
- EXECUTE FUNCTION fn_insert_node_collaborators();
-
- CREATE OR REPLACE FUNCTION fn_update_node_collaborators() RETURNS TRIGGER AS $$
- DECLARE
- collaborator_key text;
- collaborator_role text;
- BEGIN
- DELETE FROM node_collaborators WHERE node_id = NEW.id;
-
- FOR collaborator_key, collaborator_role IN
- SELECT * FROM jsonb_each_text(NEW.attributes->'collaborators')
- LOOP
- INSERT INTO node_collaborators (node_id, collaborator_id, role, created_at)
- VALUES (NEW.id, collaborator_key, collaborator_role, NOW());
- END LOOP;
-
- RETURN NEW;
- END;
- $$ LANGUAGE plpgsql;
-
- CREATE TRIGGER trg_update_node_collaborators
- AFTER UPDATE ON nodes
- FOR EACH ROW
- EXECUTE FUNCTION fn_update_node_collaborators();
- `.execute(db);
- },
- down: async (db) => {
- await sql`
- DROP TRIGGER IF EXISTS trg_insert_node_collaborators ON nodes;
- DROP TRIGGER IF EXISTS trg_update_node_collaborators ON nodes;
- DROP FUNCTION IF EXISTS fn_insert_node_collaborators();
- DROP FUNCTION IF EXISTS fn_update_node_collaborators();
- `.execute(db);
-
- await db.schema.dropTable('node_collaborators').execute();
- },
-};
-
const createUserNodesTable: Migration = {
up: async (db) => {
await db.schema
@@ -332,7 +256,6 @@ export const databaseMigrations: Record<string, Migration> = {
'00004_create_workspace_users_table': createWorkspaceUsersTable,
'00005_create_nodes_table': createNodesTable,
'00006_create_node_paths_table': createNodePathsTable,
- '00007_create_node_collaborators_table': createNodeCollaboratorsTable,
- '00008_create_user_nodes_table': createUserNodesTable,
- '00009_create_device_nodes_table': createDeviceNodesTable,
+ '00007_create_user_nodes_table': createUserNodesTable,
+ '00008_create_device_nodes_table': createDeviceNodesTable,
};
diff --git a/server/src/data/schema.ts b/server/src/data/schema.ts
index f4d37032..59e76d6a 100644
--- a/server/src/data/schema.ts
+++ b/server/src/data/schema.ts
@@ -117,17 +117,6 @@ export type SelectNodePath = Selectable<NodePathTable>;
export type CreateNodePath = Insertable<NodePathTable>;
export type UpdateNodePath = Updateable<NodePathTable>;
-interface NodeCollaboratorTable {
- node_id: ColumnType<string, string, never>;
- collaborator_id: ColumnType<string, string, never>;
- role: ColumnType<string, string, string>;
- created_at: ColumnType<Date, Date, never>;
-}
-
-export type SelectNodeCollaborator = Selectable<NodeCollaboratorTable>;
-export type CreateNodeCollaborator = Insertable<NodeCollaboratorTable>;
-export type UpdateNodeCollaborator = Updateable<NodeCollaboratorTable>;
-
interface UserNodeTable {
node_id: ColumnType<string, string, never>;
user_id: ColumnType<string, string, never>;
@@ -167,7 +156,6 @@ export interface DatabaseSchema {
workspace_users: WorkspaceUserTable;
nodes: NodeTable;
node_paths: NodePathTable;
- node_collaborators: NodeCollaboratorTable;
user_nodes: UserNodeTable;
device_nodes: DeviceNodeTable;
}
diff --git a/server/src/lib/constants.ts b/server/src/lib/constants.ts
index 67dacb75..9e0607ed 100644
--- a/server/src/lib/constants.ts
+++ b/server/src/lib/constants.ts
@@ -1,9 +1,3 @@
-export const PostgresOperation = {
- CREATE: 'c',
- UPDATE: 'u',
- DELETE: 'd',
-} as const;
-
export const NodeTypes = {
User: 'user',
Space: 'space',
@@ -11,7 +5,6 @@ export const NodeTypes = {
Channel: 'channel',
Chat: 'chat',
Message: 'message',
- HorizontalRule: 'horizontal_rule',
Database: 'database',
DatabaseReplica: 'database_replica',
Record: 'record',
@@ -23,3 +16,42 @@ export const NodeTypes = {
SelectOption: 'select_option',
File: 'file',
};
+
+export const NodeRoles = {
+ Owner: 'owner',
+ Admin: 'admin',
+ Collaborator: 'collaborator',
+ Viewer: 'viewer',
+};
+
+export const nodeRoleHierarchy = [
+ NodeRoles.Owner,
+ NodeRoles.Admin,
+ NodeRoles.Collaborator,
+ NodeRoles.Viewer,
+];
+
+export const hasOwnerAccess = (role: string): boolean => {
+ return role === NodeRoles.Owner;
+};
+
+export const hasAdminAccess = (role: string): boolean => {
+ return role === NodeRoles.Owner || role === NodeRoles.Admin;
+};
+
+export const hasCollaboratorAccess = (role: string): boolean => {
+ return (
+ role === NodeRoles.Owner ||
+ role === NodeRoles.Admin ||
+ role === NodeRoles.Collaborator
+ );
+};
+
+export const hasViewerAccess = (role: string): boolean => {
+ return (
+ role === NodeRoles.Owner ||
+ role === NodeRoles.Admin ||
+ role === NodeRoles.Collaborator ||
+ role === NodeRoles.Viewer
+ );
+};
diff --git a/server/src/lib/nodes.ts b/server/src/lib/nodes.ts
index 55a63847..2e52a9dd 100644
--- a/server/src/lib/nodes.ts
+++ b/server/src/lib/nodes.ts
@@ -1,6 +1,10 @@
import { database } from '@/data/database';
import { SelectNode } from '@/data/schema';
-import { NodeCollaborator, ServerNode } from '@/types/nodes';
+import {
+ NodeCollaborator,
+ ServerNode,
+ ServerNodeAttributes,
+} from '@/types/nodes';
export const mapNode = (node: SelectNode): ServerNode => {
return {
@@ -21,43 +25,18 @@ export const mapNode = (node: SelectNode): ServerNode => {
};
};
-export const fetchCollaboratorRole = async (
+export const fetchNodeAncestors = async (
nodeId: string,
- collaboratorId: string,
-): Promise<string | null> => {
+): Promise<SelectNode[]> => {
const result = await database
- .selectFrom('node_paths as np')
- .innerJoin('node_collaborators as nc', 'np.ancestor_id', 'nc.node_id')
- .select(['np.ancestor_id as node_id', 'np.level as node_level', 'nc.role'])
- .where('np.descendant_id', '=', nodeId)
- .where('nc.collaborator_id', '=', collaboratorId)
+ .selectFrom('nodes')
+ .selectAll()
+ .innerJoin('node_paths', 'nodes.id', 'node_paths.ancestor_id')
+ .where('node_paths.descendant_id', '=', nodeId)
+ .orderBy('node_paths.level', 'desc')
.execute();
- if (result.length === 0) {
- return null;
- }
-
- const roleHierarchy = ['owner', 'admin', 'collaborator'];
- const highestRole = result.reduce((highest, row) => {
- const currentRoleIndex = roleHierarchy.indexOf(row.role);
- const highestRoleIndex = roleHierarchy.indexOf(highest);
- return currentRoleIndex < highestRoleIndex ? row.role : highest;
- }, 'collaborator');
-
- return highestRole;
-};
-
-export const fetchNodeAscendants = async (
- nodeId: string,
-): Promise<string[]> => {
- const result = await database
- .selectFrom('node_paths')
- .select('ancestor_id')
- .where('descendant_id', '=', nodeId)
- .orderBy('level', 'desc')
- .execute();
-
- return result.map((row) => row.ancestor_id);
+ return result;
};
export const fetchNodeDescendants = async (
@@ -76,24 +55,44 @@ export const fetchNodeDescendants = async (
export const fetchNodeCollaborators = async (
nodeId: string,
): Promise<NodeCollaborator[]> => {
- const result = await database
- .selectFrom('node_paths as np')
- .innerJoin('node_collaborators as nc', 'np.ancestor_id', 'nc.node_id')
- .select([
- 'np.ancestor_id as node_id',
- 'np.level as node_level',
- 'nc.collaborator_id',
- 'nc.role',
- ])
- .where('np.descendant_id', '=', nodeId)
- .execute();
+ const ancestors = await fetchNodeAncestors(nodeId);
+ const collaboratorsMap = new Map<string, string>();
+
+ for (const ancestor of ancestors) {
+ const collaborators = extractCollaborators(ancestor.attributes);
+ for (const [collaboratorId, role] of Object.entries(collaborators)) {
+ collaboratorsMap.set(collaboratorId, role);
+ }
+ }
- return result.map((row) => ({
- nodeId: row.node_id,
- level: row.node_level,
- collaboratorId: row.collaborator_id,
- role: row.role,
- }));
+ return Array.from(collaboratorsMap.entries()).map(
+ ([collaboratorId, role]) => ({
+ nodeId: nodeId,
+ collaboratorId: collaboratorId,
+ role: role,
+ }),
+ );
+};
+
+export const fetchNodeRole = async (
+ nodeId: string,
+ collaboratorId: string,
+): Promise<string | null> => {
+ const ancestors = await fetchNodeAncestors(nodeId);
+ if (ancestors.length === 0) {
+ return null;
+ }
+
+ let role: string | null = null;
+ for (const ancestor of ancestors) {
+ const collaborators = extractCollaborators(ancestor.attributes);
+ const collaboratorRole = collaborators[collaboratorId];
+ if (collaboratorRole) {
+ role = collaboratorRole;
+ }
+ }
+
+ return role;
};
export const fetchWorkspaceUsers = async (
@@ -107,3 +106,9 @@ export const fetchWorkspaceUsers = async (
return result.map((row) => row.id);
};
+
+export const extractCollaborators = (
+ attribues: ServerNodeAttributes,
+): Record<string, string> => {
+ return attribues.collaborators ?? {};
+};
diff --git a/server/src/routes/files.ts b/server/src/routes/files.ts
index 72300456..796919c7 100644
--- a/server/src/routes/files.ts
+++ b/server/src/routes/files.ts
@@ -1,6 +1,7 @@
import { database } from '@/data/database';
import { BUCKET_NAMES, filesStorage } from '@/data/storage';
-import { fetchCollaboratorRole } from '@/lib/nodes';
+import { hasCollaboratorAccess, hasViewerAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
import { ApiError, NeuronRequest, NeuronResponse } from '@/types/api';
import { GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
@@ -48,8 +49,8 @@ filesRouter.get(
});
}
- const role = await fetchCollaboratorRole(fileId, workspaceUser.id);
- if (role === null) {
+ const role = await fetchNodeRole(fileId, workspaceUser.id);
+ if (role === null || !hasCollaboratorAccess(role)) {
return res.status(403).json({
code: ApiError.Forbidden,
message: 'Forbidden.',
@@ -123,8 +124,8 @@ filesRouter.post(
});
}
- const role = await fetchCollaboratorRole(fileId, workspaceUser.id);
- if (role === null) {
+ const role = await fetchNodeRole(fileId, workspaceUser.id);
+ if (role === null || !hasViewerAccess(role)) {
return res.status(403).json({
code: ApiError.Forbidden,
message: 'Forbidden.',
diff --git a/server/src/routes/sync.ts b/server/src/routes/sync.ts
index 59e011ea..2416e28e 100644
--- a/server/src/routes/sync.ts
+++ b/server/src/routes/sync.ts
@@ -14,7 +14,6 @@ import {
SyncLocalChangesInput,
} from '@/types/sync';
import { SelectWorkspaceUser } from '@/data/schema';
-import { fetchCollaboratorRole } from '@/lib/nodes';
import { ServerNodeAttributes } from '@/types/nodes';
import { fromUint8Array, toUint8Array } from 'js-base64';
import {
@@ -24,6 +23,8 @@ import {
} from '@/types/events';
import { enqueueEvent } from '@/queues/events';
import { synapse } from '@/services/synapse';
+import { getValidator } from '@/validators';
+import { mapNode } from '@/lib/nodes';
export const syncRouter = Router();
@@ -39,23 +40,10 @@ syncRouter.post(
});
}
- const workspace = await database
- .selectFrom('workspaces')
- .selectAll()
- .where('id', '=', workspaceId)
- .executeTakeFirst();
-
- if (!workspace) {
- return res.status(404).json({
- code: ApiError.ResourceNotFound,
- message: 'Workspace not found.',
- });
- }
-
const workspaceUser = await database
.selectFrom('workspace_users')
.selectAll()
- .where('workspace_id', '=', workspace.id)
+ .where('workspace_id', '=', workspaceId)
.where('account_id', '=', req.account.id)
.executeTakeFirst();
@@ -138,20 +126,17 @@ const handleCreateNodeChange = async (
const attributesMap = doc.getMap('attributes');
const attributes = attributesMap.toJSON() as ServerNodeAttributes;
- if (attributes.parentId) {
- const parentRole = await fetchCollaboratorRole(
- attributes.parentId,
- workspaceUser.id,
- );
+ const validator = getValidator(attributes.type);
+ if (!validator) {
+ return {
+ status: 'error',
+ };
+ }
- if (
- parentRole === null ||
- (parentRole !== 'owner' && parentRole !== 'admin')
- ) {
- return {
- status: 'error',
- };
- }
+ if (!(await validator.canCreate(workspaceUser, attributes))) {
+ return {
+ status: 'error',
+ };
}
await database
@@ -194,7 +179,7 @@ const handleUpdateNodeChange = async (
while (count++ < 10) {
const existingNode = await database
.selectFrom('nodes')
- .select(['id', 'workspace_id', 'attributes', 'state', 'version_id'])
+ .selectAll()
.where('id', '=', changeData.id)
.executeTakeFirst();
@@ -207,13 +192,6 @@ const handleUpdateNodeChange = async (
};
}
- const role = await fetchCollaboratorRole(changeData.id, workspaceUser.id);
- if (role === null) {
- return {
- status: 'error',
- };
- }
-
const doc = new Y.Doc({
guid: changeData.id,
});
@@ -229,6 +207,25 @@ const handleUpdateNodeChange = async (
const attributesJson = JSON.stringify(attributes);
const encodedState = fromUint8Array(Y.encodeStateAsUpdate(doc));
+ const validator = getValidator(existingNode.type);
+ if (!validator) {
+ return {
+ status: 'error',
+ };
+ }
+
+ if (
+ !(await validator.canUpdate(
+ workspaceUser,
+ mapNode(existingNode),
+ attributes,
+ ))
+ ) {
+ return {
+ status: 'error',
+ };
+ }
+
const result = await database
.updateTable('nodes')
.set({
@@ -276,7 +273,7 @@ const handleDeleteNodeChange = async (
const existingNode = await database
.selectFrom('nodes')
.where('id', '=', changeData.id)
- .select(['id', 'workspace_id', 'attributes'])
+ .selectAll()
.executeTakeFirst();
if (!existingNode) {
@@ -291,8 +288,14 @@ const handleDeleteNodeChange = async (
};
}
- const role = await fetchCollaboratorRole(changeData.id, workspaceUser.id);
- if (role === null) {
+ const validator = getValidator(existingNode.type);
+ if (!validator) {
+ return {
+ status: 'error',
+ };
+ }
+
+ if (!(await validator.canDelete(workspaceUser, mapNode(existingNode)))) {
return {
status: 'error',
};
diff --git a/server/src/types/nodes.ts b/server/src/types/nodes.ts
index 61a258cc..558e0865 100644
--- a/server/src/types/nodes.ts
+++ b/server/src/types/nodes.ts
@@ -4,7 +4,7 @@ export type ServerNode = {
parentId?: string | null;
type: string;
index: string | null;
- attributes: ServerNodeAttributes | null;
+ attributes: ServerNodeAttributes;
state: string;
createdAt: Date;
createdBy: string;
@@ -36,7 +36,6 @@ export type NodeBlockMark = {
export type NodeCollaborator = {
nodeId: string;
- level: number;
collaboratorId: string;
role: string;
};
diff --git a/server/src/types/validators.ts b/server/src/types/validators.ts
new file mode 100644
index 00000000..90e98b15
--- /dev/null
+++ b/server/src/types/validators.ts
@@ -0,0 +1,20 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+
+export interface Validator {
+ canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean>;
+
+ canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean>;
+
+ canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean>;
+}
diff --git a/server/src/validators/board-view-validator.ts b/server/src/validators/board-view-validator.ts
new file mode 100644
index 00000000..1c2c77f6
--- /dev/null
+++ b/server/src/validators/board-view-validator.ts
@@ -0,0 +1,56 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class BoardViewValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/calendar-view-validator.ts b/server/src/validators/calendar-view-validator.ts
new file mode 100644
index 00000000..f0a04cf8
--- /dev/null
+++ b/server/src/validators/calendar-view-validator.ts
@@ -0,0 +1,58 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class CalendarViewValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/channel-validator.ts b/server/src/validators/channel-validator.ts
new file mode 100644
index 00000000..4d05f2ea
--- /dev/null
+++ b/server/src/validators/channel-validator.ts
@@ -0,0 +1,68 @@
+import { database } from '@/data/database';
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, NodeRoles, NodeTypes } from '@/lib/constants';
+import { extractCollaborators, fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class ChannelValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parent = await database
+ .selectFrom('nodes')
+ .selectAll()
+ .where('id', '=', attributes.parentId)
+ .executeTakeFirst();
+
+ if (!parent) {
+ return false;
+ }
+
+ if (parent.type !== NodeTypes.Space) {
+ return false;
+ }
+
+ const collaborators = extractCollaborators(parent);
+ const role = collaborators[workspaceUser.id];
+ if (role !== NodeRoles.Owner && role !== NodeRoles.Admin) {
+ return false;
+ }
+
+ return true;
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/chat-validator.ts b/server/src/validators/chat-validator.ts
new file mode 100644
index 00000000..324ad6ea
--- /dev/null
+++ b/server/src/validators/chat-validator.ts
@@ -0,0 +1,51 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasOwnerAccess, NodeRoles } from '@/lib/constants';
+import { extractCollaborators } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+import { WorkspaceRole } from '@/types/workspaces';
+
+export class ChatValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (workspaceUser.role === WorkspaceRole.Viewer) {
+ return false;
+ }
+
+ const collaborators = extractCollaborators(attributes);
+ if (collaborators[workspaceUser.id] !== NodeRoles.Owner) {
+ return false;
+ }
+
+ return true;
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ const collaborators = extractCollaborators(attributes);
+ const role = collaborators[workspaceUser.id];
+ if (role !== NodeRoles.Owner && role !== NodeRoles.Admin) {
+ return false;
+ }
+
+ return true;
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ const collaborators = extractCollaborators(node.attributes);
+ const role = collaborators[workspaceUser.id];
+ if (!role) {
+ return false;
+ }
+
+ return hasOwnerAccess(role);
+ }
+}
diff --git a/server/src/validators/database-validator.ts b/server/src/validators/database-validator.ts
new file mode 100644
index 00000000..4c4238c2
--- /dev/null
+++ b/server/src/validators/database-validator.ts
@@ -0,0 +1,69 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { getIdType, IdType } from '@/lib/id';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class DatabaseValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+}
diff --git a/server/src/validators/field-validator.ts b/server/src/validators/field-validator.ts
new file mode 100644
index 00000000..d4256fa8
--- /dev/null
+++ b/server/src/validators/field-validator.ts
@@ -0,0 +1,56 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class FieldValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/file-validator.ts b/server/src/validators/file-validator.ts
new file mode 100644
index 00000000..777faabc
--- /dev/null
+++ b/server/src/validators/file-validator.ts
@@ -0,0 +1,56 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class FileValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/folder-validator.ts b/server/src/validators/folder-validator.ts
new file mode 100644
index 00000000..ee342518
--- /dev/null
+++ b/server/src/validators/folder-validator.ts
@@ -0,0 +1,69 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { getIdType, IdType } from '@/lib/id';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class FolderValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+}
diff --git a/server/src/validators/index.ts b/server/src/validators/index.ts
new file mode 100644
index 00000000..10048dc2
--- /dev/null
+++ b/server/src/validators/index.ts
@@ -0,0 +1,37 @@
+import { NodeTypes } from '@/lib/constants';
+import { Validator } from '@/types/validators';
+import { BoardViewValidator } from '@/validators/board-view-validator';
+import { CalendarViewValidator } from '@/validators/calendar-view-validator';
+import { ChannelValidator } from '@/validators/channel-validator';
+import { ChatValidator } from '@/validators/chat-validator';
+import { DatabaseValidator } from '@/validators/database-validator';
+import { FieldValidator } from '@/validators/field-validator';
+import { FileValidator } from '@/validators/file-validator';
+import { FolderValidator } from '@/validators/folder-validator';
+import { MessageValidator } from '@/validators/message-validator';
+import { PageValidator } from '@/validators/page-validator';
+import { RecordValidator } from '@/validators/record-validator';
+import { SelectOptionValidator } from '@/validators/select-option-validator';
+import { SpaceValidator } from '@/validators/space-validator';
+import { TableViewValidator } from '@/validators/table-view-validator';
+
+const validators: Record<string, Validator> = {
+ [NodeTypes.BoardView]: new BoardViewValidator(),
+ [NodeTypes.CalendarView]: new CalendarViewValidator(),
+ [NodeTypes.Channel]: new ChannelValidator(),
+ [NodeTypes.Chat]: new ChatValidator(),
+ [NodeTypes.Database]: new DatabaseValidator(),
+ [NodeTypes.Field]: new FieldValidator(),
+ [NodeTypes.File]: new FileValidator(),
+ [NodeTypes.Folder]: new FolderValidator(),
+ [NodeTypes.Message]: new MessageValidator(),
+ [NodeTypes.Page]: new PageValidator(),
+ [NodeTypes.Record]: new RecordValidator(),
+ [NodeTypes.SelectOption]: new SelectOptionValidator(),
+ [NodeTypes.Space]: new SpaceValidator(),
+ [NodeTypes.TableView]: new TableViewValidator(),
+};
+
+export const getValidator = (type: string): Validator | undefined => {
+ return validators[type];
+};
diff --git a/server/src/validators/message-validator.ts b/server/src/validators/message-validator.ts
new file mode 100644
index 00000000..c6f12ff5
--- /dev/null
+++ b/server/src/validators/message-validator.ts
@@ -0,0 +1,65 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+import { isEqual } from 'lodash';
+
+export class MessageValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ if (
+ !isEqual(attributes.content, node.attributes.content) &&
+ node.createdBy !== workspaceUser.id
+ ) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (node.createdBy === workspaceUser.id) {
+ return true;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/page-validator.ts b/server/src/validators/page-validator.ts
new file mode 100644
index 00000000..f70dd1aa
--- /dev/null
+++ b/server/src/validators/page-validator.ts
@@ -0,0 +1,69 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { getIdType, IdType } from '@/lib/id';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class PageValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+}
diff --git a/server/src/validators/record-validator.ts b/server/src/validators/record-validator.ts
new file mode 100644
index 00000000..363b4153
--- /dev/null
+++ b/server/src/validators/record-validator.ts
@@ -0,0 +1,69 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { getIdType, IdType } from '@/lib/id';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class RecordValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+}
diff --git a/server/src/validators/select-option-validator.ts b/server/src/validators/select-option-validator.ts
new file mode 100644
index 00000000..cabb228e
--- /dev/null
+++ b/server/src/validators/select-option-validator.ts
@@ -0,0 +1,57 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess } from '@/lib/constants';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class SelectOptionValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(attributes.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const role = await fetchNodeRole(node.parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasAdminAccess(role);
+ }
+}
diff --git a/server/src/validators/space-validator.ts b/server/src/validators/space-validator.ts
new file mode 100644
index 00000000..d34b63fe
--- /dev/null
+++ b/server/src/validators/space-validator.ts
@@ -0,0 +1,51 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { NodeRoles } from '@/lib/constants';
+import { extractCollaborators } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+import { WorkspaceRole } from '@/types/workspaces';
+
+export class SpaceValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (workspaceUser.role === WorkspaceRole.Viewer) {
+ return false;
+ }
+
+ const collaborators = extractCollaborators(attributes);
+ if (collaborators[workspaceUser.id] !== NodeRoles.Owner) {
+ return false;
+ }
+
+ return true;
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ const collaborators = extractCollaborators(node.attributes);
+ const role = collaborators[workspaceUser.id];
+ if (role !== NodeRoles.Owner && role !== NodeRoles.Admin) {
+ return false;
+ }
+
+ return true;
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ const collaborators = extractCollaborators(node.attributes);
+ const role = collaborators[workspaceUser.id];
+ if (role !== NodeRoles.Owner && role !== NodeRoles.Admin) {
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/server/src/validators/table-view-validator.ts b/server/src/validators/table-view-validator.ts
new file mode 100644
index 00000000..faabd82a
--- /dev/null
+++ b/server/src/validators/table-view-validator.ts
@@ -0,0 +1,69 @@
+import { SelectWorkspaceUser } from '@/data/schema';
+import { hasAdminAccess, hasCollaboratorAccess } from '@/lib/constants';
+import { getIdType, IdType } from '@/lib/id';
+import { fetchNodeRole } from '@/lib/nodes';
+import { ServerNode, ServerNodeAttributes } from '@/types/nodes';
+import { Validator } from '@/types/validators';
+
+export class TableViewValidator implements Validator {
+ async canCreate(
+ workspaceUser: SelectWorkspaceUser,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId) {
+ return false;
+ }
+
+ const parentId = attributes.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canUpdate(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ attributes: ServerNodeAttributes,
+ ): Promise<boolean> {
+ if (!attributes.parentId || attributes.parentId !== node.parentId) {
+ return false;
+ }
+
+ const role = await fetchNodeRole(node.id, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+
+ async canDelete(
+ workspaceUser: SelectWorkspaceUser,
+ node: ServerNode,
+ ): Promise<boolean> {
+ if (!node.parentId) {
+ return false;
+ }
+
+ const parentId = node.parentId;
+ const parentIdType = getIdType(parentId);
+ const role = await fetchNodeRole(parentId, workspaceUser.id);
+ if (!role) {
+ return false;
+ }
+
+ if (parentIdType === IdType.Space) {
+ return hasAdminAccess(role);
+ }
+
+ return hasCollaboratorAccess(role);
+ }
+}