Comments (3)
Before you can set the current_tenant, there must be an authorized
current_user and that user must have access to the tenants being used in
Tenant.set_current_tenant. That access is established via the HABTM join
table: tenants_users. Thus if you haven't set that up correctly with your
seed_fu, the exception will be raised. I don't think the previous milia
version was properly checking this.
best, Daudi
On Dec 30, 2013 12:42 AM, "Shaabi" [email protected] wrote:
Hi there,
I'm really looking forward to the new milia gem with rails 4 and devise 3
support!I was testing out the best and ran into an issue, I am using the seed_fu
gem to populate default tenant data in the following manner, which was
working with Milia 0.3.30e.g. in a single file
Tenant.set_current_tenant Tenant.where(:name => 'First').first
Domain.seed_once(:uri,
{:uri => 'testing1.com'},
{:uri => 'testing2.com'}
)Tenant.set_current_tenant Tenant.where(:name => 'Second').first
Domain.seed_once(:uri,
{:uri => 'testing3.com', :primary => true}
)Now it throws an
Milia::Control::InvalidTenantAccess (Domain.rb uses acts_as_tenant)I get the same behaviour when trying this via the rails console, even
though Tenant.current_tenant shows the correct one is selected, it fails
exactly on base.rb:31 since the tenant_id check fails.I went through the seed_fu src to see what it was doing,
It does a Record.new followed by assign_attributes then save which when
run in that sequence in the console works just fine. confused :?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/12
.
from milia.
Hi Thanks for the reply, I see what you mean though I'm not sure how I could auth (or fake) a logged in devise user from a rake task, would it make sense to allow setting tenants without users when being run via the console or rake tasks ?
Though what I dont get is that, in the console if I do a
set_current_tenant + Model.new + assign_attributes +save it still allows me to save the record without having an authorised user but seed_once fails with invalid access even though it is also doing just the above. I feel as though it might be a different cause to the error ?
from milia.
Please see the README, towards the end or latter part. It addresses this
issue for both console, rake, and testing for how to manually sign in a
user.
Specifically (quoted from README)
console
Note that even when running the console, ($ rails console) it will be run in multi-tenanting mode. You will need to establish a current_user and setup the current_tenant, otherwise most Model DB accesses will fail.
For the author's own application, I have set up a small ruby file which I load when I start the console. This does the following:
def change_tenant(my_id,my_tenant_id)
@me = User.find( my_id )
@w = Tenant.find( my_tenant_id )
Tenant.set_current_tenant @w
end
change_tenant(1,1) # or whatever is an appropriate starting user, tenant
Now if you are only doing a rake task, or working in the console, then this should be sufficient (that is, not setting a current_user). But if you are doing anything which involves controllers, current_user will need to be established using devise methods.
I have yet to test this in the beta-3 version, however, so if you run into difficulty, let me know.
best, Daudi
On Dec 30, 2013 1:46 AM, "Shaabi" [email protected] wrote:
Hi Thanks for the reply, I see what you mean though I'm not sure how I
could auth (or fake) a logged in devise user from a rake task, would it
make sense to allow setting tenants without users when being run via the
console or rake tasks ?Though what I dont get is that, in the console if I do a
set_current_tenant + Model.new + assign_attributes +save it still allows
me to save the record without having an authorised user but seed_once fails
with invalid access even though it is also doing just the above. I feel as
though it might be a different cause to the error ?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/12#issuecomment-31339046
.
from milia.
Related Issues (20)
- Email address gets lost while inviting a new user HOT 1
- Upgrade path from 1.2.x to 1.3.x HOT 2
- Complare to ErwinM/acts_as_tenant HOT 1
- Setting tenant with JWT. Works with Thread.current_tenant? HOT 2
- Milia::Control::InvalidTenantAccess in MembersController#create no existing valid current tenant HOT 2
- can't install on rails 5.1 HOT 17
- rails 5 sign up raise error "Tenant must exists" HOT 1
- Milia gem installation problem HOT 33
- Can't install milia. plz help. HOT 3
- Can't create table using command rake db:migrate
- Can't install on Rails 5.1.3 HOT 2
- Tenant models with String primary key(ID) instead Integer(ID) - Not working HOT 3
- Error installing milia "Could not find generator 'milia:install'. Maybe you meant 'devise:install', 'migration' or 'mailer'" HOT 3
- Cannot install properly on Rails 5.2.1, uses depreciated "before_filter" HOT 3
- NoMethodError in Milia::RegistrationsController#create HOT 3
- Generator creating references which should be deleted? HOT 1
- [register user/org] tenant create failed - Tenant must exist HOT 3
- Rails 6.0.1 undefined method `skip_before_filter' for Milia::RegistrationsController:Class HOT 8
- Milia gem doesn't uploaded HOT 2
- Future of milia HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from milia.