mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): cant leave workspace (#6999)
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
type Framework,
|
||||
WorkspaceScope,
|
||||
WorkspaceService,
|
||||
WorkspacesService,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { WorkspacePermission } from './entities/permission';
|
||||
@@ -14,7 +15,11 @@ import { WorkspacePermissionStore } from './stores/permission';
|
||||
export function configurePermissionsModule(framework: Framework) {
|
||||
framework
|
||||
.scope(WorkspaceScope)
|
||||
.service(WorkspacePermissionService)
|
||||
.service(WorkspacePermissionService, [
|
||||
WorkspaceService,
|
||||
WorkspacesService,
|
||||
WorkspacePermissionStore,
|
||||
])
|
||||
.store(WorkspacePermissionStore, [GraphQLService])
|
||||
.entity(WorkspacePermission, [WorkspaceService, WorkspacePermissionStore]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
import type { WorkspaceService, WorkspacesService } from '@toeverything/infra';
|
||||
import { Service } from '@toeverything/infra';
|
||||
|
||||
import { WorkspacePermission } from '../entities/permission';
|
||||
import type { WorkspacePermissionStore } from '../stores/permission';
|
||||
|
||||
export class WorkspacePermissionService extends Service {
|
||||
permission = this.framework.createEntity(WorkspacePermission);
|
||||
|
||||
constructor(
|
||||
private readonly workspaceService: WorkspaceService,
|
||||
private readonly workspacesService: WorkspacesService,
|
||||
private readonly store: WorkspacePermissionStore
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async leaveWorkspace() {
|
||||
await this.store.leaveWorkspace(
|
||||
this.workspaceService.workspace.id,
|
||||
this.workspaceService.workspace.name$.value ?? ''
|
||||
);
|
||||
this.workspacesService.list.revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { GraphQLService } from '@affine/core/modules/cloud';
|
||||
import { getIsOwnerQuery } from '@affine/graphql';
|
||||
import { getIsOwnerQuery, leaveWorkspaceMutation } from '@affine/graphql';
|
||||
import { Store } from '@toeverything/infra';
|
||||
|
||||
export class WorkspacePermissionStore extends Store {
|
||||
@@ -18,4 +18,17 @@ export class WorkspacePermissionStore extends Store {
|
||||
|
||||
return isOwner.isOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param workspaceName for send email
|
||||
*/
|
||||
async leaveWorkspace(workspaceId: string, workspaceName: string) {
|
||||
await this.graphqlService.gql({
|
||||
query: leaveWorkspaceMutation,
|
||||
variables: {
|
||||
workspaceId,
|
||||
workspaceName,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user