Module: YiffSpace::Auth::Helper::ClassMethods

Included in:
Scoped::ClassMethods
Defined in:
lib/yiffspace/auth/helper.rb

Instance Method Summary collapse

Instance Method Details

#disable_spoof_auth(**before_action_options) ⇒ Object

Disables spoof auth for this controller (or just the actions matched by the given before_action options, e.g. only:/except:), regardless of the global switch or the client's spoof_user_id. Useful for controllers that must always see the real session (e.g. the auth engine's own login/callback controllers).



33
34
35
# File 'lib/yiffspace/auth/helper.rb', line 33

def disable_spoof_auth(**before_action_options)
  before_action(**before_action_options) { |controller| controller.request.env[SPOOF_OVERRIDE_ENV] = false }
end

#override_spoof_auth(spoof_user_id: nil, spoof_permissions: nil, spoof_roles: nil, **before_action_options) ⇒ Object

Overrides the user/permissions/roles spoofed for this controller (or just the actions matched by the given before_action options), independent of the client's configured spoof_user_id/spoof_permissions/spoof_roles. Still requires the global switch (YiffSpace::Auth.enable_spoof_auth!) to be on - this only changes who gets spoofed in, not whether spoofing happens at all.



42
43
44
45
# File 'lib/yiffspace/auth/helper.rb', line 42

def override_spoof_auth(spoof_user_id: nil, spoof_permissions: nil, spoof_roles: nil, **before_action_options)
  overrides = { spoof_user_id: spoof_user_id, spoof_permissions: spoof_permissions, spoof_roles: spoof_roles }.compact
  before_action(**before_action_options) { |controller| controller.request.env[SPOOF_OVERRIDE_ENV] = overrides }
end

#set_client_name(name) ⇒ Object

rubocop:disable Naming/AccessorMethodName



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yiffspace/auth/helper.rb', line 12

def set_client_name(name) # rubocop:disable Naming/AccessorMethodName
  before_action do |controller|
    controller.request.env[CLIENT_NAME_ENV] = name
    if controller.respond_to?(:yiffspace_client_name=)
      controller.yiffspace_client_name = name
    elsif controller.respond_to?(:client_name=)
      controller.client_name = name
    elsif controller.respond_to?(:helpers)
      if controller.helpers.respond_to?(:yiffspace_client_name=)
        controller.helpers.yiffspace_client_name = name
      elsif controller.helpers.respond_to?(:client_name=)
        controller.helpers.client_name = name
      end
    end
  end
end