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
Updates the CopyProjectJob and CopyFileLinkService to handle the new requirements
Marcello Rocha523b0b752016
diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rbindex 4fe7b3aa391..f5a1e0586cc 100644--- a/app/workers/copy_project_job.rb+++ b/app/workers/copy_project_job.rb@@ -34,7 +34,6 @@ class CopyProjectJob < ApplicationJobqueue_with_priority :above_normal- # rubocop:disable Metrics/AbcSize# Again error handling pushing the branch costs updef perform(target_project_params:, associations_to_copy:, send_mails: false)User.current = user@@ -57,7 +56,6 @@ class CopyProjectJob < ApplicationJobupdate_batch(errors:)failure_status_update(errors)end- # rubocop:enable Metrics/AbcSizedef store_status? = true@@ -145,9 +143,22 @@ class CopyProjectJob < ApplicationJob# rubocop:enable Metrics/AbcSizedef copy_project(target_project_params, associations_to_copy, send_notifications)- ::Projects::CopyService- .new(source: source_project, user:)- .call({ target_project_params:, send_notifications:, only: Array(associations_to_copy) })+ copy_service = ::Projects::CopyService.new(source: source_project, user:)+ result = copy_service.call({ target_project_params:, send_notifications:, only: Array(associations_to_copy) })++ enqueue_copy_project_folder_jobs(copy_service.state.copied_project_storages, copy_service.state.work_package_id_lookup)++ result+ end++ def enqueue_copy_project_folder_jobs(copied_storages, work_packages_map)+ Array(copied_storages).each do |storage_pair|+ batch.enqueue do+ Storages::CopyProjectFoldersJob.perform_later(source: storage_pair[:source],+ target: storage_pair[:target],+ work_packages_map:)+ end+ endenddef logger = OpenProject.loggerdiff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rbindex 8901a99b25c..d0644f82cd4 100644--- a/modules/storages/app/models/storages/storage.rb+++ b/modules/storages/app/models/storages/storage.rb@@ -41,8 +41,8 @@module Storagesclass Storage < ApplicationRecordPROVIDER_TYPES = [- PROVIDER_TYPE_NEXTCLOUD = 'Storages::NextcloudStorage',- PROVIDER_TYPE_ONE_DRIVE = 'Storages::OneDriveStorage'+ PROVIDER_TYPE_NEXTCLOUD = "Storages::NextcloudStorage",+ PROVIDER_TYPE_ONE_DRIVE = "Storages::OneDriveStorage"].freezePROVIDER_TYPE_SHORT_NAMES = {@@ -54,12 +54,12 @@ module Storagesstore_attribute :provider_fields, :automatically_managed, :boolean- has_many :file_links, class_name: 'Storages::FileLink'- belongs_to :creator, class_name: 'User'- has_many :project_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'+ has_many :file_links, class_name: "Storages::FileLink"+ belongs_to :creator, class_name: "User"+ has_many :project_storages, dependent: :destroy, class_name: "Storages::ProjectStorage"has_many :projects, through: :project_storageshas_one :oauth_client, as: :integration, dependent: :destroy- has_one :oauth_application, class_name: '::Doorkeeper::Application', as: :integration, dependent: :destroy+ has_one :oauth_application, class_name: "::Doorkeeper::Application", as: :integration, dependent: :destroyvalidates_uniqueness_of :host, allow_nil: truevalidates_uniqueness_of :name@@ -83,9 +83,9 @@ module Storagesscope :automatic_management_enabled, -> { where("provider_fields->>'automatically_managed' = 'true'") }enum health_status: {- pending: 'pending',- healthy: 'healthy',- unhealthy: 'unhealthy'+ pending: "pending",+ healthy: "healthy",+ unhealthy: "unhealthy"}.freeze, _prefix: :healthdef self.shorten_provider_type(provider_type)@@ -107,7 +107,7 @@ module Storagesdef self.extract_part_from_piped_string(text, index)return if text.nil?- split_reason = text.split('|')+ split_reason = text.split("|")if split_reason.length > indexsplit_reason[index].stripend@@ -115,8 +115,8 @@ module Storagesdef automatically_managed?ActiveSupport::Deprecation.warn(- '`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. ' \- 'NOTE: The new method name better reflects the actual behavior of the storage. ' \+ "`#automatically_managed?` is deprecated. Use `#automatic_management_enabled?` instead. " \+ "NOTE: The new method name better reflects the actual behavior of the storage. " \"It's not the storage that is automatically managed, rather the Project (Storage) Folder is. " \"A storage only has this feature enabled or disabled.")diff --git a/modules/storages/app/services/projects/copy/storages_dependent_service.rb b/modules/storages/app/services/projects/copy/storages_dependent_service.rbindex c6bb319e3f8..66b1de6ca06 100644--- a/modules/storages/app/services/projects/copy/storages_dependent_service.rb+++ b/modules/storages/app/services/projects/copy/storages_dependent_service.rb@@ -50,15 +50,10 @@ module Projects::Copy.new(user: User.current).call(storage_id: source_project_storage.storage_id,project_id: target.id,- project_folder_mode: 'inactive')+ project_folder_mode: "inactive").on_failure { |r| add_error!(source_project_storage.class.to_s, r.to_active_model_errors) }.result- Storages::CopyProjectFoldersJob.perform_later(source_id: source_project_storage.id,- target_id: project_storage_copy.id,- user_id: User.current.id,- work_package_map: state.work_package_id_lookup)-array << { source: source_project_storage, target: project_storage_copy }endenddiff --git a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb b/modules/storages/app/services/storages/file_links/copy_file_links_service.rbindex dd85313c58b..8f80da2c7b2 100644--- a/modules/storages/app/services/storages/file_links/copy_file_links_service.rb+++ b/modules/storages/app/services/storages/file_links/copy_file_links_service.rb@@ -31,6 +31,8 @@module Storagesmodule FileLinksclass CopyFileLinksService+ include OpenProject::LocaleHelper+def self.call(source:, target:, user:, work_packages_map:)new(source:, target:, user:, work_packages_map:).callend@@ -47,10 +49,12 @@ module Storages.includes(:creator).where(container_id: @work_packages_map.keys, container_type: "WorkPackage")- if @source.project_folder_automatic?- create_managed_file_links(source_file_links)- else- create_unmanaged_file_links(source_file_links)+ with_locale_for(@user) do+ if @source.project_folder_automatic?+ create_managed_file_links(source_file_links)+ else+ create_unmanaged_file_links(source_file_links)+ endendend@@ -75,7 +79,9 @@ module Storagesenddef build_location_map(source_files, target_location_map)- source_location_map = source_files.to_h { |info| [info.id, info.location] }+ source_location_map = source_files.filter { |info| info.status == "OK" }.to_h do |info|+ [info.id, info.location]+ endsource_location_map.each_with_object({}) do |(id, location), output|target = location.gsub(@source.managed_project_folder_path, @target.managed_project_folder_path)@@ -99,7 +105,6 @@ module Storagesdef create_unmanaged_file_links(source_file_links)source_file_links.find_each do |source_file_link|attributes = source_file_link.dup.attributes-attributes["creator_id"] = @user.idattributes["container_id"] = @work_packages_map[source_file_link.container_id]diff --git a/modules/storages/app/workers/storages/copy_project_folders_job.rb b/modules/storages/app/workers/storages/copy_project_folders_job.rbindex 039b66843c6..28c86151b8a 100644--- a/modules/storages/app/workers/storages/copy_project_folders_job.rb+++ b/modules/storages/app/workers/storages/copy_project_folders_job.rb@@ -35,9 +35,7 @@ module Storagesretry_on Errors::PollingRequired, wait: 3, attempts: :unlimiteddiscard_on HTTPX::HTTPError- def perform(source_id:, target_id:, work_package_map:)- target = ProjectStorage.find(target_id)- source = ProjectStorage.find(source_id)+ def perform(source:, target:, work_packages_map:)user = batch.properties[:user]project_folder_result = results_from_polling || initiate_copy(source, target)@@ -47,7 +45,7 @@ module Storagesproject_folder_mode: source.project_folder_mode).on_failure { |failed| log_failure(failed) and return failed }- FileLinks::CopyFileLinksService.call(source:, target:, user:, work_packages_map: work_package_map)+ FileLinks::CopyFileLinksService.call(source:, target:, user:, work_packages_map:)endprivate@@ -72,7 +70,7 @@ module Storagesenddef results_from_polling- return unless polling?+ return unless batch.properties[:polling_url]response = OpenProject.httpx.get(batch.properties[:polling_url]).json(symbolize_keys: true)diff --git a/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb b/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rbindex 134c0b349f5..5f5b5c0962f 100644--- a/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb+++ b/modules/storages/spec/workers/storages/copy_project_folders_job_spec.rb@@ -43,7 +43,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_balet(:target) { create(:project_storage, storage: source.storage) }let(:target_work_packages) { create_list(:work_package, 4, project: target.project) }- let(:work_package_map) do+ let(:work_packages_map) dosource_work_packages.pluck(:id).map(&:to_s)@@ -80,7 +80,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_baenddescribe "non-automatic managed folders" do- let(:inverted_wp_map) { work_package_map.invert }+ let(:inverted_wp_map) { work_packages_map.invert }before dosource.update(project_folder_mode: "manual", project_folder_id: "awesome-folder")@@ -89,7 +89,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "updates the target project storage project_folder_id to match the source" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inline@@ -100,12 +100,12 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "copies all the file link info on the corresponding work_package" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inline- WorkPackage.includes(:file_links).where(id: work_package_map.values).find_each do |target_wp|+ WorkPackage.includes(:file_links).where(id: work_packages_map.values).find_each do |target_wp|expect(target_wp.file_links.count).to eq(1)file_link = target_wp.file_links.first@@ -140,7 +140,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "copies the folders from source to target" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inline@@ -151,7 +151,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "creates the file links pointing to the newly copied files" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inline@@ -192,7 +192,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "stores the polling url on the batch properties" dobatch = GoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inlinebatch.reload@@ -212,7 +212,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "updates the storages" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inline@@ -223,7 +223,7 @@ RSpec.describe Storages::CopyProjectFoldersJob, :job, :webmock, with_good_job_bait "handles re-enqueues and polling" doGoodJob::Batch.enqueue(user:) do- described_class.perform_later(source_id: source.id, target_id: target.id, work_package_map:)+ described_class.perform_later(source:, target:, work_packages_map:)endGoodJob.perform_inlinejob = GoodJob::Job.order(:created_at).lastdiff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rbindex bd865e4b25f..9cc3f34fcc2 100644--- a/spec/features/projects/copy_spec.rb+++ b/spec/features/projects/copy_spec.rb@@ -28,7 +28,8 @@require "spec_helper"-RSpec.describe "Projects copy", :js, :with_cuprite, with_good_job_batches: [CopyProjectJob, SendCopyProjectStatusEmailJob] do+RSpec.describe "Projects copy", :js, :with_cuprite,+ with_good_job_batches: [CopyProjectJob, Storages::CopyProjectFoldersJob, SendCopyProjectStatusEmailJob] dodescribe "with a full copy example" dolet!(:project) docreate(:project,diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rbindex 64cb1ef9d6b..ce67f36ea62 100644--- a/spec/services/projects/copy_service_integration_spec.rb+++ b/spec/services/projects/copy_service_integration_spec.rb@@ -28,11 +28,11 @@# See COPYRIGHT and LICENSE files for more details.#++-require 'spec_helper'+require "spec_helper"RSpec.describe(Projects::CopyService,- 'integration',+ "integration",:webmock,type: :model,with_ee: %i[readonly_work_packages]@@ -40,17 +40,17 @@ RSpec.describe(shared_let(:status_locked) { create(:status, is_readonly: true) }shared_let(:source) docreate(:project,- name: 'Source Project Name',+ name: "Source Project Name",enabled_module_names: %i[wiki work_package_tracking storages])end- shared_let(:source_wp) { create(:work_package, project: source, subject: 'source wp') }+ shared_let(:source_wp) { create(:work_package, project: source, subject: "source wp") }shared_let(:source_wp_locked) do- create(:work_package, project: source, subject: 'source wp locked', status: status_locked)+ create(:work_package, project: source, subject: "source wp locked", status: status_locked)end- shared_let(:source_query) { create(:query, project: source, name: 'My query') }+ shared_let(:source_query) { create(:query, project: source, name: "My query") }shared_let(:source_view) { create(:view_work_packages_table, query: source_query) }- shared_let(:source_category) { create(:category, project: source, name: 'Stock management') }- shared_let(:source_version) { create(:version, project: source, name: 'Version A') }+ shared_let(:source_category) { create(:category, project: source, name: "Stock management") }+ shared_let(:source_version) { create(:version, project: source, name: "Version A") }shared_let(:source_wiki_page) { create(:wiki_page, wiki: source.wiki) }shared_let(:source_child_wiki_page) { create(:wiki_page, wiki: source.wiki, parent: source_wiki_page) }shared_let(:source_forum) { create(:forum, project: source) }@@ -63,7 +63,7 @@ RSpec.describe(let(:instance) { described_class.new(source:, user: current_user) }let(:only_args) { nil }let(:target_project_params) do- { name: 'Target Project Name', identifier: 'some-identifier' }+ { name: "Target Project Name", identifier: "some-identifier" }endlet(:params) do{ target_project_params:, only: only_args, send_notifications: }@@ -86,8 +86,8 @@ RSpec.describe(.and_return(new_project_role.id.to_s)end- describe '.copyable_dependencies' do- it 'includes the list of dependencies' do+ describe ".copyable_dependencies" do+ it "includes the list of dependencies" doexpect(described_class.copyable_dependencies.pluck(:identifier)).to eq(%w(members@@ -107,31 +107,31 @@ RSpec.describe(endend- describe '.call' do+ describe ".call" dosubject { instance.call(params) }let(:all_modules) { described_class.copyable_dependencies.pluck(:identifier) }let(:project_copy) { subject.result }- shared_examples_for 'copies public attribute' do- describe '#public' do+ shared_examples_for "copies public attribute" do+ describe "#public" dobefore dosource.update!(public:)end- context 'when not public' do+ context "when not public" dolet(:public) { false }- it 'copies correctly' do+ it "copies correctly" doexpect(subject).to be_successexpect(project_copy.public).to eq publicendend- context 'when public' do+ context "when public" dolet(:public) { true }- it 'copies correctly' do+ it "copies correctly" doexpect(subject).to be_successexpect(project_copy.public).to eq publicend@@ -139,9 +139,9 @@ RSpec.describe(endend- shared_examples_for 'copies custom fields' do- describe 'project custom fields' do- context 'with user project CF' do+ shared_examples_for "copies custom fields" do+ describe "project custom fields" do+ context "with user project CF" dolet(:user_custom_field) { create(:user_project_custom_field) }let(:user_value) docreate(:user,@@ -152,7 +152,7 @@ RSpec.describe(source.custom_values << CustomValue.new(custom_field: user_custom_field, value: user_value.id.to_s)end- it 'copies the custom_field' do+ it "copies the custom_field" doexpect(subject).to be_successexpect(project_copy.project_custom_fields).to contain_exactly(user_custom_field)@@ -164,17 +164,17 @@ RSpec.describe(endend- context 'with multi selection project list CF' do+ context "with multi selection project list CF" dolet(:list_custom_field) { create(:list_project_custom_field, multi_value: true) }before do- source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('A'))- source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of('B'))+ source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of("A"))+ source.custom_values << CustomValue.new(custom_field: list_custom_field, value: list_custom_field.value_of("B"))source.save!end- it 'copies the custom_field' do+ it "copies the custom_field" doexpect(subject).to be_successexpect(project_copy.project_custom_fields).to contain_exactly(list_custom_field)@@ -182,7 +182,7 @@ RSpec.describe(cv = project_copy.custom_values.reload.where(custom_field: list_custom_field).to_aexpect(cv).to be_a Arrayexpect(cv.count).to eq 2- expect(cv.map(&:formatted_value)).to contain_exactly('A', 'B')+ expect(cv.map(&:formatted_value)).to contain_exactly("A", "B")endend@@ -197,8 +197,8 @@ RSpec.describe(endend- context 'with disabled work package custom field' do- it 'is still disabled in the copy' do+ context "with disabled work package custom field" do+ it "is still disabled in the copy" docustom_field = create(:text_wp_custom_field)create(:type_task,projects: [source],@@ -211,8 +211,8 @@ RSpec.describe(endend- context 'with enabled work package custom field' do- it 'is still enabled in the copy' do+ context "with enabled work package custom field" do+ it "is still enabled in the copy" docustom_field = create(:text_wp_custom_field, projects: [source])create(:type_task,projects: [source],@@ -227,7 +227,7 @@ RSpec.describe(endend- context 'with all modules selected' do+ context "with all modules selected" dolet(:only_args) { all_modules }let(:storage1) { source_automatic_project_storage.storage }let(:storage2) { source_manual_project_storage.storage }@@ -235,17 +235,17 @@ RSpec.describe(shared_let(:source_automatic_project_storage) dostorage = create(:nextcloud_storage)- create(:project_storage, storage:, project: source, project_folder_id: '123', project_folder_mode: 'automatic')+ create(:project_storage, storage:, project: source, project_folder_id: "123", project_folder_mode: "automatic")endshared_let(:source_manual_project_storage) dostorage = create(:nextcloud_storage)- create(:project_storage, storage:, project: source, project_folder_id: '345', project_folder_mode: 'manual')+ create(:project_storage, storage:, project: source, project_folder_id: "345", project_folder_mode: "manual")end# rubocop:disable RSpec/ExampleLength# rubocop:disable RSpec/MultipleExpectations- it 'copies all dependencies and set attributes' do+ it "copies all dependencies and set attributes" doexpect(subject).to be_successexpect(project_copy.members.count).to eq 1@@ -261,12 +261,12 @@ RSpec.describe(expect(project_copy.versions.count).to eq 1expect(project_copy.wiki.pages.root.text).to eq source_wiki_page.textexpect(project_copy.wiki.pages.leaves.first.text).to eq source_child_wiki_page.text- expect(project_copy.wiki.start_page).to eq 'Wiki'+ expect(project_copy.wiki.start_page).to eq "Wiki"# Cleared attributesexpect(project_copy).to be_persisted- expect(project_copy.name).to eq 'Target Project Name'- expect(project_copy.identifier).to eq 'some-identifier'+ expect(project_copy.name).to eq "Target Project Name"+ expect(project_copy.identifier).to eq "some-identifier"# Duplicated attributesexpect(project_copy.description).to eq source.description@@ -288,50 +288,48 @@ RSpec.describe(expect(automatic_project_storage_copy.project_id).to eq(project_copy.id)expect(automatic_project_storage_copy.creator_id).to eq(current_user.id)expect(automatic_project_storage_copy.project_folder_id).to be_nil- expect(automatic_project_storage_copy.project_folder_mode).to eq('inactive')+ expect(automatic_project_storage_copy.project_folder_mode).to eq("inactive")manual_project_storage_copy = project_copy.project_storages.find_by(storage: storage2)expect(manual_project_storage_copy.id).not_to eq(source_manual_project_storage.id)expect(manual_project_storage_copy.project_id).to eq(project_copy.id)expect(manual_project_storage_copy.creator_id).to eq(current_user.id)expect(manual_project_storage_copy.project_folder_id).to be_nil- expect(manual_project_storage_copy.project_folder_mode).to eq('inactive')-- expect(Storages::CopyProjectFoldersJob).to have_been_enqueued.exactly(2).times+ expect(manual_project_storage_copy.project_folder_mode).to eq("inactive")end# rubocop:enable RSpec/ExampleLength# rubocop:enable RSpec/MultipleExpectations- it_behaves_like 'copies public attribute'- it_behaves_like 'copies custom fields'+ it_behaves_like "copies public attribute"+ it_behaves_like "copies custom fields"end- context 'with some modules selected' do- context 'with queries' do+ context "with some modules selected" do+ context "with queries" dolet(:only_args) { %i[queries] }- context 'with a filter' do+ context "with a filter" dolet!(:query) dobuild(:query, project: source).tap do |q|- q.add_filter('subject', '~', ['bogus'])+ q.add_filter("subject", "~", ["bogus"])q.save!create(:view_work_packages_table, query: q)endend- it 'produces a valid query in the new project' do+ it "produces a valid query in the new project" doexpect(subject).to be_successexpect(project_copy.queries.all?(&:valid?)).to be(true)expect(project_copy.queries.count).to eq 2endend- context 'with a filter to be mapped' do+ context "with a filter to be mapped" dolet(:only_args) { %w(members work_packages queries) }let!(:query) dobuild(:query, project: source).tap do |q|- q.add_filter('parent', '=', [source_wp.id.to_s])+ q.add_filter("parent", "=", [source_wp.id.to_s])# Not valid due to wp not visibleq.save!(validate: false)@@ -339,18 +337,18 @@ RSpec.describe(endend- it 'produces a valid query that is mapped in the new project' do+ it "produces a valid query that is mapped in the new project" doexpect(subject).to be_success- copied_wp = project_copy.work_packages.find_by(subject: 'source wp')+ copied_wp = project_copy.work_packages.find_by(subject: "source wp")copied = project_copy.queries.find_by(name: query.name)expect(copied.filters[1].values).to eq [copied_wp.id.to_s]endend- context 'with query with views' do+ context "with query with views" dolet!(:query_with_view) do- query = build(:query, project: source, name: 'Query with view')- query.add_filter('subject', '~', ['bogus'])+ query = build(:query, project: source, name: "Query with view")+ query.add_filter("subject", "~", ["bogus"])query.save!create(:view_work_packages_table, query:)@@ -359,33 +357,33 @@ RSpec.describe(endlet!(:query_without_view) do- query = build(:query, project: source, name: 'Query without view')- query.add_filter('subject', '~', ['bogus'])+ query = build(:query, project: source, name: "Query without view")+ query.add_filter("subject", "~", ["bogus"])query.save!queryend- it 'copies only the query with a view (non viewed queries will have to implement specific copy service)' do+ it "copies only the query with a view (non viewed queries will have to implement specific copy service)" doexpect(subject).to be_success- copied_query_with_view = project_copy.queries.find_by(name: 'Query with view')+ copied_query_with_view = project_copy.queries.find_by(name: "Query with view")expect(copied_query_with_view).to be_presentexpect(copied_query_with_view.views.length).to eq 1- expect(copied_query_with_view.views[0].type).to eq 'work_packages_table'+ expect(copied_query_with_view.views[0].type).to eq "work_packages_table"- expect(project_copy.queries).not_to exist(name: 'Query without view')+ expect(project_copy.queries).not_to exist(name: "Query without view")endendend- context 'with memeber' do+ context "with memeber" dolet(:only_args) { %w[members] }let!(:user) { create(:user) }let!(:another_role) { create(:project_role) }let!(:group) { create(:group, members: [user]) }- it 'copies them as well' do+ it "copies them as well" doMembers::CreateService.new(user: current_user, contract_class: EmptyContract).call(principal: group, roles: [another_role], project: source)@@ -414,7 +412,7 @@ RSpec.describe(endend- context 'with work_packages' do+ context "with work_packages" dolet(:only_args) { %w[work_packages] }let(:work_package) { create(:work_package, project: source) }@@ -424,61 +422,61 @@ RSpec.describe(let(:work_package3) { create(:work_package, project: source) }# rubocop:enable RSpec/IndexedLet- it 'does not copy work package budgets' do+ it "does not copy work package budgets" dobudget = create(:budget, project: source)source_wp.update!(budget:)expect(subject).to be_successexpect(source.work_packages.count).to eq(project_copy.work_packages.count)- copied_wp = project_copy.work_packages.find_by(subject: 'source wp')+ copied_wp = project_copy.work_packages.find_by(subject: "source wp")expect(copied_wp.budget).to be_nilend- context 'if categories are copied' do+ context "if categories are copied" dolet(:only_args) { %i[work_packages categories] }- it 'copies the work package with category' do+ it "copies the work package with category" dosource_wp.update!(category: source_category)expect(subject).to be_successwp = project_copy.work_packages.find_by(subject: source_wp.subject)- expect(wp.category.name).to eq 'Stock management'+ expect(wp.category.name).to eq "Stock management"# Category got copiedexpect(wp.category.id).not_to eq source_category.idendend- context 'with an assigned version' do+ context "with an assigned version" dolet(:only_args) { %i[work_packages versions] }- let!(:assigned_version) { create(:version, name: 'Assigned Issues', project: source, status: 'open') }+ let!(:assigned_version) { create(:version, name: "Assigned Issues", project: source, status: "open") }before dosource_wp.update!(version: assigned_version)- assigned_version.update!(status: 'closed')+ assigned_version.update!(status: "closed")end- it 'updates the version' do+ it "updates the version" doexpect(subject).to be_successwp = project_copy.work_packages.find_by(subject: source_wp.subject)- expect(wp.version.name).to eq 'Assigned Issues'+ expect(wp.version.name).to eq "Assigned Issues"expect(wp.version).to be_closedexpect(wp.version.id).not_to eq assigned_version.idendend- context 'with attachments' do+ context "with attachments" dobefore docreate(:attachment, container: work_package)expect(work_package.attachments.count).to eq(1) # rubocop:disable RSpec/ExpectInHookend- context 'when requested' do+ context "when requested" dolet(:only_args) { %i[work_packages work_package_attachments] }- it 'copies them' do+ it "copies them" doexpect(subject).to be_successexpect(project_copy.work_packages.count).to eq(3)@@ -488,8 +486,8 @@ RSpec.describe(endend- context 'when not requested' do- it 'ignores them' do+ context "when not requested" do+ it "ignores them" doexpect(subject).to be_successexpect(project_copy.work_packages.count).to eq(3)@@ -499,10 +497,10 @@ RSpec.describe(endend- context 'with an ordered query (Feature #31317)' do+ context "with an ordered query (Feature #31317)" dolet!(:query) do- create(:query, name: 'Manual query', user: current_user, project: source, show_hierarchies: false).tap do |q|- q.sort_criteria = [[:manual_sorting, 'asc']]+ create(:query, name: "Manual query", user: current_user, project: source, show_hierarchies: false).tap do |q|+ q.sort_criteria = [[:manual_sorting, "asc"]]q.save!create(:view_work_packages_table, query: q)@@ -516,12 +514,12 @@ RSpec.describe(OrderedWorkPackage.create(query:, work_package: work_package3, position: 50)end- it 'copies the query and order' do+ it "copies the query and order" doexpect(subject).to be_successexpect(project_copy.work_packages.count).to eq(5)expect(project_copy.queries.count).to eq(2)- manual_query = project_copy.queries.find_by name: 'Manual query'+ manual_query = project_copy.queries.find_by name: "Manual query"expect(manual_query).to be_manually_sortedexpect(query.ordered_work_packages.count).to eq 3@@ -531,7 +529,7 @@ RSpec.describe(expect(copied_order).to eq(original_order)end- context 'if one work package is a cross project reference' do+ context "if one work package is a cross project reference" dolet(:other_project) { create(:project) }let(:only_args) { %w[work_packages queries] }@@ -539,13 +537,13 @@ RSpec.describe(work_package2.update! project: other_projectend- it 'copies the query and order' do+ it "copies the query and order" doexpect(subject).to be_success# Only 4 out of the 5 work packages got copied this timeexpect(project_copy.work_packages.count).to eq(4)expect(project_copy.queries.count).to eq(2)- manual_query = project_copy.queries.find_by name: 'Manual query'+ manual_query = project_copy.queries.find_by name: "Manual query"expect(manual_query).to be_manually_sortedexpect(query.ordered_work_packages.count).to eq 3@@ -561,7 +559,7 @@ RSpec.describe(endend- context 'with parent work_package' do+ context "with parent work_package" dobefore dowork_package.parent = work_package2work_package.save!@@ -582,7 +580,7 @@ RSpec.describe(endend- context 'with category' do+ context "with category" dolet(:only_args) { %w[work_packages categories] }before do@@ -601,12 +599,12 @@ RSpec.describe(endend- context 'with watchers' do+ context "with watchers" dolet(:watcher) { create(:user, member_with_permissions: { source => [:view_work_packages] }) }let(:only_args) { %w[work_packages members] }- context 'with active watcher' do+ context "with active watcher" dobefore dowp = work_packagewp.add_watcher watcher@@ -615,14 +613,14 @@ RSpec.describe(source.work_packages << wpend- it 'does copy active watchers but does not add the copying user as a watcher' do+ it "does copy active watchers but does not add the copying user as a watcher" doexpect(subject).to be_successexpect(project_copy.work_packages[0].watcher_users).to contain_exactly(watcher)endend- context 'with locked watcher' do+ context "with locked watcher" dobefore douser = watcherwp = work_package@@ -634,14 +632,14 @@ RSpec.describe(source.work_packages << wpend- it 'does not copy locked watchers and does not add the copying user as a watcher' do+ it "does not copy locked watchers and does not add the copying user as a watcher" doexpect(subject).to be_successexpect(project_copy.work_packages[0].watcher_users).to be_emptyendendend- context 'with versions' do+ context "with versions" dolet(:version) { create(:version, project: source) }let(:version2) { create(:version, project: source) }@@ -653,7 +651,7 @@ RSpec.describe(work_package3end- it 'assigns the work packages to copies of the versions' do+ it "assigns the work packages to copies of the versions" doexpect(subject).to be_successexpect(project_copy.work_packages.detect { |wp| wp.subject == work_package.subject }.version.name).to eql version.name@@ -664,7 +662,7 @@ RSpec.describe(endend- context 'when work_package is assigned to somebody' do+ context "when work_package is assigned to somebody" dolet(:assigned_user) docreate(:user,member_with_roles: { source => role })@@ -674,10 +672,10 @@ RSpec.describe(work_package.update_column(:assigned_to_id, assigned_user.id)end- context 'with the members being copied' do+ context "with the members being copied" dolet(:only_args) { %w[members work_packages] }- it 'copies the assigned_to' do+ it "copies the assigned_to" doexpect(subject).to be_successexpect(project_copy.work_packages[0].assigned_to).to eql assigned_user@@ -689,10 +687,10 @@ RSpec.describe(endend- context 'with the member being not copied' do+ context "with the member being not copied" dolet(:only_args) { %w[work_packages] }- it 'nils the assigned_to' do+ it "nils the assigned_to" doexpect(subject).to be_successexpect(project_copy.work_packages[0].assigned_to).to be_nil@@ -703,7 +701,7 @@ RSpec.describe(endend- context 'when work_package has a responsible person' do+ context "when work_package has a responsible person" dolet(:responsible_user) docreate(:user,member_with_roles: { source => role })@@ -713,10 +711,10 @@ RSpec.describe(work_package.update_column(:responsible_id, responsible_user.id)end- context 'with the members being copied' do+ context "with the members being copied" dolet(:only_args) { %w[members work_packages] }- it 'copies the responsible' do+ it "copies the responsible" doexpect(subject).to be_successexpect(project_copy.work_packages[0].responsible).to eql responsible_user@@ -728,10 +726,10 @@ RSpec.describe(endend- context 'with the member being not copied' do+ context "with the member being not copied" dolet(:only_args) { %w[work_packages] }- it 'nils the assigned_to' do+ it "nils the assigned_to" doexpect(subject).to be_successexpect(project_copy.work_packages[0].responsible).to be_nil# No notification is sent out@@ -741,7 +739,7 @@ RSpec.describe(endend- describe 'work package user custom field' do+ describe "work package user custom field" dolet(:custom_field) docreate(:user_wp_custom_field).tap do |cf|source.work_package_custom_fields << cf@@ -757,20 +755,20 @@ RSpec.describe(work_package.save!(validate: false)end- context 'with the member being copied' do+ context "with the member being copied" dolet(:only_args) { %w[members work_packages] }- it 'copies the custom_field' do+ it "copies the custom_field" doexpect(subject).to be_successwp = project_copy.work_packages.find_by(subject: work_package.subject)expect(wp.send(custom_field.attribute_getter)).to eql current_userendend- context 'with the member being not copied' do+ context "with the member being not copied" dolet(:only_args) { %w[work_packages] }- it 'nils the custom_field' do+ it "nils the custom_field" doexpect(subject).to be_successwp = project_copy.work_packages.find_by(subject: work_package.subject)expect(wp.send(custom_field.attribute_getter)).to be_nil@@ -778,49 +776,49 @@ RSpec.describe(endend- context('with work package relations',- with_settings: { cross_project_work_package_relations: '1' }) do- let!(:source_wp2) { create(:work_package, project: source, subject: 'source wp2') }- let!(:source_relation) { create(:relation, from: source_wp, to: source_wp2, relation_type: 'relates') }+ context("with work package relations",+ with_settings: { cross_project_work_package_relations: "1" }) do+ let!(:source_wp2) { create(:work_package, project: source, subject: "source wp2") }+ let!(:source_relation) { create(:relation, from: source_wp, to: source_wp2, relation_type: "relates") }let!(:other_project) { create(:project) }- let!(:other_wp) { create(:work_package, project: other_project, subject: 'other wp') }- let!(:cross_relation) { create(:relation, from: source_wp, to: other_wp, relation_type: 'duplicates') }+ let!(:other_wp) { create(:work_package, project: other_project, subject: "other wp") }+ let!(:cross_relation) { create(:relation, from: source_wp, to: other_wp, relation_type: "duplicates") }- it 'copies relations' do+ it "copies relations" doexpect(subject).to be_successexpect(source.work_packages.count).to eq(project_copy.work_packages.count)- copied_wp = project_copy.work_packages.find_by(subject: 'source wp')- copied_wp2 = project_copy.work_packages.find_by(subject: 'source wp2')+ copied_wp = project_copy.work_packages.find_by(subject: "source wp")+ copied_wp2 = project_copy.work_packages.find_by(subject: "source wp2")# First issue with a relation on project# copied relation + reflexive relationexpect(copied_wp.relations.count).to eq 2- relates_relation = copied_wp.relations.find { |r| r.relation_type == 'relates' }+ relates_relation = copied_wp.relations.find { |r| r.relation_type == "relates" }expect(relates_relation.from_id).to eq copied_wp.idexpect(relates_relation.to_id).to eq copied_wp2.id# Second issue with a cross project relation# copied relation + reflexive relation- duplicates_relation = copied_wp.relations.find { |r| r.relation_type == 'duplicates' }+ duplicates_relation = copied_wp.relations.find { |r| r.relation_type == "duplicates" }expect(duplicates_relation.from_id).to eq copied_wp.idexpect(duplicates_relation.to_id).to eq other_wp.idendendend- context 'with wiki' do+ context "with wiki" dolet(:only_args) { %i[wiki] }- it 'copies wiki menu items' do+ it "copies wiki menu items" dosource.wiki.wiki_menu_items << create(:wiki_menu_item_with_parent, wiki: source.wiki)expect(subject).to be_successexpect(project_copy.wiki.wiki_menu_items.count).to eq 3end- it 'ignores wiki attachments' do+ it "ignores wiki attachments" docreate(:attachment, container: source_wiki_page)expect(source_wiki_page.attachments.count).to eq(1)@@ -832,10 +830,10 @@ RSpec.describe(expect(page.attachments.count).to eq(0)end- context 'when wiki attachments are requested' do+ context "when wiki attachments are requested" dolet(:only_args) { %i[wiki wiki_page_attachments] }- it 'copies them' do+ it "copies them" docreate(:attachment, container: source_wiki_page)expect(source_wiki_page.attachments.count).to eq(1)@@ -851,12 +849,12 @@ RSpec.describe(endend- context 'without anything selected' do+ context "without anything selected" dolet!(:source_member) { create(:user, member_with_roles: { source => role }) }let(:only_args) { nil }# rubocop:disable RSpec/MultipleExpectations- it 'sets attributes only without copying dependencies' do+ it "sets attributes only without copying dependencies" doexpect(subject).to be_successexpect(project_copy.members.count).to eq 1@@ -872,9 +870,9 @@ RSpec.describe(# Cleared attributesexpect(project_copy).to be_persisted- expect(project_copy.name).to eq 'Target Project Name'- expect(project_copy.name).to eq 'Target Project Name'- expect(project_copy.identifier).to eq 'some-identifier'+ expect(project_copy.name).to eq "Target Project Name"+ expect(project_copy.name).to eq "Target Project Name"+ expect(project_copy.identifier).to eq "some-identifier"# Duplicated attributesexpect(project_copy.description).to eq source.description@@ -894,14 +892,14 @@ RSpec.describe(end# rubocop:enable RSpec/MultipleExpectations- context 'with group memberships' do+ context "with group memberships" dolet!(:user) { create(:user) }let!(:another_role) { create(:project_role) }let!(:group) docreate(:group, members: [user])end- it 'does not copy group members' do+ it "does not copy group members" doMembers::CreateService.new(user: current_user, contract_class: EmptyContract).call(principal: group, roles: [another_role], project: source)@@ -926,8 +924,8 @@ RSpec.describe(endend- it_behaves_like 'copies public attribute'- it_behaves_like 'copies custom fields'+ it_behaves_like "copies public attribute"+ it_behaves_like "copies custom fields"endendend