Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.9 KiB
Ruby
Raw Permalink Normal View History

2025-07-18 17:36:37 +01:00
# frozen_string_literal: true
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2011-05-30 20:52:25 +02:00
#
# This program is free software; you can redistribute it and/or
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
#++
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
def new
2013-10-01 10:10:02 +02:00
@category = @project.categories.build
2012-08-19 22:29:26 +02:00
end
def create
2013-10-01 10:10:02 +02:00
@category = @project.categories.build
@category.attributes = permitted_params.category
2012-08-19 22:29:26 +02:00
if @category.save
flash[:notice] = I18n.t(:notice_successful_create)
redirect_to project_settings_categories_path(@project)
2012-08-19 22:29:26 +02:00
else
render action: :new, status: :unprocessable_entity
end
end
2011-05-30 20:52:25 +02:00
2012-08-19 22:29:26 +02:00
def update
@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
def destroy # rubocop:disable Metrics/AbcSize
2013-06-25 08:28:22 +02:00
@issue_count = @category.work_packages.size
if @issue_count == 0
# No issue assigned to this category
@category.destroy
redirect_to project_settings_categories_path(@project), status: :see_other
return
elsif params[:todo]
reassign_to = @project.categories.find_by(id: params[:reassign_to_id]) if params[:todo] == "reassign"
@category.destroy(reassign_to)
redirect_to project_settings_categories_path(@project), status: :see_other
return
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
end
2006-06-28 18:11:03 +00: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
def find_project
2026-02-02 13:36:51 +01:00
@project = Project.visible.find(params[:project_id])
end
2006-06-28 18:11:03 +00:00
end