Fixed an issue where departments could interact and see caches from other departments for org accounts. Fixed this issue.

This commit is contained in:
bobbert committed 2026-04-09 14:41:51 +01:00
1 parent 909cbb9de6
commit 41b0b723ca
4 files changed
+34 -22

No files matched your search

+6 -7
View File
@@ -13,6 +13,9 @@ const LeaderboardScreen = ({navigation, route}) => {
const isAdmin = session.isAcceptedAdmin; const isAdmin = session.isAcceptedAdmin;
const isBusiness = Boolean(session.isBusiness); const isBusiness = Boolean(session.isBusiness);
const selectedDepartment = route?.params?.department || null; const selectedDepartment = route?.params?.department || null;
const effectiveSGid = isBusiness
? ((isAdmin && selectedDepartment?.SGid) ? selectedDepartment.SGid : (isAdmin ? null : session.currentSGid))
: null;
const {getLobby, getSubgroup, getTeams, getTeamMembers, getGroupMembers, getCaches, getUser, deleteTeam, resetPlayerProgress, resetTeamProgress, getSubgroups} = useGameHook(); const {getLobby, getSubgroup, getTeams, getTeamMembers, getGroupMembers, getCaches, getUser, deleteTeam, resetPlayerProgress, resetTeamProgress, getSubgroups} = useGameHook();
// State ---------------------- // State ----------------------
@@ -34,10 +37,6 @@ const LeaderboardScreen = ({navigation, route}) => {
const group = await getLobby(session.currentGid); const group = await getLobby(session.currentGid);
const effectiveSGid = isBusiness
? ((isAdmin && selectedDepartment?.SGid) ? selectedDepartment.SGid : (isAdmin ? null : session.currentSGid))
: null;
let isTeams = Boolean(group?.TeamsEnabled); let isTeams = Boolean(group?.TeamsEnabled);
if (effectiveSGid !== null && effectiveSGid !== undefined) { if (effectiveSGid !== null && effectiveSGid !== undefined) {
const subgroup = await getSubgroup(effectiveSGid); const subgroup = await getSubgroup(effectiveSGid);
@@ -117,7 +116,7 @@ const LeaderboardScreen = ({navigation, route}) => {
} }
setLoading(false); setLoading(false);
}, [session.currentGid, session.currentTid, session.currentSGid, isBusiness, isAdmin, selectedDepartment, selectedDepartment?.SGid]); }, [session.currentGid, session.currentTid, session.currentSGid, isBusiness, isAdmin, selectedDepartment, selectedDepartment?.SGid, effectiveSGid]);
useEffect(() => { loadData(); }, [loadData]); useEffect(() => { loadData(); }, [loadData]);
@@ -144,7 +143,7 @@ const LeaderboardScreen = ({navigation, route}) => {
text: 'Reset', text: 'Reset',
style: 'destructive', style: 'destructive',
onPress: async () => { onPress: async () => {
await resetPlayerProgress(session.currentGid, player.uid); await resetPlayerProgress(session.currentGid, player.uid, effectiveSGid);
Alert.alert('Done', `Progress for ${player.name} has been reset.`); Alert.alert('Done', `Progress for ${player.name} has been reset.`);
await loadData(); await loadData();
}, },
@@ -159,7 +158,7 @@ const LeaderboardScreen = ({navigation, route}) => {
text: 'Reset', text: 'Reset',
style: 'destructive', style: 'destructive',
onPress: async () => { onPress: async () => {
await resetTeamProgress(session.currentGid, team.tid); await resetTeamProgress(session.currentGid, team.tid, effectiveSGid);
Alert.alert('Done', `Progress for team "${team.name}" has been reset.`); Alert.alert('Done', `Progress for team "${team.name}" has been reset.`);
await loadData(); await loadData();
}, },
+9 -3
View File
@@ -18,6 +18,7 @@ const DEFAULT_REGION = {latitude: 51.5074, longitude: -0.1278, latitudeDelta: 0.
const MapScreen = ({navigation, route}) => { const MapScreen = ({navigation, route}) => {
const session = getSession(); const session = getSession();
const isBusiness = Boolean(session.isBusiness);
const {getCaches, claimCache, upsertCache, deleteCache, joinPrivateGame, createPrivateGame, getLobby, getUser, getSubgroups, getGroupByOrgCode} = useGameHook(); const {getCaches, claimCache, upsertCache, deleteCache, joinPrivateGame, createPrivateGame, getLobby, getUser, getSubgroups, getGroupByOrgCode} = useGameHook();
// Stable ref to prevent infinite re-render loops // Stable ref to prevent infinite re-render loops
@@ -102,6 +103,10 @@ const MapScreen = ({navigation, route}) => {
} }
return map; return map;
}, [departments]); }, [departments]);
const routeDepartmentSGid = route?.params?.selectedDepartmentSGid;
const effectiveSGid = isBusiness
? (isAdmin ? (selectedCacheSubgroupId ?? routeDepartmentSGid ?? defaultMemberSGid ?? null) : (session.currentSGid ?? null))
: null;
useEffect(() => { useEffect(() => {
if (!isAdmin || departments.length === 0) return; if (!isAdmin || departments.length === 0) return;
@@ -127,9 +132,9 @@ const MapScreen = ({navigation, route}) => {
setCacheRecords([]); setCacheRecords([]);
return; return;
} }
const rows = await getCachesRef.current(currentGid, null); const rows = await getCachesRef.current(currentGid, effectiveSGid ?? null);
setCacheRecords(rows || []); setCacheRecords(rows || []);
}, []); }, [effectiveSGid]);
// Run once on mount // Run once on mount
useEffect(() => { loadCaches(); }, [loadCaches]); useEffect(() => { loadCaches(); }, [loadCaches]);
@@ -288,6 +293,7 @@ const MapScreen = ({navigation, route}) => {
cacheId, cacheId,
uid: session.currentUid, uid: session.currentUid,
tid: session.currentTid, tid: session.currentTid,
sgid: effectiveSGid,
}); });
setIsClaiming(false); setIsClaiming(false);
if (result) { if (result) {
@@ -295,7 +301,7 @@ const MapScreen = ({navigation, route}) => {
setTimeout(() => setClaimedPopupVisible(false), 3000); setTimeout(() => setClaimedPopupVisible(false), 3000);
} }
await loadCaches(); await loadCaches();
}, [session.currentGid, session.currentUid, session.currentTid, loadCaches]); }, [session.currentGid, session.currentUid, session.currentTid, effectiveSGid, loadCaches]);
const handleCreateCachePress = () => { const handleCreateCachePress = () => {
const fallback = userLocation || {latitude: mapRegion.latitude, longitude: mapRegion.longitude}; const fallback = userLocation || {latitude: mapRegion.latitude, longitude: mapRegion.longitude};
+5 -6
View File
@@ -14,6 +14,9 @@ const PlayersScreen = ({navigation, route}) => {
const isBusiness = Boolean(session.isBusiness); const isBusiness = Boolean(session.isBusiness);
const isAdmin = Boolean(session.isAcceptedAdmin); const isAdmin = Boolean(session.isAcceptedAdmin);
const selectedDepartment = route?.params?.department || null; const selectedDepartment = route?.params?.department || null;
const effectiveSGid = isBusiness
? ((isAdmin && selectedDepartment?.SGid) ? selectedDepartment.SGid : (isAdmin ? null : session.currentSGid))
: null;
// State ---------------------- // State ----------------------
@@ -26,10 +29,6 @@ const PlayersScreen = ({navigation, route}) => {
const loadData = useCallback(async () => { const loadData = useCallback(async () => {
if (!session.currentGid) { setLoading(false); return; } if (!session.currentGid) { setLoading(false); return; }
const effectiveSGid = isBusiness
? ((isAdmin && selectedDepartment?.SGid) ? selectedDepartment.SGid : (isAdmin ? null : session.currentSGid))
: null;
if (isBusiness && isAdmin && !selectedDepartment) { if (isBusiness && isAdmin && !selectedDepartment) {
const sgs = await getSubgroups(session.currentGid); const sgs = await getSubgroups(session.currentGid);
setDepartmentList((sgs || []).filter((sg) => !sg.IsAdminGroup)); setDepartmentList((sgs || []).filter((sg) => !sg.IsAdminGroup));
@@ -122,7 +121,7 @@ const PlayersScreen = ({navigation, route}) => {
setPlayers(playerList); setPlayers(playerList);
setLoading(false); setLoading(false);
}, [session.currentGid, session.currentUid, session.currentSGid, isBusiness, isAdmin, selectedDepartment, selectedDepartment?.SGid]); }, [session.currentGid, session.currentUid, session.currentSGid, isBusiness, isAdmin, selectedDepartment, selectedDepartment?.SGid, effectiveSGid]);
useEffect(() => { loadData(); }, [loadData]); useEffect(() => { loadData(); }, [loadData]);
@@ -141,7 +140,7 @@ const PlayersScreen = ({navigation, route}) => {
text: 'Reset', text: 'Reset',
style: 'destructive', style: 'destructive',
onPress: async () => { onPress: async () => {
await resetPlayerProgress(session.currentGid, player.Uid); await resetPlayerProgress(session.currentGid, player.Uid, effectiveSGid);
Alert.alert('Done', `Progress for ${player.username} has been reset.`); Alert.alert('Done', `Progress for ${player.username} has been reset.`);
}, },
}, },
+14 -6
View File
@@ -184,9 +184,13 @@ const useGameHook = () => {
}; };
const claimCache = async (payload) => { const claimCache = async (payload) => {
let url = `${cachesEndpoint}/${payload.cacheId}/claim`;
if (payload.sgid !== null && payload.sgid !== undefined) {
url += `?SGid=${payload.sgid}`;
}
const response = await API.post( const response = await API.post(
`${cachesEndpoint}/${payload.cacheId}/claim`, url,
{Uid: payload.uid, Tid: payload.tid}, {Uid: payload.uid, Tid: payload.tid, SGid: payload.sgid},
); );
return response.isSuccess ? response.result : null; return response.isSuccess ? response.result : null;
}; };
@@ -205,13 +209,17 @@ const useGameHook = () => {
}; };
// Player progress reset — clear all claims by a specific user // Player progress reset — clear all claims by a specific user
const resetPlayerProgress = async (gid, uid) => { const resetPlayerProgress = async (gid, uid, sgid = null) => {
const response = await API.post(`${cachesEndpoint}/reset-player/${uid}?Gid=${gid}`, {}); let url = `${cachesEndpoint}/reset-player/${uid}?Gid=${gid}`;
if (sgid !== null && sgid !== undefined) url += `&SGid=${sgid}`;
const response = await API.post(url, {});
return response.isSuccess; return response.isSuccess;
}; };
const resetTeamProgress = async (gid, tid) => { const resetTeamProgress = async (gid, tid, sgid = null) => {
const response = await API.post(`${cachesEndpoint}/reset-team/${tid}?Gid=${gid}`, {}); let url = `${cachesEndpoint}/reset-team/${tid}?Gid=${gid}`;
if (sgid !== null && sgid !== undefined) url += `&SGid=${sgid}`;
const response = await API.post(url, {});
return response.isSuccess; return response.isSuccess;
}; };