Skip to content

Credit the acting admin on updated_by across user account actions - #2023

Merged
maebeale merged 4 commits into
mainfrom
maebeale/attribute-user-updates
Jul 29, 2026
Merged

Credit the acting admin on updated_by across user account actions#2023
maebeale merged 4 commits into
mainfrom
maebeale/attribute-user-updates

Conversation

@maebeale

@maebeale maebeale commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

🤖 suggested review level: 3 Read 📖 small, contained attribution fixes with existing test coverage

What is the goal of this PR and why is this important?

Follow-up to #2022. Several actions write the user record (bumping updated_at) but left updated_by crediting whoever last edited the account instead of who took the action — the same wrong attribution Rachel reported for the welcome invite.

Admin actions — credit the acting admin:

  • users_controller#toggle_lock_status — lock/unlock
  • users_controller#confirm_email — manual confirm
  • users_controller#send_reset_password_instructions
  • UserServices::ProcessEmailChange — already took current_user, never applied it
  • UserServices::ProcessEmailManualConfirm — resend + confirm; same

Public setup page — welcome_controller#update (invited user sets their password):

  • Credit the signed-in admin if one is acting on the user's behalf, otherwise the account owner (current_user || @user) — never whoever last edited the account.

How did you approach the change?

  • Set updated_by at each write path (TDD: failing request/service specs first).
  • Devise's send_confirmation_instructions only saves when it regenerates a token, so the two services persist the attribution themselves (save(validate: false) if changed?) — a no-op when Devise already saved.

Anything else to add?

Deliberately out of scope: BulkInviteService (runs from rake/console, no current_user) and the people_controller nested-user autosave path.

Several admin actions write the user record (bumping updated_at) but left
updated_by pointing at whoever last edited the account — the same wrong
attribution fixed for the welcome invite in #2022. Lock/unlock, manual email
confirmation, and sending reset-password instructions all go through the
controller; email-change and manual-confirm services already accepted
current_user but never applied it. Set updated_by to the actor in each path.

The Devise confirmation flows only save when they regenerate a token, so the
services persist the attribution themselves when it's left dirty.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 02:44

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The welcome/setup flow bumps the user's updated_at but no admin is acting, so
leaving updated_by credited whoever created or invited the account. Null it out
since the actor is the account owner, not a staff member. Trim the attribution
comments added in the prior commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 03:22

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@maebeale
maebeale marked this pull request as ready for review July 29, 2026 11:26
@maebeale
maebeale requested a review from jmilljr24 July 29, 2026 11:27
@maebeale

Copy link
Copy Markdown
Collaborator Author

@jmilljr24 I merged the welcome instructions, and think we should do these too. You good w it?

Comment thread app/controllers/welcome_controller.rb Outdated
if @user.update(password_params)
# The invited user sets their own password here — no admin is acting, so clear
# updated_by rather than leaving it crediting whoever created/invited the account.
if @user.update(password_params.merge(updated_by: nil))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm missing why would wouldn't want to know that the user updated their account and/or if we don't care about that, we now clear out which admin last updated the account by setting nil.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@jmilljr24 yeah i went back and forth on this one. the button is accessible publicly, so it could've been pressed by the user, or, it could've been pressed by the admin on their behalf. i'm going to update it so if there is current_user, use that, otherwise credit it to the user. then we handle my concern and yours!

@maebeale maebeale Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 From Claude: Done in c49402dupdated_by: current_user || @user, so a signed-in user is credited and otherwise the account owner is.

The welcome page is public — the invited user may set their own password, or an
admin may do it on their behalf. Setting updated_by to nil (prior commit) lost
the admin attribution Justin flagged. Use current_user when present, otherwise
the account owner, so we never fall back to whoever last edited the account.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 12:11

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

current_user isn't necessarily an admin — reword to reflect it's whoever is
signed in.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 12:13

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@maebeale
maebeale merged commit fc0473d into main Jul 29, 2026
3 checks passed
@maebeale
maebeale deleted the maebeale/attribute-user-updates branch July 29, 2026 12:20
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.

3 participants