Reputation: 111
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?
Upvotes: 1
Views: 662
Reputation: 3054
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.
Upvotes: 1