FluxFinance commited on
Commit
f25a2bb
Β·
verified Β·
1 Parent(s): d17ddab

Update Advisernote.py

Browse files
Files changed (1) hide show
  1. Advisernote.py +62 -3
Advisernote.py CHANGED
@@ -8,6 +8,7 @@ import warnings
8
  import platform
9
  import imaplib
10
  import email
 
11
  from imaplib import IMAP4_SSL
12
  from email.header import decode_header, make_header
13
  from datetime import datetime
@@ -124,7 +125,8 @@ if 'refs' not in st.session_state: st.session_state['refs'] = ""
124
  if 'folder_path' not in st.session_state: st.session_state['folder_path'] = ""
125
  if 'doc_context' not in st.session_state: st.session_state['doc_context'] = ""
126
  if 'results' not in st.session_state: st.session_state['results'] = None
127
- if 'notion_client_name' not in st.session_state: st.session_state['notion_client_name'] = ""
 
128
 
129
  # =========================================================================
130
  # [λ³΄μ•ˆ λνŒμ™•] 졜초 둜그인 λΉ„λ²ˆ μ„ΈνŒ… & κ΄€λ¦¬μž μ‹€μ‹œκ°„ 동기화/μ‚­μ œ ν†΅μ œ μ‹œμŠ€ν…œ
@@ -165,6 +167,25 @@ def update_user_password(email_addr, new_password):
165
  conn.close()
166
  return updated
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  def revoke_user_access(email_addr):
169
  conn = sqlite3.connect(USER_DB_FILE)
170
  conn.execute("UPDATE users SET active = 0 WHERE email = ?", (email_addr,))
@@ -296,7 +317,11 @@ def fetch_notion_comments(page_id):
296
  created_at = c.get("created_time", "").split("T")[0] # YYYY-MM-DD ν˜•μ‹λ§Œ μΆ”μΆœ
297
 
298
  c_text_list = c.get("rich_text", [])
299
- c_text = c_text_list[0].get("text", {}).get("content", "").strip() if c_text_list else ""
 
 
 
 
300
 
301
  if c_text:
302
  # 🟒 [μˆ˜μ •] [λ‚ μ§œ] μ½”λ©˜νŠΈ λ‚΄μš© ν˜•μ‹μœΌλ‘œ μ‘°ν•©
@@ -489,6 +514,31 @@ if check_password():
489
  })
490
 
491
  st.table(pd.DataFrame(admin_data))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
 
493
  st.markdown("**Deactivate & Revoke User Permissions**")
494
  target_del = st.selectbox("Select email address to revoke access", ["-"] + list(current_users.keys()))
@@ -1068,6 +1118,15 @@ if check_password():
1068
  status.update(label="⚠️ λ§€μΉ­ 데이터 μ—†μŒ", state="error")
1069
  else:
1070
  status.update(label=f"❌ Failed: {msg}", state="error")
 
 
 
 
 
 
 
 
 
1071
  # TAB 2: 이메일 검색창
1072
  with tab_email:
1073
  with st.container(border=True):
@@ -1433,7 +1492,7 @@ if st.session_state['results'] is not None:
1433
  # 🟒 [κΈ°μ‘΄ κΈ°λŠ₯ μœ μ§€] μ½”λ©˜νŠΈ(Comments)κ°€ μžˆμ„ 경우, λ³Έλ¬Έ μ•„λž˜μ— λ³„λ„μ˜ 말풍선 λ°•μŠ€λ‘œ 예쁘게 λ Œλ”λ§
1434
  comments_data = row.get('Comments', '').strip()
1435
  if comments_data:
