主动管理员和公寓宝石

问题描述:

我是Active Admin的新手,但到目前为止,我认为这很容易实现。

I am new to Active Admin but from what I have seen so far I think this is quite easy to implement.

我有一个带有公寓gem的应用程序添加多租户。

I have an app with the apartment gem to add multi-tenancy.

我正在向我的应用添加活动管理员。 Apartment使用PostgreSQL模式来隔离数据。因此,例如,默认情况下,除非您调用 Apartment :: Tenant.switch!('abc')之类的东西,否则默认情况下,您在Apartment中的模型具有公共租户。

I am adding active admin to my app. Apartment uses PostgreSQL schemas to segregate data. So for example by default your models in Apartment have a 'public' tenant unless you call something like Apartment::Tenant.switch!('abc').

在我的应用中,我的 User Company 模型在公共租户中其他一切都在租户中。因此,除了租户模型不显示记录外,Active Admin都可以正常工作。

In my app my User and Company model are in the public tenant and everything else is in tenants. So out of the box Active Admin works fine except that the tenant models show no records - as they should.

我做了一些修补,并手动添加了 Apartment :: Tenant.switch!('abc')我的AA模型文件之一,效果很好。这是一个理想的解决方案:

I did some tinkering and manually added Apartment::Tenant.switch!('abc') one of my AA model files and that worked perfect. Here is an ideal solution:


  • 设置 AdminUser 登录租户时默认设置(例如第一个租户)

  • 在每个租户模型上,可能会有一个选择菜单提交参数(?tenant = abc),然后更改了租户

  • 活动的租户可能会保留在 AdminUser 会话存储中,因此您可以使用相同的租户数据,直到需要切换为止。

  • when the AdminUser logs in the tenant gets set to a default (say the first tenant)
  • On each tenanted model there could be a select menu that submits a param (?tenant=abc) and then the tenant is changed
  • The active tenant is persisted in perhaps the AdminUser session store so you can work in the same tenant data until you need to switch.

我想我自己可以很容易地做到这一点,但我想看看是否有需要解决的有关Active Admin的特定问题:

I think I can do this myself quite easily but I wanted to see if there was any Active Admin specific issues I would need to address like:


  • AA是否具有等效的应用程序控制器?最好在其中保留租户交换逻辑,而不要保留主要交换逻辑。

  • 备用AA Devise AdminUser 有一个单独的会话变量存储可用吗?

  • Does AA have an equivalent of a application controller? It would be nice to keep the tenant switching logic in there vs the main one.
  • The alternate AA Devise AdminUser has a separate session variable store available right?

任何建议都将不胜感激-排序后,我将最终解决方案/代码发布回此帖子

Any suggestions would be appreciated - I will post my final solution / code back to this post once I sort it out.


AA是否等效于应用程序控制器?

Does AA have an equivalent of a application controller? It would be nice to keep the tenant switching logic in there vs the main one.

确实,这里有一个ActiveAdmin :: BaseController,但是gem的作者并没有谈论将其用于自定义,也不知道为什么。

Indeed, there is an ActiveAdmin::BaseController, but the gem authors don't talk about using it for customization, not sure why. Seems like a fine place for the logic you're talking about.

我以前从来不需要修改它,但是这是某人的博客文章

I've never needed to modify it before, but here's a blog article from someone who did.


备用AA Devise AdminUser有一个单独的会话变量存储可用吗?

The alternate AA Devise AdminUser has a separate session variable store available right?

Hmmm。 Devise使用Warden进行会话管理,该管理器还支持同时登录的多个用户范围 格式为单独的会话数据,以及如果在我挖洞时提供内存Warden在代码中将单独的会话数据放在同一cookie的不同键中。不知道这是否是您的意思,但是我验证了在当前使用ActiveAdmin的Rails项目中,它绝对不会对用户和管理员使用不同的cookie。

Hmmm. Devise uses Warden for session management, which supports multiple user 'scopes' logged in simultaneously as well as separate session data, and if memory serves from when I've dug around in the code Warden puts the separate session data in a different key in the same cookie. Not sure if this is what you meant, but I verified that it definitely does not use a different cookie for users vs admins in my current ActiveAdmin-using Rails project.

否一个确定的答案,但要动球!

Not a definitive answer, but moving the ball!