Skip to content

Commit

Permalink
fix: add skip_first_login_authorization to omniauth controller
Browse files Browse the repository at this point in the history
  • Loading branch information
moustachu committed Jul 2, 2024
1 parent 6ce881b commit 526b6c6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 65 deletions.
58 changes: 0 additions & 58 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -121,61 +121,3 @@ RAILS_LOG_LEVEL=warn
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_FIRST_NAME
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_LAST_NAME
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_NICKNAME

# Default notifications sending frequency : (daily, weekly, none, real_time)
# NOTIFICATIONS_SENDING_FREQUENCY=daily

## SMS Gateway Service (eg: decidim-half_signup)
# SMS_GATEWAY_SERVICE="Decidim::SmsGatewayService"
# SMS_GATEWAY_URL="https://sms.gateway.service/api"
# SMS_GATEWAY_BULK_URL="https://sms.gateway.service/api/bulk"
# SMS_GATEWAY_USERNAME=
# SMS_GATEWAY_PASSWORD=
## Set to replace the organization name
# SMS_GATEWAY_PLATFORM="hashimoto.local"

#Timeout for the unsubscribe link of the newsletter
#NEWSLETTERS_UNSUBSCRIBE_TIMEOUT=

# Redirect to the TOS page after signup (default: true)
# DECIDIM_HALF_SIGNUP_SHOW_TOS_PAGE_AFTER_SIGNUP=true

## SSO SAML
# OMNIAUTH_IMT_ICON_PATH
# OMNIAUTH_IMT_IDP_ENTITY_SELECTOR_URL
# OMNIAUTH_IMT_IDP_METADATA_URL
# OMNIAUTH_IMT_ISSUER
# OMNIAUTH_IMT_ASSERTION_CONSUMER_SERVICE_URL
# OMNIAUTH_IMT_SP_ENTITY_ID
# OMNIAUTH_IMT_IDP_SSO_SERVICE_URL
# OMNIAUTH_IMT_IDP_SLO_SERVICE_URL
# OMNIAUTH_IMT_IDP_CERT
# OMNIAUTH_IMT_NAME_IDENTIFIER_FORMAT
# OMNIAUTH_IMT_ATTRIBUTE_SERVICE_NAME
# OMNIAUTH_IMT_UID_ATTRIBUTE
# OMNIAUTH_IMT_PROTOCOL_BINDING
# OMNIAUTH_IMT_IDP_SECURITY_DIGEST_METHOD
# OMNIAUTH_IMT_IDP_SECURITY_SIGNATURE_METHOD
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_EMAIL
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_NAME
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_FIRST_NAME
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_LAST_NAME
# OMNIAUTH_IMT_REQUEST_ATTRIBUTE_NICKNAME

# Default notifications sending frequency : (daily, weekly, none, real_time)
# NOTIFICATIONS_SENDING_FREQUENCY=daily

## SMS Gateway Service (eg: decidim-half_signup)
# SMS_GATEWAY_SERVICE="Decidim::SmsGatewayService"
# SMS_GATEWAY_URL="https://sms.gateway.service/api"
# SMS_GATEWAY_BULK_URL="https://sms.gateway.service/api/bulk"
# SMS_GATEWAY_USERNAME=
# SMS_GATEWAY_PASSWORD=
## Set to replace the organization name
# SMS_GATEWAY_PLATFORM="hashimoto.local"

#Timeout for the unsubscribe link of the newsletter
#NEWSLETTERS_UNSUBSCRIBE_TIMEOUT=

# Redirect to the TOS page after signup (default: true)
# DECIDIM_HALF_SIGNUP_SHOW_TOS_PAGE_AFTER_SIGNUP=true
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Application < Rails::Application
end

config.after_initialize do
require "extends/controllers/decidim/devise_controllers_extends"
require "extends/controllers/decidim/devise/sessions_controller_extends"
require "extends/controllers/decidim/editor_images_controller_extends"
require "extends/services/decidim/iframe_disabler_extends"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ def verified_email
@verified_email ||= (oauth_data.dig(:info, :email) || params.dig(:user, :verified_email))
@form.verified_email ||= @verified_email
end

def after_sign_in_path_for(user)
if user.present? && user.blocked?
check_user_block_status(user)
elsif !skip_first_login_authorization? && (!pending_redirect?(user) && first_login_and_not_authorized?(user))
decidim_verifications.authorizations_path
else
super
end
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ def after_sign_in_path_for(user)
super
end
end

private

# Skip authorization handler by default
def skip_first_login_authorization?
ActiveRecord::Type::Boolean.new.cast(ENV.fetch("SKIP_FIRST_LOGIN_AUTHORIZATION", "false"))
end
end

def destroy_france_connect_session(fc_logout_path)
Expand Down
12 changes: 12 additions & 0 deletions lib/extends/controllers/decidim/devise_controllers_extends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module DeviseControllersExtends
# Skip authorization handler by default
def skip_first_login_authorization?
ActiveRecord::Type::Boolean.new.cast(ENV.fetch("SKIP_FIRST_LOGIN_AUTHORIZATION", "false"))
end
end

Decidim::DeviseControllers.module_eval do
prepend(DeviseControllersExtends)
end

0 comments on commit 526b6c6

Please sign in to comment.