import streamlit as st from backend.actions.dsar_report import ( build_excel, exports_df, profile_rows, subscriptions_df, ) from backend.actions.fan_lookup import find_dsar_report from backend.adapters.snowflake import ( get_session, resolve_env, ) from backend.dtos import DsarResult from backend.permissions import require_access session = get_session() require_access(session, "FAN_LOOKUP") st.title("DSAR Generation") st.markdown( """ Look up all personal data held for a fan by email address. Results are organised across three sections — Export History, PII, and Active Subscriptions — and can be exported as an Excel workbook for DSAR reporting. **Note:** Due to large data volumes, queries may take up to a few minutes to complete. """ ) email = st.text_input("Fan email address") if st.button("Search"): if not email.strip(): st.warning("Please enter an email address.") else: session = get_session() with st.spinner("Fetching data…"): result: DsarResult = find_dsar_report( session, email.strip(), resolve_env(session) ) if result.profile is None and not result.exports and not result.subscriptions: st.warning("No records found for that email address.") else: st.session_state["dsar_result"] = result st.session_state["dsar_email"] = email.strip() st.session_state.pop("dsar_excel", None) if "dsar_result" in st.session_state: result = st.session_state["dsar_result"] fan_email = st.session_state["dsar_email"] tab_exports, tab_pii, tab_subs = st.tabs( ["Export History", "PII (Fan Profile)", "Fan Active Subscriptions"] ) with tab_exports: for warning in result.export_warnings: st.warning(warning) if not result.exports: st.info("No export records found.") else: st.dataframe(exports_df(result.exports), width="content") st.caption("Sources: Fansifter, Salesforce, Hightouch.") with tab_pii: if result.profile is None: st.info("No profile found.") else: if result.profile.deleted: deleted_label = ( str(result.profile.deleted_at) if result.profile.deleted_at else "Unknown" ) st.warning(f"This fan has been deleted. Deletion date: {deleted_label}") pii = profile_rows(result.profile) if pii: st.table({"Field": list(pii.keys()), "Value": list(pii.values())}) else: st.info("No PII fields with values found.") with tab_subs: if not result.subscriptions: st.info("No active subscriptions found.") else: st.dataframe(subscriptions_df(result.subscriptions), width="content") password = st.text_input( "Excel password (optional)", type="password", help="If set, the exported file will be password-protected.", ) if st.button("Prepare Excel export"): st.session_state["dsar_excel"] = build_excel(result, password=password or None) st.session_state["dsar_excel_email"] = fan_email if "dsar_excel" in st.session_state: st.download_button( label="Download Excel", data=st.session_state["dsar_excel"], file_name=f"DSAR – {st.session_state['dsar_excel_email']}.xlsx", mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", )