feat(server): auto create page owner role (#9944)
This commit is contained in:
@@ -32,6 +32,11 @@ declare global {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
docId: string;
|
docId: string;
|
||||||
};
|
};
|
||||||
|
'doc.update.pushed': {
|
||||||
|
workspaceId: string;
|
||||||
|
docId: string;
|
||||||
|
editor?: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -105,6 +110,11 @@ export class PgWorkspaceDocStorageAdapter extends DocStorageAdapter {
|
|||||||
await this.updateCachedUpdatesCount(workspaceId, docId, batch.length);
|
await this.updateCachedUpdatesCount(workspaceId, docId, batch.length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.event.emit('doc.update.pushed', {
|
||||||
|
workspaceId,
|
||||||
|
docId,
|
||||||
|
editor: editorId,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('Failed to insert doc updates', e);
|
this.logger.error('Failed to insert doc updates', e);
|
||||||
metrics.doc.counter('doc_update_insert_failed').add(1);
|
metrics.doc.counter('doc_update_insert_failed').add(1);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { groupBy } from 'lodash-es';
|
|||||||
import {
|
import {
|
||||||
DocAccessDenied,
|
DocAccessDenied,
|
||||||
EventBus,
|
EventBus,
|
||||||
|
OnEvent,
|
||||||
SpaceAccessDenied,
|
SpaceAccessDenied,
|
||||||
SpaceOwnerNotFound,
|
SpaceOwnerNotFound,
|
||||||
SpaceShouldHaveOnlyOneOwner,
|
SpaceShouldHaveOnlyOneOwner,
|
||||||
@@ -29,6 +30,18 @@ export class PermissionService {
|
|||||||
private readonly event: EventBus
|
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() {
|
private get acceptedCondition() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user