Revert "security: enforce authenticated CRM contact ownership"
This reverts commit e13700ab65.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
import { azureHeadersPaged } from "../../actions/core/headers";
|
||||
import { escapeODataString } from "../../actions/core/guards";
|
||||
import { consoleLogger } from "../../actions/core/logger";
|
||||
import { relayGetData } from "../../pages/api/middleware/relayForwarding";
|
||||
import { RELAY_POLICY_STRICT_LOGIN } from "../../pages/api/middleware/relayPolicyPresets";
|
||||
|
||||
const WELSH_LANGUAGE_CODE = 846040000;
|
||||
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
export const resolveCrmLocale = async (email) => {
|
||||
if (typeof email !== "string") return null;
|
||||
|
||||
const normalizedEmail = email.trim().toLowerCase();
|
||||
|
||||
if (!EMAIL_PATTERN.test(normalizedEmail)) return null;
|
||||
|
||||
const queryUrl =
|
||||
"contacts?$filter=emailaddress1 eq '" +
|
||||
escapeODataString(normalizedEmail) +
|
||||
"' and statuscode eq 1&$count=true&$select=pinswg_preferredlanguage";
|
||||
|
||||
try {
|
||||
const { data } = await relayGetData({
|
||||
queryUrl,
|
||||
requestOptionsBuilder: (accessToken) =>
|
||||
azureHeadersPaged(accessToken),
|
||||
relayPolicy: RELAY_POLICY_STRICT_LOGIN
|
||||
});
|
||||
const preferredLanguage = data?.value?.[0]?.pinswg_preferredlanguage;
|
||||
|
||||
if (preferredLanguage === WELSH_LANGUAGE_CODE) return "cy";
|
||||
if (preferredLanguage != null) return "en";
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
consoleLogger({
|
||||
name: "ResolveCrmLocale",
|
||||
message: "CRM locale lookup failed"
|
||||
});
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user