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
[34444] Projects copy APIv3 (#9149)
Oliver Güntherf50297227b1a
diff --git a/app/contracts/projects/copy_contract.rb b/app/contracts/projects/copy_contract.rbindex 9a0f42b82e1..cb2f6bfb82b 100644--- a/app/contracts/projects/copy_contract.rb+++ b/app/contracts/projects/copy_contract.rb@@ -31,7 +31,7 @@ module Projectsprotecteddef validate_model?- false+ options.fetch(:validate_model, false)endprivatediff --git a/app/controllers/copy_projects_controller.rb b/app/controllers/copy_projects_controller.rbindex 847812e3b50..316efe74513 100644--- a/app/controllers/copy_projects_controller.rb+++ b/app/controllers/copy_projects_controller.rb@@ -33,15 +33,20 @@ class CopyProjectsController < ApplicationControllerbefore_action :authorizedef copy- @copy_project = Project.new- call = project_copy(@copy_project)+ request_params = params+ .permit(:send_notifications, only: [])+ .to_h+ .merge(target_project_params: target_project_params)+ call = Projects::EnqueueCopyService+ .new(user: current_user, model: @project)+ .call(request_params)if call.success?- job = enqueue_copy_job-+ job = call.resultcopy_started_noticeredirect_to job_status_path job.job_idelse+ @copy_project = call.result@errors = call.errorsrender action: copy_actionend@@ -50,60 +55,28 @@ class CopyProjectsController < ApplicationControllerdef copy_project@copy_project = Projects::CopyService.new(user: current_user, source: @project)- .call(target_project_params: {}, attributes_only: true)+ .call(target_project_params: target_project_params, attributes_only: true).result- if @copy_project- project_copy(@copy_project, EmptyContract)-- render action: copy_action- else- redirect_to :back- end- rescue ActiveRecord::RecordNotFound- redirect_to :back+ render action: copy_actionendprivate+ def target_project_params+ params[:project] ? permitted_params.project.to_h : {}+ end+def copy_actionfrom = (%w(admin settings).include?(params[:coming_from]) ? params[:coming_from] : 'settings')"copy_from_#{from}"end- def project_copy(nucleus, contract = Projects::CreateContract)- Projects::SetAttributesService- .new(user: current_user,- model: nucleus,- contract_class: contract)- .call(params[:project] ? permitted_params.project : {})- end-def originparams[:coming_from] == 'admin' ? projects_path : settings_generic_project_path(@project.id)end- def enqueue_copy_job- CopyProjectJob.perform_later(user_id: User.current.id,- source_project_id: @project.id,- target_project_params: target_project_params,- associations_to_copy: params[:only],- send_mails: params[:notifications] == '1')- end-- ##- # Returns the target project params for- # the project to be copied. Stringifies id keys of custom field values- # due to serialization- def target_project_params- @copy_project- .attributes- .compact- .with_indifferent_access- .merge(custom_field_values: @copy_project.custom_value_attributes.transform_keys(&:to_s))- end-def copy_started_noticeflash[:notice] = I18n.t('copy_project.started',source_project_name: @project.name,diff --git a/app/services/base_services/base_callable.rb b/app/services/base_services/base_callable.rbindex a8cb3b82d75..9c424fe114e 100644--- a/app/services/base_services/base_callable.rb+++ b/app/services/base_services/base_callable.rb@@ -35,15 +35,15 @@ module BaseServicesinclude ::WithReversibleState- def call(params = {})+ def call(*params)run_callbacks(:call) do- perform(params)+ perform(*params)endendprotected- def perform(params = {})+ def perform(*)raise NotImplementedErrorendenddiff --git a/app/services/base_services/copy.rb b/app/services/base_services/copy.rbindex 0b5fb253045..43698841a18 100644--- a/app/services/base_services/copy.rb+++ b/app/services/base_services/copy.rb@@ -32,8 +32,33 @@ module BaseServicesclass Copy < ::BaseServices::BaseContractedalias_attribute(:source, :model)- def initialize(user:, source:, contract_class: nil, contract_options: { copy_source: source })- self.source = source+ ##+ # dependent services to copy associations+ def self.copy_dependencies+ []+ end++ ##+ # collect copyable associated modules+ def self.copyable_dependencies+ copy_dependencies.map do |service_cls|+ {+ identifier: service_cls.identifier,+ name_source: -> { service_cls.human_name },+ count_source: ->(source, user) do+ service_cls+ .new(source: source, target: nil, user: user)+ .source_count+ end+ }+ end+ end++ def initialize(user:, source: nil, model: nil, contract_class: nil, contract_options: {})+ self.source = source || model+ raise ArgumentError, "Missing source object" if self.source.nil?++ contract_options[:copy_source] = self.sourcesuper(user: user, contract_class: contract_class, contract_options: contract_options)end@@ -57,7 +82,7 @@ module BaseServicesreturn ServiceResult.new(success: false, result: copy_instance, errors: copy_instance.errors)end- copy_dependencies.each do |service_cls|+ self.class.copy_dependencies.each do |service_cls|next if skip_dependency?(params, service_cls)call.merge! call_dependent_service(service_cls, target: copy_instance, params: params),@@ -87,12 +112,9 @@ module BaseServices## Note that for dependent copy services to be called# this will already be present.- def prepare(_params); end-- ##- # dependent services to copy associations- def copy_dependencies- []+ def prepare(_params)+ # Retain the source project itself+ state.source = sourceend##diff --git a/app/services/base_services/set_attributes.rb b/app/services/base_services/set_attributes.rbindex eb03cbfb75d..d1bac18c7e4 100644--- a/app/services/base_services/set_attributes.rb+++ b/app/services/base_services/set_attributes.rb@@ -29,7 +29,7 @@#++module BaseServices- class SetAttributes+ class SetAttributes < BaseCallableinclude Contracteddef initialize(user:, model:, contract_class:, contract_options: {})@@ -40,8 +40,8 @@ module BaseServicesself.contract_options = contract_optionsend- def call(params)- set_attributes(params)+ def perform(params = nil)+ set_attributes(params || {})validate_and_resultenddiff --git a/app/services/copy/concerns/copy_attachments.rb b/app/services/copy/concerns/copy_attachments.rbindex 6a35882baf4..c68b70230d2 100644--- a/app/services/copy/concerns/copy_attachments.rb+++ b/app/services/copy/concerns/copy_attachments.rb@@ -4,19 +4,20 @@ module Copy### Tries to copy the given attachment between containersdef copy_attachments(from_container, to_container_id)- Attachment.where(container: from_container).find_each do |old_attachment|+ from_container_id = from_container.is_a?(ApplicationRecord) ? from_container.id : from_container+ Attachment.where(container_id: from_container_id).find_each do |old_attachment|copied = old_attachment.dupold_attachment.file.copy_to(copied)copied.author = user- copied.container_type = from_container.class.name+ copied.container_type = old_attachment.container_typecopied.container_id = to_container_idunless copied.saveRails.logger.error { "Attachments ##{old_attachment.id} could not be copied: #{copied.errors.full_messages} " }endrescue StandardError => e- Rails.logger.error { "Failed to copy attachments from #{from_container} to #{to_container}: #{e}" }+ Rails.logger.error { "Failed to copy attachments from ##{from_container_id} to ##{to_container_id}: #{e}" }endendenddiff --git a/app/services/grids/copy_service.rb b/app/services/grids/copy_service.rbindex dffe086ce9d..04ede606ee0 100644--- a/app/services/grids/copy_service.rb+++ b/app/services/grids/copy_service.rb@@ -32,27 +32,27 @@ module Grids### Base class for any grid-based model's copy service.class CopyService < ::BaseServices::Copy- def initialize(user:, source:, contract_class: ::EmptyContract)- super user: user, source: source, contract_class: contract_class- end-- protected-### DependentServices can be specialised through a class in the# concrete model's namespace, e.g. Boards::Copy::WidgetsDependentService.- def copy_dependencies+ def self.copy_dependencies[widgets_dependency]end- def widgets_dependency- self.class.module_parent::Copy::WidgetsDependentService+ def self.widgets_dependency+ module_parent::Copy::WidgetsDependentServicerescue NameErrorCopy::WidgetsDependentServiceend+ def initialize(user:, source:, contract_class: ::EmptyContract)+ super user: user, source: source, contract_class: contract_class+ end++ protected+def initialize_copy(source, params)grid = source.dupdiff --git a/app/services/projects/copy/boards_dependent_service.rb b/app/services/projects/copy/boards_dependent_service.rbindex 2749d158203..d5c82607551 100644--- a/app/services/projects/copy/boards_dependent_service.rb+++ b/app/services/projects/copy/boards_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:'boards.label_boards')end+ def source_count+ ::Boards::Grid.where(project: source).count+ end+protected# Copies boards from +project+diff --git a/app/services/projects/copy/categories_dependent_service.rb b/app/services/projects/copy/categories_dependent_service.rbindex e3a2ef1f86c..cbcf5135663 100644--- a/app/services/projects/copy/categories_dependent_service.rb+++ b/app/services/projects/copy/categories_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:label_work_package_category_plural)end+ def source_count+ source.categories.count+ end+protecteddef copy_dependency(params:)diff --git a/app/services/projects/copy/dependency.rb b/app/services/projects/copy/dependency.rbindex a5c646f716f..722a5eaf9d6 100644--- a/app/services/projects/copy/dependency.rb+++ b/app/services/projects/copy/dependency.rb@@ -32,6 +32,13 @@ module Projects::Copyclass Dependency < ::Copy::Dependencydelegate :should_copy?, to: :class+ ##+ # Allow to count the source dependency count+ # if applicable+ def source_count+ nil+ end+### Check whether this dependency should be copied# as it was selecteddiff --git a/app/services/projects/copy/forums_dependent_service.rb b/app/services/projects/copy/forums_dependent_service.rbindex 47ebf9e49d5..cae23a1f47f 100644--- a/app/services/projects/copy/forums_dependent_service.rb+++ b/app/services/projects/copy/forums_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:label_forum_plural)end+ def source_count+ source.forums.count+ end+protecteddef copy_dependency(params:)diff --git a/app/services/projects/copy/members_dependent_service.rb b/app/services/projects/copy/members_dependent_service.rbindex cc340201071..533e25e1fec 100644--- a/app/services/projects/copy/members_dependent_service.rb+++ b/app/services/projects/copy/members_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:label_member_plural)end+ def source_count+ source.members.count+ end+protecteddef copy_dependency(*)diff --git a/app/services/projects/copy/queries_dependent_service.rb b/app/services/projects/copy/queries_dependent_service.rbindex 765e695682f..ece4802bc6b 100644--- a/app/services/projects/copy/queries_dependent_service.rb+++ b/app/services/projects/copy/queries_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:label_query_plural)end+ def source_count+ source.queries.count+ end+protected# Copies queries from +project+diff --git a/app/services/projects/copy/versions_dependent_service.rb b/app/services/projects/copy/versions_dependent_service.rbindex be5461253f3..6e0695796f1 100644--- a/app/services/projects/copy/versions_dependent_service.rb+++ b/app/services/projects/copy/versions_dependent_service.rb@@ -34,6 +34,10 @@ module Projects::CopyI18n.t(:label_version_plural)end+ def source_count+ source.versions.count+ end+protecteddef copy_dependency(params:)diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rbindex 7ed530dd0a8..0abea55d648 100644--- a/app/services/projects/copy/wiki_dependent_service.rb+++ b/app/services/projects/copy/wiki_dependent_service.rb@@ -36,6 +36,10 @@ module Projects::CopyI18n.t(:label_wiki_page_plural)end+ def source_count+ source.wiki && source.wiki.pages.count+ end+protecteddef copy_dependency(params:)@@ -56,21 +60,15 @@ module Projects::Copy# Copying top down so that the hierarchy (parent attribute)# can be rewritten along the way.pages_top_down do |page|- new_parent = wiki_pages_map[page.parent]- wiki_pages_map[page] = copy_wiki_page(page, new_parent)+ new_parent_id = wiki_pages_map[page.parent_id]+ new_wiki_page = copy_wiki_page(page, new_parent_id)+ wiki_pages_map[page.id] = new_wiki_page.id if new_wiki_pageend- # Copy attachments- if should_copy?(params, :wiki_page_attachments)- wiki_pages_map.each do |old_page, new_page|- next unless old_page && new_page-- copy_attachments(old_page, new_page.id)- end- end+ state.wiki_page_id_lookup = wiki_pages_mapend- def copy_wiki_page(source_page, new_parent)+ def copy_wiki_page(source_page, new_parent_id)# Skip pages without contentreturn if source_page.content.nil?@@ -79,7 +77,7 @@ module Projects::Copyservice_call = WikiPages::CopyService.new(user: user, model: source_page, contract_class: WikiPages::CopyContract).call(wiki: target.wiki,- parent: new_parent,+ parent_id: new_parent_id,send_notifications: ActionMailer::Base.perform_deliveries)if service_call.success?diff --git a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb b/app/services/projects/copy/wiki_page_attachments_dependent_service.rbnew file mode 100644index 00000000000..6bd43043264--- /dev/null+++ b/app/services/projects/copy/wiki_page_attachments_dependent_service.rb@@ -0,0 +1,54 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Projects::Copy+ class WikiPageAttachmentsDependentService < Dependency+ include ::Copy::Concerns::CopyAttachments++ def self.human_name+ I18n.t(:label_wiki_page_attachments)+ end++ def source_count+ source.wiki && source.wiki.pages.joins(:attachments).count('attachments.id')+ end++ protected++ def copy_dependency(params:)+ # If no wiki pages copied, we cannot copy their attachments+ return unless state.wiki_page_id_lookup++ state.wiki_page_id_lookup.each do |old_id, new_id|+ copy_attachments(old_id, new_id)+ end+ end+ end+enddiff --git a/app/services/projects/copy/work_package_attachments_dependent_service.rb b/app/services/projects/copy/work_package_attachments_dependent_service.rbnew file mode 100644index 00000000000..1cbc4e05057--- /dev/null+++ b/app/services/projects/copy/work_package_attachments_dependent_service.rb@@ -0,0 +1,54 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Projects::Copy+ class WorkPackageAttachmentsDependentService < Dependency+ include ::Copy::Concerns::CopyAttachments++ def self.human_name+ I18n.t(:label_work_package_attachments)+ end++ def source_count+ source.work_packages.joins(:attachments).count('attachments.id')+ end++ protected++ def copy_dependency(params:)+ # If no work packages were copied, we cannot copy their attachments+ return unless state.work_package_id_lookup++ state.work_package_id_lookup.each do |old_wp_id, new_wp_id|+ copy_attachments(old_wp_id, new_wp_id)+ end+ end+ end+enddiff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rbindex c1a23c96c90..d92f8cd05e5 100644--- a/app/services/projects/copy/work_packages_dependent_service.rb+++ b/app/services/projects/copy/work_packages_dependent_service.rb@@ -30,12 +30,14 @@module Projects::Copyclass WorkPackagesDependentService < Dependency- include ::Copy::Concerns::CopyAttachments-def self.human_nameI18n.t(:label_work_package_plural)end+ def source_count+ source.work_packages.count+ end+protecteddef copy_dependency(params:)@@ -66,11 +68,6 @@ module Projects::Copynew_wp_id = work_packages_map[wp.id]next unless new_wp_id- # Attachments- if should_copy?(params, :work_package_attachments)- copy_attachments(wp, new_wp_id)- end-copy_relations(wp, new_wp_id, work_packages_map)enddiff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rbindex 7badad458b7..069b98b209d 100644--- a/app/services/projects/copy_service.rb+++ b/app/services/projects/copy_service.rb@@ -32,6 +32,22 @@ module Projectsclass CopyService < ::BaseServices::Copyinclude Projects::Concerns::NewProjectService+ def self.copy_dependencies+ [+ ::Projects::Copy::MembersDependentService,+ ::Projects::Copy::VersionsDependentService,+ ::Projects::Copy::CategoriesDependentService,+ ::Projects::Copy::WorkPackagesDependentService,+ ::Projects::Copy::WorkPackageAttachmentsDependentService,+ ::Projects::Copy::WikiDependentService,+ ::Projects::Copy::WikiPageAttachmentsDependentService,+ ::Projects::Copy::ForumsDependentService,+ ::Projects::Copy::QueriesDependentService,+ ::Projects::Copy::BoardsDependentService,+ ::Projects::Copy::OverviewDependentService+ ]+ end+### In case a rollback is needed,# destroy the copied project again.@@ -48,20 +64,6 @@ module Projects!Copy::Dependency.should_copy?(params, dependency_cls.identifier.to_sym)end- def copy_dependencies- [- ::Projects::Copy::MembersDependentService,- ::Projects::Copy::VersionsDependentService,- ::Projects::Copy::CategoriesDependentService,- ::Projects::Copy::WorkPackagesDependentService,- ::Projects::Copy::WikiDependentService,- ::Projects::Copy::ForumsDependentService,- ::Projects::Copy::QueriesDependentService,- ::Projects::Copy::BoardsDependentService,- ::Projects::Copy::OverviewDependentService- ]- end-def initialize_copy(source, params)target = Project.newtarget.attributes = source.attributes.dup.except(*skipped_attributes)@@ -88,7 +90,8 @@ module Projects.new(user: user,model: target,contract_class: Projects::CopyContract,- contract_options: { copy_source: source })+ contract_options: { copy_source: source, validate_model: true })+ .with_state(state).call(target_project_params)# Retain values after the set attributes servicediff --git a/app/services/projects/enqueue_copy_service.rb b/app/services/projects/enqueue_copy_service.rbnew file mode 100644index 00000000000..04782cb0d03--- /dev/null+++ b/app/services/projects/enqueue_copy_service.rb@@ -0,0 +1,72 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module Projects+ class EnqueueCopyService < ::BaseServices::BaseCallable+ attr_reader :source, :user++ def initialize(user:, model: nil, **)+ @user = user+ @source = model+ end++ private++ def perform(params)+ call = test_copy(params)++ if call.success?+ ServiceResult.new success: true, result: schedule_copy_job(params)+ else+ call+ end+ end++ ##+ # Tests whether the copy can be performed+ def test_copy(params)+ test_params = params.merge(attributes_only: true)++ Projects::CopyService+ .new(user: user, source: source)+ .call(test_params)+ end++ ##+ # Schedule the project copy job+ def schedule_copy_job(params)+ CopyProjectJob.perform_later(user_id: user.id,+ source_project_id: source.id,+ target_project_params: params[:target_project_params],+ associations_to_copy: params[:only].to_a,+ send_mails: ActiveRecord::Type::Boolean.new.cast(params[:send_notifications]))+ end+ end+enddiff --git a/app/services/queries/copy_service.rb b/app/services/queries/copy_service.rbindex 8a51f2a14c4..a17f3299ca8 100644--- a/app/services/queries/copy_service.rb+++ b/app/services/queries/copy_service.rb@@ -30,15 +30,15 @@module Queriesclass CopyService < ::BaseServices::Copy- protected-- def copy_dependencies+ def self.copy_dependencies[::Queries::Copy::MenuItemDependentService,::Queries::Copy::OrderedWorkPackagesDependentService]end+ protected+def initialize_copy(source, _params)new_query = ::Query.new source.attributes.dup.except(*skipped_attributes)new_query.sort_criteria = source.sort_criteria if source.sort_criteriadiff --git a/app/services/relations/base_service.rb b/app/services/relations/base_service.rbindex a8ab4113725..8da495127cf 100644--- a/app/services/relations/base_service.rb+++ b/app/services/relations/base_service.rb@@ -28,7 +28,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-class Relations::BaseService+class Relations::BaseService < ::BaseServices::BaseCallableinclude Contractedinclude Shared::ServiceContextdiff --git a/app/services/relations/create_service.rb b/app/services/relations/create_service.rbindex 5625cc3bc6c..d117d3f3d24 100644--- a/app/services/relations/create_service.rb+++ b/app/services/relations/create_service.rb@@ -34,7 +34,7 @@ class Relations::CreateService < Relations::BaseServiceself.contract_class = Relations::CreateContractend- def call(relation, send_notifications: true)+ def perform(relation, send_notifications: true)in_user_context(send_notifications) doupdate_relation relation, {}enddiff --git a/app/services/relations/update_service.rb b/app/services/relations/update_service.rbindex cef193752d2..7ad7dafff82 100644--- a/app/services/relations/update_service.rb+++ b/app/services/relations/update_service.rb@@ -37,7 +37,7 @@ class Relations::UpdateService < Relations::BaseServiceself.contract_class = Relations::UpdateContractend- def call(attributes)+ def perform(attributes)in_context(attributes[:send_notifications]) doupdate_relation model, attributesenddiff --git a/app/services/work_packages/create_service.rb b/app/services/work_packages/create_service.rbindex 8a2991aac86..c8e0b1764f4 100644--- a/app/services/work_packages/create_service.rb+++ b/app/services/work_packages/create_service.rb@@ -28,7 +28,7 @@# See docs/COPYRIGHT.rdoc for more details.#++-class WorkPackages::CreateService+class WorkPackages::CreateService < ::BaseServices::BaseCallableinclude ::WorkPackages::Shared::UpdateAncestorsinclude ::Shared::ServiceContext@@ -40,7 +40,7 @@ class WorkPackages::CreateServiceself.contract_class = contract_classend- def call(work_package: WorkPackage.new,+ def perform(work_package: WorkPackage.new,send_notifications: true,**attributes)in_user_context(send_notifications) dodiff --git a/app/services/work_packages/update_service.rb b/app/services/work_packages/update_service.rbindex 806b3cea9ad..58389c3e76e 100644--- a/app/services/work_packages/update_service.rb+++ b/app/services/work_packages/update_service.rb@@ -29,7 +29,7 @@#++# TODO: use default update base class-class WorkPackages::UpdateService+class WorkPackages::UpdateService < ::BaseServices::BaseCallableinclude ::WorkPackages::Shared::UpdateAncestorsinclude ::Shared::ServiceContext@@ -43,7 +43,7 @@ class WorkPackages::UpdateServiceself.contract_class = contract_classend- def call(send_notifications: true, **attributes)+ def perform(send_notifications: true, **attributes)in_context(model, send_notifications) doupdate(attributes)enddiff --git a/app/views/copy_projects/copy_from_settings.html.erb b/app/views/copy_projects/copy_from_settings.html.erbindex b00471a37fd..12e5cd2ccc0 100644--- a/app/views/copy_projects/copy_from_settings.html.erb+++ b/app/views/copy_projects/copy_from_settings.html.erb@@ -27,7 +27,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%>-<%= error_messages_for 'copy_project' %>+<%= error_messages_for_contract @copy_project, @errors %><%= toolbar title: t(:label_project_new) %><%= labelled_tabular_form_for @copy_project, url: { action: 'copy', coming_from: 'settings' } do |f| %>diff --git a/app/views/copy_projects/copy_settings/_copy_associations.html.erb b/app/views/copy_projects/copy_settings/_copy_associations.html.erbindex e1e1397c2ae..1b80d5f65f1 100644--- a/app/views/copy_projects/copy_settings/_copy_associations.html.erb+++ b/app/views/copy_projects/copy_settings/_copy_associations.html.erb@@ -70,7 +70,7 @@ See docs/COPYRIGHT.rdoc for more details.<br /><label class="block">- <%= check_box_tag 'notifications', 1, params[:notifications] %>+ <%= check_box_tag 'send_notifications', 1, params[:send_notifications] %><%= t(:label_project_copy_notifications) %></label></fieldset>diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rbindex b2e6e31577f..cf4c84c3735 100644--- a/app/workers/copy_project_job.rb+++ b/app/workers/copy_project_job.rb@@ -92,7 +92,7 @@ class CopyProjectJob < ApplicationJobprivatedef successful_status_update- payload = redirect_payload(url_helpers.project_path(target_project))+ payload = redirect_payload(url_helpers.project_url(target_project))if errors.any?payload[:errors] = errorsdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 5f351eff662..a21b98ce971 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -958,6 +958,10 @@ en:succeeded: "Created project %{target_project_name}"errors: "Error"project_custom_fields: 'Custom fields on project'+ x_objects_of_this_type:+ zero: 'No objects of this type'+ one: 'One object of this type'+ other: '%{count} objects of this type'text:failed: "Could not copy project \"%{source_project_name}\" to project \"%{target_project_name}\"."succeeded: "Copied project \"%{source_project_name}\" to \"%{target_project_name}\"."diff --git a/docs/api/apiv3/endpoints/projects.apib b/docs/api/apiv3/endpoints/projects.apibindex 9bea240376e..c8063bd5b13 100644--- a/docs/api/apiv3/endpoints/projects.apib+++ b/docs/api/apiv3/endpoints/projects.apib@@ -112,8 +112,9 @@ Depending on custom fields defined for projects, additional properties might exi## View project [GET]+ Parameters- + id (required, integer, `1`) ... Project id-+++ id (required, integer, `1`) ... Project id++ Response 200 (application/hal+json)[Project][]@@ -141,8 +142,9 @@ Depending on custom fields defined for projects, additional properties might exiUpdates the given project by applying the attributes provided in the body.+ Parameters- + id (required, integer, `1`) ... Project id-+++ id (required, integer, `1`) ... Project id++ Request Update project+ Body@@ -231,8 +233,9 @@ So the project might exist well after the request has returned successfully. Tothe project scheduled for deletion, it is archived at once.+ Parameters- + id (required, integer, `1`) ... Project id-+++ id (required, integer, `1`) ... Project id++ Response 204 (application/hal+json)Returned if the project was successfully deleted. There is currently no end point to query for the actual deletion status.@@ -1301,6 +1304,534 @@ For more details and all possible responses see the general specification of [Fo"message": "You are not authorized to access this resource."}++## Project copy form [/api/v3/projects/{id}/copy/form]++This endpoint returns a form allowing a guided copy process of existing projects.+The returned payload part of the form will be contain a merge between the already existing properties' values of the source project (as long as they are writeable) and the provided values to be set for a new project.++For available properties, please see the project endpoint.++The copy form has a `_meta` property that allows defining which associations to copy. Please check the table below+and copy schema embedded in the copy form response for available options.++The embedded schema of this form describes all associations to copy with a human readable string including the total count of associated objects in the source project.++For more details and all possible responses see the general specification of [Forms](#forms).++### Available meta parameters++| Meta property | Description | Type | Constraints | Supported operations |Condition |+| :------------------------: | --------------------------------------------------- | ---- | ----------- | -------------------- |----------|+| sendNotifications | Whether to send out notifications | Boolean | not null | READ/WRITE | |+| copyMembers | Whether to copy project members | Boolean | not null | READ/WRITE | |+| copyVersions | Whether to copy project versions | Boolean | not null | READ/WRITE | |+| copyCategories | Whether to copy project categories | Boolean | not null | READ/WRITE | |+| copyWorkPackages | Whether to copy project work packages | Boolean | not null | READ/WRITE | |+| copyWorkPackageAttachments | Whether to copy project attachments of work packages | Boolean | not null | READ/WRITE | |+| copyWiki | Whether to copy project wiki pages | Boolean | not null | READ/WRITE | |+| copyWikiPageAttachments | Whether to copy project wiki page attachments | Boolean | not null | READ/WRITE | |+| copyForums | Whether to copy project forums | Boolean | not null | READ/WRITE | |+| copyQueries | Whether to copy project queries | Boolean | not null | READ/WRITE | |+| copyBoards | Whether to copy project boards | Boolean | not null | READ/WRITE | |+| copyOverview | Whether to copy the project overview page | Boolean | not null | READ/WRITE | |++## Project copy form [POST]+++ Request copy project form++ + Body++ {+ "identifier": "copied_project_identifier",+ "name": "Copied project name",+ "customField35": "Text custom field value",+ "_meta": {+ "copyOverview": false,+ "copyWorkPackages": true+ }+ }+++ Response 200 (application/hal+json)++ + Body++ {+ "_type": "Form",+ "_embedded": {+ "payload": {+ "identifier": "copied_project_identifier",+ "name": "Copied project name",+ "active": true,+ "public": false,+ "description": {+ "format": "markdown",+ "raw": null,+ "html": ""+ },+ "customField30": null,+ "customField34": null,+ "customField35": "Text custom field value",+ "customField41": {+ "format": "markdown",+ "raw": "",+ "html": ""+ },+ "customField42": null,+ "status": "at risk",+ "statusExplanation": {+ "format": "markdown",+ "raw": "There is some risk of failure",+ "html": "<p>There is some risk of failure</p>"+ },+ "_links": {+ "customField26": {+ "href": null,+ "title": null+ },+ "customField31": {+ "href": null,+ "title": null+ },+ "parent": null+ },+ "_meta": {+ "copyOverview": false,+ "copyBoards": false,+ "copyForums": false,+ "copyMembers": false,+ "copyVersions": false,+ "copyWiki": false,+ "copyWikiPageAttachments": false,+ "copyWorkPackages": false,+ "copyWorkPackageAttachments": false,+ "copyQueries": false,+ "copyCategories": false+ }+ },+ "schema": {+ "_type": "Schema",+ "_dependencies": [],+ "id": {+ "type": "Integer",+ "name": "ID",+ "required": true,+ "hasDefault": false,+ "writable": false+ },+ "name": {+ "type": "String",+ "name": "Name",+ "required": true,+ "hasDefault": false,+ "writable": true,+ "minLength": 1,+ "maxLength": 255+ },+ "identifier": {+ "type": "String",+ "name": "Identifier",+ "required": true,+ "hasDefault": false,+ "writable": true,+ "minLength": 1,+ "maxLength": 100+ },+ "description": {+ "type": "Formattable",+ "name": "Description",+ "required": false,+ "hasDefault": false,+ "writable": true+ },+ "public": {+ "type": "Boolean",+ "name": "Public",+ "required": true,+ "hasDefault": false,+ "writable": true+ },+ "active": {+ "type": "Boolean",+ "name": "Active",+ "required": true,+ "hasDefault": true,+ "writable": true,+ },+ "status": {+ "type": "String",+ "name": "Status",+ "required": true,+ "hasDefault": true,+ "writable": true,+ },+ "parent": {+ "type": "Project",+ "name": "Subproject of",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "location": "_links",+ "visibility": "default",+ "_links": {+ "allowedValues": {+ "href": "/api/v3/projects/available_parent_projects?of=123"+ }+ }+ },+ "createdAt": {+ "type": "DateTime",+ "name": "Created on",+ "required": true,+ "hasDefault": false,+ "writable": false+ },+ "updatedAt": {+ "type": "DateTime",+ "name": "Updated on",+ "required": true,+ "hasDefault": false,+ "writable": false+ },+ "customField26": {+ "type": "User",+ "name": "Project user",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "location": "_links",+ "visibility": "default",+ "_links": {+ "allowedValues": {+ "href": "/api/v3/principals?filters=%5B%7B%22status%22%3A%7B%22operator%22%3A%22%21%22%2C%22values%22%3A%5B%220%22%2C%223%22%5D%7D%7D%2C%7B%22type%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22User%22%5D%7D%7D%2C%7B%22member%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22%22%5D%7D%7D%5D&pageSize=0"+ }+ }+ },+ "customField30": {+ "type": "Integer",+ "name": "some project cf",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "visibility": "default"+ },+ "customField31": {+ "type": "CustomOption",+ "name": "list project cf",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "location": "_links",+ "visibility": "default",+ "_embedded": {+ "allowedValues": [+ {+ "_type": "CustomOption",+ "id": 513,+ "value": "abc",+ "_links": {+ "self": {+ "href": "/api/v3/custom_options/513",+ "title": "abc"+ }+ }+ },+ {+ "_type": "CustomOption",+ "id": 514,+ "value": "def",+ "_links": {+ "self": {+ "href": "/api/v3/custom_options/514",+ "title": "def"+ }+ }+ },+ {+ "_type": "CustomOption",+ "id": 515,+ "value": "ghi",+ "_links": {+ "self": {+ "href": "/api/v3/custom_options/515",+ "title": "ghi"+ }+ }+ }+ ]+ },+ "_links": {+ "allowedValues": [+ {+ "href": "/api/v3/custom_options/513",+ "title": "abc"+ },+ {+ "href": "/api/v3/custom_options/514",+ "title": "def"+ },+ {+ "href": "/api/v3/custom_options/515",+ "title": "ghi"+ }+ ]+ }+ },+ "customField34": {+ "type": "Boolean",+ "name": "Bool Project CF",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "visibility": "default"+ },+ "customField35": {+ "type": "String",+ "name": "text project cf",+ "required": true,+ "hasDefault": false,+ "writable": true,+ "visibility": "default"+ },+ "customField41": {+ "type": "Formattable",+ "name": "Long text project cf",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "visibility": "default"+ },+ "customField42": {+ "type": "Date",+ "name": "Date project cf",+ "required": false,+ "hasDefault": false,+ "writable": true,+ "visibility": "default"+ },+ "copyOverview": {+ "type": "Boolean",+ "name": "Overview",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyBoards": {+ "type": "Boolean",+ "name": "Boards",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyForums": {+ "type": "Boolean",+ "name": "Forums",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyMembers": {+ "type": "Boolean",+ "name": "Members",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyVersions": {+ "type": "Boolean",+ "name": "Versions",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyWiki": {+ "type": "Boolean",+ "name": "Wiki",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyWikiPageAttachments": {+ "type": "Boolean",+ "name": "Wiki page attachments",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyWorkPackages": {+ "type": "Boolean",+ "name": "Work packages",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyWorkPackageAttachments": {+ "type": "Boolean",+ "name": "Work package attachments",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyQueries": {+ "type": "Boolean",+ "name": "Queries",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "copyCategories": {+ "type": "Boolean",+ "name": "Categories",+ "required": false,+ "hasDefault": true,+ "writable": true,+ "location:" "_meta"+ },+ "_links": {}+ },+ "validationErrors": {+ "identifier": {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",+ "message": "Identifier has already been taken.",+ "_embedded": {+ "details": {+ "attribute": "identifier"+ }+ }+ }+ }+ },+ "_links": {+ "self": {+ "href": "/api/v3/projects/5/copy/form",+ "method": "post"+ },+ "validate": {+ "href": "/api/v3/projects/5/copy/form",+ "method": "post"+ }+ }+ }+++ Response 400 (application/hal+json)++ Occurs when the client did not send a valid JSON object in the request body.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:InvalidRequestBody",+ "message": "The request body was not a single JSON object."+ }+++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** copy projects in the source project++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not authorized to access this resource."+ }++++## Create project copy [/api/v3/projects/{id}/copy]++This endpoint allows triggering a copy process of an existing project.+The request payload will be passed as attributes to the new project being created. Unset values will be retained from the existing project where possible.++For available properties, please see the project endpoint.++The copy endpoint has a `_meta` property that allows defining which associations to copy. Please check the copy schema embedded in the project copy form response for available options.++## Create project copy [POST]+++ Request Create copy project++ + Body++ {+ "identifier": "copied_project_identifier",+ "name": "Copied project name",+ "customField35": "Text custom field value",+ "_meta": {+ "copyOverview": false,+ "copyWorkPackages": true+ }+ }+++ Response 302 (application/hal+json)++ Returned if the request is successful. It will redirect to the job statuses API with the backend job that got created. You can query that endpoint to check the status of the copy, and eventually get the created project.++ + Body+++++ Response 400 (application/hal+json)++ Occurs when the client did not send a valid JSON object in the request body.++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:InvalidRequestBody",+ "message": "The request body was not a single JSON object."+ }+++ Response 403 (application/hal+json)++ Returned if the client does not have sufficient permissions.++ **Required permission:** copy projects in the source project++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:MissingPermission",+ "message": "You are not authorized to access this resource."+ }+++ Response 422 (application/hal+json)++ Returned if:++ * a constraint for a property was violated (`PropertyConstraintViolation`)++ + Body++ {+ "_type": "Error",+ "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",+ "message": "Name can't be blank.",+ "_embedded": {+ "details": {+ "attribute": "name"+ }+ }+ }+++## Available parent project candidates [/api/v3/projects/available_parent_projects{?filters,of,sortBy}]+ Model@@ -1506,8 +2037,9 @@ The projects returned depend on the sharing settings of the given version,but are also limited to the projects that the current user is allowed to see.+ Parameters- + id (required, integer, `1`) ... Version id-+++ id (required, integer, `1`) ... Version id++ Response 200 (application/hal+json)[Projects by version][]@@ -1529,3 +2061,4 @@ but are also limited to the projects that the current user is allowed to see."errorIdentifier": "urn:openproject-org:api:v3:errors:NotFound","message": "The specified version does not exist."}+diff --git a/docs/api/apiv3/endpoints/schemas.apib b/docs/api/apiv3/endpoints/schemas.apibindex 795735d4aec..0735eeddd61 100644--- a/docs/api/apiv3/endpoints/schemas.apib+++ b/docs/api/apiv3/endpoints/schemas.apib@@ -40,16 +40,17 @@ Only one of the links (`allowedValues`, `allowedValuesSchemas`) will exist for a## Local Properties-| Property | Description | Type | Default |-|:-----------------:| ---------------------------------------------------------------------------------- | -------- | ------- |-| name | Human readable name of the property as it could be displayed in a UI | String | |-| type | The data type of the properties values | MetaType | |-| minLength | The value of the property must at least contain the specified amount of characters | Integer | 0 |-| maxLength | The value of the property must at most contain the specified amount of characters | Integer | ∞ |-| regularExpression | The value of the property must match the given regular expression (if not null) | String | null |-| required | If true this property is not nullable | Boolean | true |-| writable | If false it is not allowed to **change** the properties value | Boolean | true |-| location | If present, contains a reference to the location of the property in the JSON | String | |+| Property | Description | Type | Default |+|:-----------------:| ---------------------------------------------------------------------------------- | ------------ | ------- |+| name | Human readable name of the property as it could be displayed in a UI | String | |+| type | The data type of the properties values | MetaType | |+| minLength | The value of the property must at least contain the specified amount of characters | Integer | 0 |+| maxLength | The value of the property must at most contain the specified amount of characters | Integer | ∞ |+| regularExpression | The value of the property must match the given regular expression (if not null) | String | null |+| required | If true this property is not nullable | Boolean | true |+| writable | If false it is not allowed to **change** the properties value | Boolean | true |+| location | If present, contains a reference to the location of the property in the JSON | String | |+| description | If present, contains a formattable, human readable description | Formattable | |All of the above properties that do not have a default value *must* be present in the schema.For properties that have a default value, the client can assume the default value, if the property is missing.@@ -102,6 +103,11 @@ The following excerpt examplifies the objects that can be found as a value of th"hasDefault": false,"writable": true,"location": "_links",+ "description": {+ "format": "markdown",+ "raw": "A description for field Lorem ipsum. This may contain [links](https://example.com).",+ "html": "<p>A description for field Lorem ipsum. This may contain <a href=\"https://exampel.com\">links</a>.</p>"+ };"_links": {"allowedValues": {"href": "/api/v3/some/path/to/users"diff --git a/docs/api/apiv3/forms.apib b/docs/api/apiv3/forms.apibindex d50a36e43dc..cec6661a76c 100644--- a/docs/api/apiv3/forms.apib+++ b/docs/api/apiv3/forms.apib@@ -74,6 +74,14 @@ There are only key value pairs for properties that failed validation, the elemenHowever note that even in the case of validation errors, the response you receive from the form endpoint will be an HTTP 200.That is because the main purpose of a form is helping the client to sort out validation errors.+### Meta object++Form resources may have an additional `_meta` object that contains parameters to be sent together with the resource,+but that do not belong to the resource itself. For example, parameters on if and how to send notifications for the action+performed with the API request can be sent.++Each individual endpoint will describe their meta properties, if available.+## Example Form [/api/v3/example/form]+ Modeldiff --git a/lib/api/decorators/form.rb b/lib/api/decorators/form.rbindex 654bc80b111..17ecd1fcc03 100644--- a/lib/api/decorators/form.rb+++ b/lib/api/decorators/form.rb@@ -31,10 +31,10 @@module APImodule Decoratorsclass Form < ::API::Decorators::Single- def initialize(model, current_user: nil, errors: [])+ def initialize(represented, current_user: nil, errors: [], meta: nil)@errors = errors-- super(model, current_user: current_user)+ @meta = meta+ super(represented, current_user: current_user)endproperty :payload,@@ -62,6 +62,10 @@ module APIhashendend++ protected++ attr_reader :metaendendenddiff --git a/lib/api/decorators/property_schema_representer.rb b/lib/api/decorators/property_schema_representer.rbindex 2e7e6609883..43ea2dd51ac 100644--- a/lib/api/decorators/property_schema_representer.rb+++ b/lib/api/decorators/property_schema_representer.rb@@ -34,9 +34,11 @@ require 'roar/json/hal'module APImodule Decoratorsclass PropertySchemaRepresenter < ::API::Decorators::Single+ include API::Decorators::FormattableProperty+def initialize(type:, name:, location: nil, required: true, has_default: false, writable: true,- attribute_group: nil, current_user: nil+ attribute_group: nil, description: nil, current_user: nil)@type = type@name = name@@ -45,6 +47,7 @@ module API@writable = writable@attribute_group = attribute_group@location = derive_location(location)+ @description = descriptionsuper(nil, current_user: current_user)end@@ -59,7 +62,8 @@ module API:max_length,:regular_expression,:options,- :location+ :location,+ :descriptionproperty :type, exec_context: :decoratorproperty :name, exec_context: :decorator@@ -74,6 +78,15 @@ module APIproperty :location, exec_context: :decorator, render_nil: false+ formattable_property :description,+ exec_context: :decorator,+ render_nil: false,+ setter: nil,+ getter: ->(*) do+ next unless description.present?+ ::API::Decorators::Formattable.new(description)+ end+privatedef model_required?diff --git a/lib/api/decorators/schema_representer.rb b/lib/api/decorators/schema_representer.rbindex cde7bbcd4c4..0e6fa5dc549 100644--- a/lib/api/decorators/schema_representer.rb+++ b/lib/api/decorators/schema_representer.rb@@ -65,7 +65,8 @@ module APImax_length: nil,regular_expression: nil,options: {},- show_if: true)+ show_if: true,+ description: nil)getter = ->(*) doschema_property_getter(type,name_source,@@ -77,7 +78,8 @@ module APImax_length,regular_expression,options,- location)+ location,+ description)endschema_property(property,@@ -290,12 +292,14 @@ module APImax_length,regular_expression,options,- location)+ location,+ description)name = call_or_translate(name_source)schema = ::API::Decorators::PropertySchemaRepresenter.new(type: call_or_use(type),name: name,location: location,+ description: call_or_use(description),required: call_or_use(required),has_default: call_or_use(has_default),writable: call_or_use(writable),diff --git a/lib/api/utilities/endpoints/bodied.rb b/lib/api/utilities/endpoints/bodied.rbindex c289d5a5c11..5a3bc72bd3d 100644--- a/lib/api/utilities/endpoints/bodied.rb+++ b/lib/api/utilities/endpoints/bodied.rb@@ -40,19 +40,30 @@ module APIendend+ def default_process_state+ ->(**) do+ {}+ end+ end+def initialize(model:,api_name: model.name.demodulize,instance_generator: default_instance_generator(model),params_modifier: default_params_modifier,+ process_state: default_process_state,+ parse_representer: nil,+ render_representer: nil,process_service: nil,+ process_contract: nil,parse_service: nil)self.model = modelself.api_name = api_nameself.instance_generator = instance_generatorself.params_modifier = params_modifier- self.parse_representer = deduce_parse_representer- self.render_representer = deduce_render_representer- self.process_contract = deduce_process_contract+ self.process_state = process_state+ self.parse_representer = parse_representer || deduce_parse_representer+ self.render_representer = render_representer || deduce_render_representer+ self.process_contract = process_contract || deduce_process_contractself.process_service = process_service || deduce_process_serviceself.parse_service = parse_service || deduce_parse_serviceend@@ -61,6 +72,8 @@ module APIupdate = self-> do+ update.request = self+params = update.parse(current_user, request_body)params = instance_exec(params, &update.params_modifier)@@ -91,6 +104,7 @@ module APIprocess_service.new(**args.compact)+ .with_state(process_state.call(model: instance, params: params)).call(**params)end@@ -108,6 +122,7 @@ module APIendattr_accessor :model,+ :request,:api_name,:instance_generator,:parse_representer,@@ -115,7 +130,8 @@ module API:params_modifier,:process_contract,:process_service,- :parse_service+ :parse_service,+ :process_stateprivatediff --git a/lib/api/utilities/meta_property.rb b/lib/api/utilities/meta_property.rbnew file mode 100644index 00000000000..0cc00253624--- /dev/null+++ b/lib/api/utilities/meta_property.rb@@ -0,0 +1,69 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module Utilities+ module MetaProperty+ extend ActiveSupport::Concern++ included do+ attr_accessor :meta++ property :meta,+ as: :_meta,+ exec_context: :decorator,+ getter: ->(*) { meta_representer },+ setter: ->(fragment:, **) { represented.meta = meta_representer.from_hash(fragment) }++ singleton_class.prepend MetaPropertyConstructor+ end++ module MetaPropertyConstructor+ def create(model, **args)+ meta = args.delete(:meta)++ super(model, **args).tap do |instance|+ instance.meta = meta+ end+ end+ end++ protected++ def meta_representer+ meta_representer_class.create(meta || OpenStruct.new, current_user: current_user)+ end++ def meta_representer_class+ raise NotImplementedError+ end+ end+ end+enddiff --git a/lib/api/utilities/payload_representer.rb b/lib/api/utilities/payload_representer.rbindex e6a0274f960..c6bd2972629 100644--- a/lib/api/utilities/payload_representer.rb+++ b/lib/api/utilities/payload_representer.rb@@ -35,6 +35,8 @@ module APIbase.extend(ClassMethods)base.representable_attrs.each do |property|+ next if property.name == 'meta'+if property.name == 'links'add_filter(property, LinkRenderBlock)nextdiff --git a/lib/api/v3/projects/copy/copy_api.rb b/lib/api/v3/projects/copy/copy_api.rbnew file mode 100644index 00000000000..db5da811b1b--- /dev/null+++ b/lib/api/v3/projects/copy/copy_api.rb@@ -0,0 +1,61 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'api/v3/users/user_collection_representer'++module API+ module V3+ module Projects+ module Copy+ class CopyAPI < ::API::OpenProjectAPI+ resource :copy do+ after_validation do+ authorize(:copy_projects, context: @project)+ end++ mount ::API::V3::Projects::Copy::CreateFormAPI++ post &::API::V3::Utilities::Endpoints::DelayedModify+ .new(+ model: Project,+ instance_generator: ->(*) { @project },+ process_state: ->(params:, **) do+ params.slice(:only, :send_notifications)+ end,+ parse_service: ParseCopyParamsService,+ process_service: ::Projects::EnqueueCopyService,+ process_contract: ::Projects::CopyContract,+ parse_representer: ProjectCopyPayloadRepresenter+ )+ .mount+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/create_form_api.rb b/lib/api/v3/projects/copy/create_form_api.rbnew file mode 100644index 00000000000..63a426cbaa6--- /dev/null+++ b/lib/api/v3/projects/copy/create_form_api.rb@@ -0,0 +1,54 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class CreateFormAPI < ::API::OpenProjectAPI+ resource :form do+ post &::API::V3::Utilities::Endpoints::CreateForm+ .new(+ model: Project,+ instance_generator: ->(*) { @project },+ process_state: ->(params:, **) do+ params.slice(:only, :send_notifications)+ end,+ parse_service: ParseCopyParamsService,+ process_service: ::Projects::CopyService,+ process_contract: ::Projects::CopyContract,+ parse_representer: ProjectCopyPayloadRepresenter,+ render_representer: CreateFormRepresenter+ )+ .mount+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/create_form_representer.rb b/lib/api/v3/projects/copy/create_form_representer.rbnew file mode 100644index 00000000000..b647c39b218--- /dev/null+++ b/lib/api/v3/projects/copy/create_form_representer.rb@@ -0,0 +1,49 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class CreateFormRepresenter < FormRepresenter+ include API::Decorators::CreateForm++ def form_url+ api_v3_paths.project_copy_form(meta.source.id)+ end++ def resource_url+ api_v3_paths.project_copy(meta.source.id)+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/form_representer.rb b/lib/api/v3/projects/copy/form_representer.rbnew file mode 100644index 00000000000..f28e1ac6e91--- /dev/null+++ b/lib/api/v3/projects/copy/form_representer.rb@@ -0,0 +1,59 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class FormRepresenter < ::API::V3::Projects::FormRepresenter+ private++ def payload_representer+ ProjectCopyPayloadRepresenter+ .create(represented, meta: meta, current_user: current_user)+ end++ ##+ # Instantiate the copy schema with the source project+ # to correctly derive available modules and counts+ def schema_representer+ contract = contract_class.new(meta.source, current_user)++ ProjectCopySchemaRepresenter+ .create(contract,+ form_embedded: true,+ current_user: current_user)+ end++ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/parse_copy_params_service.rb b/lib/api/v3/projects/copy/parse_copy_params_service.rbnew file mode 100644index 00000000000..d567052cf40--- /dev/null+++ b/lib/api/v3/projects/copy/parse_copy_params_service.rb@@ -0,0 +1,51 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class ParseCopyParamsService < ::API::V3::ParseResourceParamsService+ private++ def parse_attributes(request_body)+ attributes = super+ meta = attributes.delete(:meta) || OpenStruct.new++ {+ target_project_params: attributes,+ attributes_only: true,+ only: meta.only,+ send_notifications: meta.send_notifications != false+ }+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/project_copy_meta_representer.rb b/lib/api/v3/projects/copy/project_copy_meta_representer.rbnew file mode 100644index 00000000000..9d87e6b6724--- /dev/null+++ b/lib/api/v3/projects/copy/project_copy_meta_representer.rb@@ -0,0 +1,70 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class ProjectCopyMetaRepresenter < ::API::Decorators::Single+ ::Projects::CopyService.copyable_dependencies.each do |dep|+ identifier = dep[:identifier]++ property :"copy_#{identifier}",+ exec_context: :decorator,+ getter: ->(*) do+ only = represented&.only++ only.nil? || only.include?(identifier)+ end,+ reader: ->(doc:, **) { doc.fetch("copy#{identifier.camelize}", true) },+ setter: ->(fragment:, **) do+ represented.only ||= Set.new+ represented.only << identifier unless fragment == false+ end+ end++ property :send_notifications,+ exec_context: :decorator,+ getter: ->(*) do+ # Default to true+ represented.send_notifications != false+ end,+ setter: ->(fragment:, **) do+ represented.send_notifications = fragment+ end++ def model_required?+ false+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/project_copy_payload_representer.rb b/lib/api/v3/projects/copy/project_copy_payload_representer.rbnew file mode 100644index 00000000000..77101952edb--- /dev/null+++ b/lib/api/v3/projects/copy/project_copy_payload_representer.rb@@ -0,0 +1,48 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class ProjectCopyPayloadRepresenter < ::API::V3::Projects::ProjectRepresenter+ include ::API::Utilities::PayloadRepresenter+ include ::API::Utilities::MetaProperty++ cached_representer disabled: true++ def meta_representer_class+ ProjectCopyMetaRepresenter+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/copy/project_copy_schema_representer.rb b/lib/api/v3/projects/copy/project_copy_schema_representer.rbnew file mode 100644index 00000000000..645048bd46e--- /dev/null+++ b/lib/api/v3/projects/copy/project_copy_schema_representer.rb@@ -0,0 +1,68 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Projects+ module Copy+ class ProjectCopySchemaRepresenter < ::API::V3::Projects::Schemas::ProjectSchemaRepresenter+ extend ::API::V3::Utilities::CustomFieldInjector::RepresenterClass+ custom_field_injector type: :schema_representer++ ::Projects::CopyService.copyable_dependencies.each do |dep|+ identifier = dep[:identifier]+ name_source = dep[:name_source]++ schema :"copy_#{identifier}",+ type: 'Boolean',+ name_source: name_source,+ has_default: true,+ writable: true,+ required: false,+ description: -> do+ count = dep[:count_source].call(represented.model, current_user)++ I18n.t('copy_project.x_objects_of_this_type', count: count.to_i)+ end,+ location: :meta+ end++ schema :send_notifications,+ type: 'Boolean',+ name_source: ->(*) { I18n.t(:label_project_copy_notifications) },+ has_default: true,+ writable: true,+ required: false,+ location: :meta+ end+ end+ end+ end+enddiff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rbindex a3332394e29..afe9e0917de 100644--- a/lib/api/v3/projects/project_representer.rb+++ b/lib/api/v3/projects/project_representer.rb@@ -172,8 +172,12 @@ module API}property :id- property :identifier- property :name+ property :identifier,+ render_nil: true++ property :name,+ render_nil: true+property :activeproperty :publicdiff --git a/lib/api/v3/projects/projects_api.rb b/lib/api/v3/projects/projects_api.rbindex 86f9d732901..173015d8ba1 100644--- a/lib/api/v3/projects/projects_api.rb+++ b/lib/api/v3/projects/projects_api.rb@@ -74,6 +74,7 @@ module APImount API::V3::Projects::AvailableAssigneesAPImount API::V3::Projects::AvailableResponsiblesAPI+ mount API::V3::Projects::Copy::CopyAPImount API::V3::WorkPackages::WorkPackagesByProjectAPImount API::V3::Categories::CategoriesByProjectAPImount API::V3::Versions::VersionsByProjectAPIdiff --git a/lib/api/v3/utilities/endpoints/delayed_modify.rb b/lib/api/v3/utilities/endpoints/delayed_modify.rbnew file mode 100644index 00000000000..38f34fed31c--- /dev/null+++ b/lib/api/v3/utilities/endpoints/delayed_modify.rb@@ -0,0 +1,50 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++module API+ module V3+ module Utilities+ module Endpoints+ class DelayedModify < API::Utilities::Endpoints::Modify+ include V3Deductions+ include ::API::V3::Utilities::PathHelper++ private++ def present_success(current_user, call)+ redirect_to_status(call.result)+ end++ def redirect_to_status(job)+ request.redirect api_v3_paths.job_status(job.job_id)+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/utilities/endpoints/form.rb b/lib/api/v3/utilities/endpoints/form.rbindex f39313e5f3a..2d09fe0c6c4 100644--- a/lib/api/v3/utilities/endpoints/form.rb+++ b/lib/api/v3/utilities/endpoints/form.rb@@ -41,6 +41,7 @@ module APIrender_representer.new(call.result,errors: api_errors(call),+ meta: call.state,current_user: current_user)enddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex b1571282872..ba6f035b18a 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -247,6 +247,14 @@ module API"#{projects}/schema"end+ def self.project_copy(id)+ "#{project(id)}/copy"+ end++ def self.project_copy_form(id)+ "#{project(id)}/copy/form"+ end+resources :querydef self.query_defaultdiff --git a/lib/api/v3/work_packages/form_representer.rb b/lib/api/v3/work_packages/form_representer.rbindex ba9ea1b140d..d2858424cb2 100644--- a/lib/api/v3/work_packages/form_representer.rb+++ b/lib/api/v3/work_packages/form_representer.rb@@ -32,14 +32,6 @@ module APImodule V3module WorkPackagesclass FormRepresenter < ::API::Decorators::Form- def initialize(model, current_user: nil, errors: [], action: :update)- self.action = action-- super(model, current_user: current_user, errors: errors)- end-- attr_accessor :action-def payload_representerWorkPackagePayloadRepresenter.create_class(represented, current_user)diff --git a/spec/controllers/copy_projects_controller_spec.rb b/spec/controllers/copy_projects_controller_spec.rbindex f60f662cd5a..3d7e6daadbc 100644--- a/spec/controllers/copy_projects_controller_spec.rb+++ b/spec/controllers/copy_projects_controller_spec.rb@@ -31,13 +31,11 @@ require 'spec_helper'describe CopyProjectsController, type: :controller dolet(:current_user) { FactoryBot.create(:admin) }let(:permission) { :copy_projects }- let(:project) { FactoryBot.create(:project_with_types, public: false) }+ let(:project) { FactoryBot.create(:project, public: false) }let(:copy_project_params) do{- 'description' => 'Some pretty description',- 'enabled_module_names' => ['work_package_tracking', 'boards', ''],- 'public' => project.public,- 'type_ids' => project.types.map(&:id)+ description: 'Some pretty description',+ public: false}end@@ -74,7 +72,7 @@ describe CopyProjectsController, type: :controller doit { expect(response).to render_template('copy_from_settings') }it 'should display error validation messages' do- expect(assigns(:copy_project).errors).not_to be_empty+ expect(assigns(:errors)).not_to be_emptyendenddiff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rbindex b13c3e33d9b..4166afe2e6b 100644--- a/spec/features/projects/template_spec.rb+++ b/spec/features/projects/template_spec.rb@@ -128,7 +128,7 @@ describe 'Project templates', type: :feature, js: true doexpect(mail).not_to be_nil- expect(page).to have_current_path '/projects/foo-bar/', wait: 20+ expect(page).to have_current_path /\/projects\/foo-bar\/?/, wait: 20project = Project.find_by identifier: 'foo-bar'expect(project.name).to eq 'Foo bar'diff --git a/spec/lib/api/v3/support/schema_examples.rb b/spec/lib/api/v3/support/schema_examples.rbindex 6b8d6836575..5572e4dde1e 100644--- a/spec/lib/api/v3/support/schema_examples.rb+++ b/spec/lib/api/v3/support/schema_examples.rb@@ -70,6 +70,16 @@ shared_examples_for 'has basic schema properties' dois_expected.not_to have_json_path("#{path}/location")endend++ it 'indicates if it has a description' do+ if defined?(description)+ is_expected+ .to be_json_eql(description.to_json)+ .at_path("#{path}/description/raw")+ else+ is_expected.not_to have_json_path("#{path}/description")+ end+ endendshared_examples_for 'indicates length requirements' dodiff --git a/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rbnew file mode 100644index 00000000000..ee03a2e8a3a--- /dev/null+++ b/spec/requests/api/v3/projects/copy/copy_form_resource_spec.rb@@ -0,0 +1,250 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require 'rack/test'++describe ::API::V3::Projects::Copy::CreateFormAPI, content_type: :json do+ include Rack::Test::Methods+ include API::V3::Utilities::PathHelper++ shared_let(:text_custom_field) do+ FactoryBot.create(:text_project_custom_field)+ end+ shared_let(:list_custom_field) do+ FactoryBot.create(:list_project_custom_field)+ end++ shared_let(:source_project) do+ FactoryBot.create :project,+ custom_field_values: {+ text_custom_field.id => 'source text',+ list_custom_field.id => list_custom_field.custom_options.last.id+ }+ end++ shared_let(:current_user) do+ FactoryBot.create :user,+ member_in_project: source_project,+ member_with_permissions: %i[copy_projects view_project view_work_packages]+ end++ let(:path) { api_v3_paths.project_copy_form(source_project.id) }+ let(:params) do+ {+ }+ end++ before do+ login_as(current_user)++ post path, params.to_json+ end++ subject(:response) { last_response }++ it 'returns 200 FORM response', :aggregate_failures do+ expect(response.status).to eq(200)++ expect(response.body)+ .to be_json_eql('Form'.to_json)+ .at_path('_type')++ expect(Project.count)+ .to eql 1+ end++ it 'retains the values from the source project' do+ expect(response.body)+ .to be_json_eql('source text'.to_json)+ .at_path("_embedded/payload/customField#{text_custom_field.id}/raw")++ expect(response.body)+ .to be_json_eql(list_custom_field.custom_options.last.value.to_json)+ .at_path("_embedded/payload/_links/customField#{list_custom_field.id}/title")+ end++ it 'contains a meta property with copy properties for every module' do+ ::Projects::CopyService.copyable_dependencies.each do |dep|+ identifier = dep[:identifier].to_s.camelize+ expect(response.body)+ .to be_json_eql(true.to_json)+ .at_path("_embedded/payload/_meta/copy#{identifier}")+ end+ end++ it 'shows an empty name as not set' do+ expect(response.body)+ .to be_json_eql(''.to_json)+ .at_path("_embedded/payload/name")++ expect(response.body)+ .to be_json_eql("Name can't be blank.".to_json)+ .at_path("_embedded/validationErrors/name/message")+ end++ context 'updating the form payload' do+ let(:params) do+ {+ name: 'My copied project',+ identifier: 'foobar',+ "customField#{text_custom_field.id}": {+ "raw": "CF text"+ },+ status: 'on track',+ statusExplanation: { raw: "A magic dwells in each beginning." },+ "_links": {+ "customField#{list_custom_field.id}": {+ "href": api_v3_paths.custom_option(list_custom_field.custom_options.first.id)+ }+ }+ }+ end++ it 'sets those values' do+ expect(response.body)+ .to be_json_eql('My copied project'.to_json)+ .at_path("_embedded/payload/name")++ expect(response.body)+ .to be_json_eql('foobar'.to_json)+ .at_path("_embedded/payload/identifier")++ expect(response.body)+ .to be_json_eql('on track'.to_json)+ .at_path("_embedded/payload/status")++ expect(response.body)+ .to be_json_eql('A magic dwells in each beginning.'.to_json)+ .at_path("_embedded/payload/statusExplanation/raw")++ expect(response.body)+ .to be_json_eql('CF text'.to_json)+ .at_path("_embedded/payload/customField#{text_custom_field.id}/raw")++ expect(response.body)+ .to be_json_eql(list_custom_field.custom_options.first.value.to_json)+ .at_path("_embedded/payload/_links/customField#{list_custom_field.id}/title")++ expect(response.body)+ .to be_json_eql({}.to_json)+ .at_path("_embedded/validationErrors")++ expect(response.body)+ .to be_json_eql("/api/v3/projects/#{source_project.id}/copy".to_json)+ .at_path("_links/commit/href")++ expect(response.body)+ .to be_json_eql("/api/v3/projects/#{source_project.id}/copy/form".to_json)+ .at_path("_links/validate/href")++ expect(response.body)+ .to be_json_eql("/api/v3/projects/#{source_project.id}/copy/form".to_json)+ .at_path("_links/self/href")+ end+ end++ context 'when setting copy meta properties' do+ let(:params) do+ {+ _meta: {+ copyOverview: true+ }+ }+ end++ it 'sets all values to true' do+ ::Projects::CopyService.copyable_dependencies.each do |dep|+ identifier = dep[:identifier].to_s.camelize+ expect(response.body)+ .to be_json_eql(true.to_json)+ .at_path("_embedded/payload/_meta/copy#{identifier}")+ end+ end+ end++ describe 'send_notification' do+ context 'when not present' do+ let(:params) do+ {}+ end++ it 'returns it as false' do+ expect(response.body)+ .to be_json_eql(true.to_json)+ .at_path("_embedded/payload/_meta/sendNotifications")+ end+ end++ context 'when set to false' do+ let(:params) do+ {+ _meta: {+ sendNotifications: false+ }+ }+ end++ it 'returns it as false' do+ expect(response.body)+ .to be_json_eql(false.to_json)+ .at_path("_embedded/payload/_meta/sendNotifications")+ end+ end++ context 'when set to true' do+ let(:params) do+ {+ _meta: {+ sendNotifications: true+ }+ }+ end++ it 'returns it as true' do+ expect(response.body)+ .to be_json_eql(true.to_json)+ .at_path("_embedded/payload/_meta/sendNotifications")+ end+ end+ end+++ context 'without the necessary permission' do+ let(:current_user) do+ FactoryBot.create :user,+ member_in_project: source_project,+ member_with_permissions: %i[view_project view_work_packages]+ end++ it 'returns 403 Not Authorized' do+ expect(response.status).to eq(403)+ end+ end+enddiff --git a/spec/requests/api/v3/projects/copy/copy_resource_spec.rb b/spec/requests/api/v3/projects/copy/copy_resource_spec.rbnew file mode 100644index 00000000000..d419d0a5e8e--- /dev/null+++ b/spec/requests/api/v3/projects/copy/copy_resource_spec.rb@@ -0,0 +1,213 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 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 docs/COPYRIGHT.rdoc for more details.++require 'spec_helper'+require 'rack/test'++describe ::API::V3::Projects::Copy::CopyAPI, content_type: :json do+ include Rack::Test::Methods+ include API::V3::Utilities::PathHelper++ shared_let(:text_custom_field) do+ FactoryBot.create(:text_project_custom_field)+ end+ shared_let(:list_custom_field) do+ FactoryBot.create(:list_project_custom_field)+ end++ shared_let(:source_project) do+ FactoryBot.create :project,+ enabled_module_names: %w[work_package_tracking wiki],+ custom_field_values: {+ text_custom_field.id => 'source text',+ list_custom_field.id => list_custom_field.custom_options.last.id+ }+ end++ shared_let(:work_package) { FactoryBot.create :work_package, project: source_project }+ shared_let(:wiki_page) { FactoryBot.create :wiki_page, wiki: source_project.wiki }++ shared_let(:current_user) do+ FactoryBot.create :user,+ member_in_project: source_project,+ member_with_permissions: %i[copy_projects view_project view_work_packages]+ end++ let(:path) { api_v3_paths.project_copy(source_project.id) }+ let(:params) do+ {+ }+ end++ before do+ login_as(current_user)++ post path, params.to_json+ end++ subject(:response) { last_response }++ describe '#POST /api/v3/projects/:id/copy' do+ describe 'with empty params' do+ it 'returns 422', :aggregate_failures do+ expect(response.status).to eq(422)++ expect(response.body)+ .to be_json_eql('Error'.to_json)+ .at_path('_type')++ expect(response.body)+ .to be_json_eql("Multiple field constraints have been violated.".to_json)+ .at_path("message")++ errors = JSON.parse(response.body)['_embedded']['errors']+ expect(errors.collect { |el| el['message'] })+ .to contain_exactly "Identifier can't be blank.", "Name can't be blank."+ end+ end++ describe 'with attributes given' do+ let(:params) do+ { name: 'My copied project',+ identifier: 'my-copied-project',+ "customField#{text_custom_field.id}": {+ "raw": "CF text"+ },+ }+ end++ it 'returns with a redirect to job' do++ aggregate_failures do+ expect(response.status).to eq(302)++ expect(response).to be_redirect++ expect(response.location).to match /\/api\/v3\/job_statuses\/[\w-]+\z/+ end++ get response.location++ expect(last_response.status).to eq 200++ expect(last_response.body)+ .to be_json_eql('in_queue'.to_json)+ .at_path("status")++ perform_enqueued_jobs++ get response.location++ expect(last_response.status).to eq 200++ expect(last_response.body)+ .to be_json_eql('success'.to_json)+ .at_path("status")++ expect(last_response.body)+ .to be_json_eql("Created project My copied project".to_json)+ .at_path("message")++ project = Project.find_by(identifier: 'my-copied-project')+ expect(project).to be_present++ expect(project.custom_value_for(text_custom_field).value).to eq 'CF text'+ expect(project.custom_value_for(list_custom_field).formatted_value).to eq list_custom_field.custom_options.last.value+ end+ end++ describe 'with restricted copying' do+ let(:params) do+ { name: 'My copied project',+ identifier: 'my-copied-project',+ _meta: {+ copyWorkPackages: true,+ copyWiki: false,+ }+ }+ end++ it 'does not copy the wiki' do+ perform_enqueued_jobs++ project = Project.find_by(identifier: 'my-copied-project')+ expect(project).to be_present++ expect(source_project.wiki.pages.count).to eq 1+ expect(project.wiki.pages.count).to eq 0++ expect(source_project.work_packages.count).to eq 1+ expect(project.work_packages.count).to eq 1+ end+ end++ describe 'sendNotifications' do+ let(:params) do+ { name: 'My copied project',+ identifier: 'my-copied-project',+ _meta: {+ sendNotifications: sendNotifications+ }+ }+ end++ context 'when false' do+ let(:sendNotifications) { false }+ it 'queues the job without notifications' do+ expect(CopyProjectJob)+ .to have_been_enqueued.with do |args|+ expect(args[:send_mails]).to eq false+ end+ end+ end++ context 'when true' do+ let(:sendNotifications) { true }+ it 'queues the job with notifications' do+ expect(CopyProjectJob)+ .to have_been_enqueued.with do |args|+ expect(args[:send_mails]).to eq true+ end+ end+ end+ end++ context 'without the necessary permission' do+ let(:current_user) do+ FactoryBot.create :user,+ member_in_project: source_project,+ member_with_permissions: %i[view_project view_work_packages]+ end++ it 'returns 403 Not Authorized' do+ expect(response.status).to eq(403)+ end+ end+ end+enddiff --git a/spec/requests/api/v3/projects/copy/project_copy_payload_representer_spec.rb b/spec/requests/api/v3/projects/copy/project_copy_payload_representer_spec.rbnew file mode 100644index 00000000000..fb268d72a0f--- /dev/null+++ b/spec/requests/api/v3/projects/copy/project_copy_payload_representer_spec.rb@@ -0,0 +1,157 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe ::API::V3::Projects::Copy::ProjectCopyPayloadRepresenter do+ shared_let(:current_user, reload: false) { FactoryBot.build_stubbed(:user) }+ shared_let(:project, reload: false) { FactoryBot.build_stubbed(:project) }++ describe 'generation' do+ let(:meta) { OpenStruct.new }+ let(:representer) do+ described_class.create(project,+ meta: meta,+ current_user: current_user)+ end+ subject { representer.to_json }++ it 'has a _meta property with the copy properties set to true by default' do+ is_expected.to have_json_path '_meta'++ is_expected+ .to be_json_eql(true.to_json)+ .at_path("_meta/sendNotifications")++ ::Projects::CopyService.copyable_dependencies.each do |dep|+ is_expected+ .to be_json_eql(true.to_json)+ .at_path("_meta/copy#{dep[:identifier].camelize}")+ end+ end++ context 'with the meta property containing which associations to copy' do+ let(:meta) { OpenStruct.new only: %[work_packages wiki] }++ it 'renders only the selected dependencies as true' do+ ::Projects::CopyService.copyable_dependencies.each do |dep|+ is_expected+ .to be_json_eql(meta.only.include?(dep[:identifier].to_s).to_json)+ .at_path("_meta/copy#{dep[:identifier].camelize}")+ end+ end+ end++ context 'with the meta property to send notifications disabled' do+ let(:meta) { OpenStruct.new send_notifications: false }++ it 'renders only the selected dependencies as true' do+ is_expected+ .to be_json_eql(false.to_json)+ .at_path("_meta/sendNotifications")+ end+ end+ end++ describe 'parsing' do+ let(:representer) do+ described_class.create(OpenStruct.new(available_custom_fields: []),+ meta: OpenStruct.new,+ current_user: current_user)+ end+ subject { representer.from_hash parsed_hash }++ context 'with meta set' do+ let(:parsed_hash) do+ {+ 'name' => 'The copied project',+ '_meta' => {+ 'copyWorkPackages' => true,+ 'copyWiki' => true,+ 'sendNotifications' => false+ }+ }+ end++ it 'sets all of them to true' do+ expect(subject.name).to eq 'The copied project'+ expected_names = ::Projects::CopyService.copyable_dependencies.map { |dep| dep[:identifier] }+ expect(subject.meta.only).to match_array(expected_names)+ expect(subject.meta.send_notifications).to eq false+ end+ end++ context 'with one meta copy set to false' do+ let(:parsed_hash) do+ {+ 'name' => 'The copied project',+ '_meta' => {+ 'copyWorkPackages' => false+ }+ }+ end++ it 'sets all others to true' do+ expect(subject.name).to eq 'The copied project'+ expected_names = ::Projects::CopyService.copyable_dependencies.map { |dep| dep[:identifier] }+ expect(subject.meta.only).to match_array(expected_names - %w[work_packages])+ end+ end++ context 'with a mixture of meta copy set to false' do+ let(:parsed_hash) do+ {+ 'name' => 'The copied project',+ '_meta' => {+ 'copyWorkPackages' => false,+ 'copyWiki' => true,+ }+ }+ end++ it 'still sets all of them to true except work packages' do+ expect(subject.name).to eq 'The copied project'+ expected_names = ::Projects::CopyService.copyable_dependencies.map { |dep| dep[:identifier] }+ expect(subject.meta.only).to match_array(expected_names - %w[work_packages])+ end+ end++ context 'with meta unset' do+ let(:parsed_hash) do+ {+ 'name' => 'The copied project',+ }+ end++ it 'does not set meta' do+ expect(subject.name).to eq 'The copied project'+ expect(subject.meta).to be_nil+ end+ end+ end+enddiff --git a/spec/requests/api/v3/projects/copy/project_copy_schema_representer_spec.rb b/spec/requests/api/v3/projects/copy/project_copy_schema_representer_spec.rbnew file mode 100644index 00000000000..2acc0075b82--- /dev/null+++ b/spec/requests/api/v3/projects/copy/project_copy_schema_representer_spec.rb@@ -0,0 +1,79 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe ::API::V3::Projects::Copy::ProjectCopySchemaRepresenter do+ include API::V3::Utilities::PathHelper++ shared_let(:current_user, reload: false) { FactoryBot.build_stubbed(:user) }+ shared_let(:source_project, reload: false) { FactoryBot.build_stubbed(:project) }+ shared_let(:contract, reload: false) { ::Projects::CreateContract.new(source_project, current_user) }++ shared_let(:representer, reload: false) do+ described_class.create(contract,+ self_link: '/a/self/link',+ form_embedded: true,+ current_user: current_user)+ end++ shared_let(:subject, reload: false) { representer.to_json }++ describe '_type' do+ it 'is indicated as Schema' do+ is_expected.to be_json_eql('Schema'.to_json).at_path('_type')+ end+ end++ describe 'send_notifications' do+ it_behaves_like 'has basic schema properties' do+ let(:path) { "sendNotifications" }+ let(:type) { 'Boolean' }+ let(:name) { I18n.t(:label_project_copy_notifications) }+ let(:required) { false }+ let(:has_default) { true }+ let(:writable) { true }+ let(:location) { '_meta' }+ end+ end++ describe 'copy properties' do+ ::Projects::CopyService.copyable_dependencies.each do |dep|+ it_behaves_like 'has basic schema properties' do+ let(:path) { "copy#{dep[:identifier].camelize}" }+ let(:type) { 'Boolean' }+ let(:name) { dep[:name_source].call }+ let(:required) { false }+ let(:has_default) { true }+ let(:writable) { true }+ let(:location) { '_meta' }+ let(:description) { "No objects of this type" }+ end+ end+ end+enddiff --git a/spec/services/base/base_callable_spec.rb b/spec/services/base/base_callable_spec.rbindex 8ecca257bb3..862c5ea7f62 100644--- a/spec/services/base/base_callable_spec.rb+++ b/spec/services/base/base_callable_spec.rb@@ -31,7 +31,7 @@ require 'spec_helper'describe ::BaseServices::BaseCallable, type: :model dolet(:test_service) doClass.new(::BaseServices::BaseCallable) do- def perform(_params)+ def perform(*)state.test = 'foo'ServiceResult.new(success: true, result: 'something')end@@ -44,7 +44,7 @@ describe ::BaseServices::BaseCallable, type: :model dolet(:test_service2) doClass.new(::BaseServices::BaseCallable) do- def perform(_params)+ def perform(*)state.test2 = 'foo'ServiceResult.new(success: true, result: 'something')enddiff --git a/spec/workers/copy_project_job_spec.rb b/spec/workers/copy_project_job_spec.rbindex 7161608deab..0b6c1fe6045 100644--- a/spec/workers/copy_project_job_spec.rb+++ b/spec/workers/copy_project_job_spec.rb@@ -109,7 +109,7 @@ describe CopyProjectJob, type: :model do# expect to create a statusexpect(copy_job.job_status).to be_presentexpect(copy_job.job_status[:status]).to eq 'success'- expect(copy_job.job_status[:payload]['redirect']).to eq '/projects/copy'+ expect(copy_job.job_status[:payload]['redirect']).to include '/projects/copy'endend