基于会话数据的验证,子域之间共享数据
我们正在构建一个产品支持应用程序。这个想法是拥有多个子域,每个子域都用于支持其他组织的产品。我们将此称为帐户 - 每个帐户都与一个子域绑定。 用户也有角色 - 但是,用户可以在 account1 上拥有一个角色,在 account2 上拥有其他角色。
基本上,存在两个问题:
1)许多验证都是基于当前用户所具有的角色。由于它取决于 current_account (即会话数据),因此我无法在模型中进行此类验证。这导致我发现一些丑陋的控制器代码(丑陋,是指它确实感觉不合适)。我想过将 current_account 存储在模型类变量中,但我读到这不是线程安全的。有什么建议吗?
2)几乎每条数据库记录都是特定于当前账户的;因此,几乎每个表都应该有一个 account_id 列,并且模型应该有一个 own_to account 关联。我想避免这种情况。第一件(显而易见的)事情是每个帐户都有一个单独的数据库,但是
a)有共享表
b)老板说这个解决方案是不可接受的(会有很多帐户,用户数量相对较少)。还有第三条路吗?
We're building an application for product support. The idea is to have multiple subdomains, each for supporting other organizations products. We call this Account - each account is tied to exactly one subdomain.
Users also have roles - but, user can have one role on account1, and other role on account2.
Basically, there are two problems:
1) many validations are based on the role current user has. Since it depends on current_account (which is session data), I cannot do these kinds of validations in the model. This leads me to some ugly controller code (ugly, in the sense that it really feels out of place). I thought of storing current_account after in the model class variable, but I read that this is not thread safe. Any recommendations?
2) almost every database record is specific to the current account; so, almost every table should have an account_id column and the model should have a belongs_to account association. I want to avoid that. The first (obvious) thing is to have a seperate database for every account, but
a) there are shared tables
b) the boss says this solution is unacceptable (there will be many accounts, with relatively low number of users). Is there a third way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人遇到类似的问题:
所描述的问题称为多租户;理解 default_scope 应该会有所帮助。另外,还有 多租户 gem 对我来说效果很好。
If anyone runs into similar problem:
The problem described is called multitenancy; understanding default_scope should help. Also, there is the multitenant gem which worked for me nicely.