mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 21:38:44 +08:00
chore: cleanup outdated api (#6604)
This commit is contained in:
@@ -36,10 +36,17 @@ export class WorkspacesController {
|
||||
@Get('/:id/blobs/:name')
|
||||
@CallTimer('controllers', 'workspace_get_blob')
|
||||
async blob(
|
||||
@CurrentUser() user: CurrentUser | undefined,
|
||||
@Param('id') workspaceId: string,
|
||||
@Param('name') name: string,
|
||||
@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);
|
||||
|
||||
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> {
|
||||
// workspace
|
||||
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);
|
||||
@@ -155,21 +167,6 @@ export class PermissionService {
|
||||
if (count > 0) {
|
||||
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) {
|
||||
|
||||
@@ -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, {
|
||||
description: 'Get workspace by id',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user