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 ruby 2.7 deprecations (#8867)

ulfertsa112999dcca5
diff --git a/app/models/group.rb b/app/models/group.rb
index 8a37e71820b..9913ca005c1 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -85,7 +85,7 @@ class Group < Principal
::Groups::AddUsersService
.new(self, current_user: User.current)
- .call(user_ids)
+ .call(ids: user_ids)
.tap do |result|
raise "Failed to add to group #{result.message}" if result.failure?
end
diff --git a/app/services/base_services/base_callable.rb b/app/services/base_services/base_callable.rb
index a95a8c51cfd..43b9746d136 100644
--- a/app/services/base_services/base_callable.rb
+++ b/app/services/base_services/base_callable.rb
@@ -43,7 +43,7 @@ module BaseServices
protected
- def perform(params)
+ def perform(params = {})
raise NotImplementedError
end
end
diff --git a/app/services/custom_actions/update_work_package_service.rb b/app/services/custom_actions/update_work_package_service.rb
index 3f878f9c6d7..6788f91a4b7 100644
--- a/app/services/custom_actions/update_work_package_service.rb
+++ b/app/services/custom_actions/update_work_package_service.rb
@@ -47,7 +47,7 @@ class CustomActions::UpdateWorkPackageService
result = ::WorkPackages::UpdateService
.new(user: user,
model: work_package)
- .call({})
+ .call(**{})
block_with_result(result, &block)
end
diff --git a/app/services/groups/add_users_service.rb b/app/services/groups/add_users_service.rb
index 8f421dea442..88ec3439b74 100644
--- a/app/services/groups/add_users_service.rb
+++ b/app/services/groups/add_users_service.rb
@@ -38,9 +38,9 @@ module Groups
contract_class: Groups::AddUsersContract
end
- def after_validate(user_ids, _call)
+ def after_validate(params, _call)
::Group.transaction do
- add_to_user_and_projects(user_ids)
+ add_to_user_and_projects(params[:ids])
end
end
diff --git a/app/services/work_packages/bulk/update_service.rb b/app/services/work_packages/bulk/update_service.rb
index ee131d40ca3..7bbb3d0c530 100644
--- a/app/services/work_packages/bulk/update_service.rb
+++ b/app/services/work_packages/bulk/update_service.rb
@@ -69,7 +69,7 @@ module WorkPackages
service_call = WorkPackages::UpdateService
.new(user: user, model: work_package)
- .call(attributes.merge(send_notifications: params[:send_notification] == '1').symbolize_keys)
+ .call(**attributes.merge(send_notifications: params[:send_notification] == '1').symbolize_keys)
if service_call.success?
saved << work_package.id
diff --git a/app/services/work_packages/move_service.rb b/app/services/work_packages/move_service.rb
index c30f4cec956..527391905bb 100644
--- a/app/services/work_packages/move_service.rb
+++ b/app/services/work_packages/move_service.rb
@@ -43,14 +43,14 @@ class WorkPackages::MoveService
WorkPackages::CopyService
.new(user: user,
work_package: wp)
- .call(attributes.symbolize_keys)
+ .call(**attributes.symbolize_keys)
end
def update(attributes)
WorkPackages::UpdateService
.new(user: user,
model: work_package)
- .call(attributes.symbolize_keys)
+ .call(**attributes.symbolize_keys)
end
def copy_with_updated_parent_id(wp, attributes, ancestors)
diff --git a/config/routes.rb b/config/routes.rb
index ce44a6808f5..2e375c7af16 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -42,7 +42,10 @@ OpenProject::Application.routes.draw do
get '/issues(/)' => redirect("#{rails_relative_url_root}/work_packages")
# The URI.escape doesn't escape / unless you ask it to.
# see https://github.com/rails/rails/issues/5688
- get '/issues/*rest' => redirect { |params, _req| "#{rails_relative_url_root}/work_packages/#{URI.escape(params[:rest])}" }
+ get '/issues/*rest' => redirect { |params, _req|
+ "#{rails_relative_url_root}/work_packages/#{URI::RFC2396_Parser.new.escape(params[:rest])}"
+ }
+
# Respond with 410 gone for APIV2 calls
match '/api/v2(/*unmatched_route)', to: proc { [410, {}, ['']] }, via: :all
@@ -50,7 +53,9 @@ OpenProject::Application.routes.draw do
# Redirect wp short url for work packages to full URL
get '/wp(/)' => redirect("#{rails_relative_url_root}/work_packages")
- get '/wp/*rest' => redirect { |params, _req| "#{rails_relative_url_root}/work_packages/#{URI.escape(params[:rest])}" }
+ get '/wp/*rest' => redirect { |params, _req|
+ "#{rails_relative_url_root}/work_packages/#{URI::RFC2396_Parser.new.escape(params[:rest])}"
+ }
# Add catch method for Rack OmniAuth to allow route helpers
# Note: This renders a 404 in rails but is caught by omniauth in Rack before
diff --git a/lib/api/v3/attachments/attachment_upload_representer.rb b/lib/api/v3/attachments/attachment_upload_representer.rb
index fa186bc6e85..950ab196139 100644
--- a/lib/api/v3/attachments/attachment_upload_representer.rb
+++ b/lib/api/v3/attachments/attachment_upload_representer.rb
@@ -72,7 +72,7 @@ module API
attr_reader :attachment
- def initialize(attachment, options = {})
+ def initialize(attachment, current_user:)
super
fog_hash = DirectFogUploader.direct_fog_hash attachment: attachment
diff --git a/lib/open_project/patches/carrierwave.rb b/lib/open_project/patches/carrierwave_sanitized_file.rb
similarity index 52%
rename from lib/open_project/patches/carrierwave.rb
rename to lib/open_project/patches/carrierwave_sanitized_file.rb
index aec0c69f921..8951e55e8fc 100644
--- a/lib/open_project/patches/carrierwave.rb
+++ b/lib/open_project/patches/carrierwave_sanitized_file.rb
@@ -5,7 +5,12 @@ require 'carrierwave/storage/fog'
# All we did is add `options[:expire_at]`.
#
# @todo Upgrade to CarrierWave 2.0.2 to make this patch obsolete.
-module OpenProject::Patches::Carrierwave
+
+if Gem.loaded_specs["carrierwave"].version > Gem::Version.new('1.3.1')
+ raise "Check if these patches of Carrierwave are still required"
+end
+
+module OpenProject::Patches::FogFile
extend ActiveSupport::Concern
included do
@@ -16,24 +21,24 @@ module OpenProject::Patches::Carrierwave
local_file = local_directory.files.new(:key => path)
expire_at = options[:expire_at] || ::Fog::Time.now + @uploader.fog_authenticated_url_expiration
case @uploader.fog_credentials[:provider]
- when 'AWS', 'Google'
- # Older versions of fog-google do not support options as a parameter
- if url_options_supported?(local_file)
- local_file.url(expire_at, options)
- else
- warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider."
- local_file.url(expire_at)
- end
- when 'Rackspace'
- connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options)
- when 'OpenStack'
- connection.get_object_https_url(@uploader.fog_directory, path, expire_at)
+ when 'AWS', 'Google'
+ # Older versions of fog-google do not support options as a parameter
+ if url_options_supported?(local_file)
+ local_file.url(expire_at, options)
else
+ warn "Options hash not supported in #{local_file.class}. You may need to upgrade your Fog provider."
local_file.url(expire_at)
+ end
+ when 'Rackspace'
+ connection.get_object_https_url(@uploader.fog_directory, path, expire_at, options)
+ when 'OpenStack'
+ connection.get_object_https_url(@uploader.fog_directory, path, expire_at)
+ else
+ local_file.url(expire_at)
end
end
end
end
end
-CarrierWave::Storage::Fog::File.send(:include, OpenProject::Patches::Carrierwave)
+CarrierWave::Storage::Fog::File.send(:include, OpenProject::Patches::FogFile)
diff --git a/lib/open_project/patches/fog_file.rb b/lib/open_project/patches/fog_file.rb
new file mode 100644
index 00000000000..4265dc6ea3b
--- /dev/null
+++ b/lib/open_project/patches/fog_file.rb
@@ -0,0 +1,19 @@
+if Gem.loaded_specs["carrierwave"].version > Gem::Version.new('1.3.1')
+ raise "Check if these patches of Carrierwave are still required"
+end
+
+module OpenProject::Patches::CarrierwaveSanitizedFile
+ extend ActiveSupport::Concern
+
+ included do
+ # create the directory if it doesn't exist
+ # Overwritten to avoid ruby 2.7 deprecations
+ def mkdir!(path, directory_permissions)
+ options = {}
+ options[:mode] = directory_permissions if directory_permissions
+ FileUtils.mkdir_p(File.dirname(path), **options) unless File.exist?(File.dirname(path))
+ end
+ end
+end
+
+CarrierWave::SanitizedFile.send(:include, OpenProject::Patches::CarrierwaveSanitizedFile)
diff --git a/modules/bim/app/services/bim/bcf/issues/create_service.rb b/modules/bim/app/services/bim/bcf/issues/create_service.rb
index 681789e146f..356628c6465 100644
--- a/modules/bim/app/services/bim/bcf/issues/create_service.rb
+++ b/modules/bim/app/services/bim/bcf/issues/create_service.rb
@@ -63,11 +63,13 @@ module Bim::Bcf
::WorkPackages::UpdateService
.new(user: user, model: work_package)
- .call(params)
+ .call(**params)
end
def create_work_package(params)
- ::WorkPackages::CreateService.new(user: user).call(params)
+ ::WorkPackages::CreateService
+ .new(user: user)
+ .call(**params)
end
def work_package_id_from_links(links)
diff --git a/modules/bim/app/services/bim/bcf/issues/update_service.rb b/modules/bim/app/services/bim/bcf/issues/update_service.rb
index 1096980ee50..27a90c7779b 100644
--- a/modules/bim/app/services/bim/bcf/issues/update_service.rb
+++ b/modules/bim/app/services/bim/bcf/issues/update_service.rb
@@ -38,7 +38,7 @@ module Bim::Bcf
.new(model: model.work_package,
user: user,
contract_class: ::WorkPackages::UpdateContract)
- .call(params)
+ .call(**params)
if wp_call.success?
issue_params = params.slice(*Bim::Bcf::Issue::SETTABLE_ATTRIBUTES)
diff --git a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
index 94e934c3170..90727378d25 100644
--- a/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
+++ b/modules/bim/lib/open_project/bim/bcf_xml/issue_reader.rb
@@ -70,7 +70,7 @@ module OpenProject::Bim::BcfXml
def create_work_package
attributes = work_package_attributes.merge(project: project)
- call = WorkPackages::CreateService.new(user: user).call(attributes)
+ call = WorkPackages::CreateService.new(user: user).call(**attributes)
force_overwrite(call.result) if call.success?
diff --git a/modules/costs/spec/requests/api/time_entry_resource_spec.rb b/modules/costs/spec/requests/api/time_entry_resource_spec.rb
index 9029ffd2a70..6802780c710 100644
--- a/modules/costs/spec/requests/api/time_entry_resource_spec.rb
+++ b/modules/costs/spec/requests/api/time_entry_resource_spec.rb
@@ -456,7 +456,7 @@ describe 'API v3 time_entry resource', type: :request do
context 'if sending an activity the project disables' do
let(:disable_activity) do
- TimeEntryActivitiesProject.insert activity_id: activity.id, project_id: project.id, active: false
+ TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: false } )
end
let(:additional_setup) { -> { disable_activity } }
@@ -549,7 +549,7 @@ describe 'API v3 time_entry resource', type: :request do
context 'if sending an activity the project disables' do
let(:disable_activity) do
- TimeEntryActivitiesProject.insert activity_id: activity.id, project_id: project.id, active: false
+ TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: false } )
end
let(:additional_setup) { -> { disable_activity } }
diff --git a/spec/factories/group_factory.rb b/spec/factories/group_factory.rb
index 118f15ebbc6..a80d8225118 100644
--- a/spec/factories/group_factory.rb
+++ b/spec/factories/group_factory.rb
@@ -42,7 +42,7 @@ FactoryBot.define do
User.system.run_given do |system_user|
::Groups::AddUsersService
.new(group, current_user: system_user)
- .call(members.map(&:id))
+ .call(ids: members.map(&:id))
.on_failure { |call| raise call.message }
end
end
diff --git a/spec/models/projects/scopes/activated_time_activity_spec.rb b/spec/models/projects/scopes/activated_time_activity_spec.rb
index 0948b158045..d193fa0d310 100644
--- a/spec/models/projects/scopes/activated_time_activity_spec.rb
+++ b/spec/models/projects/scopes/activated_time_activity_spec.rb
@@ -60,8 +60,8 @@ describe Projects::Scopes::ActivatedTimeActivity, type: :model do
context 'with project specific overrides' do
before do
- TimeEntryActivitiesProject.insert(activity_id: activity.id, project_id: project.id, active: true)
- TimeEntryActivitiesProject.insert(activity_id: activity.id, project_id: other_project.id, active: false)
+ TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: true } )
+ TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: other_project.id, active: false } )
end
context 'and being active' do
diff --git a/spec/requests/api/v3/watcher_resource_spec.rb b/spec/requests/api/v3/watcher_resource_spec.rb
index dc7c6bcf490..c279d222d2a 100644
--- a/spec/requests/api/v3/watcher_resource_spec.rb
+++ b/spec/requests/api/v3/watcher_resource_spec.rb
@@ -269,7 +269,7 @@ describe 'API v3 Watcher resource', type: :request, content_type: :json do
path = api_v3_paths.available_watchers work_package.id
filters = %([{ "name": { "operator": "~", "values": ["#{query}"] } }])
- "#{path}?filters=#{URI::escape(filters)}"
+ "#{path}?filters=#{URI::RFC2396_Parser.new.escape(filters)}"
end
context 'that does not exist' do
diff --git a/spec/services/groups/add_users_service_integration_spec.rb b/spec/services/groups/add_users_service_integration_spec.rb
index 561fbb34068..60d31ed574f 100644
--- a/spec/services/groups/add_users_service_integration_spec.rb
+++ b/spec/services/groups/add_users_service_integration_spec.rb
@@ -48,7 +48,7 @@ describe Groups::AddUsersService, 'integration', type: :model do
let(:user2) { FactoryBot.create :user }
let(:user_ids) { [user1.id, user2.id] }
- subject { instance.call(user_ids) }
+ subject { instance.call(ids: user_ids) }
context 'as an admin user' do
let(:current_user) { admin }
diff --git a/spec/services/work_packages/create_service_integration_spec.rb b/spec/services/work_packages/create_service_integration_spec.rb
index 1d5ecee8526..da5a5258063 100644
--- a/spec/services/work_packages/create_service_integration_spec.rb
+++ b/spec/services/work_packages/create_service_integration_spec.rb
@@ -69,7 +69,7 @@ describe WorkPackages::CreateService, 'integration', type: :model do
end
let(:service_result) do
instance
- .call(attributes)
+ .call(**attributes)
end
before do
@@ -138,7 +138,7 @@ describe WorkPackages::CreateService, 'integration', type: :model do
end
it 'reports on invalid attachments and sets the new if everything is valid' do
- result = instance.call(attributes.merge(attachment_ids: [other_users_attachment.id]))
+ result = instance.call(**attributes.merge(attachment_ids: [other_users_attachment.id]))
expect(result)
.to be_failure
@@ -153,7 +153,7 @@ describe WorkPackages::CreateService, 'integration', type: :model do
expect(other_users_attachment.reload.container)
.to be_nil
- result = instance.call(attributes.merge(attachment_ids: [users_attachment.id]))
+ result = instance.call(**attributes.merge(attachment_ids: [users_attachment.id]))
expect(result)
.to be_success
diff --git a/spec/services/work_packages/update_service_integration_spec.rb b/spec/services/work_packages/update_service_integration_spec.rb
index 97f67566db2..a13991aa2b1 100644
--- a/spec/services/work_packages/update_service_integration_spec.rb
+++ b/spec/services/work_packages/update_service_integration_spec.rb
@@ -104,7 +104,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma
end
subject do
- instance.call(attributes.merge(send_notifications: false).symbolize_keys)
+ instance.call(**attributes.merge(send_notifications: false).symbolize_keys)
end
describe '#call' do
diff --git a/spec/services/work_packages/update_service_spec.rb b/spec/services/work_packages/update_service_spec.rb
index 63841d134e4..67174c21c06 100644
--- a/spec/services/work_packages/update_service_spec.rb
+++ b/spec/services/work_packages/update_service_spec.rb
@@ -98,7 +98,7 @@ describe WorkPackages::UpdateService, type: :model do
end
shared_examples_for 'service call' do
- subject { instance.call(call_attributes.merge(send_notifications: send_notifications).symbolize_keys) }
+ subject { instance.call(**call_attributes.merge(send_notifications: send_notifications).symbolize_keys) }
it 'is successful' do
expect(subject.success?).to be_truthy
diff --git a/spec/support/queries/shared_get_individual_query_examples.rb b/spec/support/queries/shared_get_individual_query_examples.rb
index 75271691081..99b1b82c994 100644
--- a/spec/support/queries/shared_get_individual_query_examples.rb
+++ b/spec/support/queries/shared_get_individual_query_examples.rb
@@ -31,7 +31,7 @@ shared_examples_for 'GET individual query' do
let(:filter) { [] }
let(:path) do
if filter.any?
- params = URI.encode(JSON.dump(filter))
+ params = CGI.escape(JSON.dump(filter))
"#{base_path}?filters=#{params}"
else
base_path
diff --git a/spec_legacy/unit/member_spec.rb b/spec_legacy/unit/member_spec.rb
index def31bf89e5..59037ddcd00 100644
--- a/spec_legacy/unit/member_spec.rb
+++ b/spec_legacy/unit/member_spec.rb
@@ -26,7 +26,7 @@
#
# See docs/COPYRIGHT.rdoc for more details.
#++
-require 'legacy_spec_helper'
+require_relative '../legacy_spec_helper'
describe Member, type: :model do
before do