Skip to content

Commit a679b64

Browse files
authored
feat: Add basic data consent dialog (#132)
Adds a basic data consent dialog. If consent is not given, the extension will not run and it will continue to show the popup on subsequent github page loads until consent is given or the app is uninstalled.
1 parent 5a0f7d8 commit a679b64

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/content/github/common/consent.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { print } from "src/utils";
2+
import { consentStorageKey, consentDialogCopy } from "./constants";
3+
4+
export async function ensureConsent(
5+
{ checkOnly }: { checkOnly: boolean } = { checkOnly: false }
6+
): Promise<boolean> {
7+
let consent: boolean = await chrome.storage.local
8+
.get(consentStorageKey)
9+
.then((res) => res[consentStorageKey]);
10+
11+
if (consent) {
12+
return consent;
13+
}
14+
15+
if (!checkOnly) {
16+
consent = window.confirm(consentDialogCopy);
17+
}
18+
19+
if (!consent) {
20+
print("no consent was given, so the extension will not run");
21+
return consent;
22+
}
23+
24+
const storageObject: { [id: string]: boolean } = {};
25+
storageObject[consentStorageKey] = consent;
26+
27+
chrome.storage.local.set(storageObject);
28+
29+
return consent;
30+
}

src/content/github/common/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// The version number here should represent the last version where consent requirement was updated.
2+
// We must update the key's version to re-request consent whenever the data we collect changes.
3+
export const consentStorageKey = "codecov-consent-0.5.9";
4+
export const consentDialogCopy =
5+
"By clicking OK, you are authorizing the Codecov browser extension to collect your IP address and the URLs you visit on domains you've given the extension access to. Declining this will prevent the extension from working. For more information see the Privacy Policy in the Codecov extension store listing.";
6+
17
export const animationName = "codecov-gh-observer";
28

39
export const animationDefinitionId = `${animationName}-keyframe`;

src/content/github/file/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from "../common/fetchers";
3333
import { print } from "src/utils";
3434
import Sentry from "../../common/sentry";
35+
import { ensureConsent } from "../common/consent";
3536

3637
const globals: {
3738
coverageReport?: FileCoverageReport;
@@ -59,6 +60,11 @@ function init(): Promise<void> {
5960

6061
async function main(): Promise<void> {
6162
try {
63+
const consent = await ensureConsent();
64+
if (!consent) {
65+
return;
66+
}
67+
6268
const urlMetadata = getMetadataFromURL();
6369
if (!urlMetadata) {
6470
print("file not detected at current URL");

src/content/github/pr/main.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "dom-chef";
2-
import browser from "webextension-polyfill";
32
import _ from "lodash";
43

54
import "src/basscss.css";
@@ -16,13 +15,19 @@ import { print } from "src/utils";
1615
import { getPRReport } from "../common/fetchers";
1716
import { isPrUrl } from "../common/utils";
1817
import Sentry from "src/content/common/sentry";
18+
import { ensureConsent } from "../common/consent";
1919

2020
const globals: {
2121
coverageReport?: PullCoverageReport;
2222
} = {};
2323

2424
async function main() {
2525
try {
26+
const consent = await ensureConsent({ checkOnly: true });
27+
if (!consent) {
28+
return;
29+
}
30+
2631
document.addEventListener("soft-nav:end", execute);
2732
await execute();
2833
} catch (e) {

0 commit comments

Comments
 (0)