Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/api/src/auth/hybrid-auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export class HybridAuthGuard implements CanActivate {
where: {
userId,
organizationId,
deactivated: false,
},
select: {
id: true,
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/comments/comments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class CommentsService {
name: comment.author.user.name,
email: comment.author.user.email,
image: comment.author.user.image,
deactivated: comment.author.deactivated,
},
attachments,
createdAt: comment.createdAt,
Expand Down Expand Up @@ -154,6 +155,7 @@ export class CommentsService {
where: {
userId,
organizationId,
deactivated: false,
},
include: {
user: true,
Expand Down Expand Up @@ -211,6 +213,7 @@ export class CommentsService {
name: member.user.name,
email: member.user.email,
image: member.user.image,
deactivated: member.deactivated,
},
attachments: result.attachments,
createdAt: result.comment.createdAt,
Expand Down Expand Up @@ -284,6 +287,7 @@ export class CommentsService {
name: existingComment.author.user.name,
email: existingComment.author.user.email,
image: existingComment.author.user.image,
deactivated: existingComment.author.deactivated,
},
attachments,
createdAt: updatedComment.createdAt,
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/comments/dto/comment-responses.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ export class AuthorResponseDto {
nullable: true,
})
image: string | null;

@ApiProperty({
description: 'Whether the user is deactivated',
example: false,
nullable: true,
})
deactivated: boolean;
}

export class CommentResponseDto {
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/devices/devices.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class DevicesService {
where: {
id: memberId,
organizationId: organizationId,
deactivated: false,
},
select: {
id: true,
Expand Down Expand Up @@ -165,6 +166,7 @@ export class DevicesService {
where: {
id: memberId,
organizationId: organizationId,
deactivated: false,
},
select: {
id: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/people/utils/member-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class MemberQueries {
organizationId: string,
): Promise<PeopleResponseDto[]> {
return db.member.findMany({
where: { organizationId },
where: { organizationId, deactivated: false },
select: this.MEMBER_SELECT,
orderBy: { createdAt: 'desc' },
});
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/people/utils/member-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MemberValidator {
where: {
id: memberId,
organizationId,
deactivated: false,
},
select: { id: true, userId: true },
});
Expand All @@ -71,6 +72,7 @@ export class MemberValidator {
const whereClause: any = {
userId,
organizationId,
deactivated: false,
};

if (excludeMemberId) {
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/actions/add-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const addCommentAction = authActionClient
where: {
userId: session.userId,
organizationId: session.activeOrganizationId,
deactivated: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/actions/change-organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const changeOrganizationAction = authActionClient
where: {
userId: user.id,
organizationId,
deactivated: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/actions/organization/accept-invitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const completeInvitation = authActionClientWithoutOrg
where: {
userId: user.id,
organizationId: invitation.organizationId,
deactivated: false,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getOrganizationUsersAction = authActionClient
const users = await db.member.findMany({
where: {
organizationId: ctx.session.activeOrganizationId,
deactivated: false,
},
select: {
user: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const acceptRequestedPolicyChangesAction = authActionClient
where: {
organizationId: session.activeOrganizationId,
isActive: true,
deactivated: false,
},
include: {
user: true,
Expand Down Expand Up @@ -131,6 +132,7 @@ export const acceptRequestedPolicyChangesAction = authActionClient
where: {
userId: user.id,
organizationId: session.activeOrganizationId,
deactivated: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/actions/policies/create-new-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const createPolicyAction = authActionClient
where: {
userId: user.id,
organizationId: activeOrganizationId,
deactivated: false,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const denyRequestedPolicyChangesAction = authActionClient
where: {
userId: user.id,
organizationId: session.activeOrganizationId,
deactivated: false,
},
});

Expand Down
2 changes: 2 additions & 0 deletions apps/app/src/actions/policies/publish-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const publishAllPoliciesAction = authActionClient
where: {
userId: user.id,
organizationId: parsedInput.organizationId,
deactivated: false,
},
});

Expand Down Expand Up @@ -104,6 +105,7 @@ export const publishAllPoliciesAction = authActionClient
where: {
organizationId: parsedInput.organizationId,
isActive: true,
deactivated: false,
OR: [
{ role: { contains: Role.employee } },
{ role: { contains: Role.contractor } },
Expand Down
1 change: 1 addition & 0 deletions apps/app/src/actions/safe-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const authWithOrgAccessClient = authActionClient.use(async ({ next, clien
where: {
userId: ctx.user.id,
organizationId,
deactivated: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/app/(app)/[orgId]/frameworks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default async function DashboardPage({ params }: { params: Promise<{ orgI
where: {
userId: session.user.id,
organizationId,
deactivated: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions apps/app/src/app/(app)/[orgId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default async function Layout({
where: {
userId: session.user.id,
organizationId: requestedOrgId,
deactivated: false,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const addEmployeeWithoutInvite = async ({
where: {
organizationId: organizationId,
userId: currentUserId,
deactivated: false,
},
});

Expand Down Expand Up @@ -57,16 +58,45 @@ export const addEmployeeWithoutInvite = async ({
userId = newUser.id;
}

const member = await auth.api.addMember({
body: {
userId: existingUser?.id ?? userId,
const finalUserId = existingUser?.id ?? userId;

// Check if there's an existing member (including deactivated ones) for this user and organization
const existingMember = await db.member.findFirst({
where: {
userId: finalUserId,
organizationId,
role: roles, // Auth API expects role or role array
},
});

// Create training video completion entries for the new member
if (member?.id) {
let member;
if (existingMember) {
// If member exists but is deactivated, reactivate it and update roles
if (existingMember.deactivated) {
const roleString = roles.sort().join(',');
member = await db.member.update({
where: { id: existingMember.id },
data: {
deactivated: false,
role: roleString,
},
});
} else {
// Member already exists and is active, return existing member
member = existingMember;
}
} else {
// No existing member, create a new one
member = await auth.api.addMember({
body: {
userId: finalUserId,
organizationId,
role: roles, // Auth API expects role or role array
},
});
}

// Create training video completion entries for the new member (only if member was just created/reactivated)
if (member?.id && !existingMember) {
await createTrainingVideoEntries(member.id);
}

Expand Down
Loading
Loading