acts_as_tenant icon indicating copy to clipboard operation
acts_as_tenant copied to clipboard

Add support for setting the current tenant in an ActionCable context

Open scarhand opened this issue 2 years ago • 4 comments

Allows you to use set_current_tenant_through_filter, set_current_tenant_by_subdomain_or_domain and set_current_tenant_by_subdomain in ActionCable channels, in a similar vein as ActionControllers.

E.g.:

class SpecSubdomainOrDomainChannel < ApplicationCable::Channel
  set_current_tenant_by_subdomain_or_domain

  def subscribed
    reject if params[:room_id].nil?
  end

  def whoami
    transmit current_tenant.name
  end
end

Haven't made any changes to the README, as I wasn't sure where to put it :)

scarhand avatar Mar 18 '22 09:03 scarhand

@scarhand Looks like ActiveSupport.on_load(:action_cable_channel) wasn't added until Rails 6, which is the cause for the failures on Rails 5.2.

Rails 5.2 is EOL on June 1st, 2022, so we can't really drop support for it yet I feel like.

Maybe we can do a different method for Rails 5, like a config.to_prepare block or something?

excid3 avatar Apr 15 '22 18:04 excid3

Looks like the PR is about a month too early then ;) I'll see if config.to_prepare can be used, or if there's something else that works with Rails 5(.2).

scarhand avatar Apr 21 '22 08:04 scarhand

If there's nothing easy, we can wait on Rails 5.2 to be EOL and update the required versions here soon.

excid3 avatar Apr 21 '22 13:04 excid3