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
Expose User#authentication_provider as AR class
Jan Sandbrink3708fa4513a3
diff --git a/app/models/user.rb b/app/models/user.rbindex 4b3d3317572..e5f2d462219 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -304,16 +304,16 @@ class User < Principalendend- # Return user's authentication provider for displaydef authentication_provider- return if identity_url.blank?+ return nil if identity_url.blank?- identity_url.split(":", 2).first+ slug = identity_url.split(":", 2).first+ AuthProvider.find_by(slug:)end# Return user's authentication provider for displaydef human_authentication_provider- authentication_provider&.titleize+ authentication_provider&.display_nameend##diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rbindex 3ab6efc7baa..b498044d593 100644--- a/app/services/users/register_user_service.rb+++ b/app/services/users/register_user_service.rb@@ -137,7 +137,7 @@ module Usersenddef provider_name(user)- user.authentication_provider&.downcase+ user.authentication_provider&.slug&.downcaseenddef register_by_email_activationdiff --git a/spec/features/auth/lost_password_spec.rb b/spec/features/auth/lost_password_spec.rbindex f7652f67207..0928f5ba77e 100644--- a/spec/features/auth/lost_password_spec.rb+++ b/spec/features/auth/lost_password_spec.rb@@ -90,6 +90,7 @@ RSpec.describe "Lost password" doendcontext "when user has identity_url" do+ let!(:provider) { create(:saml_provider, slug: "saml", display_name: "The SAML provider") }let!(:user) { create(:user, identity_url: "saml:foobar") }it "sends an email with external auth info" do@@ -105,7 +106,7 @@ RSpec.describe "Lost password" doexpect(ActionMailer::Base.deliveries.size).to be 1mail = ActionMailer::Base.deliveries.firstexpect(mail.subject).to eq I18n.t("mail_password_change_not_possible.title")- expect(mail.body.parts.first.body.to_s).to include "Saml"+ expect(mail.body.parts.first.body.to_s).to include "(The SAML provider)"endendenddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex c0ac9094fbc..11e084ab73a 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -365,17 +365,44 @@ RSpec.describe User doenddescribe "#authentication_provider" do+ let!(:provider) { create(:oidc_provider, slug: "test_provider") }++ before do+ user.identity_url = "test_provider:veryuniqueid"+ user.save!+ end++ it "returns the provider" do+ expect(user.authentication_provider).to eql(provider)+ end++ context "when no matching provider exists" do+ let!(:provider) { nil }++ it "returns nil" do+ expect(user.authentication_provider).to be_nil+ end+ end+ end++ describe "#human_authentication_provider" do+ let!(:provider) { create(:oidc_provider, slug: "test_provider", display_name: "Karl") }+before douser.identity_url = "test_provider:veryuniqueid"user.save!end- it "returns the internal provider slug" do- expect(user.authentication_provider).to eql("test_provider")+ it "returns a human readable name" do+ expect(user.human_authentication_provider).to eql("Karl")end- it "creates a human readable name" do- expect(user.human_authentication_provider).to eql("Test Provider")+ context "when no matching provider exists" do+ let!(:provider) { nil }++ it "returns nil" do+ expect(user.authentication_provider).to be_nil+ endendenddiff --git a/spec/views/users/edit.html.erb_spec.rb b/spec/views/users/edit.html.erb_spec.rbindex 78db605d151..ef07941e9a4 100644--- a/spec/views/users/edit.html.erb_spec.rb+++ b/spec/views/users/edit.html.erb_spec.rb@@ -43,6 +43,7 @@ RSpec.describe "users/edit" dobuild(:user, id: 1, # id is required to create route to editidentity_url: "test_provider:veryuniqueid")end+ let!(:provider) { create(:oidc_provider, slug: "test_provider", display_name: "The Test Provider") }before doassign(:user, user)@@ -56,7 +57,7 @@ RSpec.describe "users/edit" doit "shows the authentication provider" dorender- expect(rendered).to include("Test Provider")+ expect(rendered).to include("The Test Provider")endit "does not show a no-login warning when password login is disabled" do