mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
132 lines
4.2 KiB
Ruby
132 lines
4.2 KiB
Ruby
# 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.
|
|
#
|
|
# See COPYRIGHT and LICENSE files for more details.
|
|
#++
|
|
|
|
class Projects::Settings::CreationWizardController < Projects::SettingsController
|
|
include OpTurbo::ComponentStream
|
|
|
|
menu_item :settings_creation_wizard
|
|
|
|
before_action :check_feature_flag
|
|
|
|
def show; end
|
|
|
|
def disable_dialog
|
|
respond_with_dialog Projects::Settings::CreationWizard::DisableDialogComponent.new(
|
|
project: @project
|
|
)
|
|
end
|
|
|
|
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
|
|
|
|
def update_submission_settings
|
|
call = Projects::UpdateService
|
|
.new(model: @project, user: current_user)
|
|
.call(submission_settings_params)
|
|
|
|
@project = call.result
|
|
|
|
if call.success?
|
|
flash[:notice] = I18n.t(:notice_successful_update)
|
|
redirect_to project_settings_creation_wizard_path(@project, tab: "submission")
|
|
else
|
|
flash.now[:error] = I18n.t(:notice_unsuccessful_update_with_reason, reason: call.message)
|
|
render action: :show, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
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
|
|
|
|
def toggle_project_custom_field
|
|
mapping = ProjectCustomFieldProjectMapping.find_by(
|
|
project_id: permitted_params.project_custom_field_project_mapping[:project_id],
|
|
custom_field_id: permitted_params.project_custom_field_project_mapping[:custom_field_id]
|
|
)
|
|
if mapping&.update(creation_wizard: !mapping.creation_wizard)
|
|
render json: {}, status: :ok
|
|
else
|
|
render json: {}, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def enable_all_of_section
|
|
update_section_mappings(true)
|
|
end
|
|
|
|
def disable_all_of_section
|
|
update_section_mappings(false)
|
|
end
|
|
|
|
private
|
|
|
|
def update_section_mappings(value)
|
|
section_id = permitted_params.project_custom_field_project_mapping[:custom_field_section_id]
|
|
project_id = permitted_params.project_custom_field_project_mapping[:project_id]
|
|
|
|
custom_field_ids = ProjectCustomField
|
|
.where(custom_field_section_id: section_id)
|
|
.where(is_required: false)
|
|
.pluck(:id)
|
|
|
|
ProjectCustomFieldProjectMapping
|
|
.where(project_id:, custom_field_id: custom_field_ids)
|
|
.update_all(creation_wizard: value)
|
|
|
|
redirect_to project_settings_creation_wizard_path(@project, tab: "attributes"), status: :see_other
|
|
end
|
|
|
|
def check_feature_flag
|
|
unless OpenProject::FeatureDecisions.project_initiation_active?
|
|
render_404
|
|
end
|
|
end
|
|
|
|
def submission_settings_params
|
|
params.expect(
|
|
project: %i[submission_work_package_type_id
|
|
submission_status_when_submitted_id
|
|
submission_send_confirmation_email
|
|
submission_notification_text
|
|
submission_assignee_id
|
|
submission_work_package_comment]
|
|
)
|
|
end
|
|
end
|