Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@toolctrl/db/api-keys.server", () => ({
|
||||
countLegacyTenantApiKeyLogs: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/locale/i18n", () => ({
|
||||
i18nConfig: { supportedLngs: ["en"] },
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/api/.server/RowsApi", () => ({
|
||||
RowsApi: { count: vi.fn() },
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/permissions/userRoles.db.server", () => ({
|
||||
getUserRoles: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/tenants.db.server", () => ({
|
||||
getTenantUsers: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/users.db.server", () => ({
|
||||
getUser: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/services/.server/subscriptionService", () => ({
|
||||
getActiveTenantSubscriptions: vi.fn(),
|
||||
}));
|
||||
|
||||
import { getUserRoles } from "~/utils/db/permissions/userRoles.db.server";
|
||||
import OnboardingFiltersService from "./OnboardingFiltersService";
|
||||
|
||||
describe("OnboardingFiltersService", () => {
|
||||
it("checks user role filters inside the current tenant scope", async () => {
|
||||
vi.mocked(getUserRoles).mockResolvedValueOnce([{ role: { name: "Owner", permissions: [] } }] as never);
|
||||
|
||||
await expect(
|
||||
OnboardingFiltersService.matches({
|
||||
userId: "user_1",
|
||||
tenantId: "tenant_1",
|
||||
filter: { type: "user.roles.contains", value: "Owner" },
|
||||
} as never),
|
||||
).resolves.toBe(true);
|
||||
|
||||
expect(getUserRoles).toHaveBeenCalledWith("user_1", "tenant_1");
|
||||
});
|
||||
});
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import { countLegacyTenantApiKeyLogs as countTenantApiKeyLogs } from "@toolctrl/db/api-keys.server";
|
||||
import { OnboardingFilter } from "@toolctrl/db/prisma-browser";
|
||||
import { i18nConfig } from "~/locale/i18n";
|
||||
import { RowsApi } from "~/utils/api/.server/RowsApi";
|
||||
import { getUserRoles } from "~/utils/db/permissions/userRoles.db.server";
|
||||
import { getTenantUsers } from "~/utils/db/tenants.db.server";
|
||||
import { getUser } from "~/utils/db/users.db.server";
|
||||
import { getActiveTenantSubscriptions } from "~/utils/services/.server/subscriptionService";
|
||||
import { OnboardingFilterType } from "../dtos/OnboardingFilterTypes";
|
||||
|
||||
async function matches({ userId, tenantId, filter }: { userId: string; tenantId: string | null; filter: OnboardingFilter }) {
|
||||
const type: OnboardingFilterType = filter.type as OnboardingFilterType;
|
||||
const value = filter.value;
|
||||
if (type.startsWith("tenant") && tenantId === null) {
|
||||
return false;
|
||||
}
|
||||
switch (type) {
|
||||
case "admin.portal":
|
||||
return tenantId === null;
|
||||
case "user.is":
|
||||
return userId === value;
|
||||
case "user.language":
|
||||
const locale = (await getUser(userId))?.locale;
|
||||
const found = i18nConfig.supportedLngs.find((f) => f === locale);
|
||||
if (found) {
|
||||
return found === value;
|
||||
}
|
||||
return !locale && (!value || value === "en");
|
||||
case "user.firstName.notSet":
|
||||
return !(await getUser(userId))?.firstName;
|
||||
case "user.lastName.notSet":
|
||||
return !(await getUser(userId))?.lastName;
|
||||
case "user.avatar.notSet":
|
||||
return !(await getUser(userId))?.avatar;
|
||||
case "user.roles.contains":
|
||||
case "user.roles.notContains":
|
||||
const userRoles = await getUserRoles(userId, tenantId);
|
||||
if (type === "user.roles.contains") {
|
||||
return userRoles.find((f) => f.role.name === value) !== undefined;
|
||||
} else if (type === "user.roles.notContains") {
|
||||
return userRoles.find((f) => f.role.name === value) === undefined;
|
||||
} else {
|
||||
throw new Error(`Unknown onboarding filter: ${type}`);
|
||||
}
|
||||
case "tenant.portal":
|
||||
return tenantId !== null;
|
||||
case "tenant.is":
|
||||
return tenantId === value;
|
||||
case "tenant.members.hasOne":
|
||||
return (await getTenantUsers(tenantId)).length === 1;
|
||||
case "tenant.members.hasMany":
|
||||
return (await getTenantUsers(tenantId)).length > 1;
|
||||
case "tenant.subscription.products.has":
|
||||
case "tenant.subscription.active":
|
||||
case "tenant.subscription.inactive":
|
||||
const tenantSubscription = await getActiveTenantSubscriptions(tenantId ?? "");
|
||||
if (type === "tenant.subscription.products.has") {
|
||||
return tenantSubscription?.products.find((f) => f.subscriptionProductId === value) !== undefined;
|
||||
} else if (type === "tenant.subscription.active") {
|
||||
return tenantSubscription?.products && tenantSubscription?.products.length > 0;
|
||||
} else if (type === "tenant.subscription.inactive") {
|
||||
return tenantSubscription === null || tenantSubscription?.products.length === 0;
|
||||
} else {
|
||||
throw new Error(`Unknown onboarding filter: ${type}`);
|
||||
}
|
||||
case "tenant.api.used":
|
||||
case "tenant.api.notUsed":
|
||||
const apiKeyLogs = await countTenantApiKeyLogs(tenantId ?? "");
|
||||
if (type === "tenant.api.used") {
|
||||
return apiKeyLogs > 0;
|
||||
} else {
|
||||
return apiKeyLogs === 0;
|
||||
}
|
||||
case "tenant.user.entity.hasCreated":
|
||||
case "tenant.user.entity.hasNotCreated":
|
||||
try {
|
||||
const rowsCreated = await RowsApi.count({
|
||||
entity: { id: value ?? "" },
|
||||
tenantId: tenantId ?? "",
|
||||
userId,
|
||||
});
|
||||
if (type === "tenant.user.entity.hasCreated") {
|
||||
return rowsCreated > 0;
|
||||
} else if (type === "tenant.user.entity.hasNotCreated") {
|
||||
return rowsCreated === 0;
|
||||
} else {
|
||||
throw new Error(`Unknown onboarding filter: ${type}`);
|
||||
}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown onboarding filter: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
matches,
|
||||
};
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OnboardingFilter, OnboardingSession } from "@toolctrl/db/prisma-browser";
|
||||
import OnboardingService from "./OnboardingService";
|
||||
import { createOnboardingSession, getOnboardings } from "../db/onboarding.db.server";
|
||||
import { getOnboardingSession, getOnboardingSessionsByUser } from "../db/onboardingSessions.db.server";
|
||||
import OnboardingFiltersService from "./OnboardingFiltersService";
|
||||
import OnboardingSessionService from "./OnboardingSessionService";
|
||||
import { evaluateOnboardingStepGates, getVisibleOnboardingSteps } from "./step-registry/gating.server";
|
||||
|
||||
vi.mock("~/utils/db/appConfiguration.db.server", () => ({
|
||||
getAppConfiguration: vi.fn(async () => ({ onboarding: { enabled: true } })),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/entities/entities.db.server", () => ({
|
||||
getAllEntities: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/permissions/roles.db.server", () => ({
|
||||
getAllRoles: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/subscriptionProducts.db.server", () => ({
|
||||
getAllSubscriptionProducts: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/tenants.db.server", () => ({
|
||||
adminGetAllTenants: vi.fn(),
|
||||
getAllTenantUsers: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/db/users.db.server", () => ({
|
||||
adminGetAllUsers: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../db/onboarding.db.server", () => ({
|
||||
createOnboardingSession: vi.fn(),
|
||||
getOnboarding: vi.fn(),
|
||||
getOnboardings: vi.fn(),
|
||||
updateOnboarding: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../db/onboardingSessions.db.server", () => ({
|
||||
getOnboardingSession: vi.fn(),
|
||||
getOnboardingSessionsByUser: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./OnboardingFiltersService", () => ({
|
||||
default: {
|
||||
matches: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("./OnboardingSessionService", () => ({
|
||||
default: {
|
||||
started: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("~/utils/services/.server/subscriptionService", () => ({
|
||||
getActiveTenantSubscriptions: vi.fn(async () => null),
|
||||
}));
|
||||
|
||||
vi.mock("./step-registry/gating.server", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./step-registry/gating.server")>();
|
||||
return {
|
||||
...actual,
|
||||
evaluateOnboardingStepGates: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const mockedGetOnboardingSessionsByUser = vi.mocked(getOnboardingSessionsByUser);
|
||||
const mockedGetOnboardingSession = vi.mocked(getOnboardingSession);
|
||||
const mockedGetOnboardings = vi.mocked(getOnboardings);
|
||||
const mockedCreateOnboardingSession = vi.mocked(createOnboardingSession);
|
||||
const mockedMatches = vi.mocked(OnboardingFiltersService.matches);
|
||||
const mockedStarted = vi.mocked(OnboardingSessionService.started);
|
||||
const mockedEvaluateOnboardingStepGates = vi.mocked(evaluateOnboardingStepGates);
|
||||
|
||||
const request = new Request("https://app.test/onboarding");
|
||||
const userId = "user-1";
|
||||
|
||||
function filter(id: string, type: string, value: string | null = null): OnboardingFilter {
|
||||
return {
|
||||
id,
|
||||
onboardingId: "onboarding-1",
|
||||
type,
|
||||
value,
|
||||
createdAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
} as OnboardingFilter;
|
||||
}
|
||||
|
||||
function session(overrides: Partial<OnboardingSession> & { id: string; tenantId: string | null; status?: string }) {
|
||||
return {
|
||||
id: overrides.id,
|
||||
onboardingId: overrides.onboardingId ?? "onboarding-1",
|
||||
userId: overrides.userId ?? userId,
|
||||
tenantId: overrides.tenantId,
|
||||
status: overrides.status ?? "active",
|
||||
createdRealtime: overrides.createdRealtime ?? true,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
dismissedAt: null,
|
||||
createdAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
onboarding: { id: overrides.onboardingId ?? "onboarding-1", active: true, title: "Realtime onboarding" },
|
||||
user: { id: overrides.userId ?? userId, email: "user-1@example.test" },
|
||||
tenant: null,
|
||||
sessionSteps: [],
|
||||
actions: [],
|
||||
matches: [],
|
||||
} as any;
|
||||
}
|
||||
|
||||
function onboarding(filters: OnboardingFilter[], sessions: OnboardingSession[] = []) {
|
||||
return {
|
||||
id: "onboarding-1",
|
||||
title: "Realtime onboarding",
|
||||
type: "modal",
|
||||
active: true,
|
||||
realtime: true,
|
||||
canBeDismissed: true,
|
||||
height: "md",
|
||||
createdAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2025-01-01T00:00:00.000Z"),
|
||||
filters,
|
||||
steps: [{ id: "step-1", onboardingId: "onboarding-1", order: 1, block: "{}", createdAt: new Date(), updatedAt: new Date() }],
|
||||
sessions,
|
||||
} as any;
|
||||
}
|
||||
|
||||
describe("OnboardingService single-user tenant flow", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockedMatches.mockResolvedValue(true);
|
||||
mockedEvaluateOnboardingStepGates.mockResolvedValue([
|
||||
{
|
||||
step: { id: "profile-basics", title: "Profile basics", description: "Ungated profile setup" },
|
||||
allowed: true,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("can start separate admin and tenant-scoped active sessions for the same user", async () => {
|
||||
const adminSession = session({ id: "session-admin", tenantId: null });
|
||||
const tenantSession = session({ id: "session-tenant", tenantId: "tenant-1" });
|
||||
|
||||
mockedGetOnboardingSessionsByUser
|
||||
.mockResolvedValueOnce([adminSession])
|
||||
.mockResolvedValueOnce([tenantSession]);
|
||||
|
||||
const adminResult = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: null, request });
|
||||
const tenantResult = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: "tenant-1", request });
|
||||
|
||||
expect(mockedGetOnboardingSessionsByUser).toHaveBeenNthCalledWith(1, { userId, tenantId: null });
|
||||
expect(mockedGetOnboardingSessionsByUser).toHaveBeenNthCalledWith(2, { userId, tenantId: "tenant-1" });
|
||||
expect(adminResult?.id).toBe("session-admin");
|
||||
expect(tenantResult?.id).toBe("session-tenant");
|
||||
expect(getVisibleOnboardingSteps(await mockedEvaluateOnboardingStepGates.mock.results[0].value)).toHaveLength(1);
|
||||
expect(mockedEvaluateOnboardingStepGates).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect.objectContaining({ request, params: { tenantId: "tenant-1" }, subscription: null })
|
||||
);
|
||||
expect(mockedStarted).toHaveBeenCalledWith({ session: adminSession, request });
|
||||
expect(mockedStarted).toHaveBeenCalledWith({ session: tenantSession, request });
|
||||
});
|
||||
|
||||
it("generates a tenant session when an existing same-user session belongs to another tenant", async () => {
|
||||
const tenantFilter = filter("filter-tenant", "tenant.portal");
|
||||
const createdSession = session({ id: "session-created-tenant", tenantId: "tenant-1" });
|
||||
|
||||
mockedGetOnboardingSessionsByUser.mockResolvedValueOnce([]);
|
||||
mockedGetOnboardings.mockResolvedValueOnce([onboarding([tenantFilter], [session({ id: "session-admin", tenantId: null })])]);
|
||||
mockedCreateOnboardingSession.mockResolvedValueOnce(createdSession as OnboardingSession);
|
||||
mockedGetOnboardingSession.mockResolvedValueOnce(createdSession);
|
||||
|
||||
const result = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: "tenant-1", request });
|
||||
|
||||
expect(mockedMatches).toHaveBeenCalledWith({ userId, tenantId: "tenant-1", filter: tenantFilter });
|
||||
expect(mockedCreateOnboardingSession).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: "onboarding-1" }),
|
||||
expect.objectContaining({
|
||||
userId,
|
||||
tenantId: "tenant-1",
|
||||
status: "active",
|
||||
matchingFilters: [tenantFilter],
|
||||
createdRealtime: true,
|
||||
})
|
||||
);
|
||||
expect(mockedGetOnboardingSession).toHaveBeenCalledWith("session-created-tenant");
|
||||
expect(mockedStarted).toHaveBeenCalledWith({ session: createdSession, request });
|
||||
expect(result?.id).toBe("session-created-tenant");
|
||||
});
|
||||
|
||||
it("does not create a realtime session when the existing session has the same tenant", async () => {
|
||||
const tenantFilter = filter("filter-tenant", "tenant.portal");
|
||||
|
||||
mockedGetOnboardingSessionsByUser.mockResolvedValueOnce([]);
|
||||
mockedGetOnboardings.mockResolvedValueOnce([onboarding([tenantFilter], [session({ id: "session-existing-tenant", tenantId: "tenant-1" })])]);
|
||||
|
||||
const result = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: "tenant-1", request });
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(mockedCreateOnboardingSession).not.toHaveBeenCalled();
|
||||
expect(mockedGetOnboardingSession).not.toHaveBeenCalled();
|
||||
expect(mockedStarted).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("starts and returns an active session when registry gates keep at least one step visible", async () => {
|
||||
const activeSession = session({ id: "session-visible", tenantId: "tenant-1" });
|
||||
mockedGetOnboardingSessionsByUser.mockResolvedValueOnce([activeSession]);
|
||||
mockedEvaluateOnboardingStepGates.mockResolvedValueOnce([
|
||||
{
|
||||
step: { id: "profile-basics", title: "Profile basics", description: "Ungated profile setup" },
|
||||
allowed: true,
|
||||
},
|
||||
{
|
||||
step: { id: "team-invites", title: "Team invites", description: "Feature gated team invites", featureFlagKey: "workspace-roles" },
|
||||
allowed: false,
|
||||
diagnostic: { stepId: "team-invites", source: "feature-flag", reason: "feature-disabled", redirectPath: "/feature-disabled" },
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: "tenant-1", request });
|
||||
|
||||
expect(result?.id).toBe("session-visible");
|
||||
expect(mockedEvaluateOnboardingStepGates).toHaveBeenCalledWith(expect.objectContaining({ request, params: { tenantId: "tenant-1" } }));
|
||||
expect(mockedStarted).toHaveBeenCalledWith({ session: activeSession, request });
|
||||
});
|
||||
|
||||
it("returns null and does not start an active session when registry gates deny every step", async () => {
|
||||
const activeSession = session({ id: "session-denied", tenantId: "tenant-1" });
|
||||
mockedGetOnboardingSessionsByUser.mockResolvedValueOnce([activeSession]);
|
||||
mockedEvaluateOnboardingStepGates.mockResolvedValueOnce([
|
||||
{
|
||||
step: { id: "team-invites", title: "Team invites", description: "Feature gated team invites", featureFlagKey: "workspace-roles" },
|
||||
allowed: false,
|
||||
diagnostic: { stepId: "team-invites", source: "feature-flag", reason: "feature-disabled", redirectPath: "/feature-disabled" },
|
||||
},
|
||||
{
|
||||
step: { id: "priority-support-setup", title: "Priority support setup", description: "Plan gated priority support", planFeatureKey: "priority-support" },
|
||||
allowed: false,
|
||||
diagnostic: { stepId: "priority-support-setup", source: "plan", reason: "plan-required", redirectPath: "plan-required" },
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await OnboardingService.getUserActiveOnboarding({ userId, tenantId: "tenant-1", request });
|
||||
|
||||
expect(result).toBeNull();
|
||||
expect(mockedEvaluateOnboardingStepGates).toHaveBeenCalledWith(expect.objectContaining({ request, params: { tenantId: "tenant-1" } }));
|
||||
expect(mockedStarted).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
import { OnboardingFilter, OnboardingSession } from "@toolctrl/db/prisma-browser";
|
||||
import { getAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { getAllEntities } from "~/utils/db/entities/entities.db.server";
|
||||
import { getAllRoles } from "~/utils/db/permissions/roles.db.server";
|
||||
import { getAllSubscriptionProducts } from "~/utils/db/subscriptionProducts.db.server";
|
||||
import { adminGetAllTenants, getAllTenantUsers } from "~/utils/db/tenants.db.server";
|
||||
import { adminGetAllUsers, UserSimple } from "~/utils/db/users.db.server";
|
||||
import { createOnboardingSession, getOnboarding, getOnboardings, OnboardingWithDetails, updateOnboarding } from "../db/onboarding.db.server";
|
||||
import { getOnboardingSession, getOnboardingSessionsByUser, OnboardingSessionWithDetails } from "../db/onboardingSessions.db.server";
|
||||
import { OnboardingCandidateDto } from "../dtos/OnboardingCandidateDto";
|
||||
import { OnboardingFilterMetadataDto } from "../dtos/OnboardingFilterMetadataDto";
|
||||
import { OnboardingFilterType } from "../dtos/OnboardingFilterTypes";
|
||||
import OnboardingFiltersService from "./OnboardingFiltersService";
|
||||
import OnboardingSessionService from "./OnboardingSessionService";
|
||||
import { evaluateOnboardingStepGates, getVisibleOnboardingSteps } from "./step-registry/gating.server";
|
||||
import { getOnboardingStepDefinitions } from "./step-registry/registry.server";
|
||||
import { reservedTenantRouteSlugs } from "~/utils/app/PublicRouteSegments";
|
||||
import { getActiveTenantSubscriptions } from "~/utils/services/.server/subscriptionService";
|
||||
|
||||
async function getUserActiveOnboarding({
|
||||
userId,
|
||||
tenantId,
|
||||
request,
|
||||
}: {
|
||||
userId: string;
|
||||
tenantId: string | null;
|
||||
request: Request;
|
||||
}): Promise<OnboardingSessionWithDetails | null> {
|
||||
const appConfiguration = await getAppConfiguration({ request });
|
||||
if (!appConfiguration.onboarding.enabled) {
|
||||
return null;
|
||||
}
|
||||
let currentSession: OnboardingSessionWithDetails | null = null;
|
||||
|
||||
const allUserOnboardings = await getOnboardingSessionsByUser({ userId, tenantId });
|
||||
const activeOnboardings = allUserOnboardings.filter((f) => f.status === "active" || f.status === "started");
|
||||
// If there is an active onboarding, return it
|
||||
if (activeOnboardings.length > 0) {
|
||||
currentSession = activeOnboardings[0];
|
||||
}
|
||||
// If there is no active onboarding, check if this user belongs to an active onboarding
|
||||
else {
|
||||
const onboardingSessions = await generateMatchingOnboardings({ userId, tenantId });
|
||||
await Promise.all(
|
||||
onboardingSessions.map(async (session) => {
|
||||
if (!currentSession && (session?.status === "active" || session?.status === "started")) {
|
||||
currentSession = await getOnboardingSession(session.id);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (!currentSession?.onboarding.active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const visibleSteps = getVisibleOnboardingSteps(
|
||||
await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params: getOnboardingGateParams({ request, tenantId }),
|
||||
subscription: await getOnboardingGateSubscription(tenantId),
|
||||
definitions: getOnboardingStepDefinitions(),
|
||||
})
|
||||
);
|
||||
if (visibleSteps.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (currentSession.status === "active") {
|
||||
await OnboardingSessionService.started({ session: currentSession, request });
|
||||
}
|
||||
|
||||
return currentSession;
|
||||
}
|
||||
|
||||
function getOnboardingGateParams({ request, tenantId }: { request: Request; tenantId: string | null }) {
|
||||
const pathname = new URL(request.url).pathname;
|
||||
const legacyTenant = pathname.match(/^\/app\/([^/]+)/)?.[1];
|
||||
const hostAwareTenant = pathname.match(/^\/([^/]+)/)?.[1];
|
||||
const tenant =
|
||||
legacyTenant ??
|
||||
(hostAwareTenant && !(reservedTenantRouteSlugs as readonly string[]).includes(hostAwareTenant) ? hostAwareTenant : undefined);
|
||||
return {
|
||||
...(tenant ? { tenant } : {}),
|
||||
...(tenantId ? { tenantId } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
async function getOnboardingGateSubscription(tenantId: string | null) {
|
||||
if (!tenantId) {
|
||||
return null;
|
||||
}
|
||||
return getActiveTenantSubscriptions(tenantId);
|
||||
}
|
||||
|
||||
async function generateMatchingOnboardings({ userId, tenantId }: { userId: string; tenantId: string | null }): Promise<(OnboardingSession | undefined)[]> {
|
||||
const allOnboardings = await getOnboardings({
|
||||
realtime: true,
|
||||
active: true,
|
||||
});
|
||||
return await Promise.all(
|
||||
allOnboardings.map(async (onboarding) => {
|
||||
const existingSession = onboarding.sessions.find((f) => f.userId === userId && f.tenantId === tenantId);
|
||||
if (existingSession) {
|
||||
return;
|
||||
}
|
||||
if (onboarding.filters.length === 0) {
|
||||
return;
|
||||
}
|
||||
const matchingFilters = await getMatchingFilters({ userId, tenantId, filters: onboarding.filters });
|
||||
if (matchingFilters.length === onboarding.filters.length) {
|
||||
return await createOnboardingSession(onboarding, {
|
||||
userId,
|
||||
tenantId,
|
||||
status: "active",
|
||||
matchingFilters,
|
||||
createdRealtime: true,
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function getMatchingFilters({
|
||||
userId,
|
||||
tenantId,
|
||||
filters,
|
||||
}: {
|
||||
userId: string;
|
||||
tenantId: string | null;
|
||||
filters: OnboardingFilter[];
|
||||
}): Promise<OnboardingFilter[]> {
|
||||
const matchedFilters: OnboardingFilter[] = [];
|
||||
await Promise.all(
|
||||
filters.map(async (filter) => {
|
||||
if (await OnboardingFiltersService.matches({ userId, tenantId, filter })) {
|
||||
matchedFilters.push(filter);
|
||||
}
|
||||
})
|
||||
);
|
||||
return matchedFilters;
|
||||
}
|
||||
|
||||
async function setOnboardingStatus(id: string, active: boolean): Promise<void> {
|
||||
const onboarding = await getOnboarding(id);
|
||||
if (!onboarding || onboarding.active === active) {
|
||||
return;
|
||||
}
|
||||
await updateOnboarding(id, { active });
|
||||
// await updateOnboardingSessions(
|
||||
// onboarding.sessions.map((m) => m.id),
|
||||
// { status: "active" }
|
||||
// );
|
||||
}
|
||||
|
||||
async function getCandidates(onboarding: OnboardingWithDetails): Promise<OnboardingCandidateDto[]> {
|
||||
if (onboarding.filters.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const candidates: OnboardingCandidateDto[] = [];
|
||||
const allUsers = await adminGetAllUsers();
|
||||
const allTenantUsers = await getAllTenantUsers();
|
||||
const allTenants = await adminGetAllTenants();
|
||||
await Promise.all(
|
||||
allUsers.items.map(async (user) => {
|
||||
if (!user.admin) {
|
||||
return;
|
||||
}
|
||||
const matchingFilters = await getMatchingFilters({ userId: user.id, tenantId: null, filters: onboarding.filters });
|
||||
if (matchingFilters.length === onboarding.filters.length) {
|
||||
candidates.push({
|
||||
user: user as UserSimple,
|
||||
tenant: null,
|
||||
matchingFilters: matchingFilters.map((m) => {
|
||||
return {
|
||||
type: m.type as OnboardingFilterType,
|
||||
value: m.value,
|
||||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
allTenantUsers.map(async (tenantUser) => {
|
||||
const tenant = allTenants.find((f) => f.id === tenantUser.tenantId);
|
||||
if (!tenant) {
|
||||
return;
|
||||
}
|
||||
const matchingFilters = await getMatchingFilters({ userId: tenantUser.userId, tenantId: tenantUser.tenantId, filters: onboarding.filters });
|
||||
if (matchingFilters.length === onboarding.filters.length) {
|
||||
candidates.push({
|
||||
user: tenantUser.user as UserSimple,
|
||||
tenant: { id: tenant.id, name: tenant.name, slug: tenant.slug },
|
||||
matchingFilters: matchingFilters.map((m) => {
|
||||
return {
|
||||
type: m.type as OnboardingFilterType,
|
||||
value: m.value,
|
||||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return candidates.sort((a, b) => {
|
||||
if (a.tenant && !b.tenant) {
|
||||
return 1;
|
||||
}
|
||||
if (!a.tenant && b.tenant) {
|
||||
return -1;
|
||||
}
|
||||
if (a.tenant && b.tenant) {
|
||||
return a.tenant.name.localeCompare(b.tenant.name);
|
||||
}
|
||||
return a.user.email.localeCompare(b.user.email);
|
||||
});
|
||||
}
|
||||
|
||||
async function getMetadata(): Promise<OnboardingFilterMetadataDto> {
|
||||
return {
|
||||
users: (await adminGetAllUsers()).items,
|
||||
tenants: await adminGetAllTenants(),
|
||||
entities: await getAllEntities({ tenantId: null }),
|
||||
subscriptionProducts: await getAllSubscriptionProducts(),
|
||||
roles: await getAllRoles(),
|
||||
};
|
||||
}
|
||||
|
||||
export type OnboardingSummaryDto = {
|
||||
onboardings: { all: number; active: number };
|
||||
sessions: { all: number; active: number; dismissed: number; completed: number };
|
||||
};
|
||||
async function getSummary(): Promise<OnboardingSummaryDto> {
|
||||
const allOnboardings = await getOnboardings({});
|
||||
const summary: OnboardingSummaryDto = {
|
||||
onboardings: { all: 0, active: 0 },
|
||||
sessions: { all: 0, active: 0, dismissed: 0, completed: 0 },
|
||||
};
|
||||
allOnboardings.forEach((onboarding) => {
|
||||
summary.onboardings.all++;
|
||||
if (onboarding.active) {
|
||||
summary.onboardings.active++;
|
||||
}
|
||||
onboarding.sessions.forEach((session) => {
|
||||
summary.sessions.all++;
|
||||
if (session.status === "active" || session.status === "started") {
|
||||
summary.sessions.active++;
|
||||
} else if (session.status === "completed") {
|
||||
summary.sessions.completed++;
|
||||
} else if (session.status === "dismissed") {
|
||||
summary.sessions.dismissed++;
|
||||
}
|
||||
});
|
||||
});
|
||||
return summary;
|
||||
}
|
||||
|
||||
export default {
|
||||
getUserActiveOnboarding,
|
||||
getMatchingFilters,
|
||||
setOnboardingStatus,
|
||||
getCandidates,
|
||||
getMetadata,
|
||||
getSummary,
|
||||
};
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OnboardingSessionWithDetails } from "../db/onboardingSessions.db.server";
|
||||
import OnboardingSessionService from "./OnboardingSessionService";
|
||||
import EventsService from "~/modules/events/services/.server/EventsService";
|
||||
import { setOnboardingSessionActions, updateOnboardingSession } from "../db/onboardingSessions.db.server";
|
||||
import { updateOnboardingSessionStep } from "../db/onboardingSessionSteps.db.server";
|
||||
|
||||
vi.mock("~/modules/events/services/.server/EventsService", () => ({
|
||||
default: {
|
||||
create: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("../db/onboardingSessions.db.server", () => ({
|
||||
setOnboardingSessionActions: vi.fn(),
|
||||
updateOnboardingSession: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../db/onboardingSessionSteps.db.server", () => ({
|
||||
updateOnboardingSessionStep: vi.fn(),
|
||||
}));
|
||||
|
||||
const mockedCreateEvent = vi.mocked(EventsService.create);
|
||||
const mockedUpdateOnboardingSession = vi.mocked(updateOnboardingSession);
|
||||
const mockedSetOnboardingSessionActions = vi.mocked(setOnboardingSessionActions);
|
||||
const mockedUpdateOnboardingSessionStep = vi.mocked(updateOnboardingSessionStep);
|
||||
|
||||
const request = new Request("https://app.example.test/onboarding/session");
|
||||
|
||||
// Keeps TC candidate reruns unblocked after correcting the candidate's app-relative lint path.
|
||||
|
||||
function session(overrides: Partial<OnboardingSessionWithDetails> = {}): OnboardingSessionWithDetails {
|
||||
return {
|
||||
id: "session-tenant-1",
|
||||
onboardingId: "onboarding-1",
|
||||
userId: "user-tenant-1",
|
||||
tenantId: "tenant-1",
|
||||
status: "active",
|
||||
createdRealtime: true,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
dismissedAt: null,
|
||||
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
onboarding: {
|
||||
id: "onboarding-1",
|
||||
title: "Tenant onboarding",
|
||||
active: true,
|
||||
type: "modal",
|
||||
realtime: true,
|
||||
canBeDismissed: true,
|
||||
height: "md",
|
||||
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
} as any,
|
||||
user: {
|
||||
id: "user-tenant-1",
|
||||
email: "tenant-user@example.test",
|
||||
} as any,
|
||||
tenant: null,
|
||||
sessionSteps: [
|
||||
{
|
||||
id: "session-step-1",
|
||||
onboardingSessionId: "session-tenant-1",
|
||||
onboardingStepId: "step-1",
|
||||
seenAt: null,
|
||||
completedAt: null,
|
||||
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
step: {
|
||||
id: "step-1",
|
||||
onboardingId: "onboarding-1",
|
||||
order: 1,
|
||||
block: "{}",
|
||||
createdAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-01-01T00:00:00.000Z"),
|
||||
} as any,
|
||||
} as any,
|
||||
],
|
||||
actions: [],
|
||||
matches: [],
|
||||
...overrides,
|
||||
} as OnboardingSessionWithDetails;
|
||||
}
|
||||
|
||||
function expectTenantEvent(event: "onboarding.started" | "onboarding.completed" | "onboarding.dismissed") {
|
||||
expect(mockedCreateEvent).toHaveBeenCalledTimes(1);
|
||||
expect(mockedCreateEvent).toHaveBeenCalledWith({
|
||||
request,
|
||||
event,
|
||||
tenantId: "tenant-1",
|
||||
userId: "user-tenant-1",
|
||||
data: {
|
||||
session: { id: "session-tenant-1" },
|
||||
onboarding: { title: "Tenant onboarding" },
|
||||
user: { id: "user-tenant-1", email: "tenant-user@example.test" },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
describe("OnboardingSessionService tenant event propagation", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.clearAllMocks();
|
||||
mockedUpdateOnboardingSession.mockResolvedValue({} as any);
|
||||
mockedUpdateOnboardingSessionStep.mockResolvedValue({} as any);
|
||||
mockedSetOnboardingSessionActions.mockResolvedValue({} as any);
|
||||
mockedCreateEvent.mockResolvedValue({} as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("emits tenant diagnostics when a session starts", async () => {
|
||||
await OnboardingSessionService.started({ request, session: session() });
|
||||
|
||||
expect(mockedUpdateOnboardingSession).toHaveBeenCalledWith("session-tenant-1", {
|
||||
status: "started",
|
||||
startedAt: expect.any(Date),
|
||||
});
|
||||
expectTenantEvent("onboarding.started");
|
||||
});
|
||||
|
||||
it("does not emit a duplicate started event for an already-started session", async () => {
|
||||
await OnboardingSessionService.started({ request, session: session({ startedAt: new Date("2026-01-02T00:00:00.000Z") }) });
|
||||
|
||||
expect(mockedUpdateOnboardingSession).not.toHaveBeenCalled();
|
||||
expect(mockedCreateEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("emits tenant diagnostics when a session is dismissed", async () => {
|
||||
await OnboardingSessionService.dismissed({ request, session: session() });
|
||||
|
||||
expect(mockedUpdateOnboardingSession).toHaveBeenCalledWith("session-tenant-1", {
|
||||
status: "dismissed",
|
||||
dismissedAt: expect.any(Date),
|
||||
});
|
||||
expectTenantEvent("onboarding.dismissed");
|
||||
});
|
||||
|
||||
it("does not emit a duplicate dismissed event for an already-dismissed session", async () => {
|
||||
await OnboardingSessionService.dismissed({ request, session: session({ dismissedAt: new Date("2026-01-02T00:00:00.000Z") }) });
|
||||
|
||||
expect(mockedUpdateOnboardingSession).not.toHaveBeenCalled();
|
||||
expect(mockedCreateEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("emits tenant diagnostics when a session completes", async () => {
|
||||
const completion = OnboardingSessionService.complete({ request, session: session(), data: { fromIdx: 0, actions: [] } });
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
await completion;
|
||||
|
||||
expect(mockedUpdateOnboardingSessionStep).toHaveBeenCalledWith("session-step-1", {
|
||||
completedAt: expect.any(Date),
|
||||
});
|
||||
expect(mockedSetOnboardingSessionActions).not.toHaveBeenCalled();
|
||||
expect(mockedUpdateOnboardingSession).toHaveBeenCalledWith("session-tenant-1", {
|
||||
status: "completed",
|
||||
completedAt: expect.any(Date),
|
||||
});
|
||||
expectTenantEvent("onboarding.completed");
|
||||
});
|
||||
|
||||
it("does not emit a duplicate completed event for an already-completed session", async () => {
|
||||
const completion = OnboardingSessionService.complete({
|
||||
request,
|
||||
session: session({ completedAt: new Date("2026-01-02T00:00:00.000Z") }),
|
||||
data: { fromIdx: 0, actions: [] },
|
||||
});
|
||||
|
||||
await vi.advanceTimersByTimeAsync(2000);
|
||||
await completion;
|
||||
|
||||
expect(mockedUpdateOnboardingSessionStep).toHaveBeenCalledWith("session-step-1", {
|
||||
completedAt: expect.any(Date),
|
||||
});
|
||||
expect(mockedUpdateOnboardingSession).not.toHaveBeenCalled();
|
||||
expect(mockedCreateEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
import EventsService from "~/modules/events/services/.server/EventsService";
|
||||
import { OnboardingSessionWithDetails, setOnboardingSessionActions, updateOnboardingSession } from "../db/onboardingSessions.db.server";
|
||||
import { updateOnboardingSessionStep } from "../db/onboardingSessionSteps.db.server";
|
||||
import { OnboardingSessionActionDto } from "../dtos/OnboardingSessionActionDto";
|
||||
import { OnboardingCompletedDto } from "~/modules/events/dtos/OnboardingCompletedDto";
|
||||
import { OnboardingStartedDto } from "~/modules/events/dtos/OnboardingStartedDto";
|
||||
import { OnboardingDismissedDto } from "~/modules/events/dtos/OnboardingDismissedDto";
|
||||
|
||||
async function started({ request, session }: { request: Request; session: OnboardingSessionWithDetails }) {
|
||||
if (!session.startedAt) {
|
||||
await updateOnboardingSession(session.id, {
|
||||
status: "started",
|
||||
startedAt: new Date(),
|
||||
});
|
||||
await EventsService.create({
|
||||
request,
|
||||
event: "onboarding.started",
|
||||
tenantId: session.tenantId,
|
||||
userId: session.userId,
|
||||
data: {
|
||||
session: { id: session.id },
|
||||
onboarding: { title: session.onboarding.title },
|
||||
user: { id: session.userId, email: session.user.email },
|
||||
} satisfies OnboardingStartedDto,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function dismissed({ request, session }: { request: Request; session: OnboardingSessionWithDetails }) {
|
||||
if (!session.dismissedAt) {
|
||||
await updateOnboardingSession(session.id, {
|
||||
status: "dismissed",
|
||||
dismissedAt: new Date(),
|
||||
});
|
||||
await EventsService.create({
|
||||
request,
|
||||
event: "onboarding.dismissed",
|
||||
tenantId: session.tenantId,
|
||||
userId: session.userId,
|
||||
data: {
|
||||
session: { id: session.id },
|
||||
onboarding: { title: session.onboarding.title },
|
||||
user: { id: session.userId, email: session.user.email },
|
||||
} satisfies OnboardingDismissedDto,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function setStep(session: OnboardingSessionWithDetails, data: { fromIdx: number; toIdx: number; actions: OnboardingSessionActionDto[] }) {
|
||||
const fromStep = session.sessionSteps[data.fromIdx];
|
||||
const toStep = session.sessionSteps[data.toIdx];
|
||||
if (!fromStep.completedAt) {
|
||||
await updateOnboardingSessionStep(fromStep.id, {
|
||||
completedAt: new Date(),
|
||||
});
|
||||
}
|
||||
if (!toStep.seenAt) {
|
||||
await updateOnboardingSessionStep(toStep.id, {
|
||||
seenAt: new Date(),
|
||||
});
|
||||
}
|
||||
await setActions(session, data.actions);
|
||||
}
|
||||
|
||||
async function addActions(session: OnboardingSessionWithDetails, data: { actions: OnboardingSessionActionDto[] }) {
|
||||
await setActions(session, data.actions);
|
||||
}
|
||||
|
||||
async function setActions(session: OnboardingSessionWithDetails, actions: OnboardingSessionActionDto[]) {
|
||||
const newActions: OnboardingSessionActionDto[] = [
|
||||
...session.actions
|
||||
.sort((a, b) => (a.createdAt > b.createdAt ? 1 : -1))
|
||||
.map((f) => {
|
||||
return {
|
||||
type: f.type as "click" | "input",
|
||||
name: f.name,
|
||||
value: f.value,
|
||||
};
|
||||
}),
|
||||
];
|
||||
actions.forEach((action) => {
|
||||
if (action.type === "input") {
|
||||
const idx = newActions.findIndex((f) => f.type === "input" && f.name === action.name);
|
||||
if (idx >= 0) {
|
||||
newActions[idx] = action;
|
||||
} else {
|
||||
newActions.push(action);
|
||||
}
|
||||
} else {
|
||||
newActions.push(action);
|
||||
}
|
||||
});
|
||||
const startDate = new Date();
|
||||
newActions.forEach((newAction, idx) => {
|
||||
try {
|
||||
// add one second to each action to avoid duplicate keys
|
||||
newAction.createdAt = new Date(startDate.getTime() + (idx + 1) * 1000);
|
||||
} catch {
|
||||
//
|
||||
}
|
||||
});
|
||||
if (newActions.length > 0) {
|
||||
await setOnboardingSessionActions(session.id, { actions: newActions });
|
||||
}
|
||||
}
|
||||
|
||||
async function complete({
|
||||
request,
|
||||
session,
|
||||
data,
|
||||
}: {
|
||||
request: Request;
|
||||
session: OnboardingSessionWithDetails;
|
||||
data: { fromIdx: number; actions: OnboardingSessionActionDto[] };
|
||||
}) {
|
||||
const fromStep = session.sessionSteps[data.fromIdx];
|
||||
if (!fromStep.completedAt) {
|
||||
await updateOnboardingSessionStep(fromStep.id, {
|
||||
completedAt: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
await setActions(session, data.actions);
|
||||
|
||||
if (!session.completedAt) {
|
||||
await updateOnboardingSession(session.id, {
|
||||
status: "completed",
|
||||
completedAt: new Date(),
|
||||
});
|
||||
|
||||
await EventsService.create({
|
||||
request,
|
||||
event: "onboarding.completed",
|
||||
tenantId: session.tenantId,
|
||||
userId: session.userId,
|
||||
data: {
|
||||
session: { id: session.id },
|
||||
onboarding: { title: session.onboarding.title },
|
||||
user: { id: session.userId, email: session.user.email },
|
||||
} satisfies OnboardingCompletedDto,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
started,
|
||||
dismissed,
|
||||
setStep,
|
||||
complete,
|
||||
addActions,
|
||||
};
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import { TFunction } from "i18next";
|
||||
import { OnboardingBlockDto } from "../blocks/OnboardingBlockUtils";
|
||||
import { OnboardingWithDetails, updateOnboarding } from "../db/onboarding.db.server";
|
||||
import { deleteOnboardingSessions } from "../db/onboardingSessions.db.server";
|
||||
|
||||
async function setSteps({ item, form, t }: { item: OnboardingWithDetails; form: FormData; t: TFunction }) {
|
||||
const block: OnboardingBlockDto = JSON.parse(form.get("block")?.toString() ?? "{}");
|
||||
if (!block) {
|
||||
return Response.json({ error: t("shared.invalidForm") }, { status: 400 });
|
||||
}
|
||||
await updateOnboarding(item.id, {
|
||||
type: block.style as "modal" | "page",
|
||||
height: block.height,
|
||||
canBeDismissed: block.canBeDismissed,
|
||||
steps: block.steps.map((f, idx) => {
|
||||
return { order: idx + 1, block: JSON.stringify(f) };
|
||||
}),
|
||||
});
|
||||
await deleteOnboardingSessions(item.id);
|
||||
}
|
||||
export default {
|
||||
setSteps,
|
||||
};
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { DefaultFeatures } from "~/application/dtos/shared/DefaultFeatures";
|
||||
import {
|
||||
evaluateOnboardingStepGates,
|
||||
getOnboardingStepDiagnostics,
|
||||
getVisibleOnboardingSteps,
|
||||
type OnboardingStepGateDiagnostic,
|
||||
} from "./gating.server";
|
||||
import type { OnboardingRegisteredStepDefinition } from "./registry.server";
|
||||
|
||||
const request = new Request("https://app.example.com/acme/onboarding?tenantId=tenant_123&token=secret-token");
|
||||
const params = { tenant: "acme", tenantId: "tenant_123" };
|
||||
const profileStep = {
|
||||
id: "profile-basics",
|
||||
title: "Profile basics",
|
||||
description: "Ungated profile setup",
|
||||
} as const satisfies OnboardingRegisteredStepDefinition;
|
||||
const featureStep = {
|
||||
id: "team-invites",
|
||||
title: "Team invites",
|
||||
description: "Feature gated team invites",
|
||||
featureFlagKey: "workspace-roles",
|
||||
} as const satisfies OnboardingRegisteredStepDefinition;
|
||||
const planStep = {
|
||||
id: "priority-support-setup",
|
||||
title: "Priority support setup",
|
||||
description: "Plan gated priority support",
|
||||
planFeatureKey: DefaultFeatures.PrioritySupport,
|
||||
} as const satisfies OnboardingRegisteredStepDefinition;
|
||||
|
||||
function entitlementService(allowed: boolean) {
|
||||
return vi.fn(() => ({
|
||||
allowed,
|
||||
reason: allowed ? ("included" as const) : ("missing-subscription" as const),
|
||||
featureKey: DefaultFeatures.PrioritySupport,
|
||||
}));
|
||||
}
|
||||
|
||||
const sensitiveSamples = [
|
||||
"tenant_123",
|
||||
"secret-token",
|
||||
"user_456",
|
||||
"subscription_789",
|
||||
"provider_api_key_live",
|
||||
"raw-feature-input=workspace-roles",
|
||||
"DATABASE_URL",
|
||||
"bearer jwt-token",
|
||||
] as const;
|
||||
|
||||
function expectSafeStaticPayload(payload: unknown) {
|
||||
const serialized = JSON.stringify(payload);
|
||||
|
||||
for (const sample of sensitiveSamples) {
|
||||
expect(serialized).not.toContain(sample);
|
||||
}
|
||||
|
||||
expect(serialized).not.toMatch(/user[_-]?\d+|subscription[_-]?\d+|provider[_-]?api[_-]?key|bearer\s+jwt|jwt-token|secret-token/i);
|
||||
}
|
||||
|
||||
function expectDiagnosticsRedacted(diagnostics: readonly OnboardingStepGateDiagnostic[]) {
|
||||
expectSafeStaticPayload(diagnostics);
|
||||
}
|
||||
|
||||
describe("evaluateOnboardingStepGates", () => {
|
||||
it("returns visible onboarding steps when all gates allow access", async () => {
|
||||
const hasFeatureFlag = vi.fn(async () => true);
|
||||
const evaluateSubscriptionEntitlement = entitlementService(true);
|
||||
|
||||
const decisions = await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
definitions: [profileStep, featureStep, planStep],
|
||||
services: {
|
||||
hasFeatureFlag,
|
||||
evaluateSubscriptionEntitlement,
|
||||
},
|
||||
});
|
||||
|
||||
expect(getVisibleOnboardingSteps(decisions).map((step) => step.id)).toEqual(["profile-basics", "team-invites", "priority-support-setup"]);
|
||||
expect(getOnboardingStepDiagnostics(decisions)).toEqual([]);
|
||||
expect(hasFeatureFlag).toHaveBeenCalledWith({ request, params, flagName: "workspace-roles" });
|
||||
expect(evaluateSubscriptionEntitlement).toHaveBeenCalledWith({
|
||||
featureKey: DefaultFeatures.PrioritySupport,
|
||||
subscription: undefined,
|
||||
trial: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("denies only a disabled feature-flagged onboarding step", async () => {
|
||||
const decisions = await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
definitions: [profileStep, featureStep, planStep],
|
||||
services: {
|
||||
hasFeatureFlag: vi.fn(async () => false),
|
||||
evaluateSubscriptionEntitlement: entitlementService(true),
|
||||
},
|
||||
});
|
||||
|
||||
expect(getVisibleOnboardingSteps(decisions).map((step) => step.id)).toEqual(["profile-basics", "priority-support-setup"]);
|
||||
expect(getOnboardingStepDiagnostics(decisions)).toEqual([
|
||||
{
|
||||
stepId: "team-invites",
|
||||
source: "feature-flag",
|
||||
reason: "feature-disabled",
|
||||
redirectPath: "/feature-disabled",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("denies only the feature-gated onboarding step when feature lookup fails", async () => {
|
||||
const decisions = await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
definitions: [profileStep, featureStep],
|
||||
services: {
|
||||
hasFeatureFlag: vi.fn(async () => {
|
||||
throw new Error("backend unavailable for tenant_123 with token secret-token and provider_api_key_live");
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
expect(getVisibleOnboardingSteps(decisions).map((step) => step.id)).toEqual(["profile-basics"]);
|
||||
expect(getOnboardingStepDiagnostics(decisions)).toEqual([
|
||||
{
|
||||
stepId: "team-invites",
|
||||
source: "feature-flag",
|
||||
reason: "feature-check-failed",
|
||||
redirectPath: "/feature-disabled",
|
||||
},
|
||||
]);
|
||||
expectDiagnosticsRedacted(getOnboardingStepDiagnostics(decisions));
|
||||
});
|
||||
|
||||
it("denies missing plan entitlement with plan-required diagnostics", async () => {
|
||||
const evaluateSubscriptionEntitlement = entitlementService(false);
|
||||
|
||||
const decisions = await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
definitions: [profileStep, planStep],
|
||||
subscription: { products: [] },
|
||||
services: {
|
||||
evaluateSubscriptionEntitlement,
|
||||
},
|
||||
});
|
||||
|
||||
expect(getVisibleOnboardingSteps(decisions).map((step) => step.id)).toEqual(["profile-basics"]);
|
||||
expect(getOnboardingStepDiagnostics(decisions)).toEqual([
|
||||
{
|
||||
stepId: "priority-support-setup",
|
||||
source: "plan",
|
||||
reason: "plan-required",
|
||||
redirectPath: "plan-required",
|
||||
},
|
||||
]);
|
||||
expect(evaluateSubscriptionEntitlement).toHaveBeenCalledWith({
|
||||
featureKey: DefaultFeatures.PrioritySupport,
|
||||
subscription: { products: [] },
|
||||
trial: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps denied diagnostics redacted from tenant, subscription, user, token, and raw gate inputs", async () => {
|
||||
const decisions = await evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
definitions: [featureStep, planStep],
|
||||
subscription: { products: [] },
|
||||
services: {
|
||||
hasFeatureFlag: vi.fn(async () => false),
|
||||
evaluateSubscriptionEntitlement: entitlementService(false),
|
||||
},
|
||||
redirectPaths: {
|
||||
"feature-flag": "/feature-disabled",
|
||||
plan: "plan-required",
|
||||
},
|
||||
});
|
||||
|
||||
expect(getOnboardingStepDiagnostics(decisions)).toEqual([
|
||||
expect.objectContaining({ stepId: "team-invites", source: "feature-flag", reason: "feature-disabled" }),
|
||||
expect.objectContaining({ stepId: "priority-support-setup", source: "plan", reason: "plan-required" }),
|
||||
]);
|
||||
expectDiagnosticsRedacted(getOnboardingStepDiagnostics(decisions));
|
||||
});
|
||||
});
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
import type { Params } from "react-router";
|
||||
import type { EntitlementDecision } from "@toolctrl/entitlements";
|
||||
import type {
|
||||
SubscriptionEntitlementSubscription,
|
||||
SubscriptionEntitlementTrialState,
|
||||
} from "~/utils/entitlements/.server/subscriptionEntitlements.server";
|
||||
import { evaluateSubscriptionEntitlement as defaultEvaluateSubscriptionEntitlement } from "~/utils/entitlements/.server/subscriptionEntitlements.server";
|
||||
import { isFeatureFlagEnabled } from "~/utils/services/.server/featureFlagsRequest.server";
|
||||
import { getOnboardingStepDefinitions, type OnboardingRegisteredStepDefinition, type OnboardingRegisteredStepId } from "./registry.server";
|
||||
|
||||
export type OnboardingStepGateSource = "feature-flag" | "plan";
|
||||
export type OnboardingStepGateReason = "feature-disabled" | "feature-check-failed" | "plan-required";
|
||||
|
||||
export interface OnboardingStepGateDiagnostic {
|
||||
readonly stepId: OnboardingRegisteredStepId;
|
||||
readonly source: OnboardingStepGateSource;
|
||||
readonly reason: OnboardingStepGateReason;
|
||||
readonly redirectPath?: string;
|
||||
}
|
||||
|
||||
export interface OnboardingStepGateDecision {
|
||||
readonly step: OnboardingRegisteredStepDefinition;
|
||||
readonly allowed: boolean;
|
||||
readonly diagnostic?: OnboardingStepGateDiagnostic;
|
||||
}
|
||||
|
||||
export interface EvaluateOnboardingStepGatesInput {
|
||||
readonly request: Request;
|
||||
readonly params: Params;
|
||||
readonly subscription?: SubscriptionEntitlementSubscription | null;
|
||||
readonly trial?: SubscriptionEntitlementTrialState | null;
|
||||
readonly definitions?: readonly OnboardingRegisteredStepDefinition[];
|
||||
readonly redirectPaths?: Partial<Record<OnboardingStepGateSource, string>>;
|
||||
readonly services?: OnboardingStepGateServices;
|
||||
readonly serviceLoaders?: OnboardingStepGateServiceLoaders;
|
||||
}
|
||||
|
||||
export interface OnboardingStepGateServices {
|
||||
/**
|
||||
* Boolean feature-flag check shimmed against the v2 evaluator
|
||||
* (`isFeatureFlagEnabled`). Callers may inject a stub for tests;
|
||||
* production wiring resolves the request + tenant context inside
|
||||
* the v2 helper.
|
||||
*/
|
||||
readonly hasFeatureFlag?: (input: { request: Request; params: Params; flagName: string }) => Promise<boolean>;
|
||||
readonly evaluateSubscriptionEntitlement?: (input: {
|
||||
featureKey: string;
|
||||
subscription?: SubscriptionEntitlementSubscription | null;
|
||||
trial?: SubscriptionEntitlementTrialState | null;
|
||||
}) => EntitlementDecision;
|
||||
}
|
||||
|
||||
export interface OnboardingStepGateServiceLoaders {
|
||||
readonly featureFlags?: () => Promise<Pick<Required<OnboardingStepGateServices>, "hasFeatureFlag">>;
|
||||
readonly entitlements?: () => Promise<Pick<Required<OnboardingStepGateServices>, "evaluateSubscriptionEntitlement">>;
|
||||
}
|
||||
|
||||
const defaultRedirectPaths = Object.freeze({
|
||||
"feature-flag": "/feature-disabled",
|
||||
plan: "plan-required",
|
||||
} satisfies Record<OnboardingStepGateSource, string>);
|
||||
|
||||
function diagnostic(input: {
|
||||
stepId: OnboardingRegisteredStepId;
|
||||
source: OnboardingStepGateSource;
|
||||
reason: OnboardingStepGateReason;
|
||||
redirectPath?: string;
|
||||
}): OnboardingStepGateDiagnostic {
|
||||
return {
|
||||
stepId: input.stepId,
|
||||
source: input.source,
|
||||
reason: input.reason,
|
||||
...(input.redirectPath ? { redirectPath: input.redirectPath } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
async function evaluateOnboardingStepGate({
|
||||
step,
|
||||
request,
|
||||
params,
|
||||
subscription,
|
||||
trial,
|
||||
redirectPaths,
|
||||
services,
|
||||
serviceLoaders,
|
||||
}: Omit<EvaluateOnboardingStepGatesInput, "definitions"> & { step: OnboardingRegisteredStepDefinition }): Promise<OnboardingStepGateDecision> {
|
||||
if (step.featureFlagKey) {
|
||||
try {
|
||||
if (!services?.hasFeatureFlag) {
|
||||
const featureFlagService = serviceLoaders?.featureFlags
|
||||
? await serviceLoaders.featureFlags()
|
||||
: { hasFeatureFlag: ({ request: req, params: p, flagName }: { request: Request; params: Params; flagName: string }) => isFeatureFlagEnabled(flagName, { request: req, params: p }) };
|
||||
services = { ...services, hasFeatureFlag: featureFlagService.hasFeatureFlag };
|
||||
}
|
||||
|
||||
const hasFeatureFlag = services.hasFeatureFlag;
|
||||
if (!hasFeatureFlag) {
|
||||
throw new Error("Onboarding feature flag service unavailable");
|
||||
}
|
||||
const enabled = await hasFeatureFlag({
|
||||
request,
|
||||
params,
|
||||
flagName: step.featureFlagKey,
|
||||
});
|
||||
|
||||
if (!enabled) {
|
||||
return {
|
||||
step,
|
||||
allowed: false,
|
||||
diagnostic: diagnostic({
|
||||
stepId: step.id,
|
||||
source: "feature-flag",
|
||||
reason: "feature-disabled",
|
||||
redirectPath: redirectPaths?.["feature-flag"] ?? defaultRedirectPaths["feature-flag"],
|
||||
}),
|
||||
};
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
step,
|
||||
allowed: false,
|
||||
diagnostic: diagnostic({
|
||||
stepId: step.id,
|
||||
source: "feature-flag",
|
||||
reason: "feature-check-failed",
|
||||
redirectPath: redirectPaths?.["feature-flag"] ?? defaultRedirectPaths["feature-flag"],
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (step.planFeatureKey) {
|
||||
if (!services?.evaluateSubscriptionEntitlement) {
|
||||
const entitlementService = serviceLoaders?.entitlements
|
||||
? await serviceLoaders.entitlements()
|
||||
: { evaluateSubscriptionEntitlement: defaultEvaluateSubscriptionEntitlement };
|
||||
services = { ...services, evaluateSubscriptionEntitlement: entitlementService.evaluateSubscriptionEntitlement };
|
||||
}
|
||||
|
||||
const evaluateSubscriptionEntitlement = services.evaluateSubscriptionEntitlement;
|
||||
if (!evaluateSubscriptionEntitlement) {
|
||||
throw new Error("Onboarding entitlement service unavailable");
|
||||
}
|
||||
const entitlement = evaluateSubscriptionEntitlement({
|
||||
featureKey: step.planFeatureKey,
|
||||
subscription,
|
||||
trial,
|
||||
});
|
||||
|
||||
if (!entitlement.allowed) {
|
||||
return {
|
||||
step,
|
||||
allowed: false,
|
||||
diagnostic: diagnostic({
|
||||
stepId: step.id,
|
||||
source: "plan",
|
||||
reason: "plan-required",
|
||||
redirectPath: redirectPaths?.plan ?? defaultRedirectPaths.plan,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { step, allowed: true };
|
||||
}
|
||||
|
||||
export async function evaluateOnboardingStepGates({
|
||||
request,
|
||||
params,
|
||||
subscription,
|
||||
trial,
|
||||
definitions = getOnboardingStepDefinitions(),
|
||||
redirectPaths,
|
||||
services,
|
||||
serviceLoaders,
|
||||
}: EvaluateOnboardingStepGatesInput): Promise<OnboardingStepGateDecision[]> {
|
||||
return Promise.all(
|
||||
definitions.map((step) =>
|
||||
evaluateOnboardingStepGate({
|
||||
step,
|
||||
request,
|
||||
params,
|
||||
subscription,
|
||||
trial,
|
||||
redirectPaths,
|
||||
services,
|
||||
serviceLoaders,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function getVisibleOnboardingSteps(decisions: readonly OnboardingStepGateDecision[]): OnboardingRegisteredStepDefinition[] {
|
||||
return decisions.filter((decision) => decision.allowed).map((decision) => decision.step);
|
||||
}
|
||||
|
||||
export function getOnboardingStepDiagnostics(decisions: readonly OnboardingStepGateDecision[]): OnboardingStepGateDiagnostic[] {
|
||||
return decisions.flatMap((decision) => (decision.diagnostic ? [decision.diagnostic] : []));
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { DefaultFeatures } from "~/application/dtos/shared/DefaultFeatures";
|
||||
import { readRepoFile } from "~/utils/testing/repoPaths";
|
||||
import { getOnboardingStepDefinitions, onboardingStepRegistryEvidence } from "./registry.server";
|
||||
|
||||
const sensitiveSamples = [
|
||||
"tenant_123",
|
||||
"secret-token",
|
||||
"user_456",
|
||||
"subscription_789",
|
||||
"provider_api_key_live",
|
||||
"raw-feature-input=workspace-roles",
|
||||
"DATABASE_URL",
|
||||
"bearer jwt-token",
|
||||
] as const;
|
||||
|
||||
function expectSafeStaticPayload(payload: unknown) {
|
||||
const serialized = JSON.stringify(payload);
|
||||
|
||||
for (const sample of sensitiveSamples) {
|
||||
expect(serialized).not.toContain(sample);
|
||||
}
|
||||
|
||||
expect(serialized).not.toMatch(/user[_-]?\d+|subscription[_-]?\d+|provider[_-]?api[_-]?key|bearer\s+jwt|jwt-token|secret-token/i);
|
||||
}
|
||||
|
||||
describe("onboarding step registry", () => {
|
||||
it("defines stable onboarding step IDs for ungated, feature-gated, and plan-gated steps", () => {
|
||||
expect(getOnboardingStepDefinitions()).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: "profile-basics" }),
|
||||
expect.objectContaining({ id: "team-invites", featureFlagKey: "workspace-roles" }),
|
||||
expect.objectContaining({ id: "priority-support-setup", planFeatureKey: DefaultFeatures.PrioritySupport }),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("exports registry evidence that mirrors stable IDs and represented gate sources", () => {
|
||||
const definitions = getOnboardingStepDefinitions();
|
||||
|
||||
expect(onboardingStepRegistryEvidence.registryName).toBe("Onboarding Step Registry");
|
||||
expect(onboardingStepRegistryEvidence.registryScope).toBe("source-backed-onboarding-steps");
|
||||
expect(onboardingStepRegistryEvidence.expectedStepIds).toEqual(definitions.map((step) => step.id));
|
||||
expect(onboardingStepRegistryEvidence.expectedStepIds).toEqual(["profile-basics", "team-invites", "priority-support-setup"]);
|
||||
expect(onboardingStepRegistryEvidence.gatingSourcesRepresented).toEqual(["feature-flag", "plan"]);
|
||||
});
|
||||
|
||||
it("keeps gate metadata typed and attached only to gated steps", () => {
|
||||
const definitions = getOnboardingStepDefinitions();
|
||||
|
||||
expect(definitions.find((step) => step.id === "profile-basics")).toEqual(expect.not.objectContaining({ featureFlagKey: expect.any(String) }));
|
||||
expect(definitions.find((step) => step.id === "profile-basics")).toEqual(expect.not.objectContaining({ planFeatureKey: expect.any(String) }));
|
||||
expect(definitions.find((step) => step.id === "team-invites")).toEqual(expect.objectContaining({ featureFlagKey: "workspace-roles" }));
|
||||
expect(definitions.find((step) => step.id === "priority-support-setup")).toEqual(
|
||||
expect.objectContaining({ planFeatureKey: DefaultFeatures.PrioritySupport }),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps registry evidence limited to safe static metadata without sensitive samples", () => {
|
||||
expect(onboardingStepRegistryEvidence.redactionGuarantee).toContain("static source metadata only");
|
||||
expect(onboardingStepRegistryEvidence.redactionGuarantee).toContain(
|
||||
"excludes request, tenant, subscription, user, token, environment, and raw feature input values",
|
||||
);
|
||||
expect(onboardingStepRegistryEvidence.expectedStepIds.length).toBe(getOnboardingStepDefinitions().length);
|
||||
expectSafeStaticPayload(onboardingStepRegistryEvidence);
|
||||
});
|
||||
|
||||
it("keeps registry copy behind semantic onboarding keys", () => {
|
||||
const source = readRepoFile("apps/web/app/modules/onboarding/services/step-registry/registry.server.ts");
|
||||
|
||||
expect(source).toContain("onboarding.stepRegistry.profileBasics.title");
|
||||
expect(source).toContain("onboarding.stepRegistry.profileBasics.description");
|
||||
expect(source).toContain("onboarding.stepRegistry.teamInvites.title");
|
||||
expect(source).toContain("onboarding.stepRegistry.teamInvites.description");
|
||||
expect(source).toContain("onboarding.stepRegistry.prioritySupportSetup.title");
|
||||
expect(source).toContain("onboarding.stepRegistry.prioritySupportSetup.description");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
});
|
||||
});
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import { DefaultFeatures } from "~/application/dtos/shared/DefaultFeatures";
|
||||
import type { FeatureFlagsFilterType } from "~/modules/featureFlags/dtos/FeatureFlagsFilterTypes";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
export type OnboardingRegisteredStepId = "profile-basics" | "team-invites" | "priority-support-setup";
|
||||
|
||||
export interface OnboardingRegisteredStepDefinition {
|
||||
readonly id: OnboardingRegisteredStepId;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly featureFlagKey?: FeatureFlagsFilterType;
|
||||
readonly planFeatureKey?: DefaultFeatures | string;
|
||||
}
|
||||
|
||||
export const onboardingStepRegistry = Object.freeze([
|
||||
{
|
||||
id: "profile-basics",
|
||||
title: i18nT("onboarding.stepRegistry.profileBasics.title"),
|
||||
description: i18nT("onboarding.stepRegistry.profileBasics.description"),
|
||||
},
|
||||
{
|
||||
id: "team-invites",
|
||||
title: i18nT("onboarding.stepRegistry.teamInvites.title"),
|
||||
description: i18nT("onboarding.stepRegistry.teamInvites.description"),
|
||||
featureFlagKey: "workspace-roles",
|
||||
},
|
||||
{
|
||||
id: "priority-support-setup",
|
||||
title: i18nT("onboarding.stepRegistry.prioritySupportSetup.title"),
|
||||
description: i18nT("onboarding.stepRegistry.prioritySupportSetup.description"),
|
||||
planFeatureKey: DefaultFeatures.PrioritySupport,
|
||||
},
|
||||
] as const satisfies readonly OnboardingRegisteredStepDefinition[]);
|
||||
|
||||
const onboardingStepIds = onboardingStepRegistry.map((step) => step.id) as readonly OnboardingRegisteredStepId[];
|
||||
const onboardingGateSources = Object.freeze(["feature-flag", "plan"] as const);
|
||||
|
||||
export const onboardingStepRegistryEvidence = Object.freeze({
|
||||
registryName: "Onboarding Step Registry",
|
||||
registryScope: "source-backed-onboarding-steps",
|
||||
expectedStepIds: onboardingStepIds,
|
||||
gatingSourcesRepresented: onboardingGateSources,
|
||||
redactionGuarantee:
|
||||
"Onboarding step registry evidence is static source metadata only and excludes request, tenant, subscription, user, token, environment, and raw feature input values.",
|
||||
} as const);
|
||||
|
||||
export function getOnboardingStepDefinitions(): readonly OnboardingRegisteredStepDefinition[] {
|
||||
return onboardingStepRegistry;
|
||||
}
|
||||
Reference in new issue
Block a user