Skip to content

feat: add missing CRUD hooks and auth event hooks#2450

Open
dpgaspar wants to merge 1 commit intomasterfrom
feat/audit-hooks
Open

feat: add missing CRUD hooks and auth event hooks#2450
dpgaspar wants to merge 1 commit intomasterfrom
feat/audit-hooks

Conversation

@dpgaspar
Copy link
Copy Markdown
Owner

@dpgaspar dpgaspar commented Apr 2, 2026

Summary

  • Add missing post_add/post_update hook calls in UserApi.post()/put() and GroupApi.post()/put() — these custom overrides were skipping the hooks that ModelRestApi normally calls
  • Add on_user_login, on_user_login_failed, and on_user_logout overridable methods on BaseSecurityManager for audit logging and custom auth event handling
  • Call on_user_login/on_user_login_failed from update_user_auth_stat() and on_user_logout from all logout views (including SAML SLO)
  • Uses get_user_by_id(g.user.id) to resolve the user before logout_user() since g.user is a LocalProxy that would resolve to anonymous after logout

Test plan

  • 8 new tests in tests/test_hooks.py — all passing
    • UserApi: post_add called on POST, post_update called on PUT
    • GroupApi: post_add called on POST, post_update called on PUT
    • on_user_login called on successful login
    • on_user_login_failed called on bad password
    • on_user_logout called on browser logout
    • Hooks receive correct User model instance

🤖 Generated with Claude Code

@dpgaspar dpgaspar force-pushed the feat/audit-hooks branch 3 times, most recently from 6b6d813 to fbdf1a1 Compare April 2, 2026 13:30
Add post_add/post_update calls to UserApi and GroupApi post()/put()
methods which were skipping these hooks unlike the base ModelRestApi.

Add on_user_login, on_user_login_failed, and on_user_logout overridable
hooks to BaseSecurityManager for audit logging and custom auth event
handling. Called from update_user_auth_stat and logout views respectively.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant