2025-07-18 17:36:37 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2013-06-07 14:14:56 +02: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
|
2013-06-07 14:14:56 +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.
|
|
|
|
|
#
|
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.
|
2013-06-07 14:14:56 +02:00
|
|
|
#++
|
|
|
|
|
|
2018-05-10 23:05:06 +02:00
|
|
|
class ColorsController < ApplicationController
|
2016-09-06 15:40:49 +02:00
|
|
|
before_action :require_admin_unless_readonly_api_request
|
2024-06-11 10:20:38 +02:00
|
|
|
authorization_checked! :index, :show, :new, :edit, :create, :update, :confirm_destroy, :destroy
|
2013-06-20 17:41:14 +02:00
|
|
|
|
2013-06-06 17:28:38 +02:00
|
|
|
layout "admin"
|
|
|
|
|
|
2015-08-10 11:36:59 +02:00
|
|
|
menu_item :colors
|
|
|
|
|
|
2013-06-06 17:28:38 +02:00
|
|
|
def index
|
2021-10-21 13:43:23 +02:00
|
|
|
@colors = Color.all.sort_by(&:name)
|
2013-06-06 17:28:38 +02:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.find(params[:id])
|
2014-11-03 21:26:12 +01:00
|
|
|
respond_to do |_format|
|
2013-06-06 17:28:38 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.new
|
2013-06-06 17:28:38 +02:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-03-09 10:25:57 +01:00
|
|
|
def edit
|
|
|
|
|
@color = Color.find(params[:id])
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-06 17:28:38 +02:00
|
|
|
def create
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.new(permitted_params.color)
|
2013-06-06 17:28:38 +02:00
|
|
|
|
|
|
|
|
if @color.save
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_create)
|
2013-05-29 17:15:28 +02:00
|
|
|
redirect_to colors_path
|
2013-06-06 17:28:38 +02:00
|
|
|
else
|
2023-07-21 14:20:37 -05:00
|
|
|
flash.now[:error] = I18n.t(:error_color_could_not_be_saved)
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: :new, status: :unprocessable_entity
|
2013-06-06 17:28:38 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.find(params[:id])
|
2013-06-06 17:28:38 +02:00
|
|
|
|
2019-09-20 08:34:51 +02:00
|
|
|
if @color.update(permitted_params.color)
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_update)
|
2013-05-29 17:15:28 +02:00
|
|
|
redirect_to colors_path
|
2013-06-06 17:28:38 +02:00
|
|
|
else
|
2023-07-21 14:20:37 -05:00
|
|
|
flash.now[:error] = I18n.t(:error_color_could_not_be_saved)
|
2024-08-28 12:43:09 +02:00
|
|
|
render action: :edit, status: :unprocessable_entity
|
2013-06-06 17:28:38 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def confirm_destroy
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.find(params[:id])
|
2013-06-06 17:28:38 +02:00
|
|
|
respond_to do |format|
|
|
|
|
|
format.html
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
2018-05-10 23:05:06 +02:00
|
|
|
@color = Color.find(params[:id])
|
2013-06-06 17:28:38 +02:00
|
|
|
@color.destroy
|
|
|
|
|
|
2020-09-16 11:26:15 +02:00
|
|
|
flash[:notice] = I18n.t(:notice_successful_delete)
|
2025-07-31 20:32:57 +01:00
|
|
|
redirect_to colors_path, status: :see_other
|
2013-06-06 17:28:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
|
|
def require_admin_unless_readonly_api_request
|
2024-08-29 15:26:34 +02:00
|
|
|
require_admin unless %w[index show].include? action_name and
|
2013-06-06 17:28:38 +02:00
|
|
|
api_request?
|
|
|
|
|
end
|
|
|
|
|
end
|