2025-07-18 17:36:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2011-05-29 13:11:52 -07:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2011-05-29 13:11:52 -07:00
|
|
|
# This program is free software; you can redistribute it and/or
|
2013-06-05 16:27:56 +02:00
|
|
|
# modify it under the terms of the GNU General Public License version 3.
|
2011-05-30 20:52:25 +02:00
|
|
|
#
|
2013-09-16 17:59:31 +02:00
|
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2013-09-16 17:59:31 +02:00
|
|
|
# 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.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2011-05-29 13:11:52 -07:00
|
|
|
#++
|
|
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
class VersionsController < ApplicationController
|
2020-02-05 16:06:01 +01:00
|
|
|
menu_item :roadmap, only: %i(index show)
|
2020-01-13 10:27:44 +01:00
|
|
|
menu_item :settings_versions
|
2020-02-05 16:06:01 +01:00
|
|
|
|
2026-02-02 13:36:51 +01:00
|
|
|
before_action :find_version, except: %i[index new create close_completed]
|
2019-05-22 09:29:06 +02:00
|
|
|
before_action :find_project, only: %i[index new create close_completed]
|
2016-09-06 15:40:49 +02:00
|
|
|
before_action :authorize
|
2006-07-30 10:47:02 +00:00
|
|
|
|
2010-08-30 15:30:28 +00:00
|
|
|
def index
|
2018-11-20 16:23:33 +01:00
|
|
|
@types = @project.types.order(Arel.sql("position"))
|
2014-11-03 21:26:12 +01:00
|
|
|
retrieve_selected_type_ids(@types, @types.select(&:is_in_roadmap?))
|
2013-09-19 13:13:11 +02:00
|
|
|
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_work_packages? : (params[:with_subprojects].to_i == 1)
|
2023-09-07 18:30:29 +02:00
|
|
|
project_ids = @with_subprojects ? @project.self_and_descendants.includes(:wiki).map(&:id) : [@project.id]
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2020-03-24 16:27:15 +01:00
|
|
|
@versions = find_versions(@with_subprojects, params[:completed])
|
2020-02-06 11:14:07 +01:00
|
|
|
|
2020-03-24 16:27:15 +01:00
|
|
|
@wps_by_version = {}
|
2013-07-18 16:17:02 +02:00
|
|
|
unless @selected_type_ids.empty?
|
2010-08-30 15:30:28 +00:00
|
|
|
@versions.each do |version|
|
2020-03-24 16:27:15 +01:00
|
|
|
@wps_by_version[version] = work_packages_of_version(version, project_ids, @selected_type_ids)
|
2010-08-30 15:30:28 +00:00
|
|
|
end
|
|
|
|
|
end
|
2020-03-24 16:27:15 +01:00
|
|
|
@versions.reject! { |version| !project_ids.include?(version.project_id) && @wps_by_version[version].blank? }
|
2010-08-30 15:30:28 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2007-12-07 10:26:07 +00:00
|
|
|
def show
|
2019-05-22 09:29:06 +02:00
|
|
|
@issues = @version
|
2023-08-15 09:16:00 +02:00
|
|
|
.work_packages
|
|
|
|
|
.visible
|
|
|
|
|
.includes(:status, :type, :priority)
|
|
|
|
|
.order("#{::Type.table_name}.position, #{WorkPackage.table_name}.id")
|
2007-12-07 10:26:07 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2010-03-06 18:25:01 +00:00
|
|
|
def new
|
|
|
|
|
@version = @project.versions.build
|
2010-09-16 18:27:33 +00:00
|
|
|
end
|
|
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
def edit; end
|
|
|
|
|
|
2010-09-16 18:27:33 +00:00
|
|
|
def create
|
2019-05-22 09:29:06 +02:00
|
|
|
attributes = permitted_params
|
2023-08-15 09:16:00 +02:00
|
|
|
.version
|
|
|
|
|
.merge(project_id: @project.id)
|
2010-09-16 18:27:33 +00:00
|
|
|
|
2019-05-22 09:29:06 +02:00
|
|
|
call = Versions::CreateService
|
2023-08-15 09:16:00 +02:00
|
|
|
.new(user: current_user)
|
|
|
|
|
.call(attributes)
|
2019-05-22 09:29:06 +02:00
|
|
|
|
2019-12-10 09:35:16 +01:00
|
|
|
render_cu(call, :notice_successful_create, "new")
|
2010-03-06 18:25:01 +00:00
|
|
|
end
|
2010-09-15 16:50:25 +00:00
|
|
|
|
|
|
|
|
def update
|
2019-05-22 09:29:06 +02:00
|
|
|
attributes = permitted_params
|
2023-08-15 09:16:00 +02:00
|
|
|
.version
|
2019-05-22 09:29:06 +02:00
|
|
|
|
|
|
|
|
call = Versions::UpdateService
|
2023-08-15 09:16:00 +02:00
|
|
|
.new(user: current_user,
|
|
|
|
|
model: @version)
|
|
|
|
|
.call(attributes)
|
2019-05-22 09:29:06 +02:00
|
|
|
|
2019-12-10 09:35:16 +01:00
|
|
|
render_cu(call, :notice_successful_update, "edit")
|
2006-07-30 10:47:02 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2009-11-09 18:53:12 +00:00
|
|
|
def close_completed
|
2025-10-22 08:54:16 +02:00
|
|
|
@project.close_completed_versions
|
|
|
|
|
redirect_to project_settings_versions_path(@project), status: :see_other
|
2009-11-09 18:53:12 +00:00
|
|
|
end
|
2006-07-30 10:47:02 +00:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
def destroy
|
2019-05-22 09:29:06 +02:00
|
|
|
call = Versions::DeleteService
|
2023-08-15 09:16:00 +02:00
|
|
|
.new(user: current_user,
|
|
|
|
|
model: @version)
|
|
|
|
|
.call
|
2019-05-22 09:29:06 +02:00
|
|
|
|
|
|
|
|
unless call.success?
|
|
|
|
|
flash[:error] = call.errors.full_messages
|
2023-08-15 09:16:00 +02:00
|
|
|
flash[:error] << archived_project_mesage if archived_projects.any?
|
2026-05-05 14:34:20 +02:00
|
|
|
else
|
|
|
|
|
flash[:notice] = I18n.t :notice_successful_delete
|
2010-04-11 17:47:29 +00:00
|
|
|
end
|
2019-05-22 09:29:06 +02:00
|
|
|
|
2025-07-24 16:02:40 +02:00
|
|
|
redirect_to project_settings_versions_path(@project), status: :see_other
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2014-11-03 21:26:12 +01:00
|
|
|
private
|
|
|
|
|
|
2026-02-02 13:36:51 +01:00
|
|
|
def find_version
|
|
|
|
|
@version = Version.visible.find(params[:id])
|
|
|
|
|
@project = @version.project
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-15 09:16:00 +02:00
|
|
|
def archived_project_mesage
|
|
|
|
|
if current_user.admin?
|
|
|
|
|
ApplicationController.helpers.sanitize(
|
|
|
|
|
t(:error_can_not_delete_in_use_archived_work_packages,
|
|
|
|
|
archived_projects_urls: helpers.archived_projects_urls_for(archived_projects)),
|
|
|
|
|
attributes: %w(href target)
|
|
|
|
|
)
|
|
|
|
|
else
|
|
|
|
|
t(:error_can_not_delete_in_use_archived_undisclosed)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def archived_projects
|
|
|
|
|
@archived_projects ||= @version.projects.archived
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-22 09:29:06 +02:00
|
|
|
def redirect_back_or_version_settings
|
2021-10-29 14:41:12 +02:00
|
|
|
redirect_back_or_default(project_settings_versions_path(@project))
|
2019-05-22 09:29:06 +02:00
|
|
|
end
|
|
|
|
|
|
2009-11-09 18:53:12 +00:00
|
|
|
def find_project
|
2026-02-02 13:36:51 +01:00
|
|
|
@project = Project.visible.find(params[:project_id])
|
2009-11-09 18:53:12 +00:00
|
|
|
end
|
2010-08-30 15:30:28 +00:00
|
|
|
|
2014-11-03 21:26:12 +01:00
|
|
|
def retrieve_selected_type_ids(selectable_types, default_types = nil)
|
2019-05-29 10:12:49 +01:00
|
|
|
@selected_type_ids = selected_type_ids selectable_types, default_types
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def selected_type_ids(selectable_types, default_types = nil)
|
|
|
|
|
if (ids = params[:type_ids])
|
|
|
|
|
ids.is_a?(Array) ? ids.map(&:to_s) : ids.split("/")
|
|
|
|
|
else
|
|
|
|
|
(default_types || selectable_types).map { |t| t.id.to_s }
|
|
|
|
|
end
|
2010-08-30 15:30:28 +00:00
|
|
|
end
|
2019-12-10 09:35:16 +01:00
|
|
|
|
|
|
|
|
def render_cu(call, success_message, failure_action)
|
|
|
|
|
@version = call.result
|
|
|
|
|
|
|
|
|
|
if call.success?
|
|
|
|
|
flash[:notice] = t(success_message)
|
|
|
|
|
redirect_back_or_version_settings
|
|
|
|
|
else
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: failure_action, status: :unprocessable_entity
|
2019-12-10 09:35:16 +01:00
|
|
|
end
|
|
|
|
|
end
|
2020-03-24 16:27:15 +01:00
|
|
|
|
|
|
|
|
def find_versions(subprojects, completed)
|
2023-09-07 18:30:29 +02:00
|
|
|
versions = @project.shared_versions.includes(:custom_values)
|
2020-03-24 16:27:15 +01:00
|
|
|
|
|
|
|
|
if subprojects
|
2023-09-07 18:30:29 +02:00
|
|
|
versions = versions.or(@project.rolled_up_versions.includes(:custom_values))
|
2020-03-24 16:27:15 +01:00
|
|
|
end
|
|
|
|
|
|
2025-06-27 19:45:00 +02:00
|
|
|
versions = versions.visible.order(:name).except(:distinct).uniq
|
2020-03-24 16:27:15 +01:00
|
|
|
versions.reject! { |version| version.closed? || version.completed? } unless completed
|
|
|
|
|
versions
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def work_packages_of_version(version, project_ids, selected_type_ids)
|
|
|
|
|
version
|
2020-03-26 15:37:24 +01:00
|
|
|
.work_packages
|
2020-03-24 16:27:15 +01:00
|
|
|
.visible
|
|
|
|
|
.includes(:project, :status, :type, :priority)
|
|
|
|
|
.where(type_id: selected_type_ids, project_id: project_ids)
|
|
|
|
|
.order("#{Project.table_name}.lft, #{::Type.table_name}.position, #{WorkPackage.table_name}.id")
|
|
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|