feat: add candidate privacy controls
This commit is contained in:
1 parent
e6bd66c560
commit
95b8e566c4
20 files changed
+2592
-11
No files matched your search
@@ -0,0 +1,271 @@
|
||||
import type {
|
||||
CardAccess,
|
||||
CardCategory,
|
||||
CardField,
|
||||
CardPreview,
|
||||
CardSelfAssessment,
|
||||
CandidateExperienceBand,
|
||||
CandidateSalaryCompatibility,
|
||||
CandidateWorkFormat,
|
||||
ConsentRecord,
|
||||
HiddenOrganization,
|
||||
PrivacySettings,
|
||||
PublicationUpdate,
|
||||
SearchStatusUpdate,
|
||||
} from "../../../shared/api/schemas";
|
||||
|
||||
export const publishableCardFields = [
|
||||
"categories",
|
||||
"self_assessment",
|
||||
"stack",
|
||||
"experience",
|
||||
"work_formats",
|
||||
"salary_compatibility",
|
||||
] as const satisfies readonly CardField[];
|
||||
|
||||
export type PublishableCardField = (typeof publishableCardFields)[number];
|
||||
|
||||
export type PublicationDraft = {
|
||||
state: "closed" | "published";
|
||||
fields: PublishableCardField[];
|
||||
expectedVersion: number;
|
||||
};
|
||||
|
||||
export type PublicationSubmission =
|
||||
{ ok: true; body: PublicationUpdate } | { ok: false; reason: "select_field" | "c2_required" };
|
||||
|
||||
export type OrganizationReference = { id: string; name: string };
|
||||
|
||||
export type C2State = "active" | "inactive" | "checking";
|
||||
|
||||
export function publicationDraftFromSettings(settings: PrivacySettings): PublicationDraft {
|
||||
return {
|
||||
state: settings.publication.state,
|
||||
fields: editableCardFields(settings.publication.fields),
|
||||
expectedVersion: settings.publication.version,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPublicationSubmission(
|
||||
draft: PublicationDraft,
|
||||
hasActiveC2: boolean,
|
||||
): PublicationSubmission {
|
||||
if (draft.state === "closed") {
|
||||
return {
|
||||
ok: true,
|
||||
body: {
|
||||
expected_version: draft.expectedVersion,
|
||||
state: "closed",
|
||||
fields: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const fields = editableCardFields(draft.fields);
|
||||
if (fields.length === 0) return { ok: false, reason: "select_field" };
|
||||
if (!hasActiveC2) return { ok: false, reason: "c2_required" };
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
body: {
|
||||
expected_version: draft.expectedVersion,
|
||||
state: "published",
|
||||
fields,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function buildSearchStatusSubmission(
|
||||
settings: PrivacySettings,
|
||||
value: SearchStatusUpdate["value"],
|
||||
): SearchStatusUpdate {
|
||||
return { expected_version: settings.search_status.version, value };
|
||||
}
|
||||
|
||||
export function isSamePublicationDraft(first: PublicationDraft, second: PublicationDraft): boolean {
|
||||
return (
|
||||
first.state === second.state &&
|
||||
first.expectedVersion === second.expectedVersion &&
|
||||
first.fields.length === second.fields.length &&
|
||||
first.fields.every((field, index) => field === second.fields[index])
|
||||
);
|
||||
}
|
||||
|
||||
export function organizationsAvailableToHide(
|
||||
accessRecords: readonly CardAccess[],
|
||||
hiddenOrganizations: readonly HiddenOrganization[],
|
||||
): OrganizationReference[] {
|
||||
const hiddenIds = new Set(hiddenOrganizations.map((item) => item.organization.id));
|
||||
const visibleOrganizations = new Map<string, OrganizationReference>();
|
||||
|
||||
for (const record of accessRecords) {
|
||||
const organization = record.organization;
|
||||
if (
|
||||
!organization ||
|
||||
hiddenIds.has(organization.id) ||
|
||||
visibleOrganizations.has(organization.id)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
visibleOrganizations.set(organization.id, {
|
||||
id: organization.id,
|
||||
name: organization.name,
|
||||
});
|
||||
}
|
||||
|
||||
return [...visibleOrganizations.values()];
|
||||
}
|
||||
|
||||
export function currentC2State(
|
||||
records: readonly ConsentRecord[],
|
||||
historyIsComplete: boolean,
|
||||
): C2State {
|
||||
if (records.some((record) => record.purpose === "c2" && record.state === "active")) {
|
||||
return "active";
|
||||
}
|
||||
return historyIsComplete ? "inactive" : "checking";
|
||||
}
|
||||
|
||||
export function hasUnsupportedPublishedFields(settings: PrivacySettings): boolean {
|
||||
return settings.publication.fields.some(
|
||||
(field) => !publishableCardFields.includes(field as PublishableCardField),
|
||||
);
|
||||
}
|
||||
|
||||
export const cardFieldLabels: Readonly<Record<PublishableCardField, string>> = {
|
||||
categories: "Подтвержденная категория и уровень",
|
||||
self_assessment: "Самооценка по направлениям",
|
||||
stack: "Технологии из подтвержденного профиля",
|
||||
experience: "Общий опыт",
|
||||
work_formats: "Форматы работы",
|
||||
salary_compatibility: "Совместимость по зарплатным ожиданиям",
|
||||
};
|
||||
|
||||
export const specializationLabels = {
|
||||
backend: "Backend",
|
||||
frontend: "Frontend",
|
||||
mobile: "Мобильная разработка",
|
||||
network_engineer: "Сетевое администрирование",
|
||||
devops_sre: "DevOps/SRE",
|
||||
data_analyst: "Аналитика данных",
|
||||
ds_ml: "Data Science и машинное обучение",
|
||||
information_security: "Информационная безопасность",
|
||||
qa: "Тестирование",
|
||||
} as const;
|
||||
|
||||
const gradeLabels = {
|
||||
intern: "Стажер",
|
||||
junior: "Junior",
|
||||
middle: "Middle",
|
||||
senior: "Senior",
|
||||
} as const;
|
||||
|
||||
const stackLabels = {
|
||||
go: "Go",
|
||||
postgresql: "PostgreSQL",
|
||||
kafka: "Kafka",
|
||||
docker: "Docker",
|
||||
} as const;
|
||||
|
||||
const workFormatLabels: Readonly<Record<CandidateWorkFormat, string>> = {
|
||||
remote: "Удаленно",
|
||||
office: "В офисе",
|
||||
hybrid: "Гибридно",
|
||||
};
|
||||
|
||||
const experienceBandLabels: Readonly<Record<CandidateExperienceBand, string>> = {
|
||||
"0_1": "До 1 года",
|
||||
"1_3": "1-3 года",
|
||||
"3_6": "3-6 лет",
|
||||
"6_plus": "6 лет и больше",
|
||||
"0_3": "0-3 года",
|
||||
"3_plus": "3 года и больше",
|
||||
};
|
||||
|
||||
const salaryCompatibilityLabels: Readonly<Record<CandidateSalaryCompatibility, string>> = {
|
||||
compatible: "Ожидания совместимы",
|
||||
not_compatible: "Ожидания не совпадают",
|
||||
};
|
||||
|
||||
export type CategoryPresentation = {
|
||||
specialization: string;
|
||||
grade: string;
|
||||
strength: string;
|
||||
};
|
||||
|
||||
export type SelfAssessmentPresentation = {
|
||||
specialization: string;
|
||||
declaredGrade: string | null;
|
||||
confirmation: string;
|
||||
};
|
||||
|
||||
export type CandidateViewPresentation = {
|
||||
pseudonym: string;
|
||||
categories: readonly CategoryPresentation[] | null;
|
||||
selfAssessments: readonly SelfAssessmentPresentation[] | null;
|
||||
stack: readonly string[] | null;
|
||||
experience: string | null;
|
||||
workFormats: readonly string[] | null;
|
||||
salaryCompatibility: string | null;
|
||||
};
|
||||
|
||||
function categoryPresentation(category: CardCategory): CategoryPresentation {
|
||||
return {
|
||||
specialization: specializationLabels[category.specialization],
|
||||
grade: gradeLabels[category.grade],
|
||||
strength:
|
||||
category.strength === "strong" ? "Сильное подтверждение" : "Стандартное подтверждение",
|
||||
};
|
||||
}
|
||||
|
||||
function selfAssessmentPresentation(item: CardSelfAssessment): SelfAssessmentPresentation {
|
||||
return {
|
||||
specialization: specializationLabels[item.specialization],
|
||||
declaredGrade: item.declared_grade ? gradeLabels[item.declared_grade] : null,
|
||||
confirmation:
|
||||
item.confirmation_status === "confirmed" ? "Грейд подтвержден" : "Грейд не подтвержден",
|
||||
};
|
||||
}
|
||||
|
||||
export function presentCandidatePreview(preview: CardPreview): CandidateViewPresentation | null {
|
||||
const card = preview.card;
|
||||
if (!card) return null;
|
||||
|
||||
return {
|
||||
pseudonym: card.pseudonym,
|
||||
categories: card.categories?.map(categoryPresentation) ?? null,
|
||||
selfAssessments: card.self_assessment?.map(selfAssessmentPresentation) ?? null,
|
||||
stack: card.stack?.map((tag) => stackLabels[tag]) ?? null,
|
||||
experience: card.experience_band ? experienceBandLabels[card.experience_band] : null,
|
||||
workFormats: card.work_formats?.map((format) => workFormatLabels[format]) ?? null,
|
||||
salaryCompatibility: card.salary_compatibility
|
||||
? salaryCompatibilityLabels[card.salary_compatibility]
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function editableCardFields(fields: readonly CardField[]): PublishableCardField[] {
|
||||
return publishableCardFields.filter((field) => fields.includes(field));
|
||||
}
|
||||
|
||||
export function formatPrivacyDate(value: string): string {
|
||||
return new Intl.DateTimeFormat("ru-RU", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
export const privacyEventLabels = {
|
||||
publication_opened: "Профиль опубликован",
|
||||
publication_changed: "Настройки публикации изменены",
|
||||
publication_closed: "Публикация закрыта",
|
||||
search_status_confirmed: "Подтвержден статус поиска",
|
||||
search_status_cleared: "Статус поиска скрыт",
|
||||
organization_hidden: "Профиль скрыт от компании",
|
||||
organization_unhidden: "Профиль снова доступен компании",
|
||||
} as const;
|
||||
|
||||
export const cardAccessLabels = {
|
||||
card_viewed: "Просмотрена карточка профиля",
|
||||
contact_read: "Открыты контактные данные",
|
||||
} as const;
|
||||
Reference in new issue
Block a user