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

[#63912] React on PR comments.

Pavel Balashou83794a74663b
diff --git a/app/contracts/users/base_contract.rb b/app/contracts/users/base_contract.rb
index 2a19ecc3deb..70d38278d5e 100644
--- a/app/contracts/users/base_contract.rb
+++ b/app/contracts/users/base_contract.rb
@@ -62,6 +62,9 @@ module Users
def reduce_writable_attributes(attributes)
super.tap do |writable|
+ # `password` and `identity_url` are not regular attributes so they bypass
+ # attribute writable checks. therewore they must be added to the list
+ # of writable attributes under certain conditions.
writable << "password" if password_writable?
writable << "identity_url" if identity_url_writable?
end
@@ -69,9 +72,6 @@ module Users
private
- ##
- # Password is not a regular attribute so it bypasses
- # attribute writable checks
def password_writable?
user.admin? || user.id == model.id
end
diff --git a/app/controllers/concerns/user_invitation.rb b/app/controllers/concerns/user_invitation.rb
index f2e8076f010..b11137b4038 100644
--- a/app/controllers/concerns/user_invitation.rb
+++ b/app/controllers/concerns/user_invitation.rb
@@ -103,7 +103,7 @@ module UserInvitation
end
def reset_login(user_id)
- UserAuthProviderLink.where(user_id:).destroy_all
+ UserAuthProviderLink.where(user_id:).delete_all
UserPassword.where(user_id:).destroy_all
end
diff --git a/app/models/auth_provider.rb b/app/models/auth_provider.rb
index 1070da838fd..6b93ece9382 100644
--- a/app/models/auth_provider.rb
+++ b/app/models/auth_provider.rb
@@ -30,6 +30,7 @@ class AuthProvider < ApplicationRecord
belongs_to :creator, class_name: "User"
has_many :user_auth_provider_links, dependent: :destroy
+ has_many :users, through: :user_auth_provider_links
validates :display_name, presence: true
validates :display_name, uniqueness: true
@@ -57,10 +58,6 @@ class AuthProvider < ApplicationRecord
URI.join(auth_url, "callback").to_s
end
- def to_s
- slug
- end
-
protected
def unset_direct_provider
diff --git a/app/models/user.rb b/app/models/user.rb
index 0bdae4df2cd..dc09e8cd937 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -97,6 +97,7 @@ class User < Principal
has_many :reminders, foreign_key: "creator_id", dependent: :destroy, inverse_of: :creator
has_many :remote_identities, dependent: :destroy
has_many :user_auth_provider_links, dependent: :destroy
+ has_many :auth_providers, through: :user_auth_provider_links
# Users blocked via brute force prevention
# use lambda here, so time is evaluated on each query
@@ -110,6 +111,8 @@ class User < Principal
:with_time_zone,
:having_reminder_mail_to_send
+ self.ignored_columns += [:identity_url]
+
def self.create_blocked_scope(scope, blocked)
scope.where(blocked_condition(blocked))
end
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
index afd703eac6b..5faf0209595 100644
--- a/app/services/authentication/omniauth_service.rb
+++ b/app/services/authentication/omniauth_service.rb
@@ -37,7 +37,6 @@ module Authentication
:controller,
:contract,
:user_attributes,
- :identity_url,
:user
delegate :session, to: :controller
@@ -122,7 +121,6 @@ module Authentication
def update_user_from_omniauth!(additional_user_params)
# Find or create the user from the auth hash
self.user_attributes = build_omniauth_hash_to_user_attributes.merge(additional_user_params)
- self.identity_url = user_attributes[:identity_url]
self.user = lookup_or_initialize_user
# Assign or update the user with the omniauth attributes
@@ -153,8 +151,8 @@ module Authentication
return unless token
token.user.tap do |user|
- if identity_url.present?
- slug, external_id = identity_url.split(":", 2)
+ if user_attributes[:identity_url].present?
+ slug, external_id = user_attributes[:identity_url].split(":", 2)
link = user.user_auth_provider_links.find_or_initialize_by(auth_provider: AuthProvider.find_by!(slug:))
link.external_id = external_id
link.save!
@@ -170,7 +168,7 @@ module Authentication
if developer_provider?
User.find_by(mail: auth_hash[:uid])
else
- UserAuthProviderLink.with_identity_url(identity_url).first&.user
+ UserAuthProviderLink.with_identity_url(user_attributes[:identity_url]).first&.user
end
end
@@ -294,7 +292,7 @@ module Authentication
# Indicates whether OmniAuth::Strategies::Delevoper strategy is used.
# https://github.com/omniauth/omniauth/blob/0bcfd5b25bf946422cd4d9c40c4f514121ac04d6/lib/omniauth/strategies/developer.rb
# if true:
- # identity_url should no be set i
+ # identity_url should not be set and
# user should be found by mail, because mail plays uid role in developer strategy
def developer_provider?
Rails.env.local? && auth_hash[:provider] == "developer"
diff --git a/db/migrate/20250512114003_move_users_identity_url_to_user_auth_provider_links.rb b/db/migrate/20250512114003_move_users_identity_url_to_user_auth_provider_links.rb
index 64705083537..1e492080c24 100644
--- a/db/migrate/20250512114003_move_users_identity_url_to_user_auth_provider_links.rb
+++ b/db/migrate/20250512114003_move_users_identity_url_to_user_auth_provider_links.rb
@@ -36,6 +36,7 @@ class MoveUsersIdentityUrlToUserAuthProviderLinks < ActiveRecord::Migration[8.0]
t.string :external_id, null: false
t.timestamps null: false
t.index %i[user_id auth_provider_id], unique: true
+ t.index %i[auth_provider_id external_id], unique: true
end
reversible do |direction|
@@ -67,6 +68,5 @@ class MoveUsersIdentityUrlToUserAuthProviderLinks < ActiveRecord::Migration[8.0]
end
end
end
- remove_column :users, :identity_url, :string
end
end
diff --git a/docs/api/apiv3/components/schemas/user_model.yml b/docs/api/apiv3/components/schemas/user_model.yml
index 1ebbe6ebf5f..b5a8286ca84 100644
--- a/docs/api/apiv3/components/schemas/user_model.yml
+++ b/docs/api/apiv3/components/schemas/user_model.yml
@@ -83,7 +83,7 @@ allOf:
- 'null'
description: |-
User's identity_url for OmniAuth authentication.
- **Deprecated:** It will be removed in the near future. Use `UserAuthProviderLink` API instead.
+ **Deprecated:** It will be removed in the near future.
# Conditions
diff --git a/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb b/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb
index fb17558f8e0..1088aa1c0c6 100644
--- a/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb
+++ b/lib_static/open_project/authentication/strategies/warden/jwt_oidc.rb
@@ -30,7 +30,7 @@ module OpenProject
error_description: "Requires scope #{scope} to access this resource."
end
- user = UserAuthProviderLink.where(auth_provider: provider, external_id: payload["sub"]).first&.user
+ user = provider.user_auth_provider_links.find_by(external_id: payload["sub"])&.user
authentication_result(user)
end,
->(error) { fail_with_header!(error: "invalid_token", error_description: error) }
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index 57bf0644b6f..cab39ac30b1 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -73,9 +73,7 @@ FactoryBot.define do
raise "slug or external_id is blank" if slug.blank? || external_id.blank?
auth_provider = AuthProvider.find_by(slug:) || create(:oidc_provider, slug:)
- user.user_auth_provider_links.create!(auth_provider:,
- external_id: external_id)
-
+ user.user_auth_provider_links.create!(auth_provider:, external_id:)
end
end