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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Review feedback
Oliver Günther4856cf8522b9
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rbindex edf3c7859c8..031b0512691 100644--- a/app/controllers/account_controller.rb+++ b/app/controllers/account_controller.rb@@ -172,14 +172,18 @@ class AccountController < ApplicationControllerenddef handle_expired_token(token)- new_token = Token::Invitation.create!(user: token.user)- UserMailer.user_signed_up(new_token).deliver_later+ send_activation_email! token.userflash[:warning] = I18n.t :warning_registration_token_expired, email: token.user.mailredirect_to home_urlend+ 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 < ApplicationControllerendif 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]++ valend+ 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).callif call.success?flash[:notice] = call.message.presencelogin_user_if_active(call.result, just_registered: true)elseflash[: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)endend@@ -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.rbindex 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 errorsdef auth_uid- auth_hash.try(:[], :uid) || 'unknown'+ hash = (auth_hash || {})+ hash.dig(:info, :uid) || hash.dig(:uid) || 'unknown'endendenddiff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rbindex 103e5580ff6..ac7047a077d 100644--- a/app/services/users/register_user_service.rb+++ b/app/services/users/register_user_service.rb@@ -156,7 +156,7 @@ module UsersServiceResult.new(success: false).tap do |call|# Avoid using the errors from the usercall.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)endendenddiff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rbindex 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 doUser.current = nilend- context 'GET #omniauth_login', with_settings: { self_registration: '3' } do+ context 'GET #omniauth_login', with_settings: { self_registration: Setting::SelfRegistration.automatic} dodescribe 'with on-the-fly registration' docontext 'providing all required fields' dolet(:omniauth_hash) do@@ -244,7 +244,7 @@ describe AccountController, type: :controller doendcontext 'with self-registration disabled',- with_settings: { self_registration: 0 } do+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dolet(:omniauth_hash) doOmniAuth::AuthHash.new(provider: 'google',@@ -442,7 +442,7 @@ describe AccountController, type: :controller doendcontext 'with a registered and not activated accout',- with_settings: { self_registration: '1' } do+ with_settings: { self_registration: Setting::SelfRegistration.by_email } dobefore douser.registeruser.save!@@ -460,7 +460,7 @@ describe AccountController, type: :controller doendcontext 'with an invited user and self registration disabled',- with_settings: { self_registration: '0' } do+ with_settings: { self_registration: Setting::SelfRegistration.disabled } dobefore douser.inviteuser.save!