add permissin check to sendInviteEmail

This commit is contained in:
Alex Holliday committed 2026-02-04 17:57:00 +00:00
1 parent b4c929963f
commit 97dd3ec9cb
2 files changed
+20 -2

No files matched your search

+15 -1
View File
@@ -51,7 +51,21 @@ class InviteService {
return inviteToken;
};
sendInviteEmail = async ({ invite, firstName }: { invite: Partial<Invite>; firstName: any }) => {
sendInviteEmail = async ({ invite, firstName, userRoles }: { invite: Partial<Invite>; firstName: any; userRoles: UserRole[] }) => {
const inviteRoles = invite.role ?? [];
for (const targetRole of inviteRoles) {
const canManage = userRoles.some((actorRole) => canManageRole(actorRole, targetRole));
if (!canManage) {
throw new AppError({
message: "You do not have permission to create this invite",
service: SERVICE_NAME,
method: "getInviteToken",
status: 403,
});
}
}
const inviteToken = await this.invitesRepository.create(invite);
const { clientHost } = this.settingsService.getSettings();