File size: 3,566 Bytes
a384b03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import streamlit as st
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))

from utils import init_supabase, get_student_debate_case

def main():
    st.title("πŸ” Week 4 Debate Case Debug")
    
    st.markdown("---")
    
    # Test 1: Supabase Connection
    st.subheader("1. Testing Supabase Connection")
    try:
        supabase = init_supabase()
        if supabase:
            st.success("βœ… Supabase connection successful")
        else:
            st.error("❌ Supabase connection failed")
            return
    except Exception as e:
        st.error(f"❌ Supabase connection error: {str(e)}")
        return
    
    # Test 2: Check if table exists
    st.subheader("2. Testing student_debate_case table")
    try:
        response = supabase.table('student_debate_case').select('*').limit(1).execute()
        st.success(f"βœ… Table accessible, found {len(response.data)} records")
    except Exception as e:
        st.error(f"❌ Table access error: {str(e)}")
        return
    
    # Test 3: List all records
    st.subheader("3. Listing all debate cases in table")
    try:
        response = supabase.table('student_debate_case').select('*').execute()
        if response.data:
            st.success(f"βœ… Found {len(response.data)} debate cases:")
            for i, case in enumerate(response.data, 1):
                st.write(f"   **{i}.** Student ID: `{case.get('student_id', 'N/A')}`")
                st.write(f"       Link: {case.get('google_doc_link', 'N/A')}")
                st.write(f"       Created: {case.get('created_at', 'N/A')}")
                st.write("---")
        else:
            st.warning("❌ No debate cases found in table")
    except Exception as e:
        st.error(f"❌ Error listing cases: {str(e)}")
    
    # Test 4: Test with specific usernames
    st.subheader("4. Testing with specific usernames")
    test_usernames = ["lily", "reed", "instructor", "admin"]
    
    for username in test_usernames:
        try:
            result = get_student_debate_case(username)
            if result:
                st.success(f"βœ… Found case for '{username}': {result.get('google_doc_link', 'N/A')}")
            else:
                st.info(f"❌ No case found for '{username}'")
        except Exception as e:
            st.error(f"❌ Error testing '{username}': {str(e)}")
    
    # Test 5: Test with current user
    st.subheader("5. Testing with current user")
    if st.session_state.get('authenticated', False):
        username = st.session_state.get('username')
        st.write(f"**Current user:** {username}")
        
        try:
            result = get_student_debate_case(username)
            if result:
                st.success(f"βœ… Found case for current user '{username}': {result.get('google_doc_link', 'N/A')}")
            else:
                st.warning(f"❌ No case found for current user '{username}'")
        except Exception as e:
            st.error(f"❌ Error testing current user: {str(e)}")
    else:
        st.warning("⚠️ No user currently authenticated")
    
    # Test 6: Check RLS policies
    st.subheader("6. RLS Policy Check")
    st.info("""
    **RLS Policies Applied:**
    - Users can read their own debate cases
    - Users can insert their own debate cases  
    - Users can update their own debate cases
    - Users can delete their own debate cases
    
    **Note:** If you're testing with a service role or admin user, you might need additional policies.
    """)

if __name__ == "__main__":
    main()