문제

I'm using acts_as_tenant keyed on subdomain, and would like the "tenant" to be able to make changes to his Account record (change his subdomain), but not see anyone elses entry.

Adding an account_id column to Account with the same id as Account.id, and making the account model

acts_as_tenant(:account)

works, but feels icky! Also, it means I can't use the config.require_tenant = true initializer, as then I'm trying to access a tenanted model in order to set the current tenant, when the tenant isn't yet set, which naturally doesn't work.

I'm convinced I'm going about this completely the wrong way, and that the correct solution will be blindingly obvious, but sleep defecit is preventing me from seeing the light. Any and all help appreciated!

도움이 되었습니까?

해결책

The tenant or account owner will only need access to a single account, namely his own.

What we do is we add a column to the accounts table named owner_id with the id of the user who owns the account.

In the accounts_controller we then check explicitly:

before_filter current_account.is_owned_by?(current_user)

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top