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
Fix ScimClients::DeleteService
Jan Sandbrinkc263d9d794d9
diff --git a/app/services/scim_clients/delete_service.rb b/app/services/scim_clients/delete_service.rbindex 1ad31afae8b..42b100da4ea 100644--- a/app/services/scim_clients/delete_service.rb+++ b/app/services/scim_clients/delete_service.rb@@ -29,11 +29,16 @@#++class ScimClients::DeleteService < BaseServices::Delete- def after_perform(call)- return call if call.failure?+ def before_perform(_, call)+ # pre-loading service_account association before destroy to ensure it's available afterwards+ call.result.service_account+ call+ end+ def after_perform(call)client = call.resultclient.service_account.update_column(:status, User.statuses[:locked])+ client.service_account.user_auth_provider_links.delete_allcallendenddiff --git a/spec/services/scim_clients/delete_service_spec.rb b/spec/services/scim_clients/delete_service_spec.rbnew file mode 100644index 00000000000..5becdcbafc3--- /dev/null+++ b/spec/services/scim_clients/delete_service_spec.rb@@ -0,0 +1,58 @@+# 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.+#++++require "spec_helper"+require "services/base_services/behaves_like_delete_service"++RSpec.describe ScimClients::DeleteService, type: :model do+ subject { instance.call }++ let(:instance) { described_class.new(user:, model: scim_client) }+ let(:user) { build_stubbed(:admin) }+ let!(:scim_client) do+ # loading the freshly created client from the database, so that associations are not preloaded+ # (because this leads to different behaviour after destroy)+ ScimClient.find(create(:scim_client, service_account:).id)+ end+ let(:service_account) { create(:service_account, authentication_provider: create(:oidc_provider)) }++ it_behaves_like "BaseServices delete service" do+ let(:model_instance) { scim_client }+ end++ it "locks the service account" do+ subject+ expect(service_account.reload).to be_locked+ end++ it "deassociates the service account from its authentication provider" do+ expect { subject }.to change(UserAuthProviderLink, :count).from(1).to(0)+ end+end