OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#64607] added work package type create service
Eric Schubert33e8b319c559
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rbindex b22c5245aa6..5480472dae7 100644--- a/app/controllers/types_controller.rb+++ b/app/controllers/types_controller.rb@@ -59,18 +59,16 @@ class TypesController < ApplicationControllerenddef create- CreateTypeService- .new(current_user)- .call(permitted_type_params, copy_workflow_from: params.dig(:type, :copy_workflow_from)) do |call|- @type = call.result-- call.on_success do- redirect_to_type_tab_path(@type, t(:notice_successful_create))- end-- call.on_failure do- render action: :new, status: :unprocessable_entity- end+ additional_params = { copy_workflow_from: params.dig(:type, :copy_workflow_from) }+ service_call = WorkPackageTypes::CreateService+ .new(user: current_user)+ .call(permitted_type_params.merge(additional_params))++ @type = service_call.result+ if service_call.success?+ redirect_to_type_tab_path(@type, t(:notice_successful_create))+ else+ render action: :new, status: :unprocessable_entityendenddiff --git a/app/services/work_package_types/create_service.rb b/app/services/work_package_types/create_service.rbnew file mode 100644index 00000000000..ae23deeb9e3--- /dev/null+++ b/app/services/work_package_types/create_service.rb@@ -0,0 +1,49 @@+# 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.+#++++module WorkPackageTypes+ class CreateService < ::BaseServices::Create+ protected++ # FIXME: remove, if we can have model namespace "WorkPackageTypes" and no longer ambiguous "Types"+ def instance_class+ Type+ end++ def after_perform(service_call)+ type = service_call.result+ if @params[:copy_workflow_from].present? && (copy_from = ::Type.find_by(id: @params[:copy_workflow_from]))+ type.workflows.copy_from_type(copy_from)+ end++ service_call+ end+ end+enddiff --git a/app/services/work_package_types/set_attributes_service.rb b/app/services/work_package_types/set_attributes_service.rbnew file mode 100644index 00000000000..0251bf61689--- /dev/null+++ b/app/services/work_package_types/set_attributes_service.rb@@ -0,0 +1,39 @@+# 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.+#++++module WorkPackageTypes+ class SetAttributesService < ::BaseServices::SetAttributes+ private++ def set_attributes(params)+ super(params.except(:copy_workflow_from))+ end+ end+end