docbrown/app/helpers/authentication_helper.rb
Suzanne Aitchison 5069cd681a
Markdown editor toolbar (#14876)
* rough starting point, roving tabindex in toolbar, bold and italic buttons

* refactor, add link

* add ul

* add ordered list

* core formatters in place, wip

* overflow options

* add keyboard shortcuts

* tidy up some dodgy classes

* add mocks for runtime in test and storybook, use correct modifier key for tooltip

* style tweaks

* refactor tooltips

* add markdown formatters tests

* add tests for toolbar component, fix mistake in overflow menu tooltips

* undo change no longer needed to button

* fix issue accessing runtime in formatters file

* only show darkened buttons and tooltips when focus-visible is true

* mobile view

* fix for responsive buttons & roving tabindex

* tweaks from PR review

* update cursor position on link insertion

* add a new line after block selection formatting

* align icons in center

* tidy up overflow menu listeners

* small refactors

* test for new text area util

* tidy up new lines after syntaxes

* fix logic in cursor offsets for links

* prevent scroll jumps after inserting syntax

* some style tweaks

* insert level 2 heading with new lines above and below

* update icons

* use margin instead of gap
2021-10-19 09:22:54 +01:00

86 lines
2.8 KiB
Ruby

module AuthenticationHelper
def authentication_provider(provider_name)
Authentication::Providers.get!(provider_name)
end
def authentication_available_providers
Authentication::Providers.available.map do |provider_name|
Authentication::Providers.const_get(provider_name.to_s.titleize)
end
end
def authentication_enabled_providers
Authentication::Providers.enabled.map do |provider_name|
Authentication::Providers.get!(provider_name)
end
end
def authentication_provider_enabled?(provider_name)
authentication_enabled_providers.include?(provider_name)
end
def authentication_enabled_providers_for_user(user = current_user)
Authentication::Providers.enabled_for_user(user)
end
def signed_up_with(user = current_user)
providers = Authentication::Providers.enabled_for_user(user)
# If the user did not authenticate with any provider, they signed up with an email.
auth_method = providers.any? ? providers.map(&:official_name).to_sentence : "Email & Password"
verb = providers.size > 1 ? "any of those" : "that"
"Reminder: you used #{auth_method} to authenticate your account, so please use #{verb} to sign in if prompted."
end
def available_providers_array
Authentication::Providers.available.map(&:to_s)
end
def forem_creator_flow_enabled?
FeatureFlag.enabled?(:creator_onboarding) && waiting_on_first_user?
end
def waiting_on_first_user?
Settings::General.waiting_on_first_user
end
def invite_only_mode_or_no_enabled_auth_options
ForemInstance.invitation_only? ||
(authentication_enabled_providers.none? &&
!Settings::Authentication.allow_email_password_registration)
end
def tooltip_class_on_auth_provider_enablebtn
invite_only_mode_or_no_enabled_auth_options ? "crayons-hover-tooltip" : ""
end
def disabled_attr_on_auth_provider_enable_btn
invite_only_mode_or_no_enabled_auth_options ? "disabled" : ""
end
def tooltip_text_email_or_auth_provider_btns
if invite_only_mode_or_no_enabled_auth_options
"You cannot do this until you disable Invite Only Mode"
else
""
end
end
def came_from_sign_up?
request.referer&.include?(new_user_registration_path)
end
def display_social_login?
return true if Authentication::Providers.enabled.include?(:apple)
return true if request.user_agent.to_s.match?(/Android/i)
# Don't display (return false) if UserAgent includes ForemWebview - iOS only
request.user_agent.to_s.exclude?("ForemWebView")
end
# Display the fallback message if we can't register with email and at the same time can't display the social options.
def display_registration_fallback?(state)
state == "new-user" && !Settings::Authentication.allow_email_password_registration && !display_social_login?
end
end