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

Fix account controller specs

Oliver Güntherfc99f8596a06
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 6918ea67e5f..c6d903850ec 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -172,7 +172,8 @@ class AccountController < ApplicationController
end
def handle_expired_token(token)
- send_activation_email! Token::Invitation.create!(user: token.user)
+ new_token = Token::Invitation.create!(user: token.user)
+ UserMailer.user_signed_up(new_token).deliver_later
flash[:warning] = I18n.t :warning_registration_token_expired, email: token.user.mail
@@ -337,7 +338,16 @@ class AccountController < ApplicationController
@user.password = params[:user][:password]
@user.password_confirmation = params[:user][:password_confirmation]
- register_user_according_to_setting @user
+ call = ::Users::RegisterUserService.new(@user).call
+
+ if call.success?
+ flash[:notice] = call.message.presence
+ login_user_if_active(call.result)
+ else
+ flash[:error] = error = call.message
+ Rails.logger.error "Registration of user #{@user.login} failed: #{error}"
+ onthefly_creation_failed(@user, login: @user.login)
+ end
end
end
@@ -454,7 +464,7 @@ class AccountController < ApplicationController
successful_authentication(user)
else
account_inactive(user, flash_now: false)
- redirect_to signin_path
+ redirect_to signin_path(back_url: params[:back_url])
end
end
@@ -514,7 +524,7 @@ class AccountController < ApplicationController
end
def self_registration_disabled
- flash[:error] = I18n.t(:error_self_registration_disabled)
+ flash[:error] = I18n.t('account.error_self_registration_disabled')
redirect_to signin_url
end
@@ -544,14 +554,6 @@ class AccountController < ApplicationController
end
end
- # def account_pending
- #
- # # Set back_url to make sure user is not redirected to an external login page
- # # when registering via the external service. This also redirects the user
- # # to the original page where the user clicked on the omniauth login link for a provider.
- # redirect_to action: 'login', back_url: params[:back_url]
- # end
-
def invited_user
if session.include? :invitation_token
token = Token::Invitation.find_by_plaintext_value session[:invitation_token]
diff --git a/app/controllers/concerns/accounts/user_limits.rb b/app/controllers/concerns/accounts/user_limits.rb
index dd76f35fb49..fbceb14ac2e 100644
--- a/app/controllers/concerns/accounts/user_limits.rb
+++ b/app/controllers/concerns/accounts/user_limits.rb
@@ -55,7 +55,7 @@ module Accounts::UserLimits
def enforce_activation_user_limit(user: nil, redirect_to: signin_path)
if user_limit_reached?
- show_user_limit_activation_error!
+ flash[:error] = I18n.t(:error_enterprise_activation_user_limit)
send_activation_limit_notification_about user if user
redirect_back fallback_location: redirect_to