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
[#62107] React on PR comments volume 2.
Pavel Balashou601b054e044c
diff --git a/app/controllers/scim_v2/users_controller.rb b/app/controllers/scim_v2/users_controller.rbindex e211be004b1..aaeb30ebb59 100644--- a/app/controllers/scim_v2/users_controller.rb+++ b/app/controllers/scim_v2/users_controller.rb@@ -37,8 +37,6 @@ module ScimV2storage_class.transaction douser = storage_class.newuser.from_scim!(scim_hash: scim_resource.as_json)- user.firstname = "123" if user.firstname.blank?- user.lastname = "456" if user.lastname.blank?call = Users::CreateService.new(user: User.current, model: user).call(user.attributes)diff --git a/app/models/principal.rb b/app/models/principal.rbindex 5e10900f000..88dce60da38 100644--- a/app/models/principal.rb+++ b/app/models/principal.rb@@ -67,7 +67,10 @@ class Principal < ApplicationRecordforeign_key: "user_id"has_many :projects, through: :membershipshas_many :categories, foreign_key: "assigned_to_id", dependent: :nullify, inverse_of: :assigned_to- has_many :user_auth_provider_links, dependent: :destroy, foreign_key: :user_id+ has_many :user_auth_provider_links,+ dependent: :destroy,+ foreign_key: :user_id,+ inverse_of: :principalhas_many :auth_providers, through: :user_auth_provider_linkshas_paper_trail@@ -210,20 +213,6 @@ class Principal < ApplicationRecordendend- def scim_active=(is_active)- if is_active- activate- true- else- lock if active?- false- end- end-- def scim_active- active?- end-def scim_external_idactive_user_auth_provider_link&.external_idenddiff --git a/app/models/user.rb b/app/models/user.rbindex 1bfcd5b80fd..f3595c16f78 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -278,7 +278,7 @@ class User < Principaldef self.try_to_autologin(key)token = Token::AutoLogin.find_by_plaintext_value(key) # rubocop:disable Rails/DynamicFindBy# Make sure there's only 1 token that matches the key- if token && ((token.created_at > Setting.autologin.to_i.day.ago) && token.user&.active?)+ if token && (token.created_at > Setting.autologin.to_i.day.ago) && token.user&.active?token.userendend@@ -565,11 +565,27 @@ class User < Principaldef scim_emails=(emails)email = (emails.find { |email| email.primary == true }) ||(emails.find { |email| email.type == "work" }) ||- emails.sort.first+ emails.minself.mail = email&.valueend+ # rubocop:disable Naming/PredicateMethod+ def scim_active=(is_active)+ if is_active+ activate+ true+ else+ lock if active?+ false+ end+ end++ def scim_active+ active?+ end+ # rubocop:enable Naming/PredicateMethod+def self.scim_resource_typeScimitar::Resources::Userenddiff --git a/app/models/user_auth_provider_link.rb b/app/models/user_auth_provider_link.rbindex de7925b22d7..f3fdc331c9e 100644--- a/app/models/user_auth_provider_link.rb+++ b/app/models/user_auth_provider_link.rb@@ -29,7 +29,7 @@#++class UserAuthProviderLink < ApplicationRecord- belongs_to :principal, foreign_key: :user_id+ belongs_to :principal, foreign_key: :user_id, inverse_of: :user_auth_provider_linksbelongs_to :auth_providerscope :with_identity_url, ->(identity_url) dodiff --git a/config/initializers/scimitar.rb b/config/initializers/scimitar.rbindex a50550655fb..266285e1c8b 100644--- a/config/initializers/scimitar.rb+++ b/config/initializers/scimitar.rb@@ -37,15 +37,6 @@ Rails.application.config.to_prepare doapplication_controller_mixin: ScimV2::ScimControllerMixins)- module ScimitarSchemaExtension- def scim_attributes- super + [Scimitar::Schema::Attribute.new(name: "externalId",- type: "string",- caseExact: true,- required: true)]- end- end-Scimitar::Schema::User.singleton_class.class_eval doprepend ScimitarSchemaExtensionenddiff --git a/lib/scimitar_schema_extension.rb b/lib/scimitar_schema_extension.rbnew file mode 100644index 00000000000..c94019ab766--- /dev/null+++ b/lib/scimitar_schema_extension.rb@@ -0,0 +1,38 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module ScimitarSchemaExtension+ def scim_attributes+ super + [Scimitar::Schema::Attribute.new(name: "externalId",+ type: "string",+ caseExact: true,+ required: true)]+ end+enddiff --git a/spec/requests/scim_v2/authentication_spec.rb b/spec/requests/scim_v2/authentication_spec.rbindex d765b3b3a85..fe45d51854b 100644--- a/spec/requests/scim_v2/authentication_spec.rb+++ b/spec/requests/scim_v2/authentication_spec.rb@@ -117,7 +117,7 @@ RSpec.describe "SCIM API Authentication" doheader "Authorization", "Bearer #{token}"end- it "" do+ it doget "/scim_v2/ServiceProviderConfig", {}, headersexpect(last_response).to have_http_status(200)@@ -126,18 +126,18 @@ RSpec.describe "SCIM API Authentication" docontext "when scim_v2 scope is missing in token" dolet(:token_scope) { "api_v3" }- it "" do+ it doget "/scim_v2/ServiceProviderConfig", {}, headers- expect(last_response).to have_http_status(401)expect(last_response.body).to eq("insufficient_scope")expect(last_response.headers["WWW-Authenticate"]).to eq("Bearer realm=\"OpenProject API\", error=\"insufficient_scope\", error_description=\"Requires scope scim_v2 to access this resource.\"")+ expect(last_response).to have_http_status(401)endendcontext "when token_sub does not match a service_account" dobefore { service_account.user_auth_provider_links.delete_all }- it "" do+ it doget "/scim_v2/ServiceProviderConfig", {}, headersexpect(last_response).to have_http_status(401)@@ -160,6 +160,7 @@ RSpec.describe "SCIM API Authentication" do{ "detail" => "Requires authentication", "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],"status" => "401" })+ expect(last_response).to have_http_status(401)endendenddiff --git a/spec/requests/scim_v2/groups_spec.rb b/spec/requests/scim_v2/groups_spec.rbindex f34015b096f..7f48ca00f37 100644--- a/spec/requests/scim_v2/groups_spec.rb+++ b/spec/requests/scim_v2/groups_spec.rb@@ -304,8 +304,7 @@ RSpec.describe "SCIM API Groups" do"members" => [{ "value" => user.id.to_s },{ "value" => admin.id.to_s }- ],- "schemas" => ["urn:ietf:params:scim:schemas:core:2.0:Group"]+ ]}put "/scim_v2/Groups/#{group.id}", request_body.to_json, headersdiff --git a/spec/requests/scim_v2/schemas_spec.rb b/spec/requests/scim_v2/schemas_spec.rbindex fd9bbe27afd..618e05d7b0f 100644--- a/spec/requests/scim_v2/schemas_spec.rb+++ b/spec/requests/scim_v2/schemas_spec.rb@@ -42,7 +42,7 @@ RSpec.describe "SCIM API Schemas" dodescribe "GET /scim_v2/Schemas" docontext "with the feature flag enabled", with_flag: { scim_api: true } do- it do+ it "responds with supported schemas " doget "/scim_v2/Schemas", {}, headersresponse_body = JSON.parse(last_response.body)diff --git a/spec/requests/scim_v2/users_spec.rb b/spec/requests/scim_v2/users_spec.rbindex 87fac55e617..3ea25b14b4f 100644--- a/spec/requests/scim_v2/users_spec.rb+++ b/spec/requests/scim_v2/users_spec.rb@@ -246,10 +246,12 @@ RSpec.describe "SCIM API Users" doexpect(last_response).to have_http_status(409)response_body = JSON.parse(last_response.body)- expect(response_body).to eq({ "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],- "detail" => "Operation failed due to a uniqueness constraint: Username has already been taken.",- "status" => "409",- "scimType" => "uniqueness" })+ expect(response_body).to eq(+ { "schemas" => ["urn:ietf:params:scim:api:messages:2.0:Error"],+ "detail" => "Operation failed due to a uniqueness constraint: Username has already been taken.",+ "status" => "409",+ "scimType" => "uniqueness" }+ )endenddiff --git a/spec/services/users/delete_service_spec.rb b/spec/services/users/delete_service_spec.rbindex 9a05b189bdb..2b566cdd2d4 100644--- a/spec/services/users/delete_service_spec.rb+++ b/spec/services/users/delete_service_spec.rb@@ -70,7 +70,7 @@ RSpec.describe Users::DeleteService, type: :model doallow(actor).to receive(:admin?).and_return falseend- it_behaves_like "deletes the user"+ it_behaves_like "does not delete the user"endcontext "with privileged system user" do@@ -90,7 +90,7 @@ RSpec.describe Users::DeleteService, type: :model docontext "with system user" dolet(:actor) { User.system }- it_behaves_like "deletes the user"+ it_behaves_like "does not delete the user"endendend