Files

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

103 lines
3.0 KiB
Ruby
Raw Permalink Normal View History

2025-07-18 17:36:37 +01:00
# frozen_string_literal: true
2018-01-23 10:18:49 +01:00
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2018-01-23 10:18:49 +01: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.
#
# 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
2018-01-23 10:18:49 +01: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.
2018-01-23 10:18:49 +01:00
#++
class CustomActionsController < ApplicationController
before_action :require_admin
guard_enterprise_feature(:custom_actions, only: %i[new create edit update]) do
redirect_to action: :index
end
2022-02-20 11:23:51 +01:00
2026-02-02 13:36:51 +01:00
before_action :find_custom_action, only: %i(edit update destroy)
before_action :pad_params, only: %i(create update)
2022-02-20 11:23:51 +01:00
2018-01-29 23:42:20 +01:00
layout "admin"
2018-01-23 10:18:49 +01:00
2018-01-23 16:16:02 +01:00
def index
2018-02-21 17:05:14 +01:00
@custom_actions = CustomAction.order_by_position
2018-01-23 16:16:02 +01:00
end
2018-01-23 10:18:49 +01:00
def new
2018-01-23 16:16:02 +01:00
@custom_action = CustomAction.new
2018-01-23 10:18:49 +01:00
end
2023-03-09 10:25:57 +01:00
def edit; end
2018-01-23 10:18:49 +01:00
def create
2018-01-31 15:38:33 +01:00
CustomActions::CreateService
.new(user: current_user)
2018-02-06 16:08:59 +01:00
.call(attributes: permitted_params.custom_action.to_h,
&index_or_render(:new))
2018-01-23 10:18:49 +01:00
end
2018-01-29 09:42:17 +01:00
2018-01-31 15:38:33 +01:00
def update
CustomActions::UpdateService
.new(action: @custom_action, user: current_user)
2018-02-06 16:08:59 +01:00
.call(attributes: permitted_params.custom_action.to_h,
&index_or_render(:edit))
end
def destroy
@custom_action.destroy
redirect_to custom_actions_path, status: :see_other
2018-02-06 16:08:59 +01:00
end
private
2018-01-31 15:38:33 +01:00
2026-02-02 13:36:51 +01:00
def find_custom_action
@custom_action = CustomAction.find(params[:id])
end
2018-02-06 16:08:59 +01:00
def index_or_render(render_action)
->(call) {
2018-01-31 15:38:33 +01:00
call.on_success do
redirect_to custom_actions_path, status: :see_other
2018-01-31 15:38:33 +01:00
end
call.on_failure do
@custom_action = call.result
2024-08-28 12:43:09 +02:00
render action: render_action, status: :unprocessable_entity
2018-01-31 15:38:33 +01:00
end
2018-02-06 16:08:59 +01:00
}
2018-01-31 15:59:57 +01:00
end
2018-02-07 17:12:20 +01:00
# If no action/condition is set in the view, the
# actions/conditions already existing on a custom action should be removed.
# But because it is not feasible to have an empty and hidden hash object in a form
# we have to pad the params here.
def pad_params
return if !params[:custom_action] || params[:custom_action][:move_to]
params[:custom_action][:conditions] ||= {}
params[:custom_action][:actions] ||= {}
end
2018-01-23 10:18:49 +01:00
end