Skip to content

Commit f154318

Browse files
committed
enable privacy popups for everyobe
1 parent 5cad176 commit f154318

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

functions/utilities/getTypeSafeUser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ const getTypeSafeUser = (user) => {
6666
}
6767

6868
module.exports = {
69-
getTypeSafeUser
69+
getTypeSafeUser,
70+
getGuardianEmails
7071
}

functions/utilities/privacy/debugRouter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ router.post("/reset", studentMiddleware, async (req, res) => {
8383
birthYear: req.body.birthYear || "2025",
8484
};
8585

86+
if (req.body.emails) {
87+
updateBody.emails = req.body.emails;
88+
updateBody.guardianEmail = null;
89+
}
90+
8691
await userDB.doc(req.user.uid).update(updateBody);
8792

8893
return res.status(200).send(getResponseBody(req, updateBody));

functions/utilities/privacy/router.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const {
1515
latestTouchKey
1616
} = require("./privacyKeys");
1717
const debugRouter = require("./debugRouter");
18+
const {
19+
getGuardianEmails
20+
} = require("../getTypeSafeUser");
1821

1922
router.use("/student/ultra-secret", debugRouter);
2023

@@ -140,14 +143,18 @@ router.get("/student/delay", studentMiddleware, async (req, res) => {
140143

141144
router.post("/student/update", studentMiddleware, async (req, res) => {
142145
try {
146+
const emails = mergeAccountEmailsWithReqBodyGuardianEmails(req, res);
147+
const hasGuardianEmails = emails.some(e => e?.type === 'guardian');
148+
const guardianTouchKey = req.user[userNeedsGuardianTouchKey] || Date.now();
149+
143150
const updateBody = {
144-
emails: mergeAccountEmailsWithReqBodyGuardianEmails(req, res),
151+
emails,
145152
guardianEmail: null,
146153
[guardianPrivacyAuthTokenKey]:
147154
req.user[guardianPrivacyAuthTokenKey] ||
148155
generateGuardianPrivacyAuthToken(),
149156
[userNeedsGuardianTouchKey]:
150-
req.user[userNeedsGuardianTouchKey] || Date.now(),
157+
hasGuardianEmails ? guardianTouchKey : null,
151158
[firstSeenKey]: req.user[firstSeenKey] || Date.now(),
152159
[dueByKey]: req.user[dueByKey] || Date.now() + SevenDays,
153160
[latestTouchKey]: Date.now(),

functions/utilities/privacy/utils.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const {
66
acceptedKey,
77
variantModeKey,
88
} = require("./privacyKeys");
9+
const {
10+
getGuardianEmails
11+
} = require("../getTypeSafeUser");
912

1013
const userDB = firebase.firestore().collection("users");
1114

@@ -41,6 +44,10 @@ const isUnderThirteen = (user) => {
4144
return false;
4245
}
4346

47+
if (user.code) {
48+
return false; // assume teachers are over 13
49+
}
50+
4451
return true;
4552
};
4653

@@ -56,8 +63,8 @@ const getPrivacyVariant = (user) => {
5663
}
5764
}
5865

59-
const shouldRetryPopup = (lastTouched, isUnder13) => {
60-
if (isUnder13) return false;
66+
const shouldRetryPopup = (lastTouched, isUnder13, guardianEmails) => {
67+
if (isUnder13 && guardianEmails.length) return false;
6168

6269
try {
6370
if (!lastTouched) return false;
@@ -71,21 +78,10 @@ const shouldRetryPopup = (lastTouched, isUnder13) => {
7178
const getPrivacyState = (email, user) => {
7279
const isUnder13 = isUnderThirteen(user);
7380
const variant = getPrivacyVariant(user);
81+
const guardianEmails = getGuardianEmails(user);
7482

7583
const useUnder13 = isUnder13 && variant !== 'year8webinar'
7684

77-
if (
78-
!email.includes("@mcmill.co.uk") ||
79-
process.env.IS_FIREBASE_CLI == "true"
80-
) {
81-
return {
82-
debug: 1,
83-
visible: false,
84-
mode: "none",
85-
variant
86-
};
87-
}
88-
8985
if (user[acceptedKey]) {
9086
// User has already accepted
9187
return {
@@ -100,7 +96,7 @@ const getPrivacyState = (email, user) => {
10096
const dueBy = user[dueByKey];
10197
const latestTouch = user[latestTouchKey];
10298

103-
const shouldRetry = shouldRetryPopup(latestTouch, useUnder13);
99+
const shouldRetry = shouldRetryPopup(latestTouch, useUnder13, guardianEmails);
104100

105101
const delayResponse = {
106102
visible: true,

0 commit comments

Comments
 (0)