refactor(server): permission (#10449)
This commit is contained in:
@@ -10,14 +10,12 @@ import { Config } from '../../../base';
|
||||
import { ConfigModule } from '../../../base/config';
|
||||
import { Models } from '../../../models';
|
||||
import { PgWorkspaceDocStorageAdapter } from '../../doc';
|
||||
import { PermissionService } from '../../permission';
|
||||
|
||||
const test = ava as TestFn<{
|
||||
models: Models;
|
||||
app: TestingApp;
|
||||
config: Config;
|
||||
adapter: PgWorkspaceDocStorageAdapter;
|
||||
permission: PermissionService;
|
||||
}>;
|
||||
|
||||
test.before(async t => {
|
||||
@@ -38,7 +36,6 @@ test.before(async t => {
|
||||
t.context.models = app.get(Models);
|
||||
t.context.config = app.get(Config);
|
||||
t.context.adapter = app.get(PgWorkspaceDocStorageAdapter);
|
||||
t.context.permission = app.get(PermissionService);
|
||||
t.context.app = app;
|
||||
});
|
||||
|
||||
@@ -60,7 +57,7 @@ test.after.always(async t => {
|
||||
|
||||
test('should render page success', async t => {
|
||||
const docId = randomUUID();
|
||||
const { app, adapter, permission } = t.context;
|
||||
const { app, adapter, models } = t.context;
|
||||
|
||||
const doc = new YDoc();
|
||||
const text = doc.getText('content');
|
||||
@@ -75,7 +72,7 @@ test('should render page success', async t => {
|
||||
text.insert(5, ' ');
|
||||
|
||||
await adapter.pushDocUpdates(workspace.id, docId, updates, user.id);
|
||||
await permission.publishPage(workspace.id, docId);
|
||||
await models.workspace.publishDoc(workspace.id, docId);
|
||||
|
||||
await app.GET(`/workspace/${workspace.id}/${docId}`).expect(200);
|
||||
t.pass();
|
||||
|
||||
@@ -6,10 +6,10 @@ import type { Request, Response } from 'express';
|
||||
import isMobile from 'is-mobile';
|
||||
|
||||
import { Config, metrics } from '../../base';
|
||||
import { Models } from '../../models';
|
||||
import { htmlSanitize } from '../../native';
|
||||
import { Public } from '../auth';
|
||||
import { DocReader } from '../doc';
|
||||
import { PermissionService } from '../permission';
|
||||
|
||||
interface RenderOptions {
|
||||
title: string;
|
||||
@@ -51,8 +51,8 @@ export class DocRendererController {
|
||||
|
||||
constructor(
|
||||
private readonly doc: DocReader,
|
||||
private readonly permission: PermissionService,
|
||||
private readonly config: Config
|
||||
private readonly config: Config,
|
||||
private readonly models: Models
|
||||
) {
|
||||
this.webAssets = this.readHtmlAssets(
|
||||
join(this.config.projectRoot, 'static')
|
||||
@@ -102,14 +102,15 @@ export class DocRendererController {
|
||||
workspaceId: string,
|
||||
docId: string
|
||||
): Promise<RenderOptions | null> {
|
||||
let allowUrlPreview = await this.permission.isPublicPage(
|
||||
let allowUrlPreview = await this.models.workspace.isPublicPage(
|
||||
workspaceId,
|
||||
docId
|
||||
);
|
||||
|
||||
if (!allowUrlPreview) {
|
||||
// if page is private, but workspace url preview is on
|
||||
allowUrlPreview = await this.permission.allowUrlPreview(workspaceId);
|
||||
allowUrlPreview =
|
||||
await this.models.workspace.allowUrlPreview(workspaceId);
|
||||
}
|
||||
|
||||
if (allowUrlPreview) {
|
||||
@@ -122,7 +123,8 @@ export class DocRendererController {
|
||||
private async getWorkspaceContent(
|
||||
workspaceId: string
|
||||
): Promise<RenderOptions | null> {
|
||||
const allowUrlPreview = await this.permission.allowUrlPreview(workspaceId);
|
||||
const allowUrlPreview =
|
||||
await this.models.workspace.allowUrlPreview(workspaceId);
|
||||
|
||||
if (allowUrlPreview) {
|
||||
const workspaceContent = await this.doc.getWorkspaceContent(workspaceId);
|
||||
|
||||
Reference in New Issue
Block a user