Skip to content

feat(logs): 支持用量日志显示 IP 列#5644

Open
fanfan813 wants to merge 1 commit into
QuantumNous:mainfrom
fanfan813:codex/usage-log-ip-pr
Open

feat(logs): 支持用量日志显示 IP 列#5644
fanfan813 wants to merge 1 commit into
QuantumNous:mainfrom
fanfan813:codex/usage-log-ip-pr

Conversation

@fanfan813

@fanfan813 fanfan813 commented Jun 21, 2026

Copy link
Copy Markdown

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

本 PR 为用量日志增加可选的 IP 列展示能力,虽然IP信息已经在使用日志的详情列里有了,但每次都要点开,这里直接通过开关控制将IP显示在列表上,更直观。

主要变更:

  • 在用户设置中增加“显示 IP 列”配置项。
  • 在用量日志表格中根据用户设置显示或隐藏 IP 列。
  • 开启显示 IP 列后,使用日志列表同步展示 IP 信息。
  • 补充前端类型与多语言文案。

该功能默认不改变现有日志表格展示,只有开启对应设置后才显示 IP 列。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

  • Closes # (如有)

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 本 PR 未标记为 Bug fix。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过前端类型检查与 i18n 同步。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

本地验证命令:
image

个人资料 - 设置与偏好 - 在使用日志中显示 IP
image

使用日志 列表 显示IP地址
image

该功能默认不改变现有日志表格展示,只有开启对应设置后才显示 IP 列。

补充说明:本 PR 与 #5055 都涉及用量日志中的 IP 展示,但实现目标不同。本 PR 范围更聚焦,新增用户偏好开关 show_ip_in_logs,默认不改变现有表格展示,只有用户显式开启后才显示 IP 列;#5055 则是更完整的日志表格增强,包含管理员 IP 列、用户信息和移动端可见性调整等内容。

本 PR 由 AI 辅助完成,并已由提交者人工检查和整理。
This PR was AI-assisted and manually reviewed by the submitter.

Summary by CodeRabbit

  • New Features
    • Added a profile setting to control whether IP addresses are displayed in usage logs, including an updated preference UI and conditional table/mobile rendering.
    • Added the corresponding backend support to persist and apply the setting consistently.
    • Included new translations for the IP display option across supported languages.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 23072280-2c89-4890-b14b-4b6a8fe5511b

📥 Commits

Reviewing files that changed from the base of the PR and between c8a3a25 and 89ffde6.

📒 Files selected for processing (14)
  • controller/user.go
  • dto/user_settings.go
  • web/default/src/features/profile/components/tabs/notification-tab.tsx
  • web/default/src/features/profile/types.ts
  • web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx
  • web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx
  • web/default/src/features/usage-logs/lib/columns.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json
✅ Files skipped from review due to trivial changes (5)
  • web/default/src/i18n/locales/zh.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/ja.json
🚧 Files skipped from review as they are similar to previous changes (8)
  • dto/user_settings.go
  • controller/user.go
  • web/default/src/features/profile/components/tabs/notification-tab.tsx
  • web/default/src/i18n/locales/fr.json
  • web/default/src/features/profile/types.ts
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx
  • web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx
  • web/default/src/i18n/locales/en.json

Walkthrough

Adds a show_ip_in_logs boolean user setting. The Go DTO and controller are extended to persist the field. The React profile page gains a new "Show IP in Usage Logs" toggle that saves and merges the value into the auth store. The usage-logs table reads this setting to conditionally render an IP Address column, and all six supported locales receive the new translation keys.

Changes

Show IP in Usage Logs

