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

[33445] Ensure user is activated if invited and accessing auth source

Oliver Günther70acb4c80f19
diff --git a/app/controllers/concerns/auth_source_sso.rb b/app/controllers/concerns/auth_source_sso.rb
index 171da19819d..531d008aa63 100644
--- a/app/controllers/concerns/auth_source_sso.rb
+++ b/app/controllers/concerns/auth_source_sso.rb
@@ -123,13 +123,16 @@ module AuthSourceSSO
end
def sso_login_failed?(user)
- user.nil? || user.new_record? || !user.active?
+ user.nil? || user.new_record? || !(user.active? || user.invited?)
end
def handle_sso_for!(user, login)
if sso_login_failed?(user)
handle_sso_failure!({ user: user, login: login })
else # valid user
+ # If a user is invited, ensure it gets activated
+ activate_user_if_invited! user
+
handle_sso_success user
end
end
@@ -141,6 +144,12 @@ module AuthSourceSSO
user
end
+ def activate_user_if_invited!(user)
+ return unless user.invited?
+
+ user.activate!
+ end
+
def perform_post_logout(prev_session)
if prev_session[:user_from_auth_header] && header_slo_url.present?
redirect_to header_slo_url
diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb
index ac6ddf18b05..4aec8887628 100644
--- a/spec/controllers/concerns/auth_source_sso_spec.rb
+++ b/spec/controllers/concerns/auth_source_sso_spec.rb
@@ -109,6 +109,16 @@ describe MyController, type: :controller do
end
end
+ context 'when the user is invited' do
+ let!(:user) {
+ FactoryBot.create :user, login: login, status: Principal::STATUSES[:invited], auth_source_id: auth_source.id
+ }
+
+ it "should log in given user and activate it" do
+ expect(response.body.squish).to have_content("Username h.wurst")
+ expect(user.reload).to be_active
+ end
+ end
context "with no auth source sso configured" do
let(:sso_config) { nil }