Problem changing account from url using multitenancy Path /:account_id/
I am using Multitenancy with Path
is there anything I am missing in my controllers?
/:account_id/
but I am having a problem that is when I change the account URL manually for example from http://localhost:5000/4 to http://localhost:5000/3 I can see both contents but I am only member of the /4 account and I am not a member in /3 but still can see the contentis there anything I am missing in my controllers?
I have in my controllers:
before_action :set_discussion, only: [:show, :edit, :update, :destroy] before_action :authenticate_user!
Have you added the following line to your content models?
acts_as_tenant :account
That should scope content items so only those belonging to current_account are shown
https://jumpstartrails.com/docs/accounts
I included a before_action
before_action :restrict_access, only: [:show, :edit, :update, :destroy]
and a new method
def restrict_access redirect_to root_path unless current_account.present? && current_account.discussions.pluck(:id).include?(params[:id]) end
but I still can access other teams urls, what might be wrong? thanks!
For example, this would redirect if the user was not in the account users list. And don't forget, you'll want to redirect with the script name changed so that it removes the account_id from the URL.
def restrict_access if user_signed_in? && !current_account.account_users.where(user_id: current_user.id).exists? redirect_to root_url(script_name: '/') end end
Notifications
You’re not receiving notifications from this thread.