Skip to content

Commit

Permalink
feat: member removed
Browse files Browse the repository at this point in the history
  • Loading branch information
darkskygit committed Jan 6, 2025
1 parent 5b24a80 commit 97eb5ce
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/backend/server/src/base/event/def.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface WorkspaceEvents {
}>;
ownerTransferred: Payload<{ email: string; workspaceId: Workspace['id'] }>;
updated: Payload<{ workspaceId: Workspace['id']; count: number }>;
removed: Payload<{ workspaceId: Workspace['id']; userId: User['id'] }>;
};
deleted: Payload<Workspace['id']>;
blob: {
Expand Down
17 changes: 2 additions & 15 deletions packages/backend/server/src/base/mailer/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,20 +367,7 @@ export class MailService {
return this.sendMail({ to, subject: title, html });
}

async sendOwnershipReceived(to: string, ws: { id: string; name: string }) {
const { id: workspaceId, name: workspaceName } = ws;
const title = `You are now the owner of ${workspaceName}`;

const html = emailTemplate({
title: 'Welcome, new workspace owner!',
content: `You have been assigned as the owner of ${workspaceName}. As a workspace owner, you have full control over this team workspace.`,
buttonContent: 'Open Workspace',
buttonUrl: this.url.link(`/workspace/${workspaceId}`),
});
return this.sendMail({ to, subject: title, html });
}

async sendMemberRemoved(to: string, ws: { name: string }) {
async sendMemberRemovedEmail(to: string, ws: { name: string }) {
const { name: workspaceName } = ws;
const title = `You have been removed from ${workspaceName}`;

Expand All @@ -391,7 +378,7 @@ export class MailService {
return this.sendMail({ to, subject: title, html });
}

async sendWorkspaceExpireRemind(
async sendWorkspaceExpireRemindEmail(
to: string,
ws: {
id: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/server/src/core/permission/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,10 @@ export class PermissionService {
workspaceId,
count,
});
this.event.emit('workspace.members.removed', {
workspaceId,
userId: user,
});

if (
permission.status === 'UnderReview' ||
Expand Down
1 change: 1 addition & 0 deletions packages/backend/server/src/core/workspaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
WorkspaceBlobResolver,
WorkspaceService,
],
exports: [WorkspaceService],
})
export class WorkspaceModule {}

Expand Down
25 changes: 24 additions & 1 deletion packages/backend/server/src/core/workspaces/resolvers/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { Injectable, Logger } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { getStreamAsBuffer } from 'get-stream';

import { Cache, MailService, UserNotFound } from '../../../base';
import {
Cache,
type EventPayload,
MailService,
OnEvent,
UserNotFound,
} from '../../../base';
import { DocContentService } from '../../doc-renderer';
import { Permission, PermissionService } from '../../permission';
import { WorkspaceBlobStorage } from '../../storage';
Expand Down Expand Up @@ -231,4 +237,21 @@ export class WorkspaceService {
name: workspace.name,
});
}

async sendMemberRemoved(email: string, ws: { id: string }) {
const workspace = await this.getWorkspaceInfo(ws.id);
await this.mailer.sendMemberRemovedEmail(email, {
name: workspace.name,
});
}

@OnEvent('workspace.members.removed')
async onMemberRemoved({
userId,
workspaceId,
}: EventPayload<'workspace.members.requestDeclined'>) {
const user = await this.user.findUserById(userId);
if (!user) return;
await this.sendMemberRemoved(user.email, { id: workspaceId });
}
}
9 changes: 8 additions & 1 deletion packages/backend/server/src/plugins/payment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FeatureModule } from '../../core/features';
import { PermissionModule } from '../../core/permission';
import { QuotaModule } from '../../core/quota';
import { UserModule } from '../../core/user';
import { WorkspaceModule } from '../../core/workspaces';
import { Plugin } from '../registry';
import { StripeWebhookController } from './controller';
import { SubscriptionCronJobs } from './cron';
Expand All @@ -24,7 +25,13 @@ import { StripeWebhook } from './webhook';

@Plugin({
name: 'payment',
imports: [FeatureModule, QuotaModule, UserModule, PermissionModule],
imports: [
FeatureModule,
QuotaModule,
UserModule,
PermissionModule,
WorkspaceModule,
],
providers: [
StripeProvider,
SubscriptionService,
Expand Down

0 comments on commit 97eb5ce

Please sign in to comment.