2024-10-30 15:43:06 +01:00
|
|
|
import { SelectWorkspaceUser } from '@/data/schema';
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 23:14:02 +01:00
|
|
|
const collaborators = attributes.collaborators ?? {};
|
|
|
|
|
if (!collaborators[workspaceUser.id]) {
|
2024-10-30 15:43:06 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async canUpdate(
|
|
|
|
|
workspaceUser: SelectWorkspaceUser,
|
|
|
|
|
node: ServerNode,
|
|
|
|
|
attributes: ServerNodeAttributes,
|
|
|
|
|
): Promise<boolean> {
|
2024-10-30 23:14:02 +01:00
|
|
|
return false;
|
2024-10-30 15:43:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async canDelete(
|
|
|
|
|
workspaceUser: SelectWorkspaceUser,
|
|
|
|
|
node: ServerNode,
|
|
|
|
|
): Promise<boolean> {
|
2024-10-30 23:14:02 +01:00
|
|
|
return false;
|
2024-10-30 15:43:06 +01:00
|
|
|
}
|
|
|
|
|
}
|