Skip to content

Commit

Permalink
IWB-2: added blacklist management functionality (#310)
Browse files Browse the repository at this point in the history
* added blacklist hook

* black list feature works

* some unused stuff removal

* simplified removeBlacklist.js

* removed transaction and hope that it works

* fixed useBlackList.js hook firestore error, and made blacklist check functional

* added refresh spinner for chooseTeam.js

* kinda works lmao

* minor comment change

Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com>

* changed console log wording in removeBlacklist

Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com>

* removed copied over comment

* fix - added email to blacklist record

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

* fixed "invalid-argument"

* added key

* removed redundant remove user fix

* pretty

* added missing state from merge

* simple fix

---------

Co-authored-by: Jake Gehrke <91503842+Gehrkej@users.noreply.github.com>
Co-authored-by: Jake Gehrke <gehrkej@oregonstate.edu>
  • Loading branch information
3 people committed Aug 15, 2024
1 parent 76fb5c7 commit 2589d27
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 52 deletions.
88 changes: 51 additions & 37 deletions app/content/team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,48 +244,62 @@ function Index() {
<Header
title={"Team"}
postChildren={
currentUserInfo.role === "owner" ? (
<Menu
visible={menuVisible}
onDismiss={() => {
setMenuVisible(false);
}}
anchor={
<Appbar.Action
icon="dots-horizontal-circle-outline"
onPress={() => {
setMenuVisible(true);
}}
color={themeColors.accent}
/>
}
statusBarHeight={45}
anchorPosition="bottom"
contentStyle={{
backgroundColor: themeColors.background,
}}
>
<Menu.Item
leadingIcon="pencil-outline"
<>
{currentUserInfo.role === "coach" ||
currentUserInfo.role === "owner" ? (
<Appbar.Action
icon="account-cog-outline"
onPress={() => {
bottomSheetModalRef.current?.present();
setMenuVisible(false);
router.push("/segments/(team)/manageForeignRequests");
}}
title="Edit Team"
color={themeColors.accent}
/>
<Menu.Item
leadingIcon="restart"
onPress={() => {
console.log("Reset Season Pressed!");
) : (
<></>
)}
{currentUserInfo.role === "owner" ? (
<Menu
visible={menuVisible}
onDismiss={() => {
setMenuVisible(false);
setResetDialogVisible(true);
}}
title="Reset Season"
/>
</Menu>
) : (
<></>
)
anchor={
<Appbar.Action
icon="dots-horizontal-circle-outline"
onPress={() => {
setMenuVisible(true);
}}
color={themeColors.accent}
/>
}
statusBarHeight={45}
anchorPosition="bottom"
contentStyle={{
backgroundColor: themeColors.background,
}}
>
<Menu.Item
leadingIcon="pencil-outline"
onPress={() => {
bottomSheetModalRef.current?.present();
setMenuVisible(false);
}}
title="Edit Team"
/>
<Menu.Item
leadingIcon="restart"
onPress={() => {
console.log("Reset Season Pressed!");
setMenuVisible(false);
setResetDialogVisible(true);
}}
title="Reset Season"
/>
</Menu>
) : (
<></>
)}
</>
}
/>
<BottomSheetWrapper
Expand Down
72 changes: 72 additions & 0 deletions app/segments/(team)/blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useQueryClient } from "@tanstack/react-query";
import { ScrollView, View } from "react-native";
import { Button, List } from "react-native-paper";
import { themeColors } from "~/Constants";
import ErrorComponent from "~/components/errorComponent";
import Loading from "~/components/loading";
import RefreshInvalidate from "~/components/refreshInvalidate";
import { useAuthContext } from "~/context/Auth";
import { useBlackList } from "~/dbOperations/hooks/useBlackList";
import { invalidateMultipleKeys } from "~/dbOperations/invalidateMultipleKeys";
import { removeBlacklist } from "~/dbOperations/removeBlacklist";

function Blacklist() {
const {
data: blacklist,
error: blacklistError,
isLoading: blacklistIsLoading,
} = useBlackList();

const { currentTeamId } = useAuthContext();

const queryClient = useQueryClient(); // also called here for updating name

const invalidateKeys = [["blacklist"]];

if (blacklistIsLoading) return <Loading />;

if (blacklistError) return <ErrorComponent errorList={[blacklistError]} />;

return (
<ScrollView
refreshControl={<RefreshInvalidate invalidateKeys={invalidateKeys} />}
>
<List.Section
style={{
margin: 5,
borderRadius: 5,
}}
>
{Object.keys(blacklist).map((userId) => {
return (
<List.Item
title={blacklist[userId].email}
key={userId}
right={() => (
<View
style={{
flexDirection: "row",
alignItems: "center",
paddingLeft: 10,
}}
>
<Button
onPress={async () => {
await removeBlacklist(currentTeamId, userId);
await invalidateMultipleKeys(queryClient, invalidateKeys);
}}
textColor={themeColors.accent}
>
Unban
</Button>
</View>
)}
/>
);
})}
</List.Section>
</ScrollView>
);
}

export default Blacklist;
99 changes: 99 additions & 0 deletions app/segments/(team)/manageForeignRequests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { useNavigation } from "expo-router";
import { useMemo, useState } from "react";
import { Appbar, SegmentedButtons } from "react-native-paper";
import { SafeAreaView } from "react-native-safe-area-context";
import { themeColors } from "~/Constants";
import Blacklist from "~/app/segments/(team)/blacklist";
import Header from "~/components/header";

function ManageForeignRequests() {
const [tabValue, setTabValue] = useState("invites");
const navigation = useNavigation();

const segmentedColor = (tab) => {
switch (tab) {
case "invites":
return "#008001";
case "waitlist":
return "#FFE900";
case "blacklist":
return "#FE0100";
default:
return themeColors.overlay;
}
};

const segmentedTextColor = (tab) => {
switch (tab) {
case "invites":
case "blacklist":
return "white";
case "waitlist":
return "black";
default:
return "black";
}
};

const tabComponent = useMemo(
() => ({
invites: <></>,
waitlist: <></>,
blacklist: <Blacklist />,
}),
[],
);

return (
<SafeAreaView
style={{
flex: 1,
}}
>
<Header
title="Manage Foreign Requests"
preChildren={
<Appbar.BackAction
onPress={() => {
navigation.goBack();
}}
color={themeColors.accent}
/>
}
/>
<SegmentedButtons
value={tabValue}
onValueChange={setTabValue}
style={{
marginLeft: 10,
marginRight: 10,
backgroundColor: themeColors.highlight,
borderRadius: 20,
}}
theme={{
colors: {
secondaryContainer: segmentedColor(tabValue),
onSecondaryContainer: segmentedTextColor(tabValue),
},
}}
buttons={[
{
value: "invites",
label: "Invites",
},
{
value: "waitlist",
label: "Waitlist",
},
{
value: "blacklist",
label: "Blacklist",
},
]}
/>
{tabComponent[tabValue]}
</SafeAreaView>
);
}

export default ManageForeignRequests;
13 changes: 13 additions & 0 deletions dbOperations/removeBlacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { deleteDoc, doc } from "firebase/firestore";
import { db } from "~/firebaseConfig";

async function removeBlacklist(teamId, userId) {
try {
await deleteDoc(doc(db, "teams", teamId, "blacklist", userId));
} catch (e) {
console.log("Remove User from Blacklist failed: ", e);
throw e; // Rethrow the error to handle it at the caller's level if needed
}
}

module.exports = { removeBlacklist };
32 changes: 17 additions & 15 deletions update_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
app = firebase_admin.initialize_app()
db = firestore.client()

drillInfoRef = db.collection("teams").document("1").collection("drills")
userInfoRef = db.collection("teams").document("1").collection("users")
attemptsRef = db.collection("teams").document("1").collection("attempts")
blacklistRef = db.collection("teams").document("1").collection("blacklist")

newBestAttempts = {}

# reset leaderboard
drills = [drill.to_dict() for drill in drillInfoRef.stream()]
users = [user.to_dict() for user in userInfoRef.stream()]
attempts = [attempt.to_dict() for attempt in attemptsRef.stream()]
blacklist = [user for user in blacklistRef.stream()]

userUniqueDrills = {}
for user in blacklist:
userInfoRef = db.collection("users").document(user.id)

for attempt in attempts:
if attempt["uid"] not in userUniqueDrills:
userUniqueDrills[attempt["uid"]] = set()
userUniqueDrills[attempt["uid"]].add(attempt["did"])
blacklistEntryRef = blacklistRef.document(user.id)
blacklistEntryRef.update({"email": userInfoRef.get().to_dict()["email"]})

print(userInfoRef.get().to_dict()["email"])

for user in users:
userRef = db.collection("teams").document("1").collection("users").document(user["uid"])
userRef.update({"uniqueDrills": list(userUniqueDrills.get(user["uid"], set()))})

# for attempt in attempts:
# if attempt["uid"] not in userUniqueDrills:
# userUniqueDrills[attempt["uid"]] = set()
# userUniqueDrills[attempt["uid"]].add(attempt["did"])

# for user in users:
# userRef = db.collection("teams").document("1").collection("users").document(user["uid"])
# userRef.update({"uniqueDrills": list(userUniqueDrills.get(user["uid"], set()))})

0 comments on commit 2589d27

Please sign in to comment.