Skip to content

moderation-warning-event: AccountEvent::Warned + 通報「警告で解決」+ 警告履歴 API - #60

Merged
turtton merged 2 commits into
mainfrom
moderation-warning-event
Sep 3, 2026
Merged

turtton merged 2 commits into
mainfrom
moderation-warning-event

Conversation

@turtton

@turtton turtton commented Sep 3, 2026

Copy link
Copy Markdown
Member

概要

issue #59 の実装。モデレーションに「警告」処分を追加する (org-accounts grill Q10 の実装)。

変更点

kernel

  • AccountEvent::Warned { reason, warned_at } を新設 (serde: tag type / snake_case warned。account_events に event_name='warned' で保存)。apply() は version 更新のみで status は不変 (Active のまま)。AccountStatus / CHECK 制約に変更なし
  • Account::warn(id, reason, current_version) コマンド追加
  • ReportResolution::Warned を追加 (Resolved/Dismissed は後方互換)
  • AccountReadModel::find_warnings + AccountWarning { reason, warned_at } read model

application

  • WarnAccountUseCase / ListAccountWarningsUseCase (いずれも instance_moderate() 権限チェック、非権限は PermissionDenied → 403)
  • ResolveReportUseCase::warn_report: 通報を Warned でクローズ (close_reason 必須維持、二重クローズは従来通り Rejected/422)

driver (postgres)

  • account_events から event_name='warned' AND id=account_id の警告履歴 SQL (新テーブルなし)
  • 通報 projection の warned resolution 読み書き

server

  • POST /api/v1/admin/accounts/{id}/warnings — 警告発行 (204)
  • GET /api/v1/admin/accounts/{id}/warnings — 警告履歴 (200: [{reason, warned_at}])
  • POST /api/v1/admin/reports/{id}/resolve — body に optional resolution を追加し "warned" を受理 (省略/"resolved" は従来挙動 = 後方互換)。設計判断: 専用エンドポイント追加ではなく既存 resolve エンドポイントの拡張 (packet の推奨案)
  • openapi.json 再生成

検証

  • cargo fmt --check / cargo check --workspace / cargo clippy --workspace -- -D warnings: 全 PASS
  • cargo test --workspace: 266 passed / 0 failed / 227 ignored (ignored は DATABASE_URL 必須の既存 postgres/e2e テスト)
  • 新規テスト: kernel apply/serde ラウンドトリップ、WarnAccount (発行・権限なし拒否)、warn_report (closed イベントに Warned)、HTTP (warned 解決・警告発行/履歴・403)
  • git diff --check: clean

Closes #59

- kernel: AccountEvent::Warned { reason, warned_at } (event_name="warned")、Account::warn 追加。apply は version のみ更新し status は不変
- kernel: ReportResolution::Warned を追加 (resolved/dismissed は後方互換)
- application: WarnAccountUseCase / ListAccountWarningsUseCase / warn_report を instance_moderate チェック付きで追加
- driver: account_events (event_name='warned') から警告履歴を読む find_warnings、warned resolution の読み書き対応
- server: POST/GET /api/v1/admin/accounts/{id}/warnings、通報 resolve エンドポイントで resolution='warned' を受理 (省略/resolved は従来通り)
- ユースケース単体テスト + HTTP テスト: warn 発行・warned 解決・権限なし 403 (PermissionDenied)・二重クローズ拒否は既存経路で維持

Closes #59
@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.79279% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.28%. Comparing base (c33fe53) to head (6a6b04c).

Files with missing lines Patch % Lines
application/src/service/account/moderation.rs 91.48% 8 Missing ⚠️
server/src/route/account/admin.rs 91.48% 4 Missing ⚠️
server/src/route/report/admin.rs 75.00% 4 Missing ⚠️
driver/src/database/postgres/account/mod.rs 92.30% 2 Missing ⚠️
driver/src/database/postgres/account_report.rs 33.33% 2 Missing ⚠️
kernel/src/entity/account.rs 96.00% 2 Missing ⚠️
driver/src/database/postgres/projection.rs 0.00% 1 Missing ⚠️
server/src/schema/report.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   75.99%   76.28%   +0.28%     
==========================================
  Files         211      211              
  Lines       24601    24930     +329     
==========================================
+ Hits        18696    19018     +322     
- Misses       5905     5912       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…l 単独ビルドで macros feature 未解決のため CI 失敗)
@turtton turtton added intent-target intent-cli workflow label intent-pr-approved intent-cli workflow label labels Sep 3, 2026
@turtton
turtton merged commit c696210 into main Sep 3, 2026
12 checks passed
@turtton
turtton deleted the moderation-warning-event branch September 3, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

intent-pr-approved intent-cli workflow label intent-target intent-cli workflow label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

moderation-warning-event: AccountEvent::Warning 新設 + 通報「警告で解決」+ 警告履歴参照

1 participant