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:
Peter Shcherbakov
2025-02-26 21:28:44 +03:00
committed by GitHub
parent 54d27af76a
commit 7fc1a782a7
6 changed files with 95 additions and 2 deletions

View File

@ -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 };
}
}

View File

@ -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,