Files

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

112 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
#
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
#++
class ColorsController < ApplicationController
2016-09-06 15:40:49 +02:00
before_action :require_admin_unless_readonly_api_request
authorization_checked! :index, :show, :new, :edit, :create, :update, :confirm_destroy, :destroy
2013-06-06 17:28:38 +02:00
layout "admin"
menu_item :colors
2013-06-06 17:28:38 +02:00
def index
@colors = Color.all.sort_by(&:name)
2013-06-06 17:28:38 +02:00
respond_to do |format|
format.html
end
end
def show
@color = Color.find(params[:id])
respond_to do |_format|
2013-06-06 17:28:38 +02:00
end
end
def new
@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
@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)
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
@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)
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
@color = Color.find(params[:id])
2013-06-06 17:28:38 +02:00
respond_to do |format|
format.html
end
end
def destroy
@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)
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