Added UserSummary type for UsersByIDs. - #38710
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ❌ 5❌ Failed checks (3 warnings, 2 inconclusive)
✏️ 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/datastore/mysql/users.go (1)
161-175: Use a summary-specific column list for UsersByIDs.Line 167 still selects
userSelectColumns, which includes password/salt. ForUserSummary, fetch only the required fields to reduce sensitive data exposure and I/O.♻️ Suggested refactor
const userSelectColumns = `id, created_at, updated_at, password, salt, name, email, admin_forced_password_reset, gravatar_url, position, sso_enabled, global_role, api_only, mfa_enabled, invite_id` + +const userSummarySelectColumns = `id, created_at, updated_at, name, email, + admin_forced_password_reset, gravatar_url, position, sso_enabled, global_role, + api_only, mfa_enabled, invite_id` @@ - query, args, err := sqlx.In( - fmt.Sprintf("SELECT %s FROM users WHERE id IN (?)", userSelectColumns), ids) + query, args, err := sqlx.In( + fmt.Sprintf("SELECT %s FROM users WHERE id IN (?)", userSummarySelectColumns), ids)
🤖 Fix all issues with AI agents
In `@server/fleet/users.go`:
- Around line 15-31: Remove the sensitive Password and Salt fields from the
UserSummary struct so credential material is not carried in the minimal summary
type (modify the type declaration for UserSummary to delete the Password and
Salt fields); ensure only the full User struct retains password/salt storage;
update any code that constructs or scans into UserSummary (e.g., functions that
map/scan from DB rows or convert User -> UserSummary) to stop copying or
selecting those columns (remove password/salt from SELECTs or mapping logic) and
run tests to confirm no compile or query errors.
There was a problem hiding this comment.
Pull request overview
This PR introduces a new UserSummary type to replace the full User type in the UsersByIDs method. The change is primarily aimed at optimizing data retrieval by returning only the essential user fields needed for enriching activities.
Changes:
- Introduced
UserSummarytype containing a subset ofUserfields (excludingTeams,Settings, andDeletedfields) - Updated
UsersByIDsmethod signature across all layers (service, datastore, mocks, and interfaces) to return[]*fleet.UserSummaryinstead of[]*fleet.User - Updated the activity ACL adapter's
convertUserfunction to accept*fleet.UserSummaryinstead of*fleet.User
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server/fleet/users.go | Defines new UserSummary struct with essential user fields |
| server/fleet/service.go | Updates UsersByIDs interface method signature to return UserSummary |
| server/fleet/datastore.go | Updates UsersByIDs datastore interface to return UserSummary |
| server/service/users.go | Updates service implementation to return UserSummary |
| server/datastore/mysql/users.go | Updates MySQL implementation to query and return UserSummary |
| server/acl/activityacl/fleet_adapter.go | Updates adapter to convert UserSummary to activity.User |
| server/mock/service/service_mock.go | Updates service mock function signature |
| server/mock/datastore_mock.go | Updates datastore mock function signature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #38710 +/- ##
==========================================
- Coverage 66.07% 66.07% -0.01%
==========================================
Files 2414 2414
Lines 192683 192683
Branches 8529 8529
==========================================
- Hits 127321 127320 -1
Misses 53799 53799
- Partials 11563 11564 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@iansltx I'm assigning this PR to you, since it addresses your previous PR review comment. |
Related issue: Resolves #38234
Addresses Ian's suggestion from activity bounded context code review.
Checklist for submitter
Testing
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.