Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -130,8 +130,26 @@ def get_client_ip():
|
|
| 130 |
return str(raw_ip).split(",")[0].strip()
|
| 131 |
return ""
|
| 132 |
|
| 133 |
-
def log_audit(event, room_name="", actor_name="", role="", **extra):
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
def build_word_frequencies(text_series):
|
| 137 |
tokens = []
|
|
@@ -677,6 +695,7 @@ if st.button("의견 제출", use_container_width=True, type="primary"):
|
|
| 677 |
st.session_state['reset_key'] += 1
|
| 678 |
st.rerun()
|
| 679 |
except Exception as e:
|
|
|
|
| 680 |
st.error(f"저장 실패: {e}")
|
| 681 |
else:
|
| 682 |
st.warning(f"{input_error_message} ({input_error_code})")
|
|
@@ -738,6 +757,7 @@ def live_chat_board_core():
|
|
| 738 |
log_audit("chat_deleted", room_name=room_name, actor_name=student_name, role=user_role, message_id=msg_id)
|
| 739 |
st.toast("의견이 즉시 삭제되었습니다.", icon="🗑️")
|
| 740 |
except Exception as e:
|
|
|
|
| 741 |
st.error(f"삭제 실패: {e}")
|
| 742 |
|
| 743 |
def render_msg(row):
|
|
@@ -848,6 +868,7 @@ if user_role == "교사" and teacher_auth:
|
|
| 848 |
log_audit("teacher_hint_sent", room_name=room_name, actor_name=student_name, role=user_role)
|
| 849 |
st.session_state['hint_input_widget'] = ""
|
| 850 |
except Exception as e:
|
|
|
|
| 851 |
st.error(f"힌트 전송 실패: {e}")
|
| 852 |
|
| 853 |
if AI_HINT_ENABLED:
|
|
@@ -926,6 +947,7 @@ if user_role == "교사" and teacher_auth:
|
|
| 926 |
log_audit("record_deleted", room_name=room_name, actor_name=student_name, role=user_role, record_id=del_id)
|
| 927 |
st.toast("기록이 삭제되었습니다.", icon="🗑️")
|
| 928 |
except Exception as e:
|
|
|
|
| 929 |
st.error(f"기록 삭제 실패: {e}")
|
| 930 |
|
| 931 |
col3, col4 = st.columns([1, 1])
|
|
@@ -1006,4 +1028,5 @@ if user_role == "교사" and teacher_auth:
|
|
| 1006 |
st.session_state['ai_result_text'] = ""
|
| 1007 |
st.rerun()
|
| 1008 |
except Exception as e:
|
|
|
|
| 1009 |
st.error(f"삭제 중 오류 발생: {e}")
|
|
|
|
| 130 |
return str(raw_ip).split(",")[0].strip()
|
| 131 |
return ""
|
| 132 |
|
| 133 |
+
def log_audit(event, room_name="", actor_name="", role="", error_code=None, **extra):
|
| 134 |
+
"""
|
| 135 |
+
감사 로그 표준 포맷:
|
| 136 |
+
event : 발생한 이벤트 (opinion_submitted, chat_deleted, room_destroyed 등)
|
| 137 |
+
room_name : 대상 방 이름
|
| 138 |
+
actor_name : 행위자 이름/학번
|
| 139 |
+
role : 행위자 역할 (학생 / 교사)
|
| 140 |
+
error_code : 에러 발생 시 코드 (정상 이벤트는 None)
|
| 141 |
+
extra : 추가 컨텍스트 (sentiment, client_ip 등)
|
| 142 |
+
"""
|
| 143 |
+
if error_code:
|
| 144 |
+
logger.warning(
|
| 145 |
+
"AUDIT event=%s room=%s actor=%s role=%s error_code=%s extra=%s",
|
| 146 |
+
event, room_name, actor_name, role, error_code, extra
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
logger.info(
|
| 150 |
+
"AUDIT event=%s room=%s actor=%s role=%s extra=%s",
|
| 151 |
+
event, room_name, actor_name, role, extra
|
| 152 |
+
)
|
| 153 |
|
| 154 |
def build_word_frequencies(text_series):
|
| 155 |
tokens = []
|
|
|
|
| 695 |
st.session_state['reset_key'] += 1
|
| 696 |
st.rerun()
|
| 697 |
except Exception as e:
|
| 698 |
+
log_audit("opinion_submit_failed", room_name=room_name, actor_name=safe_student_name, role=author_role_for_submit, error_code="SUBMIT_FAILED")
|
| 699 |
st.error(f"저장 실패: {e}")
|
| 700 |
else:
|
| 701 |
st.warning(f"{input_error_message} ({input_error_code})")
|
|
|
|
| 757 |
log_audit("chat_deleted", room_name=room_name, actor_name=student_name, role=user_role, message_id=msg_id)
|
| 758 |
st.toast("의견이 즉시 삭제되었습니다.", icon="🗑️")
|
| 759 |
except Exception as e:
|
| 760 |
+
log_audit("opinion_submit_failed", room_name=room_name, actor_name=safe_student_name, role=author_role_for_submit, error_code="SUBMIT_FAILED")
|
| 761 |
st.error(f"삭제 실패: {e}")
|
| 762 |
|
| 763 |
def render_msg(row):
|
|
|
|
| 868 |
log_audit("teacher_hint_sent", room_name=room_name, actor_name=student_name, role=user_role)
|
| 869 |
st.session_state['hint_input_widget'] = ""
|
| 870 |
except Exception as e:
|
| 871 |
+
log_audit("opinion_submit_failed", room_name=room_name, actor_name=safe_student_name, role=author_role_for_submit, error_code="SUBMIT_FAILED")
|
| 872 |
st.error(f"힌트 전송 실패: {e}")
|
| 873 |
|
| 874 |
if AI_HINT_ENABLED:
|
|
|
|
| 947 |
log_audit("record_deleted", room_name=room_name, actor_name=student_name, role=user_role, record_id=del_id)
|
| 948 |
st.toast("기록이 삭제되었습니다.", icon="🗑️")
|
| 949 |
except Exception as e:
|
| 950 |
+
log_audit("opinion_submit_failed", room_name=room_name, actor_name=safe_student_name, role=author_role_for_submit, error_code="SUBMIT_FAILED")
|
| 951 |
st.error(f"기록 삭제 실패: {e}")
|
| 952 |
|
| 953 |
col3, col4 = st.columns([1, 1])
|
|
|
|
| 1028 |
st.session_state['ai_result_text'] = ""
|
| 1029 |
st.rerun()
|
| 1030 |
except Exception as e:
|
| 1031 |
+
log_audit("opinion_submit_failed", room_name=room_name, actor_name=safe_student_name, role=author_role_for_submit, error_code="SUBMIT_FAILED")
|
| 1032 |
st.error(f"삭제 중 오류 발생: {e}")
|