Files
openproject/app/controllers/work_packages/moves_controller.rb
T
Henriette Darge ee8452282a [63485] Remove show_local_breadcrumb and default_breadcrumb (#18663)
* add a new helper for breadcrumb in wiki page

* set page header in destroy page

* set page header in edit page

* set page header in history and rename and edit parent pages

* change toolbar items into page header items

* add new wiki action to sub header

* remove version edit page which is not in use any more

* add export as a menu item of the header

* fix rubocup errors

* fix failing tests

* replace page header in annotate page

* replace page header in diff page

* add page header in select menu page

* fix rubocup errors

* fix errors on rename test

* fix errors on selecting items from toolbar

* fix errors on tests for child pages

* set correct permission for configure menu item

* replace page header in summary page

* replace page header in summary details page

* edit docs of sub header

* add page header in wiki new page

* remove controller and a route for edit method

* undo changes for docs of sub header

* extract header in show page into a new component

* use helper method in header component

* add wiki module to the breadcrumb

* rename page header component for wiki page

* simplify how lock and lock implemented

* extract sub header

* remove wiki title from header of history page

* fix page header in new page

* use page.find_test_selector in test

* fix failing test for summary page

* fix failing test for wiki child pages

* change the summary test

* use test selector for page header title

* undo changes for activate user in admin

* use test selector in adding editing history test

* use test selector in attachment upload test

* use test selector in child pages tests

* use test selector in wiki menu items tests

* change test selector for breadcrumbs

* extract conditions to show edit button into a method

* extract conditions to show rollback action menu item into a method

* extract conditions to show create button into a method

* fix duplicated code in test

* Remove outdated `show_local_breadcrumb` method which is replaced by the Primer::PageHeader breadcrumb

* Remove `default_breadcrumb` method as it serves no prupose any more

* Remove the old breadcrumb and its hook completely

* remove breadcrumbs path from rename

* fix translations errors in storages

* undo changes on translations

* remove default breadcrumbs in time tracking controller

---------

Co-authored-by: Behrokh Satarnejad <b.satarnejad@openproject.com>
Co-authored-by: Behrokh Satarnejad <62008897+bsatarnejad@users.noreply.github.com>
2025-04-23 10:40:43 +02:00

148 lines
4.4 KiB
Ruby

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
#++
class WorkPackages::MovesController < ApplicationController
include WorkPackages::BulkErrorMessage
default_search_scope :work_packages
before_action :find_work_packages, :check_project_uniqueness
before_action :authorize
def new
prepare_for_work_package_move
end
def create
prepare_for_work_package_move
perform_operation
end
private
def perform_operation
if within_frontend_treshold?
perform_in_frontend
else
perform_in_background
end
end
def within_frontend_treshold?
WorkPackageHierarchy.where(ancestor_id: @work_packages).count <= Setting.work_packages_bulk_request_limit
end
# rubocop:disable Metrics/AbcSize
def perform_in_frontend
call = job_class
.perform_now(**job_args)
if call.success? && @work_packages.any?
flash[:notice] = call.message
redirect_to call.result
else
flash[:error] = bulk_error_message(@work_packages, call.dependent_results.first)
redirect_back_or_default(project_work_packages_path(@project))
end
end
# rubocop:enable Metrics/AbcSize
def perform_in_background
job = job_class.perform_later(**job_args)
redirect_to job_status_path(job.job_id)
end
def job_args
{
user: current_user,
work_package_ids: @work_packages.pluck(:id),
project: @project,
target_project: @target_project,
params: attributes_for_create,
follow: params[:follow]
}
end
def job_class
if @copy
WorkPackages::BulkCopyJob
else
WorkPackages::BulkMoveJob
end
end
# Check if project is unique before bulk operations
def check_project_uniqueness
unless @project
# TODO: let users bulk move/copy work packages from different projects
render_error message: :"work_packages.move.unsupported_for_multiple_projects", status: 400
false
end
end
def prepare_for_work_package_move
@copy = params.has_key? :copy
@allowed_projects = WorkPackage.allowed_target_projects_on_move(current_user)
@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.order(:position)
@target_type = @types.find { |t| t.id.to_s == params[:new_type_id].to_s }
@unavailable_type_in_target_project = set_unavailable_type_in_target_project
@available_versions = @target_project.assignable_versions
@available_statuses = Workflow.available_statuses(@project)
@notes = params[:notes] || ""
end
def set_unavailable_type_in_target_project
if @target_project == @project
false
elsif @target_type.nil?
hierarchies = WorkPackageHierarchy
.includes(:ancestor)
.where(ancestor_id: @work_packages.select(:id))
Type.where(id: hierarchies.map { _1.ancestor.type_id })
.select("distinct id")
.pluck(:id)
.difference(@types.pluck(:id))
.any?
else
@types.exclude?(@target_type)
end
end
def attributes_for_create
permitted_params
.move_work_package
.compact_blank
# 'none' is used in the frontend as a value to unset the property, e.g. the assignee.
.transform_values { |v| v == "none" ? nil : v }
.to_h
end
end