mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-11-01 18:19:43 +00:00
fix(admin): remove enabled packs filter from outstanding questions query
The couple_packs table has no admin RLS policy, so the enabled packs query returns empty for admin users. Query all partner-answered questions instead — more useful for admin visibility anyway. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
edb2cedda0
commit
8a44fef764
1 file changed
+3
-12
@@ -493,9 +493,6 @@ export function UserDetailPage() {
|
|||||||
// Use partner from state (set earlier in the first couple_id block)
|
// Use partner from state (set earlier in the first couple_id block)
|
||||||
const partnerProfile = partner || (await supabase.from('profiles').select('id, name').eq('couple_id', profileData.couple_id).neq('id', userId).maybeSingle()).data;
|
const partnerProfile = partner || (await supabase.from('profiles').select('id, name').eq('couple_id', profileData.couple_id).neq('id', userId).maybeSingle()).data;
|
||||||
if (partnerProfile) {
|
if (partnerProfile) {
|
||||||
const enabledPackIds = (enabledPacksData || []).map((ep: any) => ep.pack_id);
|
|
||||||
|
|
||||||
if (enabledPackIds.length > 0) {
|
|
||||||
// Get question IDs user has already answered
|
// Get question IDs user has already answered
|
||||||
const { data: userResponseIds } = await supabase
|
const { data: userResponseIds } = await supabase
|
||||||
.from('responses')
|
.from('responses')
|
||||||
@@ -520,12 +517,11 @@ export function UserDetailPage() {
|
|||||||
const unansweredQuestionIds = unansweredPartnerResponses.map((r: any) => r.question_id);
|
const unansweredQuestionIds = unansweredPartnerResponses.map((r: any) => r.question_id);
|
||||||
|
|
||||||
if (unansweredQuestionIds.length > 0) {
|
if (unansweredQuestionIds.length > 0) {
|
||||||
// Fetch question details, filtered to enabled packs
|
// Fetch question details (no pack filter — admin sees all)
|
||||||
const { data: questionDetails } = await supabase
|
const { data: questionDetails } = await supabase
|
||||||
.from('questions')
|
.from('questions')
|
||||||
.select('id, text, intensity, pack:question_packs(id, name)')
|
.select('id, text, intensity, pack:question_packs(id, name)')
|
||||||
.in('id', unansweredQuestionIds)
|
.in('id', unansweredQuestionIds);
|
||||||
.in('pack_id', enabledPackIds);
|
|
||||||
|
|
||||||
const questionMap = new Map((questionDetails || []).map((q: any) => [q.id, q]));
|
const questionMap = new Map((questionDetails || []).map((q: any) => [q.id, q]));
|
||||||
const partnerResponseMap = new Map(unansweredPartnerResponses.map((r: any) => [r.question_id, r]));
|
const partnerResponseMap = new Map(unansweredPartnerResponses.map((r: any) => [r.question_id, r]));
|
||||||
@@ -572,7 +568,7 @@ export function UserDetailPage() {
|
|||||||
.eq('user_id', userId)
|
.eq('user_id', userId)
|
||||||
.eq('couple_id', profileData.couple_id);
|
.eq('couple_id', profileData.couple_id);
|
||||||
const userAhead = (userResponses || []).filter((r: any) => !partnerAllAnswered.has(r.question_id)).length;
|
const userAhead = (userResponses || []).filter((r: any) => !partnerAllAnswered.has(r.question_id)).length;
|
||||||
const partnerAhead = (partnerResponses || []).filter((r: any) => !answeredIds.has(r.question_id)).length;
|
const partnerAhead = unansweredPartnerResponses.length;
|
||||||
const gap = Math.max(0, userAhead - partnerAhead);
|
const gap = Math.max(0, userAhead - partnerAhead);
|
||||||
setNetGap(gap);
|
setNetGap(gap);
|
||||||
setGapDisabled(gap >= threshold);
|
setGapDisabled(gap >= threshold);
|
||||||
@@ -585,11 +581,6 @@ export function UserDetailPage() {
|
|||||||
setOutstandingTotal(0);
|
setOutstandingTotal(0);
|
||||||
setGapDisabled(false);
|
setGapDisabled(false);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setOutstandingQuestions([]);
|
|
||||||
setOutstandingTotal(0);
|
|
||||||
setGapDisabled(false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setMatches([]);
|
setMatches([]);
|
||||||
setMatchesTotal(0);
|
setMatchesTotal(0);
|
||||||
|
|||||||
Reference in new issue
Block a user