dosubot[bot] commented on issue #35594:
URL: https://github.com/apache/superset/issues/35594#issuecomment-3388106436

   <!-- Answer -->
   Superset 3.1.1 does not provide built-in event triggers for user management 
CRUD actions like add, edit, or delete user. These actions are handled mainly 
in the `SupersetUserApi` and `SupersetSecurityManager` classes, which use Flask 
AppBuilder (FAB) views for user management, but do not emit log events for 
these operations by default 
[reference](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/security/manager.py).
   
   To implement auditing for user management actions, you’ll need to instrument 
the relevant methods yourself. The most maintainable approaches are:
   
   - **Subclass or monkey-patch the relevant FAB views or API classes** (like 
`SupersetUserApi` or `UserView`) and add calls to your custom logger in the 
methods that handle user creation, update, and deletion.
   - **Use SQLAlchemy model events** (such as `after_insert`, `after_update`, 
`after_delete`) on the User model to trigger logging when user records are 
changed 
[reference](https://github.com/apache/superset/blob/master/superset/models/core.py).
   
   For example, you could add a SQLAlchemy event listener in your 
`superset_config.py`:
   
   ```python
   from sqlalchemy import event
   from flask_appbuilder.security.sqla.models import User
   
   def log_user_event(mapper, connection, target):
       # Replace with your custom logging logic
       EVENT_LOGGER.log(target.id, "user_update", details={"username": 
target.username})
   
   event.listen(User, 'after_update', log_user_event)
   event.listen(User, 'after_insert', log_user_event)
   event.listen(User, 'after_delete', log_user_event)
   ```
   
   Or, if you prefer to patch the view logic, override the relevant methods in 
your custom view and call your logger there.
   
   This approach keeps your changes outside the core Superset code, making 
upgrades easier. Just make sure to test after each upgrade, as internal APIs 
may change.
   
   Let me know if you want more detailed examples for a specific method or 
integration!
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/5abf3b06-621e-4697-aaba-6e299fa61d7b?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat
 with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=githu
 b)&nbsp;[![Join 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/35594)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to