I am new to Active Admin but from what I have seen so far I think this is quite easy to implement.
I have an app with the apartment gem to add multi-tenancy.
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')
.
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.
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:
- 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.
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:
- 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.