1436
- html_comments = comments_data.replace('\n', '<br>')
1437
  st.markdown(f"""
1438
  <div style='background-color: #FEF3C7; padding: 12px 15px; border-radius: 8px; border: 1px solid #FCD34D; font-size: 0.85rem; margin-top: 12px; color: #92400E; line-height: 1.6;'>
1439
  <b>πŸ’¬ Notion Comments:</b><br><br>{html_comments}
 
8
  import platform
9
  import imaplib
10
  import email
11
+ import html
12
  from imaplib import IMAP4_SSL
13
  from email.header import decode_header, make_header
14
  from datetime import datetime
 
125
  if 'folder_path' not in st.session_state: st.session_state['folder_path'] = ""
126
  if 'doc_context' not in st.session_state: st.session_state['doc_context'] = ""
127
  if 'results' not in st.session_state: st.session_state['results'] = None
128
+ if 'notion_client_name' not in st.session_state: st.session_state['notion_client_name'] = "Serafi & Tusiga"
129
+ if 'case_comments' not in st.session_state: st.session_state['case_comments'] = ""
130
 
131
  # =========================================================================
132
  # [λ³΄μ•ˆ λνŒμ™•] 졜초 둜그인 λΉ„λ²ˆ μ„ΈνŒ… & κ΄€λ¦¬μž μ‹€μ‹œκ°„ 동기화/μ‚­μ œ ν†΅μ œ μ‹œμŠ€ν…œ
 
167
  conn.close()
168
  return updated
169
 
170
+ def add_or_restore_user(email_addr, initial_password=""):
171
+ email_addr = email_addr.strip().lower()
172
+ conn = sqlite3.connect(USER_DB_FILE)
173
+ existing = conn.execute("SELECT email FROM users WHERE email = ?", (email_addr,)).fetchone()
174
+ if existing:
175
+ conn.execute(
176
+ "UPDATE users SET password = ?, active = 1 WHERE email = ?",
177
+ (initial_password, email_addr)
178
+ )
179
+ else:
180
+ conn.execute(
181
+ "INSERT INTO users (email, password, active) VALUES (?, ?, 1)",
182
+ (email_addr, initial_password)
183
+ )
184
+ conn.commit()
185
+ updated = conn.total_changes > 0
186
+ conn.close()
187
+ return updated
188
+
189
  def revoke_user_access(email_addr):
190
  conn = sqlite3.connect(USER_DB_FILE)
191
  conn.execute("UPDATE users SET active = 0 WHERE email = ?", (email_addr,))
 
317
  created_at = c.get("created_time", "").split("T")[0] # YYYY-MM-DD ν˜•μ‹λ§Œ μΆ”μΆœ
318
 
319
  c_text_list = c.get("rich_text", [])
320
+ c_text = "".join(
321
+ item.get("plain_text", item.get("text", {}).get("content", ""))
322
+ for item in c_text_list
323
+ if isinstance(item, dict)
324
+ ).strip()
325
 
326
  if c_text:
327
  # 🟒 [μˆ˜μ •] [λ‚ μ§œ] μ½”λ©˜νŠΈ λ‚΄μš© ν˜•μ‹μœΌλ‘œ μ‘°ν•©
 
514
  })
515
 
516
  st.table(pd.DataFrame(admin_data))
517
+
518
+ st.markdown("**Add or Restore User Access**")
519
+ add_col_email, add_col_password = st.columns([2, 1])
520
+ new_user_email = add_col_email.text_input(
521
+ "Employee email address",
522
+ key="admin_add_user_email",
523
+ placeholder="new.user@fluxfinance.co.nz"
524
+ ).strip().lower()
525
+ new_user_password = add_col_password.text_input(
526
+ "Initial password",
527
+ type="password",
528
+ key="admin_add_user_password",
529
+ help="Leave blank to let the user set their password on first login."
530
+ )
531
+
532
+ if st.button("βž• Add / Restore User", use_container_width=True):
533
+ if not new_user_email:
534
+ st.error("Please enter an email address.")
535
+ elif not re.match(r"^[^@\s]+@[^@\s]+\.[^@\s]+$", new_user_email):
536
+ st.error("Please enter a valid email address.")
537
+ elif add_or_restore_user(new_user_email, new_user_password):
538
+ st.success(f"βœ… Access granted for {new_user_email}.")
539
+ st.rerun()
540
+ else:
541
+ st.error("⚠️ System Error: Failed to update user access.")
542
 
543
  st.markdown("**Deactivate & Revoke User Permissions**")
544
  target_del = st.selectbox("Select email address to revoke access", ["-"] + list(current_users.keys()))
 
1118
  status.update(label="⚠️ λ§€μΉ­ 데이터 μ—†μŒ", state="error")
1119
  else:
1120
  status.update(label=f"❌ Failed: {msg}", state="error")
1121
+
1122
+ case_comments = st.session_state.get('case_comments', '').strip()
1123
+ if case_comments:
1124
+ html_case_comments = html.escape(case_comments).replace('\n', '<br>')
1125
+ st.markdown(f"""
1126
+ <div style='background-color: #F0FDF4; padding: 12px 15px; border-radius: 8px; border: 1px solid #BBF7D0; font-size: 0.85rem; margin-top: 12px; color: #166534; line-height: 1.6;'>
1127
+ <b>πŸ’¬ Case Comments:</b><br><br>{html_case_comments}
1128
+ </div>
1129
+ """, unsafe_allow_html=True)
1130
  # TAB 2: 이메일 검색창
1131
  with tab_email:
1132
  with st.container(border=True):
 
1492
  # 🟒 [κΈ°μ‘΄ κΈ°λŠ₯ μœ μ§€] μ½”λ©˜νŠΈ(Comments)κ°€ μžˆμ„ 경우, λ³Έλ¬Έ μ•„λž˜μ— λ³„λ„μ˜ 말풍선 λ°•μŠ€λ‘œ 예쁘게 λ Œλ”λ§
1493
  comments_data = row.get('Comments', '').strip()
1494
  if comments_data:
1495
+ html_comments = html.escape(comments_data).replace('\n', '<br>')
1496
  st.markdown(f"""
1497
  <div style='background-color: #FEF3C7; padding: 12px 15px; border-radius: 8px; border: 1px solid #FCD34D; font-size: 0.85rem; margin-top: 12px; color: #92400E; line-height: 1.6;'>
1498
  <b>πŸ’¬ Notion Comments:</b><br><br>{html_comments}