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
Merge origin/release/12.0
Oliver Günther409900411e69
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rbindex 1c121661e75..b4cd766d2cc 100644--- a/app/contracts/work_packages/base_contract.rb+++ b/app/contracts/work_packages/base_contract.rb@@ -304,10 +304,18 @@ module WorkPackagesendend+ def readonly_attributes_unchanged+ super.tap do+ if already_in_readonly_status? && unauthenticated_changed.any?+ # Better documentation on why a property is readonly.+ errors.add :base, :readonly_status+ end+ end+ end+def reduce_by_writable_permissions(attributes)- # If we're in a readonly status and did not move into that status right now- # only allow other status transitions. But also prevent that if the associated version is closed.- if model.readonly_status? && !model.status_id_change+ # If we're in a readonly status only allow other status transitions.+ if already_in_readonly_status?super & %w(status status_id)elsesuper@@ -420,5 +428,10 @@ module WorkPackagesdef users_roles_in_projectuser.roles_for_project(model.project)end++ # We're in a readonly status and did not move into that status right now.+ def already_in_readonly_status?+ model.readonly_status? && !model.status_id_change+ endendenddiff --git a/app/controllers/work_packages/bulk_controller.rb b/app/controllers/work_packages/bulk_controller.rbindex 7e58c2798fe..7a7e6b6aaa4 100644--- a/app/controllers/work_packages/bulk_controller.rb+++ b/app/controllers/work_packages/bulk_controller.rb@@ -37,6 +37,8 @@ class WorkPackages::BulkController < ApplicationControllerinclude RelationsHelperinclude QueriesHelper+ include WorkPackages::FlashBulkError+def editsetup_editend@@ -44,13 +46,13 @@ class WorkPackages::BulkController < ApplicationControllerdef update@call = ::WorkPackages::Bulk::UpdateService.new(user: current_user, work_packages: @work_packages)- .call(params: params)+ .call(attributes_for_update)if @call.success?flash[:notice] = t(:notice_successful_update)redirect_back_or_default(controller: '/work_packages', action: :index, project_id: @project)else- @bulk_errors = @call.errors+ error_flash(@work_packages, @call)setup_editrender action: :editend@@ -86,8 +88,7 @@ class WorkPackages::BulkController < ApplicationControllerdef setup_edit@available_statuses = @projects.map { |p| Workflow.available_statuses(p) }.inject(&:&)@custom_fields = @projects.map(&:all_work_package_custom_fields).inject(&:&)- @assignables = possible_assignees- @responsibles = @assignables+ @assignables = @responsibles = possible_assignees@types = @projects.map(&:types).inject(&:&)end@@ -109,6 +110,17 @@ class WorkPackages::BulkController < ApplicationControllerendend+ def attributes_for_update+ return {} unless params.has_key? :work_package++ permitted_params+ .update_work_package+ .tap { |attributes| attributes[:custom_field_values]&.reject! { |_k, v| v.blank? } }+ .reject { |_k, v| v.blank? }+ .transform_values { |v| v == 'none' ? '' : v }+ .to_h+ end+def usercurrent_userenddiff --git a/app/controllers/work_packages/flash_bulk_error.rb b/app/controllers/work_packages/flash_bulk_error.rbnew file mode 100644index 00000000000..6437582e7a3--- /dev/null+++ b/app/controllers/work_packages/flash_bulk_error.rb@@ -0,0 +1,43 @@+#-- 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 COPYRIGHT and LICENSE files for more details.+#++++module WorkPackages::FlashBulkError+ extend ActiveSupport::Concern++ included do+ private++ def error_flash(selected_work_packages, service_result)+ flash[:error] = render_to_string partial: 'work_packages/bulk/errors',+ locals: { service_result: service_result,+ selected_work_packages: selected_work_packages }+ end+ end+enddiff --git a/app/controllers/work_packages/moves_controller.rb b/app/controllers/work_packages/moves_controller.rbindex f0260d2fedf..0a5dd214e18 100644--- a/app/controllers/work_packages/moves_controller.rb+++ b/app/controllers/work_packages/moves_controller.rb@@ -29,6 +29,8 @@#++class WorkPackages::MovesController < ApplicationController+ include WorkPackages::FlashBulkError+default_search_scope :work_packagesbefore_action :find_work_packages, :check_project_uniquenessbefore_action :authorize@@ -40,42 +42,31 @@ class WorkPackages::MovesController < ApplicationControllerdef createprepare_for_work_package_move- new_type = params[:new_type_id].blank? ? nil : @target_project.types.find_by(id: params[:new_type_id])-- unsaved_work_package_ids = []- moved_work_packages = []+ result = modify_call- @work_packages.each do |work_package|- work_package.reload+ set_flash_from_bulk_work_package_save(@work_packages, result)- call_hook(:controller_work_packages_move_before_save,- params: params,- work_package: work_package,- target_project: @target_project,- copy: !!@copy)+ redirect_after_create(result)+ end- service_call = WorkPackages::MoveService- .new(work_package, current_user)- .call(@target_project,- new_type,- copy: @copy,- attributes: permitted_create_params,- journal_note: @notes)+ private- if service_call.success?- moved_work_packages << service_call.result- elsif @copy- unsaved_work_package_ids.concat dependent_error_ids(work_package.id, service_call)- else- unsaved_work_package_ids << work_package.id- end- end+ def modify_call+ klass = if @copy+ WorkPackages::Bulk::CopyService+ else+ WorkPackages::Bulk::MoveService+ end- set_flash_from_bulk_work_package_save(@work_packages, unsaved_work_package_ids)+ klass+ .new(user: current_user, work_packages: @work_packages)+ .call(permitted_create_params)+ end+ def redirect_after_create(result)if params[:follow]- if @work_packages.size == 1 && moved_work_packages.size == 1- redirect_to work_package_path(moved_work_packages.first)+ if result.success? && @work_packages.size == 1+ redirect_to work_package_path(result.dependent_results.first.result)elseredirect_to project_work_packages_path(@target_project || @project)end@@ -84,30 +75,12 @@ class WorkPackages::MovesController < ApplicationControllerendend- def set_flash_from_bulk_work_package_save(work_packages, unsaved_work_package_ids)- if unsaved_work_package_ids.empty? and not work_packages.empty?+ def set_flash_from_bulk_work_package_save(work_packages, service_result)+ if service_result.success? && work_packages.any?flash[:notice] = @copy ? I18n.t(:notice_successful_create) : I18n.t(:notice_successful_update)else- flash[:error] = I18n.t(:notice_failed_to_save_work_packages,- count: unsaved_work_package_ids.size,- total: work_packages.size,- ids: '#' + unsaved_work_package_ids.join(', #'))- end- end-- ##- # When copying, add work package ids that are failing- def dependent_error_ids(parent_id, service_call)- ids = service_call- .results_with_errors(include_self: false)- .map { |result| result.state.copied_from_work_package_id }- .compact-- if ids.present?- joined = ids.map { |id| "##{id}" }.join(" ")- ["#{parent_id} (+ children errors: #{joined})"]- else- [parent_id]+ error_flash(work_packages,+ service_result)endend@@ -115,8 +88,6 @@ class WorkPackages::MovesController < ApplicationControllerI18n.t(:label_move_work_package)end- private-# Check if project is unique before bulk operationsdef check_project_uniquenessunless @project@@ -133,26 +104,10 @@ class WorkPackages::MovesController < ApplicationController@target_project = @allowed_projects.detect { |p| p.id.to_s == params[:new_project_id].to_s } if params[:new_project_id]@target_project ||= @project@types = @target_project.types- @available_versions = @target_project.shared_versions.order_by_semver_name+ @available_versions = @target_project.assignable_versions@available_statuses = Workflow.available_statuses(@project)@notes = params[:notes]@notes ||= ''-- # When copying, avoid copying elements when any of their ancestors- # are in the set to be copied- if @copy- @work_packages = remove_hierarchy_duplicates- end- end-- # Check if a parent work package is also selected for copying- def remove_hierarchy_duplicates- # Get all ancestors of the work_packages to copy- selected_ids = @work_packages.pluck(:id)-- @work_packages.reject do |wp|- wp.ancestors.where(id: selected_ids).exists?- endenddef permitted_create_params@@ -165,6 +120,9 @@ class WorkPackages::MovesController < ApplicationController:version_id,:priority_id).to_h+ .merge(type_id: params[:new_type_id],+ project_id: params[:new_project_id],+ journal_notes: params[:notes]).reject { |_, v| v.blank? }endenddiff --git a/app/services/work_packages/bulk/bulked_service.rb b/app/services/work_packages/bulk/bulked_service.rbnew file mode 100644index 00000000000..a718d526c8a--- /dev/null+++ b/app/services/work_packages/bulk/bulked_service.rb@@ -0,0 +1,83 @@+#-- 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 COPYRIGHT and LICENSE files for more details.+#++++module WorkPackages+ module Bulk+ class BulkedService+ include ::Shared::ServiceContext+ include ::HookHelper++ attr_accessor :user, :work_packages++ def initialize(user:, work_packages:)+ self.user = user+ self.work_packages = work_packages+ end++ def call(params)+ # This is not an all or nothing service. We currently accept that+ # one work package might be moved while another one fails.+ # Personally, I'd rather wrap it in a transaction.+ without_context_transaction(params[:send_notification] == '1') do+ bulk(params)+ end+ end++ private++ def bulk(params)+ result = ServiceResult.new success: true, result: true++ work_packages.each do |work_package|+ # As updating one work package might have already saved another one,+ # e.g. by changing the start/due date or the version+ # we need to reload the work packages to avoid running into stale object errors.+ work_package.reload++ call_move_hook(work_package, params)++ result.add_dependent!(alter_work_package(work_package, params))+ end++ result.result = false if result.failure?++ result+ end++ def alter_work_package(_work_package, _params)+ raise NotImplementedError+ end++ def call_move_hook(_work_package, _params)+ raise NotImplementedError+ end+ end+ end+enddiff --git a/app/services/work_packages/bulk/copy_service.rb b/app/services/work_packages/bulk/copy_service.rbnew file mode 100644index 00000000000..e0cbc36c647--- /dev/null+++ b/app/services/work_packages/bulk/copy_service.rb@@ -0,0 +1,102 @@+#-- 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 COPYRIGHT and LICENSE files for more details.+#++++module WorkPackages+ module Bulk+ class CopyService < BulkedService+ def initialize(user:, work_packages:)+ super++ self.work_packages = remove_hierarchy_duplicates(work_packages)+ end++ private++ def alter_work_package(work_package, attributes)+ ancestors = {}+ result = copy_with_updated_parent_id(work_package, attributes, ancestors)++ work_package+ .descendants+ .order_by_ancestors('asc')+ .each do |wp|+ copied = copy_with_updated_parent_id(wp, attributes, ancestors)++ result.add_dependent!(copied)+ end++ result+ end++ def call_move_hook(work_package, params)+ return if OpenProject::Hook.hook_listeners(:controller_work_packages_move_before_save).empty?++ call_hook(:controller_work_packages_move_before_save,+ params: params,+ work_package: work_package,+ target_project: params[:project_id] ? Project.find_by(id: params[:project_id]) : nil,+ copy: true)+ end++ def copy_with_updated_parent_id(work_package, attributes, ancestors)+ with_updated_parent_id(work_package, attributes, ancestors) do |overridden_attributes|+ WorkPackages::CopyService+ .new(user: user,+ work_package: work_package)+ .call(**overridden_attributes.symbolize_keys)+ end+ end++ def with_updated_parent_id(work_package, attributes, ancestors)+ # avoid modifying attributes which could carry over+ # to the next work_package+ overridden_attributes = attributes.dup++ overridden_attributes[:parent_id] = ancestors[work_package.parent_id] || work_package.parent_id if work_package.parent_id++ copied = yield overridden_attributes++ ancestors[work_package.id] = copied.result.id++ copied+ end++ # Check if a parent work package is also selected for copying+ def remove_hierarchy_duplicates(work_packages)+ # Get all ancestors of the work_packages to copy+ selected_ids = work_packages.pluck(:id)++ work_packages.reject do |wp|+ wp.ancestors.exists?(id: selected_ids)+ end+ end+ end+ end+enddiff --git a/app/services/work_packages/bulk/move_service.rb b/app/services/work_packages/bulk/move_service.rbnew file mode 100644index 00000000000..4762184623d--- /dev/null+++ b/app/services/work_packages/bulk/move_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 COPYRIGHT and LICENSE files for more details.+#++++module WorkPackages+ module Bulk+ class MoveService < BulkedService+ private++ def alter_work_package(work_package, params)+ WorkPackages::UpdateService+ .new(user: user,+ model: work_package)+ .call(**params.symbolize_keys)+ end++ def call_move_hook(work_package, params)+ return if OpenProject::Hook.hook_listeners(:controller_work_packages_move_before_save).empty?++ call_hook(:controller_work_packages_move_before_save,+ params: params,+ work_package: work_package,+ target_project: params[:project_id] ? Project.find_by(id: params[:project_id]) : nil,+ copy: false)+ end+ end+ end+enddiff --git a/app/services/work_packages/bulk/update_service.rb b/app/services/work_packages/bulk/update_service.rbindex 6dd8bfcc07a..84b96a9d839 100644--- a/app/services/work_packages/bulk/update_service.rb+++ b/app/services/work_packages/bulk/update_service.rb@@ -30,69 +30,19 @@module WorkPackagesmodule Bulk- class UpdateService- include ::Shared::ServiceContext- include ::HookHelper-- attr_accessor :user, :work_packages, :permitted_params-- def initialize(user:, work_packages:)- self.user = user- self.work_packages = work_packages- end-- def call(params:)- self.permitted_params = PermittedParams.new(params, user)- in_user_context(params[:send_notification] == '1') do- bulk_update(params)- end- end-+ class UpdateService < BulkedServiceprivate- def bulk_update(params)- saved = []- errors = {}-- work_packages.each do |work_package|- # As updating one work package might have already saved another one,- # e.g. by changing the start/due date or the version- # we need to reload the work packages to avoid running into stale object errors.- work_package.reload-- work_package.add_journal(user, params[:notes])-- # filter parameters by whitelist and add defaults- attributes = parse_params_for_bulk_work_package_attributes params, work_package.project-- call_hook(:controller_work_packages_bulk_edit_before_save, params: params, work_package: work_package)-- service_call = WorkPackages::UpdateService- .new(user: user, model: work_package)- .call(**attributes.symbolize_keys)-- if service_call.success?- saved << work_package.id- else- errors[work_package.id] = service_call.errors.full_messages- end- end-- ServiceResult.new success: errors.empty?, result: saved, errors: errors+ def alter_work_package(work_package, attributes)+ WorkPackages::UpdateService+ .new(user: user, model: work_package)+ .call(**attributes.symbolize_keys)end- # TODO: move params transformation out of here as this is not the responsibility of a service- def parse_params_for_bulk_work_package_attributes(params, project)- return {} unless params.has_key? :work_package-- safe_params = permitted_params.update_work_package project: project- attributes = safe_params.reject { |_k, v| v.blank? }- attributes.keys.each do |k|- attributes[k] = '' if attributes[k] == 'none'- end- attributes[:custom_field_values].reject! { |_k, v| v.blank? } if attributes[:custom_field_values]- attributes.delete :custom_field_values if not attributes.has_key?(:custom_field_values) or attributes[:custom_field_values].empty?- attributes.to_h+ def call_move_hook(work_package, params)+ call_hook(:controller_work_packages_bulk_edit_before_save,+ params: params,+ work_package: work_package)endendenddiff --git a/app/services/work_packages/move_service.rb b/app/services/work_packages/move_service.rbdeleted file mode 100644index 373f5f3914b..00000000000--- a/app/services/work_packages/move_service.rb+++ /dev/null@@ -1,74 +0,0 @@-# Moves/copies an work_package to a new project and type--class WorkPackages::MoveService- attr_accessor :work_package,- :user-- def initialize(work_package, user)- self.work_package = work_package- self.user = user- end-- def call(new_project, new_type = nil, options = {})- attributes = options[:attributes] || {}- attributes[:project] = new_project- attributes[:type] = new_type if new_type- attributes[:journal_notes] = options[:journal_note] if options[:journal_note]-- if options[:copy]- copy_with_descendants(attributes)- else- update(attributes)- end- end-- def copy_with_descendants(attributes)- ancestors = {}- result = copy_with_updated_parent_id(work_package, attributes, ancestors)-- work_package- .descendants- .order_by_ancestors('asc')- .each do |wp|- copied = copy_with_updated_parent_id(wp, attributes, ancestors)-- result.add_dependent!(copied)- end-- result- end-- def copy(wp, attributes)- WorkPackages::CopyService- .new(user: user,- work_package: wp)- .call(**attributes.symbolize_keys)- end-- def update(attributes)- WorkPackages::UpdateService- .new(user: user,- model: work_package)- .call(**attributes.symbolize_keys)- end-- def copy_with_updated_parent_id(wp, attributes, ancestors)- with_updated_parent_id(wp, attributes, ancestors) do |overridden_attributes|- copy(wp, overridden_attributes)- end- end-- def with_updated_parent_id(work_package, attributes, ancestors)- # avoid modifying attributes which could carry over- # to the next work_package- overridden_attributes = attributes.dup-- overridden_attributes[:parent_id] = ancestors[work_package.parent_id] || work_package.parent_id if work_package.parent_id-- copied = yield overridden_attributes-- ancestors[work_package.id] = copied.result.id-- copied- end-enddiff --git a/app/views/work_packages/bulk/_errors.html.erb b/app/views/work_packages/bulk/_errors.html.erbnew file mode 100644index 00000000000..b8d066e5fd8--- /dev/null+++ b/app/views/work_packages/bulk/_errors.html.erb@@ -0,0 +1,35 @@+<%+ erroneous_results = service_result.results_with_errors(include_self: false)+ error_count = erroneous_results.count+ total_count = service_result.dependent_results.map(&:result).uniq.count+ selected_count = selected_work_packages.count+%>++<% if total_count - error_count == 0 %>+ <%= t('work_packages.bulk.none_could_be_saved',+ total: total_count) %>+<% else %>+ <%= t('work_packages.bulk.x_out_of_y_could_be_saved',+ failing: error_count,+ total: total_count,+ success: total_count - error_count) %>++ <%= t('work_packages.bulk.could_not_be_saved') %>+<% end %>++<% if selected_count < total_count %>+ <%= t('work_packages.bulk.selected_because_descendants',+ total: total_count,+ selected: selected_count) %>+<% end %>++<ul>+ <% erroneous_results.each do |call| %>+ <% wp_id = call.state.copied_from_work_package_id || call.result.id %>++ <li>+ <%= link_to "##{wp_id}", work_package_path(wp_id) %><%= selected_work_packages.map(&:id).include?(wp_id) ? '' : " (#{I18n.t('work_packages.bulk.descendant')})" %>:+ <%= safe_join call.errors.full_messages, ' ' %>+ </li>+ <% end %>+</ul>diff --git a/app/views/work_packages/bulk/edit.html.erb b/app/views/work_packages/bulk/edit.html.erbindex aa3f0c5de3a..8cfbe5101bb 100644--- a/app/views/work_packages/bulk/edit.html.erb+++ b/app/views/work_packages/bulk/edit.html.erb@@ -29,24 +29,6 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t(:label_bulk_edit_selected_work_packages) %>-<% if @bulk_errors.present? %>- <div class="op-toast -error">- <a title="close" class="op-toast--close icon-context icon-close"></a>- <div class="op-toast--content">- <p><strong><%= t('work_packages.bulk.could_not_be_saved') %></strong></p>-- <ul>- <% @bulk_errors.each do |wpid, messages| %>- <li>- <%= link_to "##{wpid}", work_package_path(wpid) %>:- <%= safe_join messages, ', ' %>- </li>- <% end %>- </ul>- </div>- </div>-<% end %>-<h2><%= t(:label_bulk_edit_selected_work_packages) %></h2><ul><% @work_packages.each do |wp| %>@@ -189,8 +171,8 @@ See COPYRIGHT and LICENSE files for more details.</fieldset><fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= Journal.human_attribute_name(:notes) %></legend>- <%= label_tag 'notes', Journal.human_attribute_name(:notes), class: 'hidden-for-sighted' %>- <%= styled_text_area_tag 'notes', @notes, class: 'wiki-edit', with_text_formatting: true %>+ <%= label_tag 'work_package_journal_notes', Journal.human_attribute_name(:notes), class: 'hidden-for-sighted' %>+ <%= styled_text_area_tag 'work_package[journal_notes]', @notes, class: 'wiki-edit', with_text_formatting: true %><p><%= send_notification_option %></p></fieldset></section>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 07e08cfbc20..714af0c086f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -366,6 +366,10 @@ en:bulk:could_not_be_saved: "The following work packages could not be saved:"+ none_could_be_saved: "None of the %{total} work packages could be updated."+ x_out_of_y_could_be_saved: "%{failing} out of the %{total} work packages could not be updated while %{success} could."+ selected_because_descendants: "While %{selected} work packages where selected, in total %{total} work packages are affected which includes descendants."+ descendant: "descendant of selected"move:@@ -797,6 +801,7 @@ en:does_not_exist: "The specified category does not exist."estimated_hours:only_values_greater_or_equal_zeroes_allowed: "must be >= 0."+ readonly_status: 'The work package is in a readonly status so its attributes cannot be changed.'type:attributes:attribute_groups:diff --git a/lib/api/v3/projects/project_collection_representer.rb b/lib/api/v3/projects/project_collection_representer.rbindex 130ee2c3a76..02b9caa8edf 100644--- a/lib/api/v3/projects/project_collection_representer.rb+++ b/lib/api/v3/projects/project_collection_representer.rb@@ -40,12 +40,6 @@ module APIself.to_eager_load = ::API::V3::Projects::ProjectRepresenter.to_eager_loadself.checked_permissions = ::API::V3::Projects::ProjectRepresenter.checked_permissions- def initialize(represented, self_link:, current_user:, query: {}, page: nil, per_page: nil, groups: nil)- super-- @represented = ::API::V3::Projects::ProjectEagerLoadingWrapper.wrap(represented)- end-links :representations do[representation_format_csv,@@ -53,6 +47,8 @@ module API]end+ protected+def representation_format(format, mime_type:){href: url_for(controller: :projects, action: :index, format: format, **query_params),@@ -71,6 +67,10 @@ module APIrepresentation_format 'csv',mime_type: 'text/csv'end++ def paged_models(models)+ ::API::V3::Projects::ProjectEagerLoadingWrapper.wrap(super)+ endendendenddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex d5c67c098c6..5de46833150 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -497,12 +497,13 @@ module API"#{project(project_id)}/work_packages"end- def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil)+ def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil)query_params = {filters: filters&.to_json,sortBy: sort_by&.to_json,groupBy: group_by,- pageSize: page_size+ pageSize: page_size,+ offset: offset}.reject { |_, v| v.blank? }if query_params.any?diff --git a/modules/backlogs/spec/models/issue_position_spec.rb b/modules/backlogs/spec/models/issue_position_spec.rbindex a35f073caaa..9920e3e3633 100644--- a/modules/backlogs/spec/models/issue_position_spec.rb+++ b/modules/backlogs/spec/models/issue_position_spec.rb@@ -267,9 +267,9 @@ describe WorkPackage, type: :model doshared_let(:admin) { FactoryBot.create :admin }def move_to_project(work_package, project)- service = WorkPackages::MoveService.new(work_package, admin)-- service.call(project)+ WorkPackages::UpdateService+ .new(model: work_package, user: admin)+ .call(project: project)endbefore dodiff --git a/modules/backlogs/spec/models/version_spec.rb b/modules/backlogs/spec/models/version_spec.rbindex 638185d4bdb..e6dde991ec3 100644--- a/modules/backlogs/spec/models/version_spec.rb+++ b/modules/backlogs/spec/models/version_spec.rb@@ -57,9 +57,9 @@ describe Version, type: :model doshared_let(:admin) { FactoryBot.create :admin }def move_to_project(work_package, project)- service = WorkPackages::MoveService.new(work_package, admin)-- service.call(project)+ WorkPackages::UpdateService+ .new(model: work_package, user: admin)+ .call(project: project)endbefore dodiff --git a/modules/costs/spec/models/work_package_spec.rb b/modules/costs/spec/models/work_package_spec.rbindex 38d760d1243..4355efb0016 100644--- a/modules/costs/spec/models/work_package_spec.rb+++ b/modules/costs/spec/models/work_package_spec.rb@@ -48,9 +48,9 @@ describe WorkPackage, type: :model dolet!(:budget) { FactoryBot.create(:budget, project: project) }def move_to_project(work_package, project)- service = WorkPackages::MoveService.new(work_package, user)-- service.call(project)+ WorkPackages::UpdateService+ .new(model: work_package, user: user)+ .call(project: project)endit 'should update cost entries on move' dodiff --git a/spec/contracts/work_packages/update_contract_spec.rb b/spec/contracts/work_packages/update_contract_spec.rbindex 62b508cbe26..44dc22960cb 100644--- a/spec/contracts/work_packages/update_contract_spec.rb+++ b/spec/contracts/work_packages/update_contract_spec.rb@@ -42,7 +42,8 @@ describe WorkPackages::UpdateContract dolet(:work_package) doFactoryBot.build_stubbed(:work_package,project: work_package_project,- type: type).tap do |wp|+ type: type,+ status: status).tap do |wp|wp_scope = double('wp scope')allow(WorkPackage)@@ -58,6 +59,7 @@ describe WorkPackages::UpdateContract doendlet(:user) { FactoryBot.build_stubbed(:user) }let(:type) { FactoryBot.build_stubbed(:type) }+ let(:status) { FactoryBot.build_stubbed(:status) }let(:permissions) { %i[view_work_packages edit_work_packages assign_versions] }before do@@ -337,4 +339,32 @@ describe WorkPackages::UpdateContract doendendend++ describe 'readonly status' do+ context 'with the status being readonly', with_ee: %i[readonly_work_packages] do+ let(:status) { FactoryBot.build_stubbed(:status, is_readonly: true) }+ let(:new_priority) { FactoryBot.build_stubbed(:priority) }++ before do+ work_package.priority = new_priority++ contract.validate+ end++ it 'is invalid' do+ expect(contract)+ .not_to be_valid+ end++ it 'adds an error to the written to attribute' do+ expect(contract.errors.symbols_for(:priority_id))+ .to include(:error_readonly)+ end++ it 'adds an error to base to better explain' do+ expect(contract.errors.symbols_for(:base))+ .to include(:readonly_status)+ end+ end+ endenddiff --git a/spec/controllers/work_packages/bulk_controller_spec.rb b/spec/controllers/work_packages/bulk_controller_spec.rbindex 9679d741fcd..f81147966a7 100644--- a/spec/controllers/work_packages/bulk_controller_spec.rb+++ b/spec/controllers/work_packages/bulk_controller_spec.rb@@ -222,65 +222,16 @@ describe WorkPackages::BulkController, type: :controller, with_settings: { journendend- context 'when updating two work packages with differing whitelisted params' do- let!(:work_package_ids) { [work_package_1.id, work_package_3.id] }-- let!(:role_with_permission_to_add_watchers) do- FactoryBot.create(:role, permissions: role.permissions + [:add_work_package_watchers])- end- let!(:other_user) { FactoryBot.create :user }-- let!(:other_member_1) do- FactoryBot.create(:member,- project: project_1,- principal: other_user,- roles: [role_with_permission_to_add_watchers])- end- let!(:other_member_2) do- FactoryBot.create(:member,- project: project_2,- principal: other_user,- roles: [role])- end-- let(:description) { 'Text' }- let(:work_package_params) do- { description: description, watcher_user_ids: [user.id] }- end-- before do- # create user memberships to allow the user to watch work packages- member1_p1- member1_p2- # let other_user perform the bulk update- allow(User).to receive(:current).and_return other_user- put :update, params: { ids: work_package_ids, work_package: work_package_params }- end-- it 'updates the description if whitelisted' do- expect(work_package_1.reload.description).to eq(description)- expect(work_package_3.reload.description).to eq(description)- end-- it 'updates the watchers if the watcher user ids are whitelisted' do- expect(work_package_1.reload.watcher_users).to include user- end-- it 'does not update the watchers if the watcher user ids are not whitelisted' do- expect(work_package_3.reload.watcher_users).not_to include user- end- end-shared_context 'update_request' dobefore doput :update,params: {ids: work_package_ids,- notes: 'Bulk editing',work_package: { priority_id: priority.id,assigned_to_id: group_id,responsible_id: responsible_id,- send_notification: send_notification }+ send_notification: send_notification,+ journal_notes: 'Bulk editing' }}endend@@ -401,10 +352,14 @@ describe WorkPackages::BulkController, type: :controller, with_settings: { journendcontext 'not allowed' do+ render_views+include_context 'update_request'it 'does not succeed' do- expect(assigns[:bulk_errors].keys).to match_array(work_package_ids)+ expect(flash[:error])+ .to include(I18n.t(:'work_packages.bulk.none_could_be_saved',+ total: 2))expect(subject).to match_array [user.id]endenddiff --git a/spec/controllers/work_packages/moves_controller_spec.rb b/spec/controllers/work_packages/moves_controller_spec.rbindex d9b50f541f6..80dd46cfd7a 100644--- a/spec/controllers/work_packages/moves_controller_spec.rb+++ b/spec/controllers/work_packages/moves_controller_spec.rb@@ -292,7 +292,7 @@ describe WorkPackages::MovesController, type: :controller, with_settings: { jourendit 'redirects to the work package copy' do- copy = WorkPackage.order(Arel.sql('id desc')).first+ copy = WorkPackage.order(id: :desc).firstis_expected.to redirect_to(work_package_path(copy))endend@@ -456,29 +456,6 @@ describe WorkPackages::MovesController, type: :controller, with_settings: { jourendendend-- context 'on create' do- it 'only copies the parent work package' do- expect(::WorkPackages::MoveService)- .to receive(:new)- .with(work_package, current_user)- .and_call_original-- expect(::WorkPackages::MoveService)- .not_to receive(:new)- .with(child_wp, current_user)-- expect do- post :create,- params: {- ids: [work_package.id, child_wp.id],- copy: ''- }- end.to change(WorkPackage, :count).by(2)-- expect(flash[:notice]).to eq(I18n.t(:notice_successful_create))- end- endendcontext 'child work package from one project to other' do@@ -519,6 +496,8 @@ describe WorkPackages::MovesController, type: :controller, with_settings: { jourendcontext 'when cross_project_work_package_relations is disabled' do+ render_views+before doallow(Setting).to receive(:cross_project_work_package_relations?).and_return(false)@@ -527,10 +506,8 @@ describe WorkPackages::MovesController, type: :controller, with_settings: { jourit 'is unsuccessful' doexpect(flash[:error])- .to eq(I18n.t(:notice_failed_to_save_work_packages,- count: 1,- total: 1,- ids: "##{child_wp.id}"))+ .to include(I18n.t(:'work_packages.bulk.none_could_be_saved',+ total: 1))endenddiff --git a/spec/features/work_packages/bulk/copy_work_package_spec.rb b/spec/features/work_packages/bulk/copy_work_package_spec.rbindex 86ab0f03261..5db7536dafa 100644--- a/spec/features/work_packages/bulk/copy_work_package_spec.rb+++ b/spec/features/work_packages/bulk/copy_work_package_spec.rb@@ -2,63 +2,50 @@ require 'spec_helper'require 'features/page_objects/notification'describe 'Copy work packages through Rails view', js: true do- let(:dev_role) do- FactoryBot.create :role,- permissions: %i[view_work_packages]- end- let(:mover_role) do- FactoryBot.create :role,- permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks assign_versions- add_work_packages]- end- let(:dev) do+ shared_let(:type) { FactoryBot.create :type, name: 'Bug' }+ shared_let(:type2) { FactoryBot.create :type, name: 'Risk' }++ shared_let(:project) { FactoryBot.create(:project, name: 'Source', types: [type, type2]) }+ shared_let(:project2) { FactoryBot.create(:project, name: 'Target', types: [type, type2]) }++ shared_let(:dev) doFactoryBot.create :user,firstname: 'Dev',lastname: 'Guy',member_in_project: project,- member_through_role: dev_role+ member_with_permissions: %i[view_work_packages]end- let(:mover) do- FactoryBot.create :admin,+ shared_let(:mover) do+ FactoryBot.create :user,firstname: 'Manager',lastname: 'Guy',- member_in_project: project,- member_through_role: mover_role+ member_in_projects: [project, project2],+ member_with_permissions: %i[view_work_packages+ copy_work_packages+ move_work_packages+ manage_subtasks+ assign_versions+ add_work_packages]end- let(:type) { FactoryBot.create :type, name: 'Bug' }- let(:type2) { FactoryBot.create :type, name: 'Risk' }-- let!(:project) { FactoryBot.create(:project, name: 'Source', types: [type, type2]) }- let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type, type2]) }-- let!(:work_package) do+ shared_let(:work_package) doFactoryBot.create(:work_package,author: dev,project: project,type: type)end- let!(:work_package2) do+ shared_let(:work_package2) doFactoryBot.create(:work_package,author: dev,project: project,type: type)end-- let(:status) { work_package.status }- let!(:version) { FactoryBot.create :version, project: project2 }- let!(:status2) { FactoryBot.create :default_status }- let!(:workflow) do- FactoryBot.create :workflow,- type_id: type2.id,- old_status: work_package.status,- new_status: status2,- role: mover_role- end+ shared_let(:version) { FactoryBot.create :version, project: project2 }let(:wp_table) { ::Pages::WorkPackagesTable.new(project) }let(:context_menu) { Components::WorkPackages::ContextMenu.new }let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new }+ let(:notes) { ::Components::WysiwygEditor.new }before dologin_as current_user@@ -80,15 +67,16 @@ describe 'Copy work packages through Rails view', js: true docontext_menu.choose 'Bulk copy'expect(page).to have_selector('#new_project_id')- select 'Target', from: 'new_project_id'+ select project2.name, from: 'new_project_id'sleep 1expect(page).to have_select('Project', selected: 'Target')end- it 'sets the version on copy' do+ it 'sets the version on copy and leaves a note' doselect version.name, from: 'version_id'+ notes.set_markdown 'A note on copy'click_on 'Copy and follow'wp_table.expect_work_package_count 2@@ -102,35 +90,83 @@ describe 'Copy work packages through Rails view', js: true docopied_wps = WorkPackage.last(2)expect(copied_wps.map(&:project_id).uniq).to eq([project2.id])expect(copied_wps.map(&:version_id).uniq).to eq([version.id])+ expect(copied_wps.map { |wp| wp.journals.last.notes }.uniq).to eq(['A note on copy'])end- describe 'copy and follow' do- before do- click_on 'Copy and follow'+ context 'with a work package having a child' do+ let!(:child) do+ FactoryBot.create(:work_package,+ author: dev,+ project: project,+ type: type,+ parent: work_package)end- it 'moves parent and child wp to a new project' do+ it 'moves parent and child wp to a new project with the hierarchy amended' do+ click_on 'Copy and follow'+expect_angular_frontend_initialized- wp_table.expect_work_package_count 2+ wp_table.expect_work_package_count 3expect(page).to have_selector('#projects-menu', text: 'Target')# Should not move the sources- work_package2.reload- work_package.reload- expect(work_package.project_id).to eq(project.id)- expect(work_package2.project_id).to eq(project.id)+ expect(work_package.reload.project_id).to eq(project.id)+ expect(work_package2.reload.project_id).to eq(project.id)# Check project of last two created wps- copied_wps = WorkPackage.last(2)- expect(copied_wps.map(&:project_id)).to eq([project2.id, project2.id])+ copied_wps = WorkPackage.last(3)+ expect(copied_wps.map(&:project_id).uniq).to eq([project2.id])++ expect(project2.work_packages.find_by(subject: child.subject).parent)+ .to eq project2.work_packages.find_by(subject: work_package.subject)end+ end- context 'when the target project does not have the type' do- let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type2]) }+ context 'when the target project does not have the type' do+ let!(:child) do+ FactoryBot.create(:work_package,+ author: dev,+ project: project,+ type: type,+ parent: work_package)+ end++ before do+ project2.types = [type2]+ end++ it 'fails, informing of the reasons' do+ click_on 'Copy and follow'- it 'does moves the work package and changes the type' do- expect(page).to have_selector('.flash.error', text: "Failed to save 2 work package(s) on 2 selected:")- end+ expect(page)+ .to have_selector(+ '.flash.error',+ text: I18n.t('work_packages.bulk.none_could_be_saved', total: 3)+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: I18n.t('work_packages.bulk.selected_because_descendants', total: 3, selected: 2)+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: "#{work_package.id}: Type #{I18n.t('activerecord.errors.messages.inclusion')}"+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: "#{work_package2.id}: Type #{I18n.t('activerecord.errors.messages.inclusion')}"+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: "#{child.id} (descendant of selected): Type #{I18n.t('activerecord.errors.messages.inclusion')}"+ )endendenddiff --git a/spec/features/work_packages/bulk/move_work_package_spec.rb b/spec/features/work_packages/bulk/move_work_package_spec.rbindex b42df0763fb..59a2ade73da 100644--- a/spec/features/work_packages/bulk/move_work_package_spec.rb+++ b/spec/features/work_packages/bulk/move_work_package_spec.rb@@ -1,6 +1,7 @@require 'spec_helper'require 'features/page_objects/notification'+# rubocop:disable RSpec/MultipleMemoizedHelpersdescribe 'Moving a work package through Rails view', js: true dolet(:dev_role) doFactoryBot.create :role,@@ -31,45 +32,48 @@ describe 'Moving a work package through Rails view', js: true dolet!(:project) { FactoryBot.create(:project, name: 'Source', types: [type, type2]) }let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type, type2]) }- let!(:work_package) do+ let(:work_package) doFactoryBot.create(:work_package,author: dev,project: project,- type: type)+ type: type,+ status: status)end- let!(:child_wp) do+ let(:work_package2) doFactoryBot.create(:work_package,author: dev,- parent: work_package,project: project,- type: type)- end-- let(:status) { work_package.status }- let!(:status2) { FactoryBot.create :default_status }- let!(:workflow) do- FactoryBot.create :workflow,- type_id: type2.id,- old_status: work_package.status,- new_status: status2,- role: mover_role+ type: type,+ status: work_package2_status)end+ let(:status) { FactoryBot.create(:status) }+ let(:work_package2_status) { status }let(:wp_table) { ::Pages::WorkPackagesTable.new(project) }let(:context_menu) { Components::WorkPackages::ContextMenu.new }let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new }+ let(:current_user) { mover }+ let(:work_packages) { [work_package, work_package2] }before do+ work_packageslogin_as current_userwp_table.visit!expect_angular_frontend_initialized- wp_table.expect_work_package_listed work_package, child_wpenddescribe 'moving a work package and its children' do- context 'with permission' do- let(:current_user) { mover }+ let(:work_packages) { [work_package, child_wp] }+ let(:child_wp) do+ FactoryBot.create(:work_package,+ author: dev,+ parent: work_package,+ project: project,+ type: type,+ status: status)+ end+ context 'with permission' dobefore doexpect(child_wp.project_id).to eq(project.id)@@ -121,6 +125,46 @@ describe 'Moving a work package through Rails view', js: true doendend+ describe 'moving an unmovable (e.g. readonly status) and a movable work package', with_ee: %i[readonly_work_packages] do+ let(:work_packages) { [work_package, work_package2] }+ let(:work_package2_status) { FactoryBot.create(:status, is_readonly: true) }++ before do+ loading_indicator_saveguard+ # Select all work packages+ find('body').send_keys [:control, 'a']++ context_menu.open_for work_package2+ context_menu.choose 'Bulk change of project'++ # On work packages move page+ select project2.name, from: 'new_project_id'+ click_on 'Move and follow'+ end++ it 'displays an error message explaining which work package could not be moved and why' do+ expect(page)+ .to have_selector('.flash.error',+ text: I18n.t('work_packages.bulk.could_not_be_saved'))++ expect(page)+ .to have_selector(+ '.flash.error',+ text: "#{work_package2.id}: Project #{I18n.t('activerecord.errors.messages.error_readonly')}"+ )++ expect(page)+ .to have_selector('.flash.error',+ text: I18n.t('work_packages.bulk.x_out_of_y_could_be_saved',+ failing: 1,+ total: 2,+ success: 1))++ expect(work_package.reload.project_id).to eq(project2.id)+ expect(work_package2.reload.project_id).to eq(project.id)+ end+ end+describe 'accessing the bulk move from the card view' dobefore dodisplay_representation.switch_to_card_layout@@ -129,8 +173,6 @@ describe 'Moving a work package through Rails view', js: true doendcontext 'with permissions' do- let(:current_user) { mover }-it 'does allow to move' docontext_menu.open_for work_packagecontext_menu.expect_options ['Bulk change of project']@@ -147,3 +189,4 @@ describe 'Moving a work package through Rails view', js: true doendendend+# rubocop:enable RSpec/MultipleMemoizedHelpersdiff --git a/spec/features/work_packages/bulk/update_work_package_spec.rb b/spec/features/work_packages/bulk/update_work_package_spec.rbindex 3438220279c..b92c73ba44a 100644--- a/spec/features/work_packages/bulk/update_work_package_spec.rb+++ b/spec/features/work_packages/bulk/update_work_package_spec.rb@@ -1,6 +1,7 @@require 'spec_helper'require 'features/page_objects/notification'+# rubocop:disable RSpec/MultipleMemoizedHelpersdescribe 'Bulk update work packages through Rails view', js: true dolet(:dev_role) doFactoryBot.create :role,@@ -30,6 +31,7 @@ describe 'Bulk update work packages through Rails view', js: true dolet!(:project) { FactoryBot.create(:project, name: 'Source', types: [type]) }let!(:status) { FactoryBot.create :status }+ let(:work_package2_status) { status }let!(:work_package) doFactoryBot.create(:work_package,@@ -41,7 +43,7 @@ describe 'Bulk update work packages through Rails view', js: true dolet!(:work_package2) doFactoryBot.create(:work_package,author: dev,- status: status,+ status: work_package2_status,project: project,type: type)end@@ -58,6 +60,7 @@ describe 'Bulk update work packages through Rails view', js: true dolet(:wp_table) { ::Pages::WorkPackagesTable.new(project) }let(:context_menu) { Components::WorkPackages::ContextMenu.new }let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new }+ let(:notes) { ::Components::WysiwygEditor.new }before dologin_as current_user@@ -80,35 +83,56 @@ describe 'Bulk update work packages through Rails view', js: true do# On work packages edit pageexpect(page).to have_selector('#work_package_status_id')select status2.name, from: 'work_package_status_id'+ notes.set_markdown('The typed note')end- it 'sets two statuses' do+ it 'sets status and leaves a note' doclick_on 'Submit'expect_angular_frontend_initializedwp_table.expect_work_package_count 2# Should update the status- work_package2.reload- work_package.reload- expect(work_package.status_id).to eq(status2.id)- expect(work_package2.status_id).to eq(status2.id)+ expect([work_package.reload.status_id, work_package2.reload.status_id].uniq)+ .to eq([status2.id])++ expect([work_package.journals.last.notes, work_package2.journals.last.notes].uniq)+ .to eq(['The typed note'])endcontext 'when making an error in the form' do+ let(:work_package2_status) { FactoryBot.create(:status) } # without creating a workflow+it 'does not update the work packages' dofill_in 'work_package_start_date', with: '123'click_on 'Submit'- expect(page).to have_selector('.op-toast', text: I18n.t('work_packages.bulk.could_not_be_saved'))- expect(page).to have_selector('.op-toast', text: work_package.id)- expect(page).to have_selector('.op-toast', text: work_package2.id)+ expect(page)+ .to have_selector(+ '.flash.error',+ text: I18n.t('work_packages.bulk.none_could_be_saved', total: 2)+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: "#{work_package.id}: Start date #{I18n.t('activerecord.errors.messages.not_a_date')}"+ )++ expect(page)+ .to have_selector(+ '.flash.error',+ text: <<~MSG.squish+ #{work_package2.id}:+ Status #{I18n.t('activerecord.errors.models.work_package.attributes.status_id.status_transition_invalid')}+ MSG+ )# Should not update the statuswork_package2.reloadwork_package.reloadexpect(work_package.status_id).to eq(status.id)- expect(work_package2.status_id).to eq(status.id)+ expect(work_package2.status_id).to eq(work_package2_status.id)endendend@@ -148,3 +172,4 @@ describe 'Bulk update work packages through Rails view', js: true doendendend+# rubocop:enable RSpec/MultipleMemoizedHelpersdiff --git a/spec/requests/api/v3/project_resource_spec.rb b/spec/requests/api/v3/project_resource_spec.rbindex aa781c9abc0..7911c26d563 100644--- a/spec/requests/api/v3/project_resource_spec.rb+++ b/spec/requests/api/v3/project_resource_spec.rb@@ -200,7 +200,27 @@ describe 'API v3 Project resource', type: :request, content_type: :json doit_behaves_like 'API V3 collection response', 1, 1, 'Project'- context 'filtering for project by ancestor' do+ context 'with a pageSize and offset' do+ let(:projects) { [project, project2, project3] }+ let(:project2) do+ FactoryBot.create(:project,+ members: { current_user => [role] })+ end+ let(:project3) do+ FactoryBot.create(:project,+ members: { current_user => [role] })+ end++ let(:get_path) do+ api_v3_paths.path_for :projects, sort_by: { id: :asc }, page_size: 2, offset: 2+ end++ it_behaves_like 'API V3 collection response', 3, 1, 'Project' do+ let(:elements) { [project3] }+ end+ end++ context 'when filtering for project by ancestor' dolet(:projects) { [project, other_project, parent_project] }let(:parent_project) dodiff --git a/spec/services/work_packages/move_service_spec.rb b/spec/services/work_packages/move_service_spec.rbdeleted file mode 100644index 11458240527..00000000000--- a/spec/services/work_packages/move_service_spec.rb+++ /dev/null@@ -1,167 +0,0 @@-#-- 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 COPYRIGHT and LICENSE files for more details.-#++--require 'spec_helper'--describe WorkPackages::MoveService, type: :model do- let(:user) { FactoryBot.build_stubbed(:user) }- let(:work_package) do- FactoryBot.build_stubbed(:stubbed_work_package)- end- let(:type) { FactoryBot.build_stubbed(:type) }- let(:project) { FactoryBot.build_stubbed(:project) }-- let(:instance) { described_class.new(work_package, user) }- let(:child_service_result_work_package) { work_package }- let(:child_service_result) do- ServiceResult.new success: true,- result: child_service_result_work_package- end-- context 'when copying' do- let(:expected_attributes) { { project: project } }- let(:child_service_result_work_package) { FactoryBot.build_stubbed(:stubbed_work_package) }-- before do- copy_double = double('copy service double')-- expect(WorkPackages::CopyService)- .to receive(:new)- .with(user: user,- work_package: work_package)- .and_return(copy_double)-- expect(copy_double)- .to receive(:call)- .with(expected_attributes)- .and_return(child_service_result)-- allow(work_package)- .to receive_message_chain(:self_and_descendants, :order_by_ancestors)- .and_return [work_package]- end-- it 'calls the copy service and merges its result' do- expect(instance.call(project, nil, copy: true).result)- .to eql child_service_result.result- end-- context 'when providing a type and attributes' do- let(:expected_attributes) do- { project: project,- type: type,- subject: 'blubs' }- end-- it 'calls the copy service and merges its result' do- expect(instance.call(project, type, attributes: { subject: 'blubs' }, copy: true).result)- .to eql child_service_result.result- end- end-- context 'for a parent' do- let(:child_work_package) do- FactoryBot.build_stubbed(:stubbed_work_package, parent: work_package)- end- let(:copied_child_work_package) do- FactoryBot.build_stubbed(:stubbed_work_package)- end- let(:child_child_service_result) do- ServiceResult.new success: true,- result: copied_child_work_package- end-- let(:expected_child_attributes) { { project: project, parent_id: child_service_result_work_package.id } }-- before do- copy_double = double('copy child service double')-- expect(WorkPackages::CopyService)- .to receive(:new)- .with(user: user,- work_package: child_work_package)- .and_return(copy_double)-- expect(copy_double)- .to receive(:call)- .with(expected_child_attributes)- .and_return(child_child_service_result)-- allow(work_package)- .to receive_message_chain(:descendants, :order_by_ancestors)- .and_return [child_work_package]- end-- it 'calls the copy service twice and merges its result' do- call = instance.call(project, nil, copy: true)-- expect(call.result)- .to eql child_service_result.result- expect(call.dependent_results)- .to match_array [child_child_service_result]- end- end- end-- context 'when moving' do- let(:expected_attributes) { { project: project } }-- before do- update_double = double('update service double')-- expect(WorkPackages::UpdateService)- .to receive(:new)- .with(user: user,- model: work_package)- .and_return(update_double)-- expect(update_double)- .to receive(:call)- .with(expected_attributes)- .and_return(child_service_result)- end-- it 'calls the update service and returns its result' do- expect(instance.call(project))- .to eql child_service_result- end-- context 'when providing a type and attributes' do- let(:expected_attributes) do- { project: project,- type: type,- subject: 'blubs' }- end-- it 'calls the update service and returns its result' do- expect(instance.call(project, type, attributes: { subject: 'blubs' }))- .to eql child_service_result- end- end- end-end