Layer / File(s) Summary
Backend DTO and API handler
dto/user_settings.go, controller/user.go
UserSetting struct gains ShowIpInLogs boolean; UpdateUserSettingRequest exposes it as optional pointer; handler derives the value with existing settings fallback and preserves sidebar/billing/language fields.
Frontend types and profile settings UI
web/default/src/features/profile/types.ts, web/default/src/features/profile/components/tabs/notification-tab.tsx
UserSettings and UpdateUserSettingsRequest interfaces gain show_ip_in_logs; NotificationTab initialises, hydrates from profile data, saves via API, and merges the flag into auth store; IP preferences section reworked into responsive grid with new Show IP in Usage Logs toggle.
Usage logs column pipeline and IP rendering
web/default/src/features/usage-logs/lib/columns.ts, web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx
useColumnsByCategory and useCommonLogsColumns accept showIpInLogs parameter; IP Address column conditionally appended with Globe icon, StatusBadge rendering, and copyText support.
Table integration and mobile view
web/default/src/features/usage-logs/components/usage-logs-table.tsx, web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
UsageLogsTable reads user setting from auth store via safe getShowIpInLogsSetting helper (supporting JSON-string or object format) and passes it to column pipeline; CommonLogsCard adds IP Address summary field for mobile.
i18n translations
web/default/src/i18n/locales/*.json
Two new translation keys added across English, French, Japanese, Russian, Vietnamese, and Chinese locales.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant NotificationTab
  participant API
  participant useAuthStore
  participant UsageLogsTable
  participant useCommonLogsColumns

  User->>NotificationTab: toggles "Show IP in Usage Logs"
  NotificationTab->>API: PATCH /user/setting {show_ip_in_logs: true}
  API-->>NotificationTab: 200 OK
  NotificationTab->>useAuthStore: setUser with merged show_ip_in_logs=true
  UsageLogsTable->>useAuthStore: reads user.setting
  UsageLogsTable->>UsageLogsTable: getShowIpInLogsSetting → showIpInLogs=true
  UsageLogsTable->>useCommonLogsColumns: useColumnsByCategory(..., showIpInLogs=true)
  useCommonLogsColumns-->>UsageLogsTable: columns including IP Address column
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

A bunny hopped through logs one day,
"Where did that IP address go?" it did say.
A toggle was born, a setting most fine,
Now Globe icons glow in every log line!
🌐🐇 The IP appears when you want it to shine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main feature: adding support for displaying IP columns in usage logs. It directly aligns with the primary objective of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controller/user.go`:
- Line 1210: The ShowIpInLogs field at line 1210 is defined as a non-pointer
bool, which causes JSON unmarshalling to default omitted fields to false instead
of nil. This causes the update logic at line 1313 to overwrite existing true
values with false when clients don't include this field. Change the ShowIpInLogs
field definition from bool to *bool (pointer to bool) so that omitted JSON
values remain nil, allowing the update logic to preserve previously stored
values when the field is not provided by the client.

In
`@web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx`:
- Around line 813-835: The IP column definition is not respecting the
sensitiveVisible masking flag that other sensitive columns use in this file. Add
a check in the cell function of the IP column to conditionally mask the IP value
when sensitiveVisible is false, similar to how other sensitive data columns
handle masking. When sensitive mode is off, display a masked representation
(like asterisks or dashes) instead of the actual IP address in the StatusBadge
component.

In `@web/default/src/features/usage-logs/lib/columns.ts`:
- Around line 32-38: In the useColumnsByCategory function signature, replace the
return type ColumnDef<any>[] with ColumnDef<Record<string, unknown>>[] to
eliminate the explicit any type. This change provides better type safety while
maintaining the necessary flexibility for the function to return column
definitions for different log types (UsageLog, MidjourneyLog, and TaskLog)
without relying on the any type escape hatch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 643cfed9-77c9-47ae-abf0-d7a37bffd4bf

📥 Commits

Reviewing files that changed from the base of the PR and between 0b7ae4e and c8a3a25.

📒 Files selected for processing (14)
  • controller/user.go
  • dto/user_settings.go
  • web/default/src/features/profile/components/tabs/notification-tab.tsx
  • web/default/src/features/profile/types.ts
  • web/default/src/features/usage-logs/components/columns/common-logs-columns.tsx
  • web/default/src/features/usage-logs/components/usage-logs-mobile-card.tsx
  • web/default/src/features/usage-logs/components/usage-logs-table.tsx
  • web/default/src/features/usage-logs/lib/columns.ts
  • web/default/src/i18n/locales/en.json
  • web/default/src/i18n/locales/fr.json
  • web/default/src/i18n/locales/ja.json
  • web/default/src/i18n/locales/ru.json
  • web/default/src/i18n/locales/vi.json
  • web/default/src/i18n/locales/zh.json

Comment thread controller/user.go Outdated
Comment thread web/default/src/features/usage-logs/lib/columns.ts
@fanfan813 fanfan813 force-pushed the codex/usage-log-ip-pr branch from c8a3a25 to 89ffde6 Compare June 21, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant