Skip to content

Commit

Permalink
add cloud function back
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonIsAzn committed Sep 10, 2024
1 parent 2a9c44b commit 05c35e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
27 changes: 27 additions & 0 deletions functions/src/restriction.ts
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit 05c35e6

Please sign in to comment.