Skip to content

Refactor the Home password-change flow #4815

Open

Description

@coderabbitai

Summary

Refactor the password-change flow in app/Controllers/Home.php to improve readability and reduce nesting while preserving its behavior.

Consider private helpers for the shared admin-or-self authorization check, verification of the logged-in employee's current password, and repeated password-change JSON responses. Use early returns where useful. Keep the authorization responses for getChangePassword() and postSave() distinct.

Acceptance criteria

  • getChangePassword() and postSave() retain their admin-or-self authorization behavior and existing 403 response formats.
  • An admin changing another employee's password must verify the logged-in admin's current password. A submitted username must not change the verification identity or the account username.
  • Password length validation, hashing, save behavior, and existing success and failure response formats remain unchanged.
  • Controller-level tests cover admin and non-admin targets, invalid current passwords, short passwords, save failures, and response formats.

Requested by: @objecttothis

Pull request: #4813
Discussion: #4813 (comment)

Activity

  1. objecttothis commented on Nov 16, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Status: Still present / not yet implemented on master.

    app/Controllers/Home.php on master still contains the original, unrefactored password-change flow: getChangePassword() and postSave() both duplicate the admin-or-self authorization check (!$this->employee->isAdmin($currentPersonId) && $employeeId !== $currentPersonId) inline, and postSave() repeats the same JSON response shape (success/message/id) in multiple branches with a deeply nested if/else rather than early returns or private helpers. There are no private helper methods for the authorization check, current-password verification, or response building, and no app/Controllers/Home.php-specific test additions matching the acceptance criteria (admin/non-admin targets, invalid current password, short password, save failure) appear to be merged.

    The linked PR (#4813) does not appear to be merged into master yet (no refactor markers found in the current file). I could not find a corresponding commit message referencing this refactor in recent history.

    Confidence: High that the refactor has not landed, based on direct inspection of the current app/Controllers/Home.php source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions