fix: validate activity, deal and lead assignees by active membership in the current environment

This commit is contained in:
2026-10-20 14:47:08 +03:30
parent bb8fd489de
commit 29398a445b
3 changed files with 16 additions and 5 deletions
@@ -976,7 +976,11 @@ export class ActivitiesService {
];
if (!ids.length) return [];
const count = await this.prisma.user.count({
where: { organizationId, id: { in: ids }, isActive: true },
where: {
id: { in: ids },
isActive: true,
memberships: { some: { organizationId, isActive: true } },
},
});
if (count !== ids.length) {
throw new BadRequestException('یکی از مسئولان انتخاب‌شده معتبر نیست');
+6 -3
View File
@@ -596,7 +596,11 @@ export class LeadsService {
throw new BadRequestException('فقط مدیر می‌تواند تخصیص دهد');
}
const user = await this.prisma.user.findFirst({
where: { id: assigneeId, organizationId: actor.organizationId },
where: {
id: assigneeId,
isActive: true,
memberships: { some: { organizationId: actor.organizationId, isActive: true } },
},
});
if (!user) throw new NotFoundException('کارشناس پیدا نشد');
@@ -669,15 +673,14 @@ export class LeadsService {
let assignees = opts.assigneeIds?.length
? await this.prisma.user.findMany({
where: {
organizationId: actor.organizationId,
id: { in: opts.assigneeIds },
isActive: true,
memberships: { some: { organizationId: actor.organizationId, isActive: true } },
},
select: { id: true, fullName: true },
})
: await this.prisma.user.findMany({
where: {
organizationId: actor.organizationId,
isActive: true,
memberships: {
some: {
+5 -1
View File
@@ -519,7 +519,11 @@ export class DealsService {
];
if (!ids.length) return [];
const count = await this.prisma.user.count({
where: { organizationId, id: { in: ids }, isActive: true },
where: {
id: { in: ids },
isActive: true,
memberships: { some: { organizationId, isActive: true } },
},
});
if (count !== ids.length) {
throw new BadRequestException('یکی از مسئولان انتخاب‌شده معتبر نیست');