diff --git a/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb b/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb index 54dae4694b7c..c09c6bd25056 100644 --- a/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb +++ b/app/components/settings/project_life_cycle_step_definitions/index_component.html.erb @@ -109,7 +109,6 @@ See COPYRIGHT and LICENSE files for more details. ) do render(Settings::ProjectLifeCycleStepDefinitions::RowComponent.new( definition, - allowed_to_customize_life_cycle?: allowed_to_customize_life_cycle?, first?: definition == definitions.first, last?: definition == definitions.last, )) diff --git a/app/components/settings/project_life_cycle_step_definitions/index_component.rb b/app/components/settings/project_life_cycle_step_definitions/index_component.rb index 0178a7fb471a..14a3963fc035 100644 --- a/app/components/settings/project_life_cycle_step_definitions/index_component.rb +++ b/app/components/settings/project_life_cycle_step_definitions/index_component.rb @@ -31,9 +31,9 @@ module ProjectLifeCycleStepDefinitions class IndexComponent < ApplicationComponent include OpPrimer::ComponentHelpers include OpTurbo::Streamable + include Projects::LifeCycleDefinitionHelper - options :definitions, - :allowed_to_customize_life_cycle? + options :definitions private diff --git a/app/components/settings/project_life_cycle_step_definitions/index_header_component.rb b/app/components/settings/project_life_cycle_step_definitions/index_header_component.rb index 3c5e28a27d2c..c0235f93d0e7 100644 --- a/app/components/settings/project_life_cycle_step_definitions/index_header_component.rb +++ b/app/components/settings/project_life_cycle_step_definitions/index_header_component.rb @@ -29,8 +29,6 @@ module Settings module ProjectLifeCycleStepDefinitions class IndexHeaderComponent < ApplicationComponent - options :allowed_to_customize_life_cycle? - def breadcrumbs_items [ { href: admin_index_path, text: t("label_administration") }, diff --git a/app/components/settings/project_life_cycle_step_definitions/row_component.rb b/app/components/settings/project_life_cycle_step_definitions/row_component.rb index 2ce3a97664c3..a1525094f8f0 100644 --- a/app/components/settings/project_life_cycle_step_definitions/row_component.rb +++ b/app/components/settings/project_life_cycle_step_definitions/row_component.rb @@ -30,11 +30,11 @@ module Settings module ProjectLifeCycleStepDefinitions class RowComponent < ApplicationComponent include OpPrimer::ComponentHelpers + include Projects::LifeCycleDefinitionHelper alias_method :definition, :model - options :allowed_to_customize_life_cycle?, - :first?, + options :first?, :last? private diff --git a/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb b/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb index 72c05dda012b..47311d480482 100644 --- a/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb +++ b/app/controllers/admin/settings/project_life_cycle_step_definitions_controller.rb @@ -30,11 +30,10 @@ module Admin::Settings class ProjectLifeCycleStepDefinitionsController < ::Admin::SettingsController include FlashMessagesOutputSafetyHelper include OpTurbo::ComponentStream + include Projects::LifeCycleDefinitionHelper menu_item :project_life_cycle_step_definitions_settings - helper_method :allowed_to_customize_life_cycle? - before_action :check_feature_flag before_action :require_enterprise_token, except: %i[index] @@ -113,10 +112,6 @@ def drop private - def allowed_to_customize_life_cycle? - EnterpriseToken.allows_to?(:customize_life_cycle) - end - def check_feature_flag render_404 unless OpenProject::FeatureDecisions.stages_and_gates_active? end @@ -140,8 +135,7 @@ def definition_params def update_definitions_via_turbo_stream update_via_turbo_stream( component: Settings::ProjectLifeCycleStepDefinitions::IndexComponent.new( - definitions: find_definitions, - allowed_to_customize_life_cycle?: allowed_to_customize_life_cycle? + definitions: find_definitions ) ) end diff --git a/app/controllers/concerns/projects/life_cycle_definition_helper.rb b/app/controllers/concerns/projects/life_cycle_definition_helper.rb new file mode 100644 index 000000000000..b645b369d7d4 --- /dev/null +++ b/app/controllers/concerns/projects/life_cycle_definition_helper.rb @@ -0,0 +1,35 @@ +#-- copyright +# 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. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# 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. +#++ + +module Projects::LifeCycleDefinitionHelper + private + + def allowed_to_customize_life_cycle? + EnterpriseToken.allows_to?(:customize_life_cycle) + end +end diff --git a/app/views/admin/settings/project_life_cycle_step_definitions/index.html.erb b/app/views/admin/settings/project_life_cycle_step_definitions/index.html.erb index ac37177f5b51..cf8877a719e5 100644 --- a/app/views/admin/settings/project_life_cycle_step_definitions/index.html.erb +++ b/app/views/admin/settings/project_life_cycle_step_definitions/index.html.erb @@ -29,10 +29,5 @@ See COPYRIGHT and LICENSE files for more details. <% html_title t(:label_administration), t("settings.project_life_cycle_step_definitions.heading") %> -<%= render Settings::ProjectLifeCycleStepDefinitions::IndexHeaderComponent.new( - allowed_to_customize_life_cycle?: allowed_to_customize_life_cycle? -) %> -<%= render Settings::ProjectLifeCycleStepDefinitions::IndexComponent.new( - definitions: @definitions, - allowed_to_customize_life_cycle?: allowed_to_customize_life_cycle? -) %> +<%= render Settings::ProjectLifeCycleStepDefinitions::IndexHeaderComponent.new %> +<%= render Settings::ProjectLifeCycleStepDefinitions::IndexComponent.new(definitions: @definitions) %>