From 05c35e6955a4e9a6504317969bbd13f9b571174e Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 10 Sep 2024 13:21:06 -0500 Subject: [PATCH] add cloud function back --- functions/src/index.ts | 1 + functions/src/restriction.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 functions/src/restriction.ts diff --git a/functions/src/index.ts b/functions/src/index.ts index ec433849..e85eacea 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -2,6 +2,7 @@ export { notifyUpcomingEvents, sendNotificationOfficeHours, sendNotificationMemb export { updateUserPoints, updateAllUserPoints, scheduledUpdateAllPoints } from "./pointSheet"; export { updateCommitteeCount, scheduleCommitteeCount } from "./committees"; // export { resetOfficeScheduler } from "./officeReset"; +export { isUserInBlacklist } from "./restriction"; export { resetOfficeOnCall } from "./officeReset"; export { zipResume } from "./resume"; export { updateUserRole } from "./roles"; diff --git a/functions/src/restriction.ts b/functions/src/restriction.ts new file mode 100644 index 00000000..ef53609f --- /dev/null +++ b/functions/src/restriction.ts @@ -0,0 +1,27 @@ +import * as functions from 'firebase-functions'; +import { db } from "./firebaseConfig"; + + +export const isUserInBlacklist = functions.https.onCall(async (data, context) => { + const uid = data.uid; + if (!uid) { + throw new functions.https.HttpsError('invalid-argument', 'The function must be called with one argument "uid".'); + } + console.log(`Checking if user ${uid} is in the blacklist...`); + + try { + const blacklistDocRef = db.doc("restrictions/blacklist"); + const docSnap = await blacklistDocRef.get(); + + // Check if the document exists and has data + if (docSnap.exists && docSnap.data()) { + const blacklist = docSnap.data()?.list; + return { isInBlacklist: Array.isArray(blacklist) && blacklist.some(user => user.uid === uid) }; + } else { + // Blacklist document does not exist or has no data + return { isInBlacklist: false }; + } + } catch (error) { + throw new functions.https.HttpsError('unknown', 'An error occurred while checking the blacklist', error); + } +}); \ No newline at end of file