fix(app): 日记可见性修复 — 私密日记仅本地 + Web 端 ID 修复 + 分享按钮
Some checks failed
Main Merge / backend (push) Has been cancelled
Main Merge / frontend (push) Has been cancelled

问题修复:
1. Web端保存的日记看不到:createJournal 返回值未捕获,server ID 丢失导致
   后续元素保存用错 ID。现在使用 saved.id 贯穿全部操作。
2. 管理端看不到新建日记:后端 list_journals 添加 is_private 过滤,admin/teacher
   查看他人日记时排除私密日记。
3. RemoteJournalRepository 添加 onJournalChanged 变更通知流,HomeBloc 可自动刷新。
4. SyncEngine(native + web)enqueue 添加 is_private 防御性检查,私密日记不入队。
5. 编辑器 _persistState 条件入队:仅非私密日记同步到后端。
6. 分享流程改造:首次从私密变为公开时入队 create 操作上传。
7. 日记卡片添加可见性标签(仅自己可见/班级可见/公开),私密日记可点击分享。
8. 首页 _sharePrivateJournal 弹出 ShareBottomSheet 主动分享。
This commit is contained in:
iven
2026-06-04 12:03:24 +08:00
parent c441aa4e34
commit bb388ed8ff
7 changed files with 276 additions and 33 deletions

View File

@@ -251,7 +251,7 @@ where
// IDOR 修复:非管理角色只能查看自己的日记
// - 学生:强制 author_id = ctx.user_id
// - 老师/管理员:允许查看所有日记
// - 老师/管理员:允许查看所有日记,但排除其他用户的私密日记
// - 家长:应通过 parent_service 专用端点查看孩子日记
let author_id = if ctx.roles.iter().any(|r| r == "teacher" || r == "admin") {
// 管理角色可查看任意作者的日记
@@ -261,6 +261,11 @@ where
Some(ctx.user_id)
};
// 管理角色查看他人日记时,排除 is_private=true 的私密日记
// 学生查看自己的日记时,包含私密日记(那是他们自己的)
let exclude_private = ctx.roles.iter().any(|r| r == "teacher" || r == "admin")
&& author_id != Some(ctx.user_id);
let (items, total) = JournalService::list(
ctx.tenant_id,
author_id,
@@ -268,6 +273,7 @@ where
params.date_from,
params.date_to,
params.class_id,
exclude_private,
page,
page_size,
&state.db,

View File

@@ -217,6 +217,7 @@ impl JournalService {
/// 日记列表(分页 + 筛选)
///
/// 支持按作者、心情、日期范围、班级筛选。
/// `exclude_private` 为 true 时排除 is_private=true 的日记(管理端查看他人日记场景)。
/// 返回 (items, total)。
pub async fn list(
tenant_id: Uuid,
@@ -225,6 +226,7 @@ impl JournalService {
date_from: Option<chrono::NaiveDate>,
date_to: Option<chrono::NaiveDate>,
class_id: Option<Uuid>,
exclude_private: bool,
page: u64,
page_size: u64,
db: &DatabaseConnection,
@@ -248,6 +250,10 @@ impl JournalService {
if let Some(cid) = class_id {
condition = condition.add(journal_entry::Column::ClassId.eq(cid));
}
// 管理角色查看他人日记时,排除私密日记
if exclude_private {
condition = condition.add(journal_entry::Column::IsPrivate.eq(false));
}
let page_size = page_size.min(100).max(1);
let page = page.max(1);