Skip to content

feat: add linux_do_id field to EditUserModal form - #2534

Closed
HenryXiaoYang wants to merge 3 commits into
QuantumNous:mainfrom
HenryXiaoYang:main
Closed

feat: add linux_do_id field to EditUserModal form#2534
HenryXiaoYang wants to merge 3 commits into
QuantumNous:mainfrom
HenryXiaoYang:main

Conversation

@HenryXiaoYang

@HenryXiaoYang HenryXiaoYang commented Dec 26, 2025

Copy link
Copy Markdown

管理员面板>用户管理>编辑用户缺失了linux_do_id
加上能有效帮助管理员查看newapi用户绑定了哪个linux do账号

Summary by CodeRabbit

  • New Features

    • Edit user modal shows an additional read-only ID field for clarity.
    • Enhanced user search: selectable search field plus multi-criteria filters and preserved pagination/group scoping.
    • Users can pick a specific field to search (via a new select) with updated search input placeholder.
  • Localization

    • Added a new "Fuzzy search (ID/Username/Display name/Email)" translation across locales.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 26, 2025 17:54
@coderabbitai

coderabbitai Bot commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Add field-based user search and propagate a new searchField/filter parameter across frontend hooks and UI; extend backend SearchUsers to accept explicit filters (including linux_do_id) and apply them in the model query; add locale entries and display linux_do_id as a read-only binding in the EditUser modal.

Changes

