fix(server): everyone can share page in workspace (#4357)

This commit is contained in:
LongYinan 2023-09-13 23:26:41 -07:00 committed by GitHub
parent 1016a47b51
commit f0de34a60b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,6 @@ import type { User, Workspace } from '@prisma/client';
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs'; import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
import { applyUpdate, Doc } from 'yjs'; import { applyUpdate, Doc } from 'yjs';
import { Config } from '../../config';
import { PrismaService } from '../../prisma'; import { PrismaService } from '../../prisma';
import { StorageProvide } from '../../storage'; import { StorageProvide } from '../../storage';
import { CloudThrottlerGuard, Throttle } from '../../throttler'; import { CloudThrottlerGuard, Throttle } from '../../throttler';
@ -139,7 +138,6 @@ export class WorkspaceResolver {
constructor( constructor(
private readonly auth: AuthService, private readonly auth: AuthService,
private readonly config: Config,
private readonly mailer: MailService, private readonly mailer: MailService,
private readonly prisma: PrismaService, private readonly prisma: PrismaService,
private readonly permissions: PermissionService, private readonly permissions: PermissionService,
@ -644,9 +642,16 @@ export class WorkspaceResolver {
@Args('workspaceId') workspaceId: string, @Args('workspaceId') workspaceId: string,
@Args('pageId') pageId: string @Args('pageId') pageId: string
) { ) {
await this.permissions.check(workspaceId, user.id, Permission.Admin); const userWorkspace = await this.prisma.userWorkspacePermission.findFirst({
where: {
return this.permissions.grantPage(workspaceId, pageId); userId: user.id,
workspaceId,
},
});
return (
userWorkspace?.accepted &&
(await this.permissions.grantPage(workspaceId, pageId))
);
} }
@Mutation(() => Boolean) @Mutation(() => Boolean)