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