拦截ActiveRecord建立_连接初始化过程
我使用 Postgresql 作为数据库,使用 Rails 3 作为多租户应用程序的中间件。
我想为通过建立连接方法创建的每个连接设置一个包含当前登录的客户端 ID 的环境变量。
无论如何,我可以通过建立连接的任何回调来拦截初始化过程来设置此环境变量吗?
I am using Postgresql as my database and rails 3 as my middleware for a multi-tenant application.
I would like to set an environment variable containing currently logged in client id for every connection that gets created via establish_connection method.
Is there anyway I can intercept initialization process through any callbacks of establish_connection to set this environment variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我倾向于通过诸如authority_level字段之类的东西来分离应用程序级别的数据。然后,您可以将“verify_permission(current_user)”方法作为 before_filter 运行。
我们通常会这样做,并有一个“kick_user_out”方法,该方法会自动强制注销并使用非敏感参数通过电子邮件发送管理员警报,以便在发生权限升级时向管理员发出警报。你得到了足够的这些,帐户也会被锁定。
I would lean towards separating data at the app level by something like an authority_level field. You could then have a "verify_permission(current_user)" method run as a before_filter.
We typically do this and have a "kick_user_out" method that automatically forces a logout and emailed admin alert with non-sensitive params for the purpose of alerting admins when a privilege escalation occurs. You get enough of those and the account gets locked as well.