mirror of https://github.com/buster-so/buster.git
add new chats to asset_permissions table
This commit is contained in:
parent
c1bce20bb5
commit
754af01ed1
|
@ -1,8 +1,10 @@
|
|||
import { canUserAccessChatCached } from '@buster/access-controls';
|
||||
import type { ModelMessage } from '@buster/ai';
|
||||
import {
|
||||
CreateAssetPermissionParams,
|
||||
type User,
|
||||
chats,
|
||||
createAssetPermission,
|
||||
createMessage,
|
||||
db,
|
||||
generateAssetMessages,
|
||||
|
@ -329,6 +331,20 @@ export async function handleNewChat({
|
|||
throw new Error('Failed to create chat');
|
||||
}
|
||||
|
||||
try {
|
||||
await createAssetPermission({
|
||||
identityId: user.id,
|
||||
identityType: 'user',
|
||||
assetId: newChat.id,
|
||||
assetType: 'chat',
|
||||
role: 'owner',
|
||||
createdBy: user.id,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to create chat asset permission for user');
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Create initial message if prompt provided
|
||||
let message: Message | null = null;
|
||||
if (prompt) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
-- Custom SQL migration file, put your code below! --
|
||||
|
||||
-- Add asset permissions for chat owners
|
||||
INSERT INTO public.asset_permissions (
|
||||
identity_id,
|
||||
identity_type,
|
||||
asset_id,
|
||||
asset_type,
|
||||
role,
|
||||
created_by,
|
||||
updated_by,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
SELECT
|
||||
c.created_by as identity_id,
|
||||
'user'::identity_type_enum as identity_type,
|
||||
c.id as asset_id,
|
||||
'chat'::asset_type_enum as asset_type,
|
||||
'owner'::asset_permission_role_enum as role,
|
||||
c.created_by as created_by,
|
||||
c.created_by as updated_by,
|
||||
NOW() as created_at,
|
||||
NOW() as updated_at
|
||||
FROM public.chats c
|
||||
WHERE c.deleted_at IS NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM public.asset_permissions ap
|
||||
WHERE ap.asset_id = c.id
|
||||
AND ap.asset_type = 'chat'::asset_type_enum
|
||||
AND ap.identity_id = c.created_by
|
||||
AND ap.identity_type = 'user'::identity_type_enum
|
||||
AND ap.deleted_at IS NULL
|
||||
);
|
File diff suppressed because it is too large
Load Diff
|
@ -708,6 +708,13 @@
|
|||
"when": 1757975000317,
|
||||
"tag": "0101_superb_norman_osborn",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 102,
|
||||
"version": "7",
|
||||
"when": 1758044404631,
|
||||
"tag": "0102_unusual_moon_knight",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue