[英]Intercept ActiveRecord establish_connection initialization process
I am using Postgresql as my database and rails 3 as my middleware for a multi-tenant application. 我将Postgresql用作数据库,将Rails 3用作多租户应用程序的中间件。
I would like to set an environment variable containing currently logged in client id for every connection that gets created via establish_connection method. 我想设置一个环境变量,该环境变量包含通过build_connection方法创建的每个连接的当前登录的客户端ID。
Is there anyway I can intercept initialization process through any callbacks of establish_connection to set this environment variable? 无论如何,我可以通过Establishment_connection的任何回调设置此环境变量来拦截初始化过程吗?
I would lean towards separating data at the app level by something like an authority_level field. 我倾向于使用诸如Authority_level字段之类的方法在应用程序级别分离数据。 You could then have a "verify_permission(current_user)" method run as a before_filter. 然后,您可以将“ verify_permission(current_user)”方法作为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. 我们通常会这样做,并具有“ kick_user_out”方法,该方法会自动使用不敏感的参数强制注销和通过电子邮件发送管理员警报,以在特权升级时向管理员发出警报。 You get enough of those and the account gets locked as well. 您将获得足够的钱,并且帐户也将被锁定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.