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

Remove legacy_upload_query and its feature_flag.

Pavel Balashov3ed96cf1b5a9
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/legacy_upload_link_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/legacy_upload_link_query.rb
deleted file mode 100644
index d41388a26f9..00000000000
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/legacy_upload_link_query.rb
+++ /dev/null
@@ -1,141 +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.
-#++
-
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class LegacyUploadLinkQuery
- using Storages::Peripherals::ServiceResultRefinements
-
- URI_BASE_PATH = '/ocs/v2.php/apps/files_sharing/api/v1/shares'.freeze
- UPLOAD_LINK_BASE = '/public.php/webdav'.freeze
-
- def initialize(storage)
- @uri = URI(storage.host).normalize
- @oauth_client = storage.oauth_client
- end
-
- def call(user:, data:)
- @user = user
- validated(data) >>
- method(:create_file_share) >>
- method(:apply_drop_permission) >>
- method(:build_upload_link)
- end
-
- private
-
- def validated(data)
- if data.nil? || data['fileName'].nil? || data['parent'].nil?
- error(:error, 'Data is invalid', data)
- else
- ServiceResult.success(
- result: Struct.new(:file_name, :parent)
- .new(data['fileName'], data['parent'])
- )
- end
- end
-
- def create_file_share(data)
- password = SecureRandom.uuid
-
- outbound_response(
- method: :post,
- relative_path: URI_BASE_PATH,
- payload: {
- shareType: 3,
- password:,
- path: data.parent,
- expireDate: Date.tomorrow
- }
- ).map do |response|
- Struct.new(:id, :token, :password, :file_name)
- .new(response.ocs.data.id, response.ocs.data.token, password, data.file_name)
- end
- end
-
- def apply_drop_permission(share)
- outbound_response(
- method: :put,
- relative_path: "#{URI_BASE_PATH}/#{share.id}",
- payload: {
- permissions: 5
- }
- ).map { share }
- end
-
- def build_upload_link(share)
- destination = @uri.merge("#{UPLOAD_LINK_BASE}/#{CGI.escapeURIComponent(share.file_name)}")
- destination.user = share.token
- destination.password = share.password
-
- ServiceResult.success(result: Storages::UploadLink.new(destination, :put))
- end
-
- def outbound_response(method:, relative_path:, payload:) # rubocop:disable Metrics/AbcSize
- response = Util.token(user: @user, oauth_client: @oauth_client) do |token|
- response = begin
- ServiceResult.success(
- result: RestClient::Request.execute(
- method:,
- url: @uri.merge(relative_path).to_s,
- payload: payload.to_json,
- headers: {
- 'Authorization' => "Bearer #{token.access_token}",
- 'OCS-APIRequest' => 'true',
- 'Accept' => 'application/json',
- 'Content-Type' => 'application/json'
- }
- )
- )
- rescue RestClient::Unauthorized => e
- Util.error(:not_authorized, 'Outbound request not authorized!', e.response)
- rescue RestClient::NotFound => e
- Util.error(:not_found, 'Outbound request destination not found!', e.response)
- rescue RestClient::ExceptionWithResponse => e
- Util.error(:error, 'Outbound request failed!', e.response)
- rescue StandardError
- Util.error(:error, 'Outbound request failed!')
- end
-
- # rubocop:disable Style/OpenStructUse
- # rubocop:disable Style/MultilineBlockChain
- response
- .bind do |r|
- # The nextcloud API returns a successful response with empty body if the authorization is missing or expired
- if r.body.blank?
- Util.error(:not_authorized, 'Outbound request not authorized!')
- else
- ServiceResult.success(result: r)
- end
- end
- .map { |r| JSON.parse(r.body, object_class: OpenStruct) }
- # rubocop:enable Style/MultilineBlockChain
- # rubocop:enable Style/OpenStructUse Style/MultilineBlockChain
- end
- end
- end
-end
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rb
index 4228a33856d..1def1670179 100644
--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb
@@ -49,29 +49,11 @@ module Storages::Peripherals
@storage = storage
end
- (COMMANDS + QUERIES - ['upload_link_query']).each do |request|
+ (COMMANDS + QUERIES).each do |request|
define_method(request) do
- result(clazz(@storage, request))
+ clazz = "::Storages::Peripherals::StorageInteraction::#{@storage.short_provider_type.capitalize}::#{request.to_s.classify}".constantize
+ clazz.new(@storage).method(:call).to_proc
end
end
-
- def upload_link_query
- query_clazz = if OpenProject::FeatureDecisions.legacy_upload_preparation_active?
- clazz(@storage, 'legacy_upload_link_query')
- else
- clazz(@storage, 'upload_link_query')
- end
- result(query_clazz)
- end
-
- private
-
- def result(request_class)
- request_class.new(@storage).method(:call).to_proc
- end
-
- def clazz(storage, request)
- "::Storages::Peripherals::StorageInteraction::#{storage.short_provider_type.capitalize}::#{request.to_s.classify}".constantize
- end
end
end
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index 2c3196baa65..080dbea7611 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -43,7 +43,6 @@ module OpenProject::Storages
initializer 'openproject_storages.feature_decisions' do
OpenProject::FeatureDecisions.add :storage_file_picking_select_all
OpenProject::FeatureDecisions.add :storage_project_folders
- OpenProject::FeatureDecisions.add :legacy_upload_preparation
OpenProject::FeatureDecisions.add :managed_project_folders
end
diff --git a/modules/storages/spec/common/peripherals/storage_requests_spec.rb b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
index b6d31e290ec..5b369ba3e13 100644
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@ -452,149 +452,6 @@ describe Storages::Peripherals::StorageRequests, webmock: true do
include_examples 'outbound is failing', 404, :not_found
include_examples 'outbound is failing', 500, :error
end
-
- describe '#legacy_upload_link_query', with_flag: { legacy_upload_preparation: true } do
- let(:query_payload) do
- Struct.new(:fileName, :parent).new("ape.png", "/Pictures")
- end
-
- let(:uri) do
- "#{url}/public.php/webdav/#{query_payload[:fileName]}"
- end
-
- let(:share_id) { 37 }
-
- before do
- stub_request(:post, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares")
- .with(
- body: hash_including(
- {
- shareType: 3,
- path: query_payload.parent,
- expireDate: Date.tomorrow.iso8601
- }
- )
- )
- .to_return(
- status: 200,
- body: {
- ocs: {
- data: {
- id: share_id,
- token: 'jJ6t8yHe7CEX5Bp'
- }
- }
- }.to_json
- )
- stub_request(:put, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares/#{share_id}")
- .with(body: { permissions: 5 })
- .to_return(status: 200, body: {}.to_json)
- end
-
- context 'with Nextcloud storage type selected' do
- it 'must return an upload link URL' do
- link = subject
- .upload_link_query
- .call(user:, data: query_payload)
- .result
- expect(link.destination.path).to be_eql("/public.php/webdav/#{query_payload.fileName}")
- expect(link.destination.host).to be_eql(URI(url).host)
- expect(link.destination.scheme).to be_eql(URI(url).scheme)
- expect(link.destination.user).not_to be_nil
- expect(link.destination.password).not_to be_nil
- expect(link.method).to eq(:put)
- end
- end
-
- context 'with not supported storage type selected' do
- before do
- allow(storage).to receive(:provider_type).and_return('not_supported_storage_type'.freeze)
- end
-
- it 'must raise ArgumentError' do
- expect do
- subject.upload_link_query.result.call(user:, data: query_payload)
- end.to raise_error(ArgumentError)
- end
- end
-
- context 'with missing OAuth token' do
- before do
- allow_any_instance_of(OAuthClients::ConnectionManager).to receive(:get_access_token).and_return(ServiceResult.failure)
- end
-
- it 'must return ":not_authorized" ServiceResult' do
- result = subject
- .upload_link_query
- .call(user:, data: query_payload)
- expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
- end
- end
-
- context 'with first outbound request returning 200 and an empty body' do
- before do
- stub_request(:post, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares")
- .with(
- body: hash_including(
- {
- shareType: 3,
- path: query_payload.parent,
- expireDate: Date.tomorrow.iso8601
- }
- )
- )
- .to_return(status: 200)
- end
-
- it 'must return :not_authorized ServiceResult' do
- result = subject
- .upload_link_query
- .call(user:, data: query_payload)
- expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
- end
- end
-
- context 'with second outbound request returning 200 and an empty body' do
- before do
- stub_request(:put, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares/#{share_id}")
- .with(body: { permissions: 5 })
- .to_return(status: 200)
- end
-
- it 'must return :not_authorized ServiceResult' do
- result = subject
- .upload_link_query
- .call(user:, data: query_payload)
- expect(result).to be_failure
- expect(result.errors.code).to be(:not_authorized)
- end
- end
-
- shared_examples_for 'outbound is failing' do |method = :get, path = '', code = 500, symbol = :error|
- context "with outbound request returning #{code}" do
- before do
- stub_request(method, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares#{path}").to_return(status: code)
- end
-
- it "must return :#{symbol} ServiceResult" do
- result = subject
- .upload_link_query
- .call(user:, data: query_payload)
- expect(result).to be_failure
- expect(result.errors.code).to be(symbol)
- end
- end
- end
-
- include_examples 'outbound is failing', :post, '', 404, :not_found
- include_examples 'outbound is failing', :post, '', 401, :not_authorized
- include_examples 'outbound is failing', :post, '', 500, :error
- include_examples 'outbound is failing', :put, '/37', 404, :not_found
- include_examples 'outbound is failing', :put, '/37', 401, :not_authorized
- include_examples 'outbound is failing', :put, '/37', 500, :error
- end
end
describe '#group_users_query' do