mirror of
https://github.com/colanode/colanode.git
synced 2025-12-16 11:47:47 +01:00
Minor renames for clarity
This commit is contained in:
@@ -112,13 +112,13 @@ export const getFileMetadata = (filePath: string): FileMetadata | null => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchNodeAncestors = async (
|
export const fetchNodeTree = async (
|
||||||
database:
|
database:
|
||||||
| Kysely<WorkspaceDatabaseSchema>
|
| Kysely<WorkspaceDatabaseSchema>
|
||||||
| Transaction<WorkspaceDatabaseSchema>,
|
| Transaction<WorkspaceDatabaseSchema>,
|
||||||
nodeId: string
|
nodeId: string
|
||||||
): Promise<SelectNode[]> => {
|
): Promise<SelectNode[]> => {
|
||||||
return database
|
const nodes = await database
|
||||||
.withRecursive('ancestor_nodes', (cte) =>
|
.withRecursive('ancestor_nodes', (cte) =>
|
||||||
cte
|
cte
|
||||||
.selectFrom('nodes')
|
.selectFrom('nodes')
|
||||||
@@ -138,6 +138,8 @@ export const fetchNodeAncestors = async (
|
|||||||
.selectFrom('ancestor_nodes')
|
.selectFrom('ancestor_nodes')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
return nodes.reverse();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchNode = (
|
export const fetchNode = (
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ChangeCheckResult, QueryHandler } from '@/main/lib/types';
|
|||||||
import { NodeTreeGetQueryInput } from '@/shared/queries/nodes/node-tree-get';
|
import { NodeTreeGetQueryInput } from '@/shared/queries/nodes/node-tree-get';
|
||||||
import { Event } from '@/shared/types/events';
|
import { Event } from '@/shared/types/events';
|
||||||
import { WorkspaceQueryHandlerBase } from '@/main/queries/workspace-query-handler-base';
|
import { WorkspaceQueryHandlerBase } from '@/main/queries/workspace-query-handler-base';
|
||||||
import { fetchNodeAncestors } from '@/main/lib/utils';
|
import { fetchNodeTree } from '@/main/lib/utils';
|
||||||
import { mapNode } from '@/main/lib/mappers';
|
import { mapNode } from '@/main/lib/mappers';
|
||||||
import { LocalNode } from '@/shared/types/nodes';
|
import { LocalNode } from '@/shared/types/nodes';
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ export class NodeTreeGetQueryHandler
|
|||||||
{
|
{
|
||||||
public async handleQuery(input: NodeTreeGetQueryInput): Promise<LocalNode[]> {
|
public async handleQuery(input: NodeTreeGetQueryInput): Promise<LocalNode[]> {
|
||||||
const workspace = this.getWorkspace(input.accountId, input.workspaceId);
|
const workspace = this.getWorkspace(input.accountId, input.workspaceId);
|
||||||
const rows = await fetchNodeAncestors(workspace.database, input.nodeId);
|
const rows = await fetchNodeTree(workspace.database, input.nodeId);
|
||||||
return rows.map(mapNode);
|
return rows.map(mapNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from '@colanode/core';
|
} from '@colanode/core';
|
||||||
import { decodeState, encodeState, YDoc } from '@colanode/crdt';
|
import { decodeState, encodeState, YDoc } from '@colanode/crdt';
|
||||||
|
|
||||||
import { fetchNodeAncestors } from '@/main/lib/utils';
|
import { fetchNodeTree } from '@/main/lib/utils';
|
||||||
import { mapFile, mapNode } from '@/main/lib/mappers';
|
import { mapFile, mapNode } from '@/main/lib/mappers';
|
||||||
import { eventBus } from '@/shared/lib/event-bus';
|
import { eventBus } from '@/shared/lib/event-bus';
|
||||||
import { WorkspaceService } from '@/main/services/workspaces/workspace-service';
|
import { WorkspaceService } from '@/main/services/workspaces/workspace-service';
|
||||||
@@ -47,8 +47,8 @@ export class NodeService {
|
|||||||
public async createNode(input: CreateNodeInput): Promise<SelectNode> {
|
public async createNode(input: CreateNodeInput): Promise<SelectNode> {
|
||||||
this.debug(`Creating ${Array.isArray(input) ? 'nodes' : 'node'}`);
|
this.debug(`Creating ${Array.isArray(input) ? 'nodes' : 'node'}`);
|
||||||
|
|
||||||
const ancestors = input.parentId
|
const tree = input.parentId
|
||||||
? await fetchNodeAncestors(this.workspace.database, input.parentId)
|
? await fetchNodeTree(this.workspace.database, input.parentId)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const model = getNodeModel(input.attributes.type);
|
const model = getNodeModel(input.attributes.type);
|
||||||
@@ -59,7 +59,7 @@ export class NodeService {
|
|||||||
workspaceId: this.workspace.id,
|
workspaceId: this.workspace.id,
|
||||||
accountId: this.workspace.accountId,
|
accountId: this.workspace.accountId,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
attributes: input.attributes,
|
attributes: input.attributes,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ export class NodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const createdAt = new Date().toISOString();
|
const createdAt = new Date().toISOString();
|
||||||
const rootId = ancestors[0]?.id ?? input.id;
|
const rootId = tree[0]?.id ?? input.id;
|
||||||
|
|
||||||
const { createdNode, createdMutation } = await this.workspace.database
|
const { createdNode, createdMutation } = await this.workspace.database
|
||||||
.transaction()
|
.transaction()
|
||||||
@@ -181,8 +181,8 @@ export class NodeService {
|
|||||||
): Promise<UpdateNodeResult | null> {
|
): Promise<UpdateNodeResult | null> {
|
||||||
this.debug(`Updating node ${nodeId}`);
|
this.debug(`Updating node ${nodeId}`);
|
||||||
|
|
||||||
const ancestors = await fetchNodeAncestors(this.workspace.database, nodeId);
|
const tree = await fetchNodeTree(this.workspace.database, nodeId);
|
||||||
const nodeRow = ancestors[ancestors.length - 1];
|
const nodeRow = tree[tree.length - 1];
|
||||||
if (!nodeRow || nodeRow.id !== nodeId) {
|
if (!nodeRow || nodeRow.id !== nodeId) {
|
||||||
return 'not_found';
|
return 'not_found';
|
||||||
}
|
}
|
||||||
@@ -201,7 +201,7 @@ export class NodeService {
|
|||||||
workspaceId: this.workspace.id,
|
workspaceId: this.workspace.id,
|
||||||
accountId: this.workspace.accountId,
|
accountId: this.workspace.accountId,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
node: node,
|
node: node,
|
||||||
attributes: updatedAttributes,
|
attributes: updatedAttributes,
|
||||||
};
|
};
|
||||||
@@ -332,8 +332,8 @@ export class NodeService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async deleteNode(nodeId: string) {
|
public async deleteNode(nodeId: string) {
|
||||||
const ancestors = await fetchNodeAncestors(this.workspace.database, nodeId);
|
const tree = await fetchNodeTree(this.workspace.database, nodeId);
|
||||||
const nodeRow = ancestors[ancestors.length - 1];
|
const nodeRow = tree[tree.length - 1];
|
||||||
if (!nodeRow || nodeRow.id !== nodeId) {
|
if (!nodeRow || nodeRow.id !== nodeId) {
|
||||||
return 'not_found';
|
return 'not_found';
|
||||||
}
|
}
|
||||||
@@ -349,7 +349,7 @@ export class NodeService {
|
|||||||
workspaceId: this.workspace.id,
|
workspaceId: this.workspace.id,
|
||||||
accountId: this.workspace.accountId,
|
accountId: this.workspace.accountId,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
node: node,
|
node: node,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ export const fetchNode = async (nodeId: string): Promise<SelectNode | null> => {
|
|||||||
return result ?? null;
|
return result ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchNodeAncestors = async (
|
export const fetchNodeTree = async (nodeId: string): Promise<SelectNode[]> => {
|
||||||
nodeId: string
|
|
||||||
): Promise<SelectNode[]> => {
|
|
||||||
const result = await database
|
const result = await database
|
||||||
.selectFrom('nodes')
|
.selectFrom('nodes')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
@@ -317,7 +315,7 @@ export const createNodeFromMutation = async (
|
|||||||
parentId = attributes.parentId;
|
parentId = attributes.parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ancestors = parentId ? await fetchNodeAncestors(parentId) : [];
|
const tree = parentId ? await fetchNodeTree(parentId) : [];
|
||||||
const canCreateNodeContext: CanCreateNodeContext = {
|
const canCreateNodeContext: CanCreateNodeContext = {
|
||||||
user: {
|
user: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
@@ -325,7 +323,7 @@ export const createNodeFromMutation = async (
|
|||||||
workspaceId: user.workspace_id,
|
workspaceId: user.workspace_id,
|
||||||
accountId: user.account_id,
|
accountId: user.account_id,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
attributes,
|
attributes,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -333,7 +331,7 @@ export const createNodeFromMutation = async (
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootId = ancestors[0]?.id ?? mutation.id;
|
const rootId = tree[0]?.id ?? mutation.id;
|
||||||
const createNode: CreateNode = {
|
const createNode: CreateNode = {
|
||||||
id: mutation.id,
|
id: mutation.id,
|
||||||
root_id: rootId,
|
root_id: rootId,
|
||||||
@@ -430,12 +428,12 @@ const tryUpdateNodeFromMutation = async (
|
|||||||
user: SelectUser,
|
user: SelectUser,
|
||||||
mutation: UpdateNodeMutationData
|
mutation: UpdateNodeMutationData
|
||||||
): Promise<ConcurrentUpdateResult<UpdateNodeOutput>> => {
|
): Promise<ConcurrentUpdateResult<UpdateNodeOutput>> => {
|
||||||
const ancestors = await fetchNodeAncestors(mutation.id);
|
const tree = await fetchNodeTree(mutation.id);
|
||||||
if (ancestors.length === 0) {
|
if (tree.length === 0) {
|
||||||
return { type: 'error', output: null };
|
return { type: 'error', output: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = ancestors[ancestors.length - 1];
|
const node = tree[tree.length - 1];
|
||||||
if (!node || node.id !== mutation.id) {
|
if (!node || node.id !== mutation.id) {
|
||||||
return { type: 'error', output: null };
|
return { type: 'error', output: null };
|
||||||
}
|
}
|
||||||
@@ -454,7 +452,7 @@ const tryUpdateNodeFromMutation = async (
|
|||||||
workspaceId: user.workspace_id,
|
workspaceId: user.workspace_id,
|
||||||
accountId: user.account_id,
|
accountId: user.account_id,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
node: mapNode(node),
|
node: mapNode(node),
|
||||||
attributes,
|
attributes,
|
||||||
};
|
};
|
||||||
@@ -544,12 +542,12 @@ export const deleteNode = async (
|
|||||||
user: SelectUser,
|
user: SelectUser,
|
||||||
input: DeleteNodeInput
|
input: DeleteNodeInput
|
||||||
): Promise<DeleteNodeOutput | null> => {
|
): Promise<DeleteNodeOutput | null> => {
|
||||||
const ancestors = await fetchNodeAncestors(input.id);
|
const tree = await fetchNodeTree(input.id);
|
||||||
if (ancestors.length === 0) {
|
if (tree.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const node = ancestors[ancestors.length - 1];
|
const node = tree[tree.length - 1];
|
||||||
if (!node || node.id !== input.id) {
|
if (!node || node.id !== input.id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -562,7 +560,7 @@ export const deleteNode = async (
|
|||||||
workspaceId: user.workspace_id,
|
workspaceId: user.workspace_id,
|
||||||
accountId: user.account_id,
|
accountId: user.account_id,
|
||||||
},
|
},
|
||||||
ancestors: ancestors.map(mapNode),
|
tree: tree.map(mapNode),
|
||||||
node: mapNode(node),
|
node: mapNode(node),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ export const channelModel: NodeModel = {
|
|||||||
type: 'channel',
|
type: 'channel',
|
||||||
attributesSchema: channelAttributesSchema,
|
attributesSchema: channelAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,11 @@ export const channelModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,11 @@ export const channelModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,26 +22,26 @@ export interface NodeMutationUser {
|
|||||||
|
|
||||||
export type CanCreateNodeContext = {
|
export type CanCreateNodeContext = {
|
||||||
user: NodeMutationUser;
|
user: NodeMutationUser;
|
||||||
ancestors: Node[];
|
tree: Node[];
|
||||||
attributes: NodeAttributes;
|
attributes: NodeAttributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CanUpdateAttributesContext = {
|
export type CanUpdateAttributesContext = {
|
||||||
user: NodeMutationUser;
|
user: NodeMutationUser;
|
||||||
ancestors: Node[];
|
tree: Node[];
|
||||||
node: Node;
|
node: Node;
|
||||||
attributes: NodeAttributes;
|
attributes: NodeAttributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CanUpdateDocumentContext = {
|
export type CanUpdateDocumentContext = {
|
||||||
user: NodeMutationUser;
|
user: NodeMutationUser;
|
||||||
ancestors: Node[];
|
tree: Node[];
|
||||||
node: Node;
|
node: Node;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CanDeleteNodeContext = {
|
export type CanDeleteNodeContext = {
|
||||||
user: NodeMutationUser;
|
user: NodeMutationUser;
|
||||||
ancestors: Node[];
|
tree: Node[];
|
||||||
node: Node;
|
node: Node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -93,11 +93,11 @@ export const databaseViewModel: NodeModel = {
|
|||||||
type: 'database_view',
|
type: 'database_view',
|
||||||
attributesSchema: databaseViewAttributesSchema,
|
attributesSchema: databaseViewAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,11 @@ export const databaseViewModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -120,11 +120,11 @@ export const databaseViewModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ export const databaseModel: NodeModel = {
|
|||||||
type: 'database',
|
type: 'database',
|
||||||
attributesSchema: databaseAttributesSchema,
|
attributesSchema: databaseAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,11 @@ export const databaseModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -47,11 +47,11 @@ export const databaseModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,16 @@ export const fileModel: NodeModel = {
|
|||||||
type: 'file',
|
type: 'file',
|
||||||
attributesSchema: fileAttributesSchema,
|
attributesSchema: fileAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = context.ancestors[context.ancestors.length - 1]!;
|
const parent = context.tree[context.tree.length - 1]!;
|
||||||
if (parent.type === 'message') {
|
if (parent.type === 'message') {
|
||||||
return hasNodeRole(role, 'collaborator');
|
return hasNodeRole(role, 'collaborator');
|
||||||
}
|
}
|
||||||
@@ -35,16 +35,16 @@ export const fileModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = context.ancestors[context.ancestors.length - 1]!;
|
const parent = context.tree[context.tree.length - 1]!;
|
||||||
if (parent.type === 'message') {
|
if (parent.type === 'message') {
|
||||||
return parent.createdBy === context.user.id || hasNodeRole(role, 'admin');
|
return parent.createdBy === context.user.id || hasNodeRole(role, 'admin');
|
||||||
}
|
}
|
||||||
@@ -55,16 +55,16 @@ export const fileModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = context.ancestors[context.ancestors.length - 1]!;
|
const parent = context.tree[context.tree.length - 1]!;
|
||||||
if (parent.type === 'message') {
|
if (parent.type === 'message') {
|
||||||
return parent.createdBy === context.user.id || hasNodeRole(role, 'admin');
|
return parent.createdBy === context.user.id || hasNodeRole(role, 'admin');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ export const folderModel: NodeModel = {
|
|||||||
type: 'folder',
|
type: 'folder',
|
||||||
attributesSchema: folderAttributesSchema,
|
attributesSchema: folderAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -30,11 +30,11 @@ export const folderModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -45,11 +45,11 @@ export const folderModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ export const messageModel: NodeModel = {
|
|||||||
type: 'message',
|
type: 'message',
|
||||||
attributesSchema: messageAttributesSchema,
|
attributesSchema: messageAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -34,11 +34,11 @@ export const messageModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'collaborator');
|
return hasNodeRole(role, 'collaborator');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -49,11 +49,11 @@ export const messageModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ export const pageModel: NodeModel = {
|
|||||||
attributesSchema: pageAttributesSchema,
|
attributesSchema: pageAttributesSchema,
|
||||||
documentSchema: richTextContentSchema,
|
documentSchema: richTextContentSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -32,11 +32,11 @@ export const pageModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -44,11 +44,11 @@ export const pageModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateDocument: (context) => {
|
canUpdateDocument: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -56,11 +56,11 @@ export const pageModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ export const recordModel: NodeModel = {
|
|||||||
attributesSchema: recordAttributesSchema,
|
attributesSchema: recordAttributesSchema,
|
||||||
documentSchema: richTextContentSchema,
|
documentSchema: richTextContentSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -35,11 +35,11 @@ export const recordModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'collaborator');
|
return hasNodeRole(role, 'collaborator');
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -51,11 +51,11 @@ export const recordModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canUpdateDocument: (context) => {
|
canUpdateDocument: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -67,11 +67,11 @@ export const recordModel: NodeModel = {
|
|||||||
return hasNodeRole(role, 'editor');
|
return hasNodeRole(role, 'editor');
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const spaceModel: NodeModel = {
|
|||||||
type: 'space',
|
type: 'space',
|
||||||
attributesSchema: spaceAttributesSchema,
|
attributesSchema: spaceAttributesSchema,
|
||||||
canCreate: (context) => {
|
canCreate: (context) => {
|
||||||
if (context.ancestors.length > 0) {
|
if (context.tree.length > 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ export const spaceModel: NodeModel = {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
canUpdateAttributes: (context) => {
|
canUpdateAttributes: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -59,11 +59,11 @@ export const spaceModel: NodeModel = {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
canDelete: (context) => {
|
canDelete: (context) => {
|
||||||
if (context.ancestors.length === 0) {
|
if (context.tree.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = extractNodeRole(context.ancestors, context.user.id);
|
const role = extractNodeRole(context.tree, context.user.id);
|
||||||
if (!role) {
|
if (!role) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user