Dan Tappin
Dan Tappin

Reputation: 3032

Rolify and acts_as_tenant with Single Signon (with some Devise & Pundit on the side) - can it be done?

I am going to try and make this work in my Rails app but I figured I would see if anyone knew of a gotcha that would stop me in the tracks.

The basic premise is that I have the following models:

From what I have read so far as long as I set this up right I will have my tenant data segregated and then users can switch between tenants and their permissions will change accordingly.

So my specific question:

Will acts_as_tenant just work with the Rolify?

So for example if and admin user in Tenant1 adds a role to a new user will that role automatically only apply to the resources owned by that tenant?

Upvotes: 1

Views: 675

Answers (2)

Gonzalo
Gonzalo

Reputation: 427

Will acts_as_tenant just work with the Rolify?

It can be done. It won't just work.

Rolify associates roles tu users in a many_to_many kind of way, using a DB table UsersRoles. But it doesn't have an active record model associated with it. In it's place it uses an "adapter" to the database, so you can't make that table use acts_as_tenant in a straight forward way.

Upvotes: 0

Dan Tappin
Dan Tappin

Reputation: 3032

I ended up with the apartment gem and my User and Company models in the public schema. I have a Role model that links User to Company and contains the Roles that the user has for a given company. Devise authenticates the User and Pundit uses Role to authorize.

Upvotes: 1

Related Questions