Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Review feedback

Oliver Günther4856cf8522b9
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index edf3c7859c8..031b0512691 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -172,14 +172,18 @@ class AccountController < ApplicationController
end
def handle_expired_token(token)
- new_token = Token::Invitation.create!(user: token.user)
- UserMailer.user_signed_up(new_token).deliver_later
+ send_activation_email! token.user
flash[:warning] = I18n.t :warning_registration_token_expired, email: token.user.mail
redirect_to home_url
end
+ def send_activation_email!(user)
+ new_token = Token::Invitation.create!(user: user)
+ UserMailer.user_signed_up(new_token).deliver_later
+ end
+
def activate_self_registered(token)
return if enforce_activation_user_limit(user: token.user)
@@ -319,38 +323,52 @@ class AccountController < ApplicationController
end
if session[:auth_source_registration]
- # on-the-fly registration via omniauth or via auth source
- if pending_omniauth_registration?
- @user.assign_attributes permitted_params.user_register_via_omniauth
- return register_via_omniauth(session, @user.attributes)
- else
- @user.attributes = permitted_params.user
- @user.activate
- @user.login = session[:auth_source_registration][:login]
- @user.auth_source_id = session[:auth_source_registration][:auth_source_id]
- end
+ register_with_auth_source(@user)
else
- @user.attributes = permitted_params.user.transform_values do |val|
- if val.is_a? String
- val.strip!
- end
+ register_plain_user(@user)
+ end
+ end
- val
+ def register_plain_user(user)
+ user.attributes = permitted_params.user.transform_values do |val|
+ if val.is_a? String
+ val.strip!
end
- @user.login = params[:user][:login].strip if params[:user][:login].present?
- @user.password = params[:user][:password]
- @user.password_confirmation = params[:user][:password_confirmation]
+
+ val
end
+ user.login = params[:user][:login].strip if params[:user][:login].present?
+ user.password = params[:user][:password]
+ user.password_confirmation = params[:user][:password_confirmation]
+
+ respond_for_registered_user(user)
+ end
+
+ def register_with_auth_source(user)
+ # on-the-fly registration via omniauth or via auth source
+ if pending_omniauth_registration?
+ user.assign_attributes permitted_params.user_register_via_omniauth
+ register_via_omniauth(session, user.attributes)
+ else
+ user.attributes = permitted_params.user
+ user.activate
+ user.login = session[:auth_source_registration][:login]
+ user.auth_source_id = session[:auth_source_registration][:auth_source_id]
+
+ respond_for_registered_user(user)
+ end
+ end
- call = ::Users::RegisterUserService.new(@user).call
+ def respond_for_registered_user(user)
+ call = ::Users::RegisterUserService.new(user).call
if call.success?
flash[:notice] = call.message.presence
login_user_if_active(call.result, just_registered: true)
else
flash[:error] = error = call.message
- Rails.logger.error "Registration of user #{@user.login} failed: #{error}"
- onthefly_creation_failed(@user)
+ Rails.logger.error "Registration of user #{user.login} failed: #{error}"
+ onthefly_creation_failed(user)
end
end
@@ -519,7 +537,7 @@ class AccountController < ApplicationController
# Log an attempt to log in to an account in "registered" state and show a flash message.
def account_not_activated(flash_now: true)
flash_error_message(log_reason: 'NOT ACTIVATED', flash_now: flash_now) do
- if Setting.self_registration == '1'
+ if Setting::SelfRegistration.by_email?
'account.error_inactive_activation_by_mail'
else
'account.error_inactive_manual_activation'
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
index 6cb58e159fc..408d25fbb67 100644
--- a/app/services/authentication/omniauth_service.rb
+++ b/app/services/authentication/omniauth_service.rb
@@ -213,7 +213,8 @@ module Authentication
##
# Try to provide some context of the auth_hash in case of errors
def auth_uid
- auth_hash.try(:[], :uid) || 'unknown'
+ hash = (auth_hash || {})
+ hash.dig(:info, :uid) || hash.dig(:uid) || 'unknown'
end
end
end
diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb
index 103e5580ff6..ac7047a077d 100644
--- a/app/services/users/register_user_service.rb
+++ b/app/services/users/register_user_service.rb
@@ -156,7 +156,7 @@ module Users
ServiceResult.new(success: false).tap do |call|
# Avoid using the errors from the user
call.result = user
- call.errors.add(:base, I18n.t(:notice_activation_failed), error_symbol: :failed_to_activate)
+ call.errors.add(:base, I18n.t(:notice_activation_failed), error: :failed_to_activate)
end
end
end
diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb
index aeeeb8bfdd3..8a129ba25f6 100644
--- a/spec/controllers/concerns/omniauth_login_spec.rb
+++ b/spec/controllers/concerns/omniauth_login_spec.rb
@@ -34,7 +34,7 @@ describe AccountController, type: :controller do
User.current = nil
end
- context 'GET #omniauth_login', with_settings: { self_registration: '3' } do
+ context 'GET #omniauth_login', with_settings: { self_registration: Setting::SelfRegistration.automatic} do
describe 'with on-the-fly registration' do
context 'providing all required fields' do
let(:omniauth_hash) do
@@ -244,7 +244,7 @@ describe AccountController, type: :controller do
end
context 'with self-registration disabled',
- with_settings: { self_registration: 0 } do
+ with_settings: { self_registration: Setting::SelfRegistration.disabled } do
let(:omniauth_hash) do
OmniAuth::AuthHash.new(
provider: 'google',
@@ -442,7 +442,7 @@ describe AccountController, type: :controller do
end
context 'with a registered and not activated accout',
- with_settings: { self_registration: '1' } do
+ with_settings: { self_registration: Setting::SelfRegistration.by_email } do
before do
user.register
user.save!
@@ -460,7 +460,7 @@ describe AccountController, type: :controller do
end
context 'with an invited user and self registration disabled',
- with_settings: { self_registration: '0' } do
+ with_settings: { self_registration: Setting::SelfRegistration.disabled } do
before do
user.invite
user.save!