jekuno / milia

Easy multi-tenanting for Rails5 (or Rails4) + Devise
MIT License
341 stars 72 forks source link

Add management GUI #59

Closed ohadco closed 9 years ago

ohadco commented 9 years ago

Hi, I'm trying to create an administration page where I can see all of the users using my app. I have created a controller with privileges only for me, and I have a regular index view. In this controller I can access the users by using '@users = User.all' but when I try to get to the tenant (to show it's ID and name), I can't do that. Any suggestions how can I access all the tenants from this admin controller?

Thanks!

dsaronin commented 9 years ago

If you set up User and Tenant models per the README instructions, then there will be no difference between accessing User.all and Tenant.all, since neither of them are tenanted tables. When you have a given user x, then list = x.tenants will be the list of all tenants belonging to that user. So, list.first.name will be the name of the first tenant for user x; list.first.id will be the tenant id, etc.

I think, however, you want to be very careful about constructing a frontdoor unlimited access for an admin, such as you are describing. With my web app, I accomplished those objectives with rake tasks which only I can run from the platform itself. Not a frontdoor solution. It is very dangerous - from a security standpoint - to have special rights for a user that are really beyond the scope of the app itself.

On Mon, May 18, 2015 at 1:51 AM ohadco notifications@github.com wrote:

Hi, I'm trying to create an administration page where I can see all of the users using my app. I have created a controller with privileges only for me, and I have a regular index view. In this controller I can access the users by using '@users = User.all' but when I try to get to the tenant (to show it's ID and name), I can't do that. Any suggestions how can I access all the tenants from this admin controller?

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59.

ohadco commented 9 years ago

I cannot use 'user.tenant' \ 'user.tenants' since the user table has an empty tenant_id attribute for all of the rows (looks like milia config - I guess it's because of user's model 'acts_as_universal_and_determines_account'). The connection is from the Member - it has both user_id and tenant_id. Is there anything wrong with my configurations? the user should hold value for tenant_id?

Thanks.

dsaronin commented 9 years ago

yes, something is definitely wrong with the setup. Member has been setup incorrectly. You must have "acts_as_universal_and_determines_tenant" in the Tenant model only. Member should have: "acts_as_tenant". Please look carefully again at the README.

On Tue, May 19, 2015 at 12:13 AM ohadco notifications@github.com wrote:

I cannot use 'user.tenant' \ 'user.tenants' since the user table has an empty tenant_id attribute for all of the rows (looks like milia config - I guess it's because of user's model 'acts_as_universal_and_determines_account'). The connection is from the Member - it has both user_id and tenant_id. Is there anything wrong with my configurations? the user should hold value for tenant_id?

Thanks.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103375997.

ohadco commented 9 years ago

Tenant model has 'acts_as_universal_and_determines_tenant' Member model has 'acts_as_tenant' User model has 'acts_as_universal_and_determines_account'

is that O.K.?

2015-05-19 12:42 GMT+03:00 Daudi Amani notifications@github.com:

yes, something is definitely wrong with the setup. Member has been setup incorrectly. You must have "acts_as_universal_and_determines_tenant" in the Tenant model only. Member should have: "acts_as_tenant". Please look carefully again at the README.

On Tue, May 19, 2015 at 12:13 AM ohadco notifications@github.com wrote:

I cannot use 'user.tenant' \ 'user.tenants' since the user table has an empty tenant_id attribute for all of the rows (looks like milia config - I guess it's because of user's model 'acts_as_universal_and_determines_account'). The connection is from the Member - it has both user_id and tenant_id. Is there anything wrong with my configurations? the user should hold value for tenant_id?

Thanks.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103375997.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103418626.

dsaronin commented 9 years ago

yes, that is correct. Make sure that your db/migrate files are correct as well and that there is a xxxxxx_create_tenants_users_join_table.rb there: class CreateTenantsUsersJoinTable < ActiveRecord::Migration def change create_join_table :tenants, :users do |t| t.index [:tenant_id, :user_id]

t.index [:user_id, :tenant_id]

end

end end

On Tue, May 19, 2015 at 3:34 AM ohadco notifications@github.com wrote:

Tenant model has 'acts_as_universal_and_determines_tenant' Member model has 'acts_as_tenant' User model has 'acts_as_universal_and_determines_account'

is that O.K.?

2015-05-19 12:42 GMT+03:00 Daudi Amani notifications@github.com:

yes, something is definitely wrong with the setup. Member has been setup incorrectly. You must have "acts_as_universal_and_determines_tenant" in the Tenant model only. Member should have: "acts_as_tenant". Please look carefully again at the README.

On Tue, May 19, 2015 at 12:13 AM ohadco notifications@github.com wrote:

I cannot use 'user.tenant' \ 'user.tenants' since the user table has an

empty tenant_id attribute for all of the rows (looks like milia config

I guess it's because of user's model 'acts_as_universal_and_determines_account'). The connection is from the Member - it has both user_id and tenant_id. Is there anything wrong with my configurations? the user should hold value for tenant_id?

Thanks.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103375997.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103418626.

— Reply to this email directly or view it on GitHub https://github.com/dsaronin/milia/issues/59#issuecomment-103431964.