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

@@ -7,12 +7,11 @@ import { LabTaskStatus, LinkStatus, CatalogEntityKind } from '@prisma/client';
import { PrismaService } from '../../../prisma/prisma.service';
import {
isUnlimitedSeats,
normalizeTabPermissions,
} from '../../common/permissions';
import {
OrganizationTypeName,
ownerPermissionsForOrgType,
} from '../../common/organization-type';
import { getEffectivePermissionNames } from '../../common/membership-permissions';
import {
CatalogLabelService,
normalizeCatalogLocale,
@@ -565,16 +564,10 @@ export class TodayService {
const members = await this.prisma.membership.findMany({
where: {
organizationId,
isActive: true,
OR: [
{ isOwner: true },
{
isOwner: false,
permissions: {
some: { permission: { name: editPermission } },
},
},
],
OR: [{ isOwner: true }, { isActive: true }],
permissions: {
some: { permission: { name: editPermission } },
},
},
select: { userId: true, isOwner: true },
});
@@ -605,10 +598,7 @@ export class TodayService {
code: member.userId,
label: nameById.get(member.userId) ?? member.userId,
count: countsByUser.get(member.userId) ?? 0,
isOwner: member.isOwner,
}))
.filter((row) => !row.isOwner || row.count > 0)
.map(({ code, label, count }) => ({ code, label, count }))
.sort((a, b) => b.count - a.count);
return rows.length >= 2 ? rows : undefined;
@@ -834,8 +824,7 @@ export class TodayService {
const members = await this.prisma.membership.findMany({
where: {
organizationId,
isOwner: false,
isActive: true,
OR: [{ isOwner: true }, { isActive: true }],
permissions: {
some: {
permission: { name: 'TAB_TREATMENT_EDIT' },
@@ -1184,19 +1173,12 @@ export class TodayService {
isOwner: boolean;
organization: {
planId: string | null;
plan?: { name: string } | null;
type: { name: string };
};
permissions: { permission: { name: string } }[];
}): string[] {
if (membership.isOwner) {
const orgType = (membership.organization.type.name === 'LAB'
? 'LAB'
: 'CLINIC') as OrganizationTypeName;
return ownerPermissionsForOrgType(orgType, Boolean(membership.organization.planId));
}
return normalizeTabPermissions(
membership.permissions.map((p) => p.permission.name),
);
return getEffectivePermissionNames(membership);
}
private assertCanViewToday(isOwner: boolean, permissionNames: string[]) {
@@ -1220,15 +1202,13 @@ export class TodayService {
);
}
private canViewTreatment(isOwner: boolean, names: string[]): boolean {
if (isOwner) return true;
private canViewTreatment(_isOwner: boolean, names: string[]): boolean {
return names.some((p) =>
['TAB_TREATMENT_READ', 'TAB_TREATMENT_EDIT'].includes(p),
);
}
private canViewMyAppointmentsWeekChart(isOwner: boolean, names: string[]): boolean {
if (isOwner) return false;
private canViewMyAppointmentsWeekChart(_isOwner: boolean, names: string[]): boolean {
return names.includes('TAB_TREATMENT_EDIT');
}
@@ -1239,15 +1219,13 @@ export class TodayService {
);
}
private canViewTasks(isOwner: boolean, names: string[]): boolean {
if (isOwner) return true;
private canViewTasks(_isOwner: boolean, names: string[]): boolean {
return names.some((p) =>
['TAB_TASKS_READ', 'TAB_TASKS_EDIT'].includes(p),
);
}
private canEditTreatment(isOwner: boolean, names: string[]): boolean {
if (isOwner) return true;
private canEditTreatment(_isOwner: boolean, names: string[]): boolean {
return names.includes('TAB_TREATMENT_EDIT');
}