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
|
|
|
#++
|
|
|
|
|
|
2013-09-30 16:52:32 +02:00
|
|
|
class CategoriesController < ApplicationController
|
2020-05-12 10:10:38 +02:00
|
|
|
menu_item :settings_categories
|
2026-02-02 13:36:51 +01:00
|
|
|
|
|
|
|
|
before_action :find_category_and_project, except: %i[new create]
|
2021-02-11 16:02:18 +01:00
|
|
|
before_action :find_project, only: %i[new create]
|
2016-09-06 15:40:49 +02:00
|
|
|
before_action :authorize
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2010-03-06 18:43:00 +00:00
|
|
|
def new
|
2013-10-01 10:10:02 +02:00
|
|
|
@category = @project.categories.build
|
2012-08-19 22:29:26 +02:00
|
|
|
end
|
|
|
|
|
|
2025-11-04 18:44:03 +00:00
|
|
|
def create
|
2013-10-01 10:10:02 +02:00
|
|
|
@category = @project.categories.build
|
2015-10-09 03:12:58 +01:00
|
|
|
@category.attributes = permitted_params.category
|
2012-08-19 22:29:26 +02:00
|
|
|
|
|
|
|
|
if @category.save
|
2025-11-04 18:44:03 +00:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_create)
|
|
|
|
|
redirect_to project_settings_categories_path(@project)
|
2012-08-19 22:29:26 +02:00
|
|
|
else
|
2025-11-04 18:44:03 +00:00
|
|
|
render action: :new, status: :unprocessable_entity
|
2010-03-06 18:43:00 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-05-30 20:52:25 +02:00
|
|
|
|
2012-08-19 22:29:26 +02:00
|
|
|
def update
|
2015-10-09 03:12:58 +01:00
|
|
|
@category.attributes = permitted_params.category
|
2012-08-19 22:29:26 +02:00
|
|
|
if @category.save
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_update)
|
2021-10-29 14:41:12 +02:00
|
|
|
redirect_to project_settings_categories_path(@project)
|
2012-08-19 22:29:26 +02:00
|
|
|
else
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: :edit, status: :unprocessable_entity
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-08-11 13:49:00 +01:00
|
|
|
def destroy # rubocop:disable Metrics/AbcSize
|
2013-06-25 08:28:22 +02:00
|
|
|
@issue_count = @category.work_packages.size
|
2007-09-15 16:52:32 +00:00
|
|
|
if @issue_count == 0
|
|
|
|
|
# No issue assigned to this category
|
|
|
|
|
@category.destroy
|
2025-07-28 11:26:15 +02:00
|
|
|
redirect_to project_settings_categories_path(@project), status: :see_other
|
2011-04-28 14:39:19 -07:00
|
|
|
return
|
2007-09-15 16:52:32 +00:00
|
|
|
elsif params[:todo]
|
2015-06-26 11:23:13 +02:00
|
|
|
reassign_to = @project.categories.find_by(id: params[:reassign_to_id]) if params[:todo] == "reassign"
|
2007-09-15 16:52:32 +00:00
|
|
|
@category.destroy(reassign_to)
|
2025-07-28 11:26:15 +02:00
|
|
|
redirect_to project_settings_categories_path(@project), status: :see_other
|
2011-04-28 14:39:19 -07:00
|
|
|
return
|
2007-09-15 16:52:32 +00:00
|
|
|
end
|
2013-10-01 10:10:02 +02:00
|
|
|
@categories = @project.categories - [@category]
|
2025-07-28 16:56:02 +02:00
|
|
|
render status: :unprocessable_entity
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
|
2014-11-03 21:26:12 +01:00
|
|
|
private
|
|
|
|
|
|
2026-02-02 13:36:51 +01:00
|
|
|
def find_category_and_project
|
|
|
|
|
@category = Category.find(params[:id])
|
|
|
|
|
@project = @category.project
|
2011-05-30 20:52:25 +02:00
|
|
|
end
|
|
|
|
|
|
2010-03-06 18:43:00 +00:00
|
|
|
def find_project
|
2026-02-02 13:36:51 +01:00
|
|
|
@project = Project.visible.find(params[:project_id])
|
2010-03-06 18:43:00 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|