improvement: a flow added for owner users to make it possible for them to participate in treatments or tasks.

This commit is contained in:
2026-07-12 15:11:50 +03:30
parent 4208d15efb
commit 39935688ad
20 changed files with 1122 additions and 154 deletions

View File

@@ -6,6 +6,7 @@ import {
import { LabCaseCommentSide, Prisma } from '@prisma/client';
import { PrismaService } from '../../../prisma/prisma.service';
import { CreateLabCaseCommentDto } from './dto/lab-case-comment.dto';
import { hasEffectivePermission } from '../../common/membership-permissions';
const commentInclude = {
authorUser: { select: { id: true, name: true } },
@@ -206,15 +207,20 @@ export class LabCaseCommentsService {
}
const membership = await this.prisma.membership.findFirst({
where: { userId: actorUserId, organizationId: labOrganizationId, isActive: true },
include: { permissions: { include: { permission: true } } },
where: {
userId: actorUserId,
organizationId: labOrganizationId,
OR: [{ isOwner: true }, { isActive: true }],
},
include: {
permissions: { include: { permission: true } },
organization: { include: { type: true, plan: true } },
},
});
if (!membership) {
throw new ForbiddenException('You are not a member of this organization');
}
if (membership.isOwner) return;
const names = membership.permissions.map((p) => p.permission.name);
if (!names.includes('TAB_TASKS_EDIT')) {
if (!hasEffectivePermission(membership, 'TAB_TASKS_EDIT')) {
throw new ForbiddenException('You do not have access to task comments');
}
}
@@ -244,15 +250,23 @@ export class LabCaseCommentsService {
) {
await this.assertClinicOwnsCase(caseId, clinicOrganizationId);
const membership = await this.prisma.membership.findFirst({
where: { userId: actorUserId, organizationId: clinicOrganizationId, isActive: true },
include: { permissions: { include: { permission: true } } },
where: {
userId: actorUserId,
organizationId: clinicOrganizationId,
OR: [{ isOwner: true }, { isActive: true }],
},
include: {
permissions: { include: { permission: true } },
organization: { include: { type: true, plan: true } },
},
});
if (!membership) {
throw new ForbiddenException('You are not a member of this organization');
}
if (membership.isOwner) return;
const names = membership.permissions.map((p) => p.permission.name);
if (names.includes('TAB_TREATMENT_READ') || names.includes('TAB_TREATMENT_EDIT')) {
if (
hasEffectivePermission(membership, 'TAB_TREATMENT_READ') ||
hasEffectivePermission(membership, 'TAB_TREATMENT_EDIT')
) {
return;
}
throw new ForbiddenException('You do not have access to treatment cases');