chore: cleanup outdated api (#6604)
This commit is contained in:
@@ -36,10 +36,17 @@ export class WorkspacesController {
|
|||||||
@Get('/:id/blobs/:name')
|
@Get('/:id/blobs/:name')
|
||||||
@CallTimer('controllers', 'workspace_get_blob')
|
@CallTimer('controllers', 'workspace_get_blob')
|
||||||
async blob(
|
async blob(
|
||||||
|
@CurrentUser() user: CurrentUser | undefined,
|
||||||
@Param('id') workspaceId: string,
|
@Param('id') workspaceId: string,
|
||||||
@Param('name') name: string,
|
@Param('name') name: string,
|
||||||
@Res() res: Response
|
@Res() res: Response
|
||||||
) {
|
) {
|
||||||
|
// if workspace is public or have any public page, then allow to access
|
||||||
|
// otherwise, check permission
|
||||||
|
if (!(await this.permission.tryCheckWorkspace(workspaceId, user?.id))) {
|
||||||
|
throw new ForbiddenException('Permission denied');
|
||||||
|
}
|
||||||
|
|
||||||
const { body, metadata } = await this.storage.get(workspaceId, name);
|
const { body, metadata } = await this.storage.get(workspaceId, name);
|
||||||
|
|
||||||
if (!body) {
|
if (!body) {
|
||||||
|
|||||||
@@ -81,10 +81,22 @@ export class PermissionService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if a doc binary is accessible by a user
|
||||||
|
*/
|
||||||
async isAccessible(ws: string, id: string, user?: string): Promise<boolean> {
|
async isAccessible(ws: string, id: string, user?: string): Promise<boolean> {
|
||||||
// workspace
|
|
||||||
if (ws === id) {
|
if (ws === id) {
|
||||||
return this.tryCheckWorkspace(ws, user, Permission.Read);
|
// if workspace is public or have any public page, then allow to access
|
||||||
|
const [isPublicWorkspace, publicPages] = await Promise.all([
|
||||||
|
this.tryCheckWorkspace(ws, user, Permission.Read),
|
||||||
|
await this.prisma.workspacePage.count({
|
||||||
|
where: {
|
||||||
|
workspaceId: ws,
|
||||||
|
public: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
return isPublicWorkspace || publicPages > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.tryCheckPage(ws, id, user);
|
return this.tryCheckPage(ws, id, user);
|
||||||
@@ -155,21 +167,6 @@ export class PermissionService {
|
|||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicPage = await this.prisma.workspacePage.findFirst({
|
|
||||||
select: {
|
|
||||||
pageId: true,
|
|
||||||
},
|
|
||||||
where: {
|
|
||||||
workspaceId: ws,
|
|
||||||
public: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// has any public pages
|
|
||||||
if (publicPage) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|||||||
@@ -188,23 +188,6 @@ export class WorkspaceResolver {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throttle('strict')
|
|
||||||
@Public()
|
|
||||||
@Query(() => WorkspaceType, {
|
|
||||||
description: 'Get public workspace by id',
|
|
||||||
})
|
|
||||||
async publicWorkspace(@Args('id') id: string) {
|
|
||||||
const workspace = await this.prisma.workspace.findUnique({
|
|
||||||
where: { id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (workspace?.public) {
|
|
||||||
return workspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundException("Workspace doesn't exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Query(() => WorkspaceType, {
|
@Query(() => WorkspaceType, {
|
||||||
description: 'Get workspace by id',
|
description: 'Get workspace by id',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -278,9 +278,6 @@ type Query {
|
|||||||
listWorkspaceFeatures(feature: FeatureType!): [WorkspaceType!]!
|
listWorkspaceFeatures(feature: FeatureType!): [WorkspaceType!]!
|
||||||
prices: [SubscriptionPrice!]!
|
prices: [SubscriptionPrice!]!
|
||||||
|
|
||||||
"""Get public workspace by id"""
|
|
||||||
publicWorkspace(id: String!): WorkspaceType!
|
|
||||||
|
|
||||||
"""server config"""
|
"""server config"""
|
||||||
serverConfig: ServerConfigType!
|
serverConfig: ServerConfigType!
|
||||||
|
|
||||||
|
|||||||
@@ -79,26 +79,6 @@ export async function getWorkspace(
|
|||||||
return res.body.data.workspace;
|
return res.body.data.workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPublicWorkspace(
|
|
||||||
app: INestApplication,
|
|
||||||
workspaceId: string
|
|
||||||
): Promise<WorkspaceType> {
|
|
||||||
const res = await request(app.getHttpServer())
|
|
||||||
.post(gql)
|
|
||||||
.set({ 'x-request-id': 'test', 'x-operation-name': 'test' })
|
|
||||||
.send({
|
|
||||||
query: `
|
|
||||||
query {
|
|
||||||
publicWorkspace(id: "${workspaceId}") {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
})
|
|
||||||
.expect(200);
|
|
||||||
return res.body.data.publicWorkspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateWorkspace(
|
export async function updateWorkspace(
|
||||||
app: INestApplication,
|
app: INestApplication,
|
||||||
token: string,
|
token: string,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {
|
|||||||
createTestingApp,
|
createTestingApp,
|
||||||
createWorkspace,
|
createWorkspace,
|
||||||
currentUser,
|
currentUser,
|
||||||
getPublicWorkspace,
|
|
||||||
getWorkspacePublicPages,
|
getWorkspacePublicPages,
|
||||||
inviteUser,
|
inviteUser,
|
||||||
publishPage,
|
publishPage,
|
||||||
@@ -87,20 +86,6 @@ test('should can publish workspace', async t => {
|
|||||||
t.false(isPrivate, 'failed to unpublish workspace');
|
t.false(isPrivate, 'failed to unpublish workspace');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should can read published workspace', async t => {
|
|
||||||
const { app } = t.context;
|
|
||||||
const user = await signUp(app, 'u1', 'u1@affine.pro', '1');
|
|
||||||
const workspace = await createWorkspace(app, user.token.token);
|
|
||||||
|
|
||||||
await t.throwsAsync(() => getPublicWorkspace(app, 'not_exists_ws'));
|
|
||||||
await t.throwsAsync(() => getPublicWorkspace(app, workspace.id));
|
|
||||||
|
|
||||||
await updateWorkspace(app, user.token.token, workspace.id, true);
|
|
||||||
|
|
||||||
const publicWorkspace = await getPublicWorkspace(app, workspace.id);
|
|
||||||
t.is(publicWorkspace.id, workspace.id, 'failed to get public workspace');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should share a page', async t => {
|
test('should share a page', async t => {
|
||||||
const { app } = t.context;
|
const { app } = t.context;
|
||||||
const u1 = await signUp(app, 'u1', 'u1@affine.pro', '1');
|
const u1 = await signUp(app, 'u1', 'u1@affine.pro', '1');
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
query getPublicWorkspace($id: String!) {
|
|
||||||
publicWorkspace(id: $id) {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -374,19 +374,6 @@ query oauthProviders {
|
|||||||
}`,
|
}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPublicWorkspaceQuery = {
|
|
||||||
id: 'getPublicWorkspaceQuery' as const,
|
|
||||||
operationName: 'getPublicWorkspace',
|
|
||||||
definitionName: 'publicWorkspace',
|
|
||||||
containsFile: false,
|
|
||||||
query: `
|
|
||||||
query getPublicWorkspace($id: String!) {
|
|
||||||
publicWorkspace(id: $id) {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getUserFeaturesQuery = {
|
export const getUserFeaturesQuery = {
|
||||||
id: 'getUserFeaturesQuery' as const,
|
id: 'getUserFeaturesQuery' as const,
|
||||||
operationName: 'getUserFeatures',
|
operationName: 'getUserFeatures',
|
||||||
|
|||||||
@@ -474,15 +474,6 @@ export type OauthProvidersQuery = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GetPublicWorkspaceQueryVariables = Exact<{
|
|
||||||
id: Scalars['String']['input'];
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type GetPublicWorkspaceQuery = {
|
|
||||||
__typename?: 'Query';
|
|
||||||
publicWorkspace: { __typename?: 'WorkspaceType'; id: string };
|
|
||||||
};
|
|
||||||
|
|
||||||
export type GetUserFeaturesQueryVariables = Exact<{ [key: string]: never }>;
|
export type GetUserFeaturesQueryVariables = Exact<{ [key: string]: never }>;
|
||||||
|
|
||||||
export type GetUserFeaturesQuery = {
|
export type GetUserFeaturesQuery = {
|
||||||
@@ -1097,11 +1088,6 @@ export type Queries =
|
|||||||
variables: OauthProvidersQueryVariables;
|
variables: OauthProvidersQueryVariables;
|
||||||
response: OauthProvidersQuery;
|
response: OauthProvidersQuery;
|
||||||
}
|
}
|
||||||
| {
|
|
||||||
name: 'getPublicWorkspaceQuery';
|
|
||||||
variables: GetPublicWorkspaceQueryVariables;
|
|
||||||
response: GetPublicWorkspaceQuery;
|
|
||||||
}
|
|
||||||
| {
|
| {
|
||||||
name: 'getUserFeaturesQuery';
|
name: 'getUserFeaturesQuery';
|
||||||
variables: GetUserFeaturesQueryVariables;
|
variables: GetUserFeaturesQueryVariables;
|
||||||
|
|||||||
Reference in New Issue
Block a user