feat(consent): add privacy settings and scoped revocation flow
This commit is contained in:
1 parent
b2322bc178
commit
3ab6bd91a3
19 files changed
+1868
-8
No files matched your search
@@ -0,0 +1,14 @@
|
||||
export {
|
||||
consentPurposeDetails,
|
||||
consentPurposeOrder,
|
||||
consentSourceLabels,
|
||||
consentStateLabels,
|
||||
contactFieldLabels,
|
||||
deletionRequestStatusMessage,
|
||||
emptyPurposeHistoryMessage,
|
||||
formatConsentDate,
|
||||
groupConsentHistory,
|
||||
groupOrganizationConsents,
|
||||
type ConsentPurposeGroup,
|
||||
type OrganizationConsentGroup,
|
||||
} from "./model/consent-presentation";
|
||||
@@ -0,0 +1,129 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { ConsentRecord } from "../../../shared/api/schemas";
|
||||
import {
|
||||
consentPurposeDetails,
|
||||
consentPurposeOrder,
|
||||
consentStateLabels,
|
||||
deletionRequestStatusMessage,
|
||||
emptyPurposeHistoryMessage,
|
||||
formatConsentDate,
|
||||
groupConsentHistory,
|
||||
groupOrganizationConsents,
|
||||
} from "./consent-presentation";
|
||||
|
||||
const record = (overrides: Partial<ConsentRecord> = {}): ConsentRecord => ({
|
||||
id: "01928f7a-9c0d-7e1f-8a2b-3c4d5e6f7a80",
|
||||
purpose: "c2",
|
||||
state: "active",
|
||||
text_version: "c2-2026-10-01",
|
||||
source: "consent_settings",
|
||||
granted_at: "2026-10-02T09:00:00Z",
|
||||
revoked_at: null,
|
||||
revocation_source: null,
|
||||
organization: null,
|
||||
fields: null,
|
||||
invitation_id: null,
|
||||
invitation_terms_version: null,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
describe("consent presentation", () => {
|
||||
it("keeps every purpose independent and gives empty purposes their own groups", () => {
|
||||
const groups = groupConsentHistory([
|
||||
record({ id: "c2-old", state: "superseded" }),
|
||||
record({ id: "c1", purpose: "c1", text_version: "c1-2026-10-01" }),
|
||||
record({ id: "c2-new", text_version: "c2-2026-10-02" }),
|
||||
]);
|
||||
|
||||
expect(groups.map(({ purpose }) => purpose)).toEqual(consentPurposeOrder);
|
||||
expect(groups.find(({ purpose }) => purpose === "c1")?.records.map(({ id }) => id)).toEqual([
|
||||
"c1",
|
||||
]);
|
||||
expect(groups.find(({ purpose }) => purpose === "c2")?.records.map(({ id }) => id)).toEqual([
|
||||
"c2-old",
|
||||
"c2-new",
|
||||
]);
|
||||
expect(groups.find(({ purpose }) => purpose === "c3")?.records).toEqual([]);
|
||||
});
|
||||
|
||||
it("groups C4 actions by organization while preserving each invitation record", () => {
|
||||
const firstOrganization = {
|
||||
id: "01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e01",
|
||||
name: "Первая тестовая компания",
|
||||
};
|
||||
const secondOrganization = {
|
||||
id: "01928f7a-1a2b-7c3d-8e4f-5a6b7c8d9e02",
|
||||
name: "Вторая тестовая компания",
|
||||
};
|
||||
const groups = groupOrganizationConsents([
|
||||
record({
|
||||
id: "first-invitation-new",
|
||||
purpose: "c4",
|
||||
organization: firstOrganization,
|
||||
fields: ["email"],
|
||||
invitation_id: "01928f7a-7a8b-7c9d-8e0f-1a2b3c4d5e61",
|
||||
invitation_terms_version: 2,
|
||||
}),
|
||||
record({
|
||||
id: "second-company",
|
||||
purpose: "c4",
|
||||
organization: secondOrganization,
|
||||
fields: ["phone"],
|
||||
invitation_id: "01928f7a-7a8b-7c9d-8e0f-1a2b3c4d5e62",
|
||||
invitation_terms_version: 1,
|
||||
}),
|
||||
record({
|
||||
id: "first-invitation-old",
|
||||
purpose: "c4",
|
||||
state: "superseded",
|
||||
organization: { ...firstOrganization, name: "Первая компания до переименования" },
|
||||
fields: ["phone"],
|
||||
invitation_id: "01928f7a-7a8b-7c9d-8e0f-1a2b3c4d5e63",
|
||||
invitation_terms_version: 1,
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(groups).toHaveLength(2);
|
||||
expect(groups[0]?.displayName).toBe("Первая тестовая компания");
|
||||
expect(groups[0]?.records.map(({ id }) => id)).toEqual([
|
||||
"first-invitation-new",
|
||||
"first-invitation-old",
|
||||
]);
|
||||
expect(groups[1]?.records.map(({ id }) => id)).toEqual(["second-company"]);
|
||||
expect(groups[0]?.records[1]?.organization?.name).toBe("Первая компания до переименования");
|
||||
});
|
||||
|
||||
it("provides distinct state labels and consequence copy for C1-C5", () => {
|
||||
expect(consentStateLabels).toEqual({
|
||||
active: "Действует",
|
||||
superseded: "Заменено новой версией",
|
||||
revoked: "Отозвано",
|
||||
});
|
||||
expect(Object.keys(consentPurposeDetails)).toEqual(consentPurposeOrder);
|
||||
expect(consentPurposeDetails.c1.consequence).toContain("удаление аккаунта");
|
||||
expect(consentPurposeDetails.c2.consequence).toContain("карточку");
|
||||
expect(consentPurposeDetails.c3.consequence).toContain("ручную оценку");
|
||||
expect(consentPurposeDetails.c4.consequence).toContain("компании");
|
||||
expect(consentPurposeDetails.c5.consequence).toContain("синхронизацию");
|
||||
});
|
||||
|
||||
it("formats server timestamps in UTC", () => {
|
||||
expect(formatConsentDate("2026-10-02T09:00:00Z")).toContain("UTC");
|
||||
});
|
||||
|
||||
it("does not claim that an unloaded history has no records", () => {
|
||||
expect(emptyPurposeHistoryMessage("c2", true)).toContain("В загруженной части истории");
|
||||
expect(emptyPurposeHistoryMessage("c2", true)).toContain("Загрузите более ранние записи");
|
||||
expect(emptyPurposeHistoryMessage("c2", false)).toBe("Записей C2 пока нет.");
|
||||
});
|
||||
|
||||
it("describes the server-reported account-deletion state without claiming completion", () => {
|
||||
const requested = deletionRequestStatusMessage("requested");
|
||||
const processing = deletionRequestStatusMessage("processing");
|
||||
|
||||
expect(requested).toContain("ожидает обработки");
|
||||
expect(processing).toContain("передан в обработку");
|
||||
expect(requested).toContain("не удаляются сразу");
|
||||
expect(processing).toContain("еще не завершено");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,137 @@
|
||||
import type {
|
||||
ConsentDeletionRequest,
|
||||
ConsentRecord,
|
||||
ConsentPurposeCode,
|
||||
} from "../../../shared/api/schemas";
|
||||
|
||||
export const consentPurposeOrder = [
|
||||
"c1",
|
||||
"c2",
|
||||
"c3",
|
||||
"c4",
|
||||
"c5",
|
||||
] as const satisfies readonly ConsentPurposeCode[];
|
||||
|
||||
export const consentPurposeDetails: Readonly<
|
||||
Record<ConsentPurposeCode, { title: string; consequence: string }>
|
||||
> = {
|
||||
c1: {
|
||||
title: "Обработка персональных данных",
|
||||
consequence:
|
||||
"Отзыв запускает запрос на удаление аккаунта и данных. Запрос обрабатывается отдельно и не удаляет данные сразу.",
|
||||
},
|
||||
c2: {
|
||||
title: "Публикация карточки кандидата",
|
||||
consequence:
|
||||
"Отзыв закроет карточку для будущих просмотров и связанные доступы. Новая публикация потребует нового согласия.",
|
||||
},
|
||||
c3: {
|
||||
title: "Автоматическая категоризация",
|
||||
consequence:
|
||||
"Отзыв остановит автоматическую категоризацию. Можно запросить ручную оценку по той же рубрике.",
|
||||
},
|
||||
c4: {
|
||||
title: "Передача выбранных данных компании",
|
||||
consequence:
|
||||
"Отзыв закроет будущий доступ указанной компании к выбранным полям и запустит уведомление интеграции.",
|
||||
},
|
||||
c5: {
|
||||
title: "Импорт результатов ФСП",
|
||||
consequence:
|
||||
"Отзыв остановит синхронизацию и закроет новые чтения импортированных результатов. Обработка сохраненных данных следует принятой политике.",
|
||||
},
|
||||
};
|
||||
|
||||
export const consentStateLabels = {
|
||||
active: "Действует",
|
||||
superseded: "Заменено новой версией",
|
||||
revoked: "Отозвано",
|
||||
} as const satisfies Record<ConsentRecord["state"], string>;
|
||||
|
||||
export const consentSourceLabels = {
|
||||
registration: "При регистрации",
|
||||
consent_settings: "В настройках согласий",
|
||||
invitation_acceptance: "При принятии приглашения",
|
||||
} as const satisfies Record<ConsentRecord["source"], string>;
|
||||
|
||||
export const contactFieldLabels = {
|
||||
full_name: "ФИО",
|
||||
email: "Электронная почта",
|
||||
phone: "Телефон",
|
||||
telegram: "Telegram",
|
||||
} as const satisfies Record<NonNullable<ConsentRecord["fields"]>[number], string>;
|
||||
|
||||
export type ConsentPurposeGroup = {
|
||||
purpose: ConsentPurposeCode;
|
||||
records: ConsentRecord[];
|
||||
};
|
||||
|
||||
export type OrganizationConsentGroup = {
|
||||
organizationId: string;
|
||||
displayName: string;
|
||||
records: ConsentRecord[];
|
||||
};
|
||||
|
||||
export function groupConsentHistory(records: readonly ConsentRecord[]): ConsentPurposeGroup[] {
|
||||
const grouped = new Map<ConsentPurposeCode, ConsentRecord[]>(
|
||||
consentPurposeOrder.map((purpose) => [purpose, []]),
|
||||
);
|
||||
|
||||
for (const record of records) {
|
||||
grouped.get(record.purpose)?.push(record);
|
||||
}
|
||||
|
||||
return consentPurposeOrder.map((purpose) => ({
|
||||
purpose,
|
||||
records: grouped.get(purpose) ?? [],
|
||||
}));
|
||||
}
|
||||
|
||||
export function groupOrganizationConsents(
|
||||
records: readonly ConsentRecord[],
|
||||
): OrganizationConsentGroup[] {
|
||||
const grouped = new Map<string, OrganizationConsentGroup>();
|
||||
|
||||
for (const record of records) {
|
||||
if (record.purpose !== "c4" || !record.organization) continue;
|
||||
|
||||
const current = grouped.get(record.organization.id);
|
||||
if (current) {
|
||||
current.records.push(record);
|
||||
continue;
|
||||
}
|
||||
|
||||
grouped.set(record.organization.id, {
|
||||
organizationId: record.organization.id,
|
||||
displayName: record.organization.name,
|
||||
records: [record],
|
||||
});
|
||||
}
|
||||
|
||||
return [...grouped.values()];
|
||||
}
|
||||
|
||||
export function formatConsentDate(value: string): string {
|
||||
return `${new Intl.DateTimeFormat("ru-RU", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
timeZone: "UTC",
|
||||
}).format(new Date(value))} UTC`;
|
||||
}
|
||||
|
||||
export function emptyPurposeHistoryMessage(purpose: ConsentPurposeCode, hasMore: boolean): string {
|
||||
if (hasMore) {
|
||||
return `В загруженной части истории записей C${purpose.slice(1)} пока нет. Загрузите более ранние записи, чтобы проверить историю.`;
|
||||
}
|
||||
if (purpose === "c4") {
|
||||
return "Записей C4 пока нет. Такое согласие появляется при принятии приглашения с показом компании и выбранных полей.";
|
||||
}
|
||||
return `Записей C${purpose.slice(1)} пока нет.`;
|
||||
}
|
||||
|
||||
export function deletionRequestStatusMessage(status: ConsentDeletionRequest["status"]): string {
|
||||
if (status === "processing") {
|
||||
return "Запрос на удаление передан в обработку. Удаление еще не завершено; данные не удаляются сразу.";
|
||||
}
|
||||
return "Запрос на удаление зарегистрирован. Он ожидает обработки; данные не удаляются сразу.";
|
||||
}
|
||||
Reference in new issue
Block a user