fix: validate activity, deal and lead assignees by active membership in the current environment
This commit is contained in:
@@ -976,7 +976,11 @@ export class ActivitiesService {
|
|||||||
];
|
];
|
||||||
if (!ids.length) return [];
|
if (!ids.length) return [];
|
||||||
const count = await this.prisma.user.count({
|
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) {
|
if (count !== ids.length) {
|
||||||
throw new BadRequestException('یکی از مسئولان انتخابشده معتبر نیست');
|
throw new BadRequestException('یکی از مسئولان انتخابشده معتبر نیست');
|
||||||
|
|||||||
@@ -596,7 +596,11 @@ export class LeadsService {
|
|||||||
throw new BadRequestException('فقط مدیر میتواند تخصیص دهد');
|
throw new BadRequestException('فقط مدیر میتواند تخصیص دهد');
|
||||||
}
|
}
|
||||||
const user = await this.prisma.user.findFirst({
|
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('کارشناس پیدا نشد');
|
if (!user) throw new NotFoundException('کارشناس پیدا نشد');
|
||||||
|
|
||||||
@@ -669,15 +673,14 @@ export class LeadsService {
|
|||||||
let assignees = opts.assigneeIds?.length
|
let assignees = opts.assigneeIds?.length
|
||||||
? await this.prisma.user.findMany({
|
? await this.prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
organizationId: actor.organizationId,
|
|
||||||
id: { in: opts.assigneeIds },
|
id: { in: opts.assigneeIds },
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
memberships: { some: { organizationId: actor.organizationId, isActive: true } },
|
||||||
},
|
},
|
||||||
select: { id: true, fullName: true },
|
select: { id: true, fullName: true },
|
||||||
})
|
})
|
||||||
: await this.prisma.user.findMany({
|
: await this.prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
organizationId: actor.organizationId,
|
|
||||||
isActive: true,
|
isActive: true,
|
||||||
memberships: {
|
memberships: {
|
||||||
some: {
|
some: {
|
||||||
|
|||||||
@@ -519,7 +519,11 @@ export class DealsService {
|
|||||||
];
|
];
|
||||||
if (!ids.length) return [];
|
if (!ids.length) return [];
|
||||||
const count = await this.prisma.user.count({
|
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) {
|
if (count !== ids.length) {
|
||||||
throw new BadRequestException('یکی از مسئولان انتخابشده معتبر نیست');
|
throw new BadRequestException('یکی از مسئولان انتخابشده معتبر نیست');
|
||||||
|
|||||||
Reference in New Issue
Block a user