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

fix[Op#50742] Replace `StorageErrorPresenter` with new contract x model errors

Kabiru Mwenja457ed3d4ecfe
diff --git a/app/services/service_result_errors_presenter.rb b/app/services/service_result_errors_presenter.rb
deleted file mode 100644
index 30a298bfeb0..00000000000
--- a/app/services/service_result_errors_presenter.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 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.
-#++
-
-class ServiceResultErrorsPresenter < SimpleDelegator
- attr_reader :service_result
-
- def initialize(service_result)
- super(service_result.result)
- @service_result = service_result
- end
-
- delegate :errors, to: :service_result
-end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 06c1de9c30f..0d7f8f06da9 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -115,12 +115,12 @@ class Storages::Admin::StoragesController < ApplicationController
service_result = ::Storages::Storages::UpdateService
.new(user: current_user, model: @storage)
.call(@storage_params)
+ @storage = service_result.result
if service_result.success?
flash[:notice] = I18n.t(:notice_successful_update)
redirect_to edit_admin_settings_storage_path(@storage)
elsif OpenProject::FeatureDecisions.storage_primer_design_active?
- @storage = ServiceResultErrorsPresenter.new(service_result)
render :edit_host
else
render :edit
@@ -141,16 +141,15 @@ class Storages::Admin::StoragesController < ApplicationController
redirect_to admin_settings_storages_path
end
- def replace_oauth_application # rubocop:disable Metrics/AbcSize
+ def replace_oauth_application
@storage.oauth_application.destroy
service_result = ::Storages::OAuthApplications::CreateService.new(storage: @storage, user: current_user).call
+ @oauth_application = service_result.result
if service_result.success?
flash[:notice] = I18n.t('storages.notice_oauth_application_replaced')
- @oauth_application = service_result.result
render :show_oauth_application
elsif OpenProject::FeatureDecisions.storage_primer_design_active?
- @oauth_application = ServiceResultErrorsPresenter.new(service_result)
render :show_oauth_application
else
render :edit
diff --git a/spec/services/service_result_errors_presenter_spec.rb b/spec/services/service_result_errors_presenter_spec.rb
deleted file mode 100644
index 68fb53055cc..00000000000
--- a/spec/services/service_result_errors_presenter_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 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'
-
-RSpec.describe ServiceResultErrorsPresenter do
- let(:model) { instance_double(ApplicationRecord, id: 1) }
- let(:errors) { ActiveModel::Errors.new([]) }
- let(:service_result) { instance_double(ServiceResult, result: model, errors:) }
-
- let(:presenter) { described_class.new(service_result) }
-
- it 'forwards model methods to the model' do
- expect(presenter.id).to eq(model.id)
- end
-
- it 'delegates errors to the service result' do
- expect(presenter.errors).to eq(errors)
- end
-end