Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Add email to blacklist + Remove user fix #302

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me realize that we currently lack functionality that allows users to delete their existing profile pictures and revert to the default profile picture. I will work on creating a ticket for this.

}

await transaction.delete(userRef);

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