Cohort / File(s) Summary
Frontend — User search hook & form
web/src/hooks/users/useUsersData.jsx, web/src/components/table/users/UsersFilters.jsx
Introduced searchField in form state and API flow; searchUsers now optionally sends a field-specific query param instead of keyword; UI adds a select for searchField.
Frontend — Edit modal
web/src/components/table/users/modals/EditUserModal.jsx
Added linux_do_id to the array of read-only binding inputs so it renders as a read-only field in the user edit modal.
Backend — Controller
controller/user.go
SearchUsers handler collects multiple query params into a filters map (github_id, discord_id, oidc_id, wechat_id, email, telegram_id, linux_do_id) and calls model.SearchUsers with the new filters parameter.
Backend — Model / DB
model/user.go
SearchUsers signature extended to accept filters map[string]string; applies exact-match filters before pagination and separates keyword/group logic; retains transactional query handling.
Localization
web/src/i18n/locales/*.json (en.json, fr.json, ja.json, ru.json, vi.json, zh.json)
Added a new translation key "模糊搜索 (ID/用户名/显示名/邮箱)" with localized values for several locales.

Sequence Diagram(s)

sequenceDiagram
    participant Browser as Browser (UI)
    participant Frontend as Frontend Hook
    participant Server as API Server (controller)
    participant Model as Model Layer
    participant DB as Database

    Browser->>Frontend: user selects searchField + value
    Frontend->>Server: GET /api/users?{<searchField>=value}&group=&start=&size
    Server->>Model: SearchUsers(keyword="", group, filters{<searchField>:value}, start, size)
    Model->>DB: Build query -> apply exact-match filters + keyword/group conditions -> execute
    DB-->>Model: rows, total
    Model-->>Server: users list, total
    Server-->>Frontend: 200 OK {users, total}
    Frontend-->>Browser: render results
    note over Model,DB: Filters (e.g., linux_do_id) applied as exact matches
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024
  • seefs001
  • Calcium-Ion

Poem

🐰 I sniffed the code and gave a hop,
A new small field — a tidy stop.
Filters flow from form to DB,
linux_do_id now in harmony.
A tiny change, a joyful hop! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to add linux_do_id field to EditUserModal form, but the changeset includes extensive user search filtering functionality across backend and frontend, plus i18n translations—far exceeding the stated scope. Update the title to reflect the primary change: 'feat: add user search filtering by field (linux_do_id, github_id, etc.) with i18n support' or similar, accurately capturing the full scope of this multi-component feature.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds the linux_do_id field to the EditUserModal form in the admin panel's user management section, enabling administrators to view which Linux DO account a user has bound.

Key Changes

  • Added 'linux_do_id' to the array of third-party account binding fields displayed in the user edit modal

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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: 0

🧹 Nitpick comments (4)
web/src/i18n/locales/en.json (1)

1252-1252: Align capitalization with existing “Display Name” usage

The English label is correct, but elsewhere this project uses “Display Name” (capital N). To keep UI text consistent, consider:

Proposed capitalization tweak
-    "模糊搜索 (ID/用户名/显示名/邮箱)": "Fuzzy search (ID/Username/Display name/Email)",
+    "模糊搜索 (ID/用户名/显示名/邮箱)": "Fuzzy search (ID/Username/Display Name/Email)",
web/src/components/table/users/UsersFilters.jsx (1)

20-21: Search-field selector is correctly wired to backend filters

The filterFields options align with the backend’s allowed filter keys, and the new searchField select integrates cleanly with the form and useUsersData hook. This gives a clear toggle between fuzzy search (empty value) and exact field filters (GitHub/Discord/OIDC/WeChat/Email/Telegram/LinuxDO), which is exactly what the new API expects.

If you want full i18n coverage later, consider localizing the non-default labels ('GitHub ID', 'Discord ID', etc.) and ensure the '输入搜索值' placeholder key exists in all locales, but this is not blocking.

Also applies to: 38-47, 75-83, 88-88

controller/user.go (1)

290-304: SearchUsers controller correctly forwards structured filters

The new filters map cleanly whitelists the supported ID/email fields and passes them to model.SearchUsers, which keeps field names under server control while allowing the frontend to send dynamic filters. This matches the model’s column definitions and the new searchField client logic.

If this list grows, consider centralizing the allowed filter keys (e.g., a shared constant or helper) to avoid drift between controller and model.

model/user.go (1)

222-290: SearchUsers filter logic matches the new API contract

The refactored SearchUsers correctly combines:

  • exact-match filters from a server-controlled filters map,
  • optional fuzzy keyword search (with numeric support for id),
  • and optional group scoping,

all within a single query that omits the password field. Column names in filters match the User model’s gorm tags, so the generated SQL is valid for the new controller wiring.

For future safety, you might consider mapping a fixed set of logical filter keys to column names (rather than using the map key directly in Where(field+" = ?", ...)) and, if you don’t depend on transactional semantics here, dropping the explicit transaction to simplify the read path; these are quality-of-implementation tweaks, not blockers.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23fcf4f and 665a02c.

📒 Files selected for processing (10)
  • controller/user.go
  • model/user.go
  • web/src/components/table/users/UsersFilters.jsx
  • web/src/hooks/users/useUsersData.jsx
  • web/src/i18n/locales/en.json
  • web/src/i18n/locales/fr.json
  • web/src/i18n/locales/ja.json
  • web/src/i18n/locales/ru.json
  • web/src/i18n/locales/vi.json
  • web/src/i18n/locales/zh.json
🧰 Additional context used
🧬 Code graph analysis (3)
model/user.go (1)
controller/user.go (1)
  • SearchUsers (290-313)
controller/user.go (2)
common/page_info.go (1)
  • GetPageQuery (41-82)
model/user.go (1)
  • SearchUsers (222-290)
web/src/hooks/users/useUsersData.jsx (1)
web/src/hooks/channels/useChannelsData.jsx (1)
  • getFormValues (303-310)
🔇 Additional comments (7)
web/src/i18n/locales/ru.json (1)

1269-1269: Fuzzy-search Russian translation is accurate and consistent

The Russian string correctly reflects the Chinese key and matches the style of surrounding entries. No functional issues here.

web/src/i18n/locales/ja.json (1)

1192-1192: LGTM! Translation is accurate and consistent.

The Japanese translation for the fuzzy search feature is correct:

  • "あいまい検索" accurately conveys "fuzzy search"
  • Field names (ID/ユーザー名/表示名/メール) are properly localized
  • Formatting and structure align with existing entries
web/src/i18n/locales/fr.json (1)

1260-1260: LGTM! Translation is accurate and follows French conventions.

The French translation for the fuzzy search feature is correct:

  • "Recherche floue" accurately translates "fuzzy search"
  • Field names (Nom d'utilisateur/Nom affiché/Email) are appropriately localized
  • Keeping "Email" in English is standard practice in French localization
  • Formatting and structure align with existing entries
web/src/i18n/locales/vi.json (1)

2439-2439: Fuzzy-search label translation looks correct and consistent

The new Vietnamese entry for the fuzzy-search label is accurate and matches the cross-locale key structure; no changes needed.

web/src/i18n/locales/zh.json (1)

1242-1242: Chinese fuzzy-search key wired correctly

The added zh entry for “模糊搜索 (ID/用户名/显示名/邮箱)” is consistent and enables i18n lookup for the new UI label.

controller/user.go (1)

456-482: linux_do_id is now exposed in GetSelf as intended

Adding "linux_do_id": user.LinuxDOId to the self payload is consistent with the User JSON tags and allows the admin UI to display the LinuxDO binding without exposing any new sensitive data.

web/src/hooks/users/useUsersData.jsx (1)

47-51: Hook correctly propagates searchField to the search API

useUsersData now threads searchField from form state into searchUsers and encodes it as either a fuzzy keyword or an exact field filter in the URL, depending on whether searchField is empty. The pagination handlers and refresh path all reuse getFormValues, so search behavior stays consistent across page changes and reloads.

Also applies to: 56-64, 91-104, 113-126, 207-214, 243-249

@HenryXiaoYang

Copy link
Copy Markdown
Author

草 忘branch了

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.

2 participants