Module: Decidim::OmniauthHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/decidim/omniauth_helper.rb

Overview

Helper that provides methods to enable or disable omniauth buttons

Instance Method Summary collapse

Instance Method Details

#any_social_provider_enabled?Boolean

Public: returns true if any provider is enabled

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/helpers/decidim/omniauth_helper.rb', line 12

def any_social_provider_enabled?
  User.omniauth_providers.any? do |provider|
    social_provider_enabled? provider
  end
end

#normalize_provider_name(provider) ⇒ Object

Public: normalize providers names to they can be used for buttons and icons.



20
21
22
# File 'app/helpers/decidim/omniauth_helper.rb', line 20

def normalize_provider_name(provider)
  provider.to_s.split("_").first
end

#oauth_icon(provider) ⇒ Object

Public: icon for omniauth buttons



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/decidim/omniauth_helper.rb', line 25

def oauth_icon(provider)
  info = Rails.application.secrets.dig(:omniauth, provider.to_sym)

  if info
    icon_path = info[:icon_path]
    return external_icon(icon_path) if icon_path

    name = info[:icon]
  end

  name ||= normalize_provider_name(provider)
  icon(name)
end

#social_provider_enabled?(provider) ⇒ Boolean

Public: returns true if the social provider is enabled

Returns:

  • (Boolean)


7
8
9
# File 'app/helpers/decidim/omniauth_helper.rb', line 7

def social_provider_enabled?(provider)
  Rails.application.secrets.dig(:omniauth, provider.to_sym, :enabled)
end