简体   繁体   English

拦截ActiveRecord建立连接初始化过程

[英]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.

相关问题 了解establish_connection如何在ActiveRecord中工作 - Understanding how establish_connection works in ActiveRecord 在ActiveRecord模型上使用Establishment_connection时,AdapterNotSpecified - AdapterNotSpecified when using establish_connection on ActiveRecord model 动态子类化和ActiveRecord建立与PostgreSQL数据库的连接 - Dynamic Subclassing and ActiveRecord establish_connection with PostgreSQL database Rails无法使用ActiveRecord :: establish_connection连接到数据库 - Rails cant connect to database with ActiveRecord::establish_connection 测试和建立连接 - testing and establish_connection 建立连接':数据库配置指定不存在的mysql2适配器(ActiveRecord::AdapterNotFound) - establish_connection': database configuration specifies nonexistent mysql2 adapter (ActiveRecord::AdapterNotFound) 无法打开rails console:生成数据库未配置,establish_connection引发ActiveRecord :: AdapterNotSpecified - Can't open rails console: production database not configured, establish_connection raises ActiveRecord::AdapterNotSpecified 建立连接和耙任务在一起的问题 - issue with establish_connection and rake task together Rails-建立连接和嵌套表单 - Rails - establish_connection and nested forms 访问模型或表时建立连接 - establish_connection when accessing model or table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM