feat: Skip contact owner even if it matches attribute routing (#17015)

Co-authored-by: Omar López <[email protected]>
This commit is contained in:
Hariom BalharaandOmar López authored and GitHub committed 2024-10-09 07:30:12 -07:00
1 parent de503add83
commit 03d0b98155
38 files changed
+608 -159

No files matched your search

+27 -8
View File
@@ -1,14 +1,18 @@
import { safeStringify } from "@calcom/lib/safeStringify";
import logger from "@calcom/lib/logger";
import { safeStringify } from "@calcom/lib/safeStringify";
const log = logger.getSubLogger({ prefix: ["[getRoutedUsers]"] });
export const getRoutedHosts = <T extends { user: { id: number }; isFixed?: boolean }>({
export const getRoutedHostsWithContactOwnerAndFixedHosts = <
T extends { user: { id: number; email: string }; isFixed?: boolean }
>({
routedTeamMemberIds,
hosts,
contactOwnerEmail,
}: {
routedTeamMemberIds: number[] | null;
hosts: T[];
contactOwnerEmail: string | null;
}) => {
// We don't want to enter a scenario where we have no team members to be booked
// So, let's just fallback to regular flow if no routedTeamMemberIds are provided
@@ -16,23 +20,38 @@ export const getRoutedHosts = <T extends { user: { id: number }; isFixed?: boole
return hosts;
}
log.debug("filtering hosts as per routedTeamMemberIds", safeStringify({ routedTeamMemberIds }));
return hosts.filter((host) => routedTeamMemberIds.includes(host.user.id) || host.isFixed);
log.debug(
"filtering hosts as per routedTeamMemberIds",
safeStringify({ routedTeamMemberIds, contactOwnerEmail })
);
return hosts.filter(
(host) =>
routedTeamMemberIds.includes(host.user.id) || host.isFixed || host.user.email === contactOwnerEmail
);
};
export const getRoutedUsers = <T extends { id: number; isFixed?: boolean }>({
export const getRoutedUsersWithContactOwnerAndFixedUsers = <
T extends { id: number; isFixed?: boolean; email: string }
>({
routedTeamMemberIds,
users,
contactOwnerEmail,
}: {
routedTeamMemberIds: number[] | null;
users: T[];
contactOwnerEmail: string | null;
}) => {
// We don't want to enter a scenario where we have no team members to be booked
// We don't want to enter a scenario where we have no team members to be booked
// So, let's just fallback to regular flow if no routedTeamMemberIds are provided
if (!routedTeamMemberIds || !routedTeamMemberIds.length) {
return users;
}
log.debug("filtering users as per routedTeamMemberIds", safeStringify({ routedTeamMemberIds }));
return users.filter((user) => routedTeamMemberIds.includes(user.id) || user.isFixed);
log.debug(
"filtering users as per routedTeamMemberIds",
safeStringify({ routedTeamMemberIds, contactOwnerEmail })
);
return users.filter(
(user) => routedTeamMemberIds.includes(user.id) || user.isFixed || user.email === contactOwnerEmail
);
};
@@ -0,0 +1,24 @@
export function fromEntriesWithDuplicateKeys(entries: IterableIterator<[string, string]> | null) {
const result: Record<string, string | string[]> = {};
if (entries === null) {
return result;
}
// Consider setting atleast ES2015 as target
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
for (const [key, value] of entries) {
if (result.hasOwnProperty(key)) {
let currentValue = result[key];
if (!Array.isArray(currentValue)) {
currentValue = [currentValue];
}
currentValue.push(value);
result[key] = currentValue;
} else {
result[key] = value;
}
}
return result;
}