mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(server): auto create page owner role (#9944)
This commit is contained in:
@@ -32,6 +32,11 @@ declare global {
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
};
|
||||
'doc.update.pushed': {
|
||||
workspaceId: string;
|
||||
docId: string;
|
||||
editor?: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
@@ -105,6 +110,11 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
|
||||
await this.updateCachedUpdatesCount(workspaceId, docId, batch.length);
|
||||
}
|
||||
});
|
||||
this.event.emit('doc.update.pushed', {
|
||||
workspaceId,
|
||||
docId,
|
||||
editor: editorId,
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error('Failed to insert doc updates', e);
|
||||
metrics.doc.counter('doc_update_insert_failed').add(1);
|
||||
|
||||
@@ -6,6 +6,7 @@ import { groupBy } from 'lodash-es';
|
||||
import {
|
||||
DocAccessDenied,
|
||||
EventBus,
|
||||
OnEvent,
|
||||
SpaceAccessDenied,
|
||||
SpaceOwnerNotFound,
|
||||
SpaceShouldHaveOnlyOneOwner,
|
||||
@@ -29,6 +30,18 @@ export class PermissionService {
|
||||
private readonly event: EventBus
|
||||
) {}
|
||||
|
||||
@OnEvent('doc.update.pushed')
|
||||
async onDocUpdatePushed(payload: Events['doc.update.pushed']) {
|
||||
const { workspaceId, docId, editor } = payload;
|
||||
|
||||
await this.prisma.$queryRaw`
|
||||
INSERT INTO "workspace_page_user_permissions" ("workspace_id", "page_id", "user_id", "type", "accepted", "created_at", "updated_at")
|
||||
VALUES (${workspaceId}, ${docId}, ${editor}, ${DocRole.Owner}, true, now(), now())
|
||||
ON CONFLICT ("workspace_id", "page_id", "user_id")
|
||||
DO NOTHING
|
||||
`;
|
||||
}
|
||||
|
||||
private get acceptedCondition() {
|
||||
return [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user