Skip to content

Commit

Permalink
MNTOR-3815 - Data broker manual removal integration (#5326)
Browse files Browse the repository at this point in the history
* fix: fix comment vars

* pass SENTRY_AUTH_TOKEN arg to docker (#5324)

* integration

* rebase

* bad rebase fix

* bad rebase fix

---------

Co-authored-by: Joey Zhou <jozhou@mozilla.com>
Co-authored-by: Robert Helmer <rhelmer@mozilla.com>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent 54a859d commit 3bab78b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ClockIcon } from "../../../../../../../../../components/server/Icons";
export type DataBrokerRemovalMaintenanceProps = {
scanResult: OnerepScanResultRow;
isPremiumUser: boolean;
onMarkAsResolved?: () => void;
};

export const DataBrokerRemovalMaintenance = (
Expand Down Expand Up @@ -86,7 +87,6 @@ export const DataBrokerRemovalMaintenance = (
))}
</div>
<div className={styles.buttonsWrapper}>
{/* TODO: Add functionality to these buttons */}
<TelemetryButton
variant="primary"
href={props.scanResult.link}
Expand All @@ -104,7 +104,7 @@ export const DataBrokerRemovalMaintenance = (
</TelemetryButton>
<TelemetryButton
variant="secondary"
href={props.scanResult.link}
onPress={props.onMarkAsResolved}
event={{
module: "ctaButton",
name: "click",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

"use client";

import { OnerepScanResultRow } from "knex/types/tables";
import {
StepDeterminationData,
getNextGuidedStep,
Expand All @@ -18,49 +17,91 @@ import { TelemetryButton } from "../../../../../../../../../components/client/Te
import { CONST_URL_SUMO_MANUAL_REMOVAL } from "../../../../../../../../../../constants";
import { useState } from "react";
import { BackArrow } from "../../../../../../../../../components/server/Icons";
import { LatestOnerepScanData } from "../../../../../../../../../../db/tables/onerep_scans";
import { hasPremium } from "../../../../../../../../../functions/universal/user";

export type Props = {
data: OnerepScanResultRow[];
data: LatestOnerepScanData;
stepDeterminationData: StepDeterminationData;
subscriberEmails: string[];
};

export const RemovalUnderMaintenanceView = (props: Props) => {
if (props.data === null) {
console.error("No scan data");
}
const l10n = useL10n();
const testScanItem = props.data;
const firstScan = testScanItem[0];

const [detailedRemovalGuide, setDetailedRemovalGuide] = useState(false);
const [firstScanResultNotResolved, setFirstScanResultNotResolved] = useState(
props.data.results[0],
);
const nextGuidedStep = getNextGuidedStep(
props.stepDeterminationData,
"DataBrokerManualRemoval",
);

async function handleManualRemovalChange() {
const response = await fetch(
`/api/v1/user/scan-result/${firstScanResultNotResolved.onerep_scan_result_id}/resolution`,
{
method: "POST",
credentials: "same-origin",
},
);

if (!response.ok) {
console.error(
"Could not update next data broker with removal under maintenance status.",
);
return;
}

// Mannualy move to next step in response works
firstScanResultNotResolved.manually_resolved = true;

// Find the next unresolved scan result
const nextScanResultNotResolved = props.data.results.find(
(scanResult) => !scanResult.manually_resolved,
);

// Update the state to the next unresolved scan result
if (nextScanResultNotResolved) {
setFirstScanResultNotResolved(nextScanResultNotResolved);
}

// Move to the next step
else {
window.location.href = nextGuidedStep.href;
}
}
const dataBrokerInformation = (
<div className={styles.dataBrokerInformationWrapper}>
<p className={styles.header}>
{l10n.getFragment("data-broker-removal-maintenance-header", {
elems: {
link_to_data_broker: (
<TelemetryLink
href={firstScan.link}
href={firstScanResultNotResolved.link}
target="_blank"
eventData={{
link_id: `go_to_${firstScan.data_broker}_link`,
link_id: `go_to_${firstScanResultNotResolved.data_broker}_link`,
}}
/>
),
},
vars: {
data_broker_name: firstScan.data_broker,
data_broker_name: firstScanResultNotResolved.data_broker,
},
})}
</p>
<div className={styles.exposureCardWrapper}>
<DataBrokerRemovalMaintenance
scanResult={testScanItem[0]}
isPremiumUser={true}
scanResult={firstScanResultNotResolved}
isPremiumUser={hasPremium(props.stepDeterminationData.user)}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onMarkAsResolved={() => {
handleManualRemovalChange().catch((error) => {
console.error("Error during manual removal change:", error);
});
}}
/>

<div className={styles.removalContentSection}>
<dt>
{l10n.getString(
Expand Down Expand Up @@ -217,7 +258,7 @@ export const RemovalUnderMaintenanceView = (props: Props) => {
return (
<FixView
subscriberEmails={props.subscriberEmails}
nextStep={getNextGuidedStep(props.stepDeterminationData, "Scan")}
nextStep={nextGuidedStep}
currentSection="data-broker-profiles"
data={props.stepDeterminationData}
hideProgressIndicator={detailedRemovalGuide}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

import { redirect } from "next/navigation";
import { getServerSession } from "../../../../../../../../../functions/server/getServerSession";
import { RemovalUnderMaintenanceView } from "./RemovalUnderMaintenanceView";
import { StepDeterminationData } from "../../../../../../../../../functions/server/getRelevantGuidedSteps";
import {
getNextGuidedStep,
StepDeterminationData,
} from "../../../../../../../../../functions/server/getRelevantGuidedSteps";
import { getCountryCode } from "../../../../../../../../../functions/server/getCountryCode";
import { headers } from "next/headers";
import {
getLatestOnerepScanResults,
getScanResultsWithBrokerUnderMaintenance,
// getScanResultsWithBrokerUnderMaintenance,
} from "../../../../../../../../../../db/tables/onerep_scans";
import { getOnerepProfileId } from "../../../../../../../../../../db/tables/subscribers";
import { getSubscriberBreaches } from "../../../../../../../../../functions/server/getSubscriberBreaches";
import { getSubscriberEmails } from "../../../../../../../../../functions/server/getSubscriberEmails";
import { RemovalUnderMaintenanceView } from "./RemovalUnderMaintenanceView";

export default async function RemovalUnderMaintenance() {
const session = await getServerSession();
Expand All @@ -25,7 +29,6 @@ export default async function RemovalUnderMaintenance() {
const countryCode = getCountryCode(headers());
const profileId = await getOnerepProfileId(session.user.subscriber.id);
const latestScan = await getLatestOnerepScanResults(profileId);

const data: StepDeterminationData = {
countryCode,
user: session.user,
Expand All @@ -36,17 +39,21 @@ export default async function RemovalUnderMaintenance() {
}),
};
const subscriberEmails = await getSubscriberEmails(session.user);
const scansWithRemovalUnderMaintenance =
(await getScanResultsWithBrokerUnderMaintenance(profileId)) ?? null;
const getNextStep = getNextGuidedStep(data, "DataBrokerManualRemoval");

if (data.latestScanData === null) {
redirect("/user/dashboard");
if (scansWithRemovalUnderMaintenance === null) {
redirect(getNextStep.href);
}

const scanData = data.latestScanData.results;
// Filtered scan data results
const scansWithRemovalUnderMaintenanceData = scansWithRemovalUnderMaintenance;

return (
<RemovalUnderMaintenanceView
stepDeterminationData={data}
data={scanData}
data={scansWithRemovalUnderMaintenanceData}
subscriberEmails={subscriberEmails}
/>
);
Expand Down
12 changes: 9 additions & 3 deletions src/app/functions/server/getRelevantGuidedSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ export function hasCompletedStepSection(
if (section === "DataBrokerManualRemoval") {
return hasCompletedStep(data, "DataBrokerManualRemoval");
}

/* c8 ignore next 5 */
// I believe this *is* covered by unit tests, but for some reason,
// since the upgrade to Node 20.10, it doesn't get marked as covered anymore:
Expand Down Expand Up @@ -245,8 +244,15 @@ export function hasCompletedStep(
data: StepDeterminationData,
stepId: StepLink["id"],
): boolean {
// TODO:
// if (stepId === "DataBrokerManualRemoval") { add business logic here }
if (stepId === "DataBrokerManualRemoval") {
const hasResolvedAllScanResults =
data.latestScanData?.results
?.filter(
(scanResult) => scanResult.status === "removal_under_maintenance",
)
.every((scanResult) => scanResult.manually_resolved) ?? false;
return hasResolvedAllScanResults;
}

if (stepId === "Scan") {
const hasRunScan =
Expand Down

0 comments on commit 3bab78b

Please sign in to comment.