Skip to content

Commit

Permalink
[Fix] Add email to blacklist + Remove user fix (#302)
Browse files Browse the repository at this point in the history
* fix - added email to blacklist record

* fix - added assertion if pfp exists when removing a user

---------

Co-authored-by: Frankreed <[email protected]>
  • Loading branch information
Gehrkej and FrankreedX authored Aug 5, 2024
1 parent 4bedb80 commit d5962cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/content/team/users/[user]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import { removeUser } from "~/dbOperations/removeUser";
import { db } from "~/firebaseConfig";

//A function to add a user to the blacklist table with a timestamp
async function blacklistUser(teamId, userId, userInfo) {
async function blacklistUser(teamId, userId, userInfo, userEmail) {
//Create new document with userId as the id and a time field

try {
await setDoc(doc(db, "teams", teamId, "blacklist", userId), {
time: Date.now(),
name: userInfo["name"],
email: userEmail,
});
//remove users data
await removeUser(teamId, userId);
Expand Down Expand Up @@ -336,7 +337,7 @@ function Index() {
hideBanDialog,
async () => {
try {
await blacklistUser(currentTeamId, userId, userInfo);
await blacklistUser(currentTeamId, userId, userInfo, userEmail);
await queryClient.removeQueries(["userInfo", userId]);
await invalidateMultipleKeys(queryClient, [
["userInfo"],
Expand Down
13 changes: 9 additions & 4 deletions dbOperations/removeUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
runTransaction,
where,
} from "firebase/firestore";
import removePfp from "~/dbOperations/removePfp";
import { db } from "~/firebaseConfig";
import { getPfpName } from "~/Utility";
import { db } from "~/firebaseConfig";
import removePfp from "./removePfp";

async function removeUser(teamId, userId) {
try {
Expand Down Expand Up @@ -47,9 +47,14 @@ async function removeUser(teamId, userId) {
//Remove user from user table where UID == userID
const userRef = doc(db, "teams", teamId, "users", userId);

await transaction.delete(userRef);
const userSnapshot = await transaction.get(userRef);

await removePfp(getPfpName(teamId, userId));
//remove pfp if there is one
if (userSnapshot.data().pfp !== "") {
await removePfp(getPfpName(teamId, userId));
}

await transaction.delete(userRef);

console.log(" Remove User Transaction has completed");
});
Expand Down

0 comments on commit d5962cf

Please sign in to comment.