mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 09:11:15 +10:00
feat: add copy invite link to invitation action menu (#360)
* +copy invite link to clipboard from invite action menu * -remove log to console for copy link action * Refactor copy invite link feature --------- Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
54d27af76a
commit
7fc1a782a7
@ -237,4 +237,30 @@ export class WorkspaceController {
|
||||
secure: this.environmentService.isHttps(),
|
||||
});
|
||||
}
|
||||
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Post('invites/link')
|
||||
async getInviteLink(
|
||||
@Body() inviteDto: InvitationIdDto,
|
||||
@AuthUser() user: User,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
) {
|
||||
if (this.environmentService.isCloud()) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
const ability = this.workspaceAbility.createForUser(user, workspace);
|
||||
if (
|
||||
ability.cannot(WorkspaceCaslAction.Manage, WorkspaceCaslSubject.Member)
|
||||
) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
const inviteLink =
|
||||
await this.workspaceInvitationService.getInvitationLinkById(
|
||||
inviteDto.invitationId,
|
||||
workspace.id,
|
||||
);
|
||||
|
||||
return { inviteLink };
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +71,21 @@ export class WorkspaceInvitationService {
|
||||
return invitation;
|
||||
}
|
||||
|
||||
async getInvitationTokenById(invitationId: string, workspaceId: string) {
|
||||
const invitation = await this.db
|
||||
.selectFrom('workspaceInvitations')
|
||||
.select(['token'])
|
||||
.where('id', '=', invitationId)
|
||||
.where('workspaceId', '=', workspaceId)
|
||||
.executeTakeFirst();
|
||||
|
||||
if (!invitation) {
|
||||
throw new NotFoundException('Invitation not found');
|
||||
}
|
||||
|
||||
return invitation;
|
||||
}
|
||||
|
||||
async createInvitation(
|
||||
inviteUserDto: InviteUserDto,
|
||||
workspaceId: string,
|
||||
@ -256,7 +271,6 @@ export class WorkspaceInvitationService {
|
||||
invitationId: string,
|
||||
workspaceId: string,
|
||||
): Promise<void> {
|
||||
//
|
||||
const invitation = await this.db
|
||||
.selectFrom('workspaceInvitations')
|
||||
.selectAll()
|
||||
@ -292,13 +306,28 @@ export class WorkspaceInvitationService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async getInvitationLinkById(
|
||||
invitationId: string,
|
||||
workspaceId: string,
|
||||
): Promise<string> {
|
||||
const token = await this.getInvitationTokenById(invitationId, workspaceId);
|
||||
return this.buildInviteLink(invitationId, token.token);
|
||||
}
|
||||
|
||||
async buildInviteLink(
|
||||
invitationId: string,
|
||||
inviteToken: string,
|
||||
): Promise<string> {
|
||||
return `${this.environmentService.getAppUrl()}/invites/${invitationId}?token=${inviteToken}`;
|
||||
}
|
||||
|
||||
async sendInvitationMail(
|
||||
invitationId: string,
|
||||
inviteeEmail: string,
|
||||
inviteToken: string,
|
||||
invitedByName: string,
|
||||
): Promise<void> {
|
||||
const inviteLink = `${this.environmentService.getAppUrl()}/invites/${invitationId}?token=${inviteToken}`;
|
||||
const inviteLink = await this.buildInviteLink(invitationId, inviteToken);
|
||||
|
||||
const emailTemplate = InvitationEmail({
|
||||
inviteLink,
|
||||
|
||||
Reference in New Issue
Block a user