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

[#62107] Reacto on PR comments.

Pavel Balashou19d76423349b
diff --git a/app/contracts/groups/base_contract.rb b/app/contracts/groups/base_contract.rb
index 9f5f436c051..16a0970a191 100644
--- a/app/contracts/groups/base_contract.rb
+++ b/app/contracts/groups/base_contract.rb
@@ -37,7 +37,6 @@ module Groups
# hence we need to put "lastname" as an attribute here
attribute :name
attribute :lastname
- attribute :identity_url
validate :validate_unique_users
diff --git a/app/contracts/users/delete_contract.rb b/app/contracts/users/delete_contract.rb
index f76eb13837e..cf3d5178e1e 100644
--- a/app/contracts/users/delete_contract.rb
+++ b/app/contracts/users/delete_contract.rb
@@ -43,8 +43,7 @@ module Users
if actor == user
Setting.users_deletable_by_self?
else
- (actor.admin? && actor.active? && Setting.users_deletable_by_admins?) ||
- User.system == actor
+ actor.admin? && actor.active? && Setting.users_deletable_by_admins?
end
end
end
diff --git a/app/controllers/scim_v2/scim_controller_mixins.rb b/app/controllers/scim_v2/scim_controller_mixins.rb
index 5a160ce334c..d44942eaf02 100644
--- a/app/controllers/scim_v2/scim_controller_mixins.rb
+++ b/app/controllers/scim_v2/scim_controller_mixins.rb
@@ -40,11 +40,10 @@ module ScimV2
return handle_scim_error(Scimitar::AuthenticationError.new) unless OpenProject::FeatureDecisions.scim_api_active?
warden = request.env["warden"]
- User.current = warden.authenticate! scope: :scim_v2
+ User.current = warden.authenticate!(scope: :scim_v2)
# Only a ServiceAccount associated with a ScimClient can use SCIM Server API
-
- unless User.current.is_a?(ServiceAccount) && User.current.service_account_association.service.is_a?(ScimClient)
+ unless User.current.respond_to?(:service) && User.current.service.is_a?(ScimClient)
handle_scim_error(Scimitar::AuthenticationError.new)
end
end
diff --git a/app/controllers/scim_v2/users_controller.rb b/app/controllers/scim_v2/users_controller.rb
index 288b37a2491..e211be004b1 100644
--- a/app/controllers/scim_v2/users_controller.rb
+++ b/app/controllers/scim_v2/users_controller.rb
@@ -114,8 +114,6 @@ module ScimV2
else
raise result.message
end
-
- raise call.message
end
end
end
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 3db8f0429b8..5e10900f000 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -239,19 +239,19 @@ class Principal < ApplicationRecord
external_id
end
- def self.scim_mutable_attributes
- # Allow mutation of everything with a write accessor
- nil
- end
+ class << self
+ def scim_mutable_attributes
+ # Allow mutation of everything with a write accessor
+ nil
+ end
- def self.scim_timestamps_map
- {
- created: :created_at,
- lastModified: :updated_at
- }
- end
+ def scim_timestamps_map
+ {
+ created: :created_at,
+ lastModified: :updated_at
+ }
+ end
- class << self
# Hack to exclude the Users::InexistentUser
# from showing up on filters for type.
# The method is copied over from rails changed only
diff --git a/app/models/service_account.rb b/app/models/service_account.rb
index 2048e2b318b..2a17c0e1a74 100644
--- a/app/models/service_account.rb
+++ b/app/models/service_account.rb
@@ -35,6 +35,8 @@ class ServiceAccount < User
has_one :service_account_association, dependent: :destroy
+ delegate :service, to: :service_account_association
+
def to_s
name
end
diff --git a/app/services/authentication/omniauth_service.rb b/app/services/authentication/omniauth_service.rb
index a59214962d9..b48d154bba1 100644
--- a/app/services/authentication/omniauth_service.rb
+++ b/app/services/authentication/omniauth_service.rb
@@ -168,7 +168,12 @@ module Authentication
if developer_provider?
User.find_by(mail: auth_hash[:uid])
else
- UserAuthProviderLink.with_identity_url(user_attributes[:identity_url]).first&.principal
+ UserAuthProviderLink
+ .left_joins(:principal)
+ .where(principal: { type: "User" })
+ .with_identity_url(user_attributes[:identity_url])
+ .first
+ &.principal
end
end
diff --git a/app/services/user_auth_provider_links_setter.rb b/app/services/user_auth_provider_links_setter.rb
index 7fdd3280b47..5082b0ca297 100644
--- a/app/services/user_auth_provider_links_setter.rb
+++ b/app/services/user_auth_provider_links_setter.rb
@@ -46,7 +46,7 @@ module UserAuthProviderLinksSetter
model.user_auth_provider_links.find { |l| l.id == link.id }.external_id_will_change!
end
else
- raise ActiveRecord::RecordNotFound, "AuthProvider with slug: \"#{slug}\" has been not found"
+ raise ActiveRecord::RecordNotFound, "AuthProvider with slug: \"#{slug}\" has not been found"
end
end
end
diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb
index 96da619d4c5..a21a7bd1291 100644
--- a/config/initializers/warden.rb
+++ b/config/initializers/warden.rb
@@ -27,7 +27,7 @@ OpenProject::Authentication.update_strategies(OpenProject::Authentication::Scope
end
OpenProject::Authentication.update_strategies(OpenProject::Authentication::Scope::SCIM_V2, { store: false }) do |_|
- %i[oauth jwt_oidc session]
+ %i[oauth jwt_oidc]
end
Rails.application.configure do |app|
diff --git a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb
index 7a690b9e7cf..dc7e1e4b6de 100644
--- a/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb
+++ b/lib_static/open_project/authentication/strategies/warden/doorkeeper_oauth.rb
@@ -42,7 +42,8 @@ module OpenProject
end
def authenticate_user(id)
- user = id && User.active.where(id:).or(ServiceAccount.where(id:)).first
+ # ServiceAccount is found explicitly because ServiceAccount is builtin, but User.active excludes builtin entities.
+ user = id && User.active.where(id:).or(ServiceAccount.where(id:, status: ServiceAccount.statuses[:active])).first
if user
success!(user)
else
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 35ebbb5a130..f6991bd137d 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,11 @@ module OpenProject
error_description: "Requires scope #{scope} to access this resource."
end
- user = provider.user_auth_provider_links.find_by(external_id: payload["sub"])&.principal
+ user = provider
+ .user_auth_provider_links
+ .left_joins(:principal)
+ .where(principal: { type: ["User", "ServiceAccount"] })
+ .find_by(external_id: payload["sub"])&.principal
authentication_result(user)
end,
->(error) { fail_with_header!(error: "invalid_token", error_description: error) }