fix: apply group filter to channel list queries#4885
Conversation
WalkthroughThis PR refactors channel query construction by extracting shared filtering and pagination logic into new helper functions in ChangesChannel Query Refactoring with Shared Helpers
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
model/channel.go (3)
155-161: 💤 Low valueAdd documentation for exported function.
The exported function
ApplyChannelGroupFilterlacks a doc comment explaining its purpose and usage.📝 Suggested documentation
+// ApplyChannelGroupFilter applies a group membership filter to the query. +// Filters channels whose comma-delimited Group column contains the specified group. +// Returns the query unchanged if group is empty, "all", or "null". func ApplyChannelGroupFilter(query *gorm.DB, group string) *gorm.DB {🤖 Prompt for 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. In `@model/channel.go` around lines 155 - 161, Add a doc comment for the exported ApplyChannelGroupFilter function describing its purpose and usage: explain that ApplyChannelGroupFilter normalizes the provided group using NormalizeChannelGroupFilter, returns the unchanged query when the normalized group is empty, and otherwise applies a WHERE clause using channelGroupFilterCondition() with channelGroupFilterPattern(group); mention expected input format for group (if any) and that it returns a *gorm.DB for chaining.
131-137: 💤 Low valueAdd documentation for exported function.
The exported function
NormalizeChannelGroupFilterlacks a doc comment. Consider adding one to explain its purpose and the special handling of "all" and "null" keywords.📝 Suggested documentation
+// NormalizeChannelGroupFilter sanitizes group filter input. +// Returns empty string for no filter (empty, "all", or "null" values). +// Note: literal group name "null" cannot be filtered due to keyword conflict. func NormalizeChannelGroupFilter(group string) string {🤖 Prompt for 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. In `@model/channel.go` around lines 131 - 137, Add a Go doc comment for the exported function NormalizeChannelGroupFilter that succinctly explains what the function does (trims whitespace and normalizes empty/"all"/"null" group values to an empty string) and documents the special-case handling of case-insensitive "all" and "null" keywords; place the comment immediately above the NormalizeChannelGroupFilter declaration so it is picked up by godoc and other tooling.
139-153: 💤 Low valueConsider adding inline comments for clarity.
The LIKE escape logic in
channelGroupFilterPatternand the comma-wrapping technique inchannelGroupFilterConditionare subtle. Adding brief inline comments would help future maintainers understand the pattern-matching strategy.📝 Suggested comments
func channelGroupFilterCondition() string { + // Wrap group column with commas to match groups in comma-delimited lists + // e.g., "vip,default" becomes ",vip,default," to match "%,vip,%" if common.UsingMySQL { return `CONCAT(',', ` + commonGroupCol + `, ',') LIKE ? ESCAPE '!'` } return `(',' || ` + commonGroupCol + ` || ',') LIKE ? ESCAPE '!'` } func channelGroupFilterPattern(group string) string { + // Escape LIKE wildcards to treat user input as literal string group = strings.NewReplacer( "!", "!!", "%", "!%", "_", "!_", ).Replace(group) + // Match group in comma-delimited list: ",vip,default," LIKE "%,vip,%" return "%," + group + ",%" }🤖 Prompt for 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. In `@model/channel.go` around lines 139 - 153, Add brief inline comments in channelGroupFilterCondition and channelGroupFilterPattern explaining the matching strategy: note that we wrap the stored comma-separated group list with commas to avoid partial matches (e.g., matching "dev" vs "devops"), explain the DB-specific concatenation/CONCAT vs '||' choice, and describe the escaping in channelGroupFilterPattern (replacing '!', '%', '_' and using ESCAPE '!' so wildcards are treated literally). Place these comments immediately above or inside the respective functions (channelGroupFilterCondition and channelGroupFilterPattern) so maintainers can quickly understand why the comma-wrapping and escape sequence are used.
🤖 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.
Nitpick comments:
In `@model/channel.go`:
- Around line 155-161: Add a doc comment for the exported
ApplyChannelGroupFilter function describing its purpose and usage: explain that
ApplyChannelGroupFilter normalizes the provided group using
NormalizeChannelGroupFilter, returns the unchanged query when the normalized
group is empty, and otherwise applies a WHERE clause using
channelGroupFilterCondition() with channelGroupFilterPattern(group); mention
expected input format for group (if any) and that it returns a *gorm.DB for
chaining.
- Around line 131-137: Add a Go doc comment for the exported function
NormalizeChannelGroupFilter that succinctly explains what the function does
(trims whitespace and normalizes empty/"all"/"null" group values to an empty
string) and documents the special-case handling of case-insensitive "all" and
"null" keywords; place the comment immediately above the
NormalizeChannelGroupFilter declaration so it is picked up by godoc and other
tooling.
- Around line 139-153: Add brief inline comments in channelGroupFilterCondition
and channelGroupFilterPattern explaining the matching strategy: note that we
wrap the stored comma-separated group list with commas to avoid partial matches
(e.g., matching "dev" vs "devops"), explain the DB-specific concatenation/CONCAT
vs '||' choice, and describe the escaping in channelGroupFilterPattern
(replacing '!', '%', '_' and using ESCAPE '!' so wildcards are treated
literally). Place these comments immediately above or inside the respective
functions (channelGroupFilterCondition and channelGroupFilterPattern) so
maintainers can quickly understand why the comma-wrapping and escape sequence
are used.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02687f45-c011-457b-b9b0-93b6aecb51d1
📒 Files selected for processing (2)
controller/channel.gomodel/channel.go
# Conflicts: # controller/channel.go
Merged 28 commits from QuantumNous/new-api upstream/main, including: Backend: - feat: support request_header key source (QuantumNous#4903) - fix: apply group filter to channel list queries (QuantumNous#4885, QuantumNous#4847) - fix: enforce header nav access control for public modules (QuantumNous#4889) - fix: correct usage logs filtering (QuantumNous#4883) - fix: allow clearing channel remark (QuantumNous#4886) - feat: track upstream request ID and prevent response header override - feat: require compliance confirmation for paid features Frontend: - fix: 修复新 UI 语言与文案显示问题 (QuantumNous#4876) - fix(web): handle unlimited API key quota validation (QuantumNous#4881) - fix(web/default): batch fix new UI issues (QuantumNous#4880, QuantumNous#4893, QuantumNous#4817, QuantumNous#4877, QuantumNous#4898) - fix: prevent combobox from over-filtering options on focus (QuantumNous#4829) - fix(default): support DropdownMenuItem onSelect (QuantumNous#4787) - chore(deps): bump axios to 1.15.2 Conflict resolution: - Locale JSONs: union merge (design overrides preserved, upstream new keys added) - router/api-router.go: kept design /public/session route, accepted upstream HeaderNavModuleAuth - common-logs-filter-bar.tsx: kept design refactor, added upstream upstreamRequestId field - summary-cards.tsx: kept design layout, adapted to new useSummaryCardsConfig interface - _reports/*.untranslated.json: design state kept (fr/vi removed, ja/ru ours) - Other UI conflicts resolved per .gitattributes ours strategy Co-authored-by: Cursor <cursoragent@cursor.com>
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
修复渠道页面中,分组筛选不生效
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)


Summary by CodeRabbit