Files

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

200 lines
6.6 KiB
Ruby
Raw Permalink Normal View History

2025-11-12 15:55:55 +01:00
# frozen_string_literal: true
#-- 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.
2025-11-12 15:55:55 +01:00
#
# See COPYRIGHT and LICENSE files for more details.
#++
2025-11-12 21:17:51 +01:00
class Projects::Settings::CreationWizardController < Projects::SettingsController
2025-11-13 12:36:19 +01:00
include OpTurbo::ComponentStream
2025-11-12 21:17:51 +01:00
menu_item :settings_creation_wizard
2025-11-12 15:55:55 +01:00
2026-01-28 10:06:44 +01:00
before_action :check_enterprise_plan, only: :toggle
before_action :check_activation_conditions, only: :toggle
2025-11-12 15:55:55 +01:00
def show; end
2025-11-13 12:36:19 +01:00
def disable_dialog
respond_with_dialog Projects::Settings::CreationWizard::DisableDialogComponent.new(
project: @project
)
end
2025-11-12 21:17:51 +01:00
def toggle
@project.update(project_creation_wizard_enabled: !@project.project_creation_wizard_enabled)
redirect_to project_settings_creation_wizard_path(@project, tab: params[:tab]), status: :see_other
end
2025-11-19 17:25:34 +01:00
def update_name_settings
update_settings_for_tab("name", name_settings_params)
end
2025-11-14 18:00:38 +01:00
2025-11-19 17:25:34 +01:00
def update_submission_settings
update_settings_for_tab("submission", submission_settings_params)
2025-11-14 18:00:38 +01:00
end
def update_artifact_export_settings
update_settings_for_tab("export", artifact_export_settings_params)
end
2025-11-14 18:00:38 +01:00
def refresh_submission_form
@project.assign_attributes(submission_settings_params)
update_via_turbo_stream(
component: Projects::Settings::CreationWizard::SubmissionFormComponent.new(project: @project)
)
respond_with_turbo_streams
end
2025-11-15 21:18:24 +01:00
def toggle_project_custom_field
cf = ProjectCustomField.find(permitted_params.project_custom_field_project_mapping[:custom_field_id])
mapping = cf.project_custom_field_project_mappings.find_by(project: @project)
if custom_field_toggleable?(cf) && toggle_mapping(mapping)
2025-11-15 21:18:24 +01:00
render json: {}, status: :ok
else
render json: {}, status: :unprocessable_entity
end
end
2025-11-18 08:52:07 +01:00
def enable_all_of_section
update_section_mappings(true)
end
def disable_all_of_section
update_section_mappings(false)
end
2025-11-12 15:55:55 +01:00
private
2026-01-28 10:06:44 +01:00
def check_enterprise_plan
# Allow disabling even without enterprise plan
return if @project.project_creation_wizard_enabled
unless EnterpriseToken.allows_to?(:project_creation_wizard)
flash[:error] = I18n.t(:notice_requires_enterprise_token)
redirect_to project_settings_creation_wizard_path(@project, tab: "attributes"), status: :see_other
end
end
def check_activation_conditions
# Allow disabling even without activation conditions met
return if @project.project_creation_wizard_enabled
error = if @project.project_creation_wizard_default_work_package_type.nil?
I18n.t("projects.settings.creation_wizard.errors.no_work_package_type")
elsif @project.project_creation_wizard_default_status_when_submitted.nil?
2026-02-10 17:37:42 +02:00
type = @project.project_creation_wizard_default_work_package_type.name
I18n.t("projects.settings.creation_wizard.errors.no_status_when_submitted", type:)
end
if error
flash[:error] = error
redirect_to project_settings_creation_wizard_path(@project, tab: params[:tab]), status: :see_other
end
end
2025-11-18 08:52:07 +01:00
def update_section_mappings(value)
section_id = permitted_params.project_custom_field_project_mapping[:custom_field_section_id]
cf_ids_to_toggle, force_enabled_cf_ids = ProjectCustomField.toggleable_ids_in_creation_wizard_settings(@project, section_id)
2025-11-18 08:52:07 +01:00
ProjectCustomFieldProjectMapping
.where(project_id: @project.id, custom_field_id: cf_ids_to_toggle)
2025-11-18 08:52:07 +01:00
.update_all(creation_wizard: value)
enable_creation_wizard!(force_enabled_cf_ids)
2025-11-18 08:52:07 +01:00
redirect_to project_settings_creation_wizard_path(@project, tab: "attributes"), status: :see_other
end
def enable_creation_wizard!(custom_field_ids)
ProjectCustomFieldProjectMapping
.where(project_id: @project.id, custom_field_id: custom_field_ids)
.update_all(creation_wizard: true)
end
def custom_field_toggleable?(custom_field)
toggleable_ids = ProjectCustomField
.toggleable_ids_in_creation_wizard_settings(@project, custom_field.custom_field_section_id)
.first
toggleable_ids.include?(custom_field.id)
end
def toggle_mapping(mapping)
mapping&.update(creation_wizard: !mapping.creation_wizard)
end
2025-11-12 15:55:55 +01:00
def check_feature_flag
unless OpenProject::FeatureDecisions.project_initiation_active?
render_404
end
end
2025-11-14 18:00:38 +01:00
2025-11-19 17:25:34 +01:00
def update_settings_for_tab(tab, settings_params)
call = Projects::UpdateService
.new(model: @project, user: current_user, contract_class: Projects::SettingsContract)
.call(settings_params)
2025-11-19 17:25:34 +01:00
@project = call.result
if call.success?
flash[:notice] = I18n.t(:notice_successful_update)
redirect_to project_settings_creation_wizard_path(@project, tab:)
else
params[:tab] = tab
render action: :show, status: :unprocessable_entity
end
end
def name_settings_params
params.expect(
2025-11-20 16:23:08 +01:00
project: %i[project_creation_wizard_artifact_name]
2025-11-19 17:25:34 +01:00
)
end
2025-11-14 18:00:38 +01:00
def submission_settings_params
params.expect(
2025-11-21 13:32:54 +01:00
project: %i[project_creation_wizard_work_package_type_id
project_creation_wizard_status_when_submitted_id
project_creation_wizard_send_confirmation_email
project_creation_wizard_notification_text
project_creation_wizard_assignee_custom_field_id
project_creation_wizard_work_package_comment]
2025-11-14 18:00:38 +01:00
)
end
def artifact_export_settings_params
params.expect(
project: %i[project_creation_wizard_artifact_export_type
project_creation_wizard_artifact_export_storage]
)
end
2025-11-12 15:55:55 +01:00
end