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
[#64621] Move Types controller to the new namespace (#19388)
Yauheni Suhakoue754ef7e5060
diff --git a/app/components/work_package_types/types/row_component.rb b/app/components/work_package_types/types/row_component.rbnew file mode 100644index 00000000000..0601ebe1d83--- /dev/null+++ b/app/components/work_package_types/types/row_component.rb@@ -0,0 +1,97 @@+# 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+ module Types+ class RowComponent < ::RowComponent+ include ApplicationHelper+ include TypesHelper++ def column_css_classes+ super.merge(+ name: "timelines-pet-name",+ color: "timelines-pet-color",+ default: "timelines-pet-is_default",+ milestone: "timelines-pet-is_milestone",+ sort: "timelines-pet-reorder"+ )+ end++ def name+ link_to model.name, edit_type_settings_path(type_id: model.id)+ end++ def workflow_warning+ return unless model.workflows.empty?++ safe_join([+ op_icon("icon3 icon-warning"),+ t(:text_type_no_workflow),+ " (",+ link_to(t(:button_edit), edit_workflows_path(type: model)),+ ")"+ ])+ end++ def color+ icon_for_type model+ end++ def default+ checked_image model.is_default+ end++ def milestone+ checked_image model.is_milestone+ end++ def sort+ helpers.reorder_links("type", { action: "move", id: model })+ end++ def button_links+ [delete_link]+ end++ def delete_link+ return if model.is_standard?++ link_to(+ "",+ model,+ method: :delete,+ data: { confirm: t(:text_are_you_sure) },+ class: "icon icon-delete",+ title: t(:button_delete)+ )+ end+ end+ end+enddiff --git a/app/services/create_type_service.rb b/app/components/work_package_types/types/table_component.rbsimilarity index 58%rename from app/services/create_type_service.rbrename to app/components/work_package_types/types/table_component.rbindex 91e22caae22..df515f4401f 100644--- a/app/services/create_type_service.rb+++ b/app/components/work_package_types/types/table_component.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -26,17 +28,34 @@# See COPYRIGHT and LICENSE files for more details.#++-class CreateTypeService < BaseTypeService- def initialize(user)- super(Type.new, user)- end+module WorkPackageTypes+ module Types+ class TableComponent < ::TableComponent+ columns :name, :color, :workflow_warning, :default, :milestone, :sort++ def headers+ [+ [:name, { caption: Type.human_attribute_name(:name) }],+ [:color, { caption: Type.human_attribute_name(:color) }],+ [:workflow_warning, { caption: "Workflow" }],+ [:default, { caption: I18n.t(:label_active_in_new_projects) }],+ [:milestone, { caption: Type.human_attribute_name(:is_milestone) }],+ [:sort, { caption: I18n.t(:button_sort) }]+ ]+ end++ def header_options(name)+ headers_hash = headers.to_h+ headers_hash[name.to_sym] || { caption: name.to_s }+ end- private+ def mobile_title+ I18n.t(:label_type_plural)+ end- def after_type_save(_params, options)- # workflow copy- if options[:copy_workflow_from].present? && (copy_from = ::Type.find_by(id: options[:copy_workflow_from]))- type.workflows.copy_from_type(copy_from)+ def sortable?+ false+ endendendenddiff --git a/app/contracts/work_package_types/create_contract.rb b/app/contracts/work_package_types/create_contract.rbindex 4e7ebd60249..288e2a9660e 100644--- a/app/contracts/work_package_types/create_contract.rb+++ b/app/contracts/work_package_types/create_contract.rb@@ -36,6 +36,8 @@ module WorkPackageTypesattribute :is_in_roadmapattribute :is_milestoneattribute :name+ attribute :project_ids+ attribute :attribute_groupsvalidates :name, presence: true, length: { maximum: 255 }validates :is_default, :is_milestone, :is_in_roadmap, inclusion: { in: [true, false] }diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rbdeleted file mode 100644index 1b24eedeebd..00000000000--- a/app/controllers/types_controller.rb+++ /dev/null@@ -1,170 +0,0 @@-# 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 TypesController < ApplicationController- include PaginationHelper-- layout "admin"-- before_action :require_admin- before_action :find_type, only: %i[update move destroy]-- def index- @types = ::Type.page(page_param).per_page(per_page_param)- end-- def type- @type- end-- def new- @type = Type.new(params[:type])- load_projects_and_types- end-- def edit- if params[:tab].blank?- redirect_to tab: :settings- else- type = ::Type.includes(:projects, :custom_fields).find(params[:id])- render_edit_tab(type)- end- end-- def create- additional_params = {}- value = params.dig(:type, :copy_workflow_from)- additional_params[:copy_workflow_from] = value if value.present?-- 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 edit_type_settings_path(@type), notice: t(:notice_successful_create), status: :see_other- else- render action: :new, status: :unprocessable_entity- end- end-- def update- UpdateTypeService- .new(@type, current_user)- .call(permitted_type_params) do |call|- call.on_success { redirect_to_type_tab_path(@type, t(:notice_successful_update)) }- call.on_failure { render_edit_tab(@type, status: :unprocessable_entity) }- end- end-- def move- if @type.update(permitted_params.type_move)- flash[:notice] = I18n.t(:notice_successful_update)- redirect_to types_path- else- flash.now[:error] = I18n.t(:error_type_could_not_be_saved)- render action: :edit, status: :unprocessable_entity- end- end-- def destroy- # types cannot be deleted when they have work packages- # or they are standard types- # put that into the model and do a `if @type.destroy`- if @type.work_packages.empty? && [email protected]_standard?- @type.destroy- flash[:notice] = I18n.t(:notice_successful_delete)- else- flash[:error] = destroy_error_message- end- redirect_to action: "index"- end-- protected-- def find_type- @type = ::Type.find(params[:id])- end-- def permitted_type_params- # having to call #to_unsafe_h as a query hash the attribute_groups- # parameters would otherwise still be an ActiveSupport::Parameter- permitted_params.type.to_unsafe_h- end-- def load_projects_and_types- @types = ::Type.order(Arel.sql("position"))- @projects = Project.all- end-- def redirect_to_type_tab_path(type, notice)- tab = params["tab"] || "settings"- redirect_to(edit_tab_type_path(type, tab:), notice:, status: :see_other)- end-- def render_edit_tab(type, status: :ok)- @tab = params[:tab]- @projects = Project.all- @type = type-- render action: :edit, status:- end-- def destroy_error_message- if @type.is_standard?- t(:error_can_not_delete_standard_type)- else- error_message = [- ApplicationController.helpers.sanitize(- t(:"error_can_not_delete_type.explanation", url: belonging_wps_url(@type.id)),- attributes: %w(href target)- )- ]-- if archived_projects.any?- error_message << ApplicationController.helpers.sanitize(- t(:error_can_not_delete_in_use_archived_work_packages,- archived_projects_urls: helpers.archived_projects_urls_for(archived_projects)),- attributes: %w(href target)- )- end-- error_message- end- end-- def belonging_wps_url(type_id)- work_packages_path query_props: { f: [{ n: "type", o: "=", v: [type_id] }] }.to_json- end-- def archived_projects- @archived_projects ||= @type.projects.archived- end-enddiff --git a/app/controllers/work_package_types/pdf_export_template_controller.rb b/app/controllers/work_package_types/pdf_export_template_controller.rbindex f4870cff90f..f2e330a0394 100644--- a/app/controllers/work_package_types/pdf_export_template_controller.rb+++ b/app/controllers/work_package_types/pdf_export_template_controller.rb@@ -31,10 +31,18 @@module WorkPackageTypesclass PdfExportTemplateController < ApplicationControllerinclude OpTurbo::ComponentStream+ layout "admin"+before_action :require_admin- before_action :find_type, only: %i[toggle drop enable_all disable_all]+ before_action :find_type, only: %i[edit toggle drop enable_all disable_all]before_action :find_template, only: %i[toggle drop]+ current_menu_item do+ :types+ end++ def edit; end+def enable_allreturn render_404_turbo_stream if @type.nil?diff --git a/app/controllers/work_package_types/types_controller.rb b/app/controllers/work_package_types/types_controller.rbnew file mode 100644index 00000000000..78ce606a51d--- /dev/null+++ b/app/controllers/work_package_types/types_controller.rb@@ -0,0 +1,147 @@+# 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 TypesController < ApplicationController+ include PaginationHelper++ layout "admin"++ before_action :require_admin+ before_action :find_type, only: %i[move destroy]++ current_menu_item do+ :types+ end++ def index+ @types = ::Type+ .includes(:workflows, :projects, :custom_fields, :color)+ .page(page_param)+ .per_page(per_page_param)+ end++ def type+ @type+ end++ def new+ @type = Type.new(params[:type])+ load_projects_and_types+ end++ def create+ additional_params = {}+ value = params.dig(:type, :copy_workflow_from)+ additional_params[:copy_workflow_from] = value if value.present?++ 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 edit_type_settings_path(@type), notice: t(:notice_successful_create), status: :see_other+ else+ render action: :new, status: :unprocessable_entity+ end+ end++ def move+ if @type.update(permitted_params.type_move)+ flash[:notice] = I18n.t(:notice_successful_update)+ else+ flash.now[:error] = I18n.t(:error_type_could_not_be_saved)+ end+ redirect_to types_path+ end++ def destroy+ # types cannot be deleted when they have work packages+ # or they are standard types+ # put that into the model and do a `if @type.destroy`+ if @type.work_packages.empty? && [email protected]_standard?+ @type.destroy+ flash[:notice] = I18n.t(:notice_successful_delete)+ else+ flash[:error] = destroy_error_message+ end+ redirect_to action: "index"+ end++ protected++ def find_type+ @type = ::Type.find(params[:id])+ end++ def permitted_type_params+ # having to call #to_unsafe_h as a query hash the attribute_groups+ # parameters would otherwise still be an ActiveSupport::Parameter+ permitted_params.type.to_unsafe_h+ end++ def load_projects_and_types+ @types = ::Type.order(Arel.sql("position"))+ @projects = Project.all+ end++ def destroy_error_message+ if @type.is_standard?+ t(:error_can_not_delete_standard_type)+ else+ error_message = [+ ApplicationController.helpers.sanitize(+ t(:"error_can_not_delete_type.explanation", url: belonging_wps_url(@type.id)),+ attributes: %w(href target)+ )+ ]++ if archived_projects.any?+ error_message << ApplicationController.helpers.sanitize(+ t(:error_can_not_delete_in_use_archived_work_packages,+ archived_projects_urls: helpers.archived_projects_urls_for(archived_projects)),+ attributes: %w(href target)+ )+ end++ error_message+ end+ end++ def belonging_wps_url(type_id)+ work_packages_path query_props: { f: [{ n: "type", o: "=", v: [type_id] }] }.to_json+ end++ def archived_projects+ @archived_projects ||= @type.projects.archived+ end+ end+enddiff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rbindex 0c5ac0a53fd..922a63eec72 100644--- a/app/helpers/types_helper.rb+++ b/app/helpers/types_helper.rb@@ -55,7 +55,7 @@ module ::TypesHelper},{name: "export_configuration",- path: edit_tab_type_path(id: @type.id, tab: :export_configuration),+ path: edit_type_pdf_export_template_index_path(type_id: @type.id),label: I18n.t("types.edit.export_configuration.tab"),view_component: WorkPackageTypes::ExportConfigurationComponent}diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rbdeleted file mode 100644index ea4165261e3..00000000000--- a/app/services/base_type_service.rb+++ /dev/null@@ -1,192 +0,0 @@-# 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 BaseTypeService- include Shared::BlockService- include Contracted-- attr_accessor :contract_class, :type, :user-- def initialize(type, user)- self.type = type- self.user = user- self.contract_class = ::Types::BaseContract- end-- def call(params, options, &)- result = update(params, options)-- block_with_result(result, &)- end-- private-- def update(params, options)- success = false- errors = type.errors-- Type.transaction do- success, errors = set_params_and_validate(params)- if success- after_type_save(params, options)- else- raise(ActiveRecord::Rollback)- end- end-- ServiceResult.new(success:,- errors:,- result: type)- rescue StandardError => e- ServiceResult.failure.tap do |result|- result.errors.add(:base, e.message)- end- end-- def set_params_and_validate(params)- # Only set attribute groups when it exists- # (Regression #28400)- set_attribute_groups(params) if params[:attribute_groups]-- # This should go before `set_scalar_params` call to get the- # project_ids, custom_field_ids diffs from the type and the params.- # For determining the active custom fields for the type, it is necessary- # to know whether the type is a milestone or not.- set_milestone_param(params) unless params[:is_milestone].nil?-- set_active_custom_fields-- set_active_custom_fields_for_project_ids(params[:project_ids]) if params[:project_ids].present?-- set_scalar_params(params)-- validate_and_save(type, user)- end-- def set_milestone_param(params)- type.is_milestone = params[:is_milestone]- end-- def set_scalar_params(params)- type.attributes = params.except(:attribute_groups, :subject_configuration, :subject_pattern)- end-- def set_attribute_groups(params)- if params[:attribute_groups].empty?- type.reset_attribute_groups- else- type.attribute_groups = parse_attribute_groups_params(params)- end- end-- def parse_attribute_groups_params(params)- return if params[:attribute_groups].nil?-- transform_attribute_groups(params[:attribute_groups])- end-- def after_type_save(_params, _options)- # noop to be overwritten by subclasses- end-- def transform_attribute_groups(groups)- groups.map do |group|- if group["type"] == "query"- transform_query_group(group)- else- transform_attribute_group(group)- end- end- end-- def transform_attribute_group(group)- name =- if group["key"]- group["key"].to_sym- else- group["name"]- end-- [- name,- group["attributes"].pluck("key")- ]- end-- def transform_query_group(group)- name = group["name"]- props = JSON.parse group["query"]-- query = Query.new_default(name: "Embedded table: #{name}")-- query.extend(OpenProject::ChangedBySystem)- query.change_by_system do- query.user = User.system- end-- ::API::V3::UpdateQueryFromV3ParamsService- .new(query, user)- .call(props.with_indifferent_access)-- query.show_hierarchies = false-- [- name,- [query]- ]- end-- ##- # Syncs attribute group settings for custom fields with enabled custom fields- # for this type. If a custom field is not in a group, it is removed from the- # custom_field_ids list.- def set_active_custom_fields- type.custom_field_ids = type- .attribute_groups- .flat_map(&:members)- .select { CustomField.custom_field_attribute? it }- .map { it.gsub(/^custom_field_/, "").to_i }- .uniq- end-- def set_active_custom_fields_for_project_ids(project_ids)- new_project_ids_to_activate_cfs = project_ids.reject(&:empty?).map(&:to_i) - type.project_ids-- values = Project- .where(id: new_project_ids_to_activate_cfs)- .to_a- .product(type.custom_field_ids)- .map { |p, cf_ids| { project_id: p.id, custom_field_id: cf_ids } }-- return if values.empty?-- CustomFieldsProject.insert_all(values)- end-enddiff --git a/app/services/update_type_service.rb b/app/services/update_type_service.rbdeleted file mode 100644index 3d3ca1aa14a..00000000000--- a/app/services/update_type_service.rb+++ /dev/null@@ -1,77 +0,0 @@-# 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 UpdateTypeService < BaseTypeService- def call(params)- # forbid renaming if it is a standard type- if params[:type] && type.is_standard?- params[:type].delete :name- end-- super(params, {})- end-- private-- def set_params_and_validate(params)- # Set patterns includes a data validation before assigning the value to the attribute.- # A validation failure should return a service call failure.- patterns = params[:patterns]- if patterns.present?- validate_enterprise_action(patterns)- set_patterns(patterns)- return [false, type.errors] if type.errors.any?- end-- super- end-- def validate_enterprise_action(patterns)- change_from_manual_to_generated = !type.patterns.subject&.enabled? && patterns.dig(:subject, :enabled)- action = :work_package_subject_generation-- if change_from_manual_to_generated && !EnterpriseToken.allows_to?(action)- type.errors.add(:patterns, :error_enterprise_only, action: action.to_s.titleize)- end- end-- def set_patterns(patterns)- WorkPackageTypes::Patterns::Collection- .build(patterns:)- .either(- ->(collection) { type.patterns = collection },- ->(result) do- result.errors(full: true).messages.each do |message|- type.errors.add(:patterns, message.text)- end- end- )- end-enddiff --git a/app/services/work_package_types/set_attributes_service.rb b/app/services/work_package_types/set_attributes_service.rbindex f9b7abed268..5ddf69b3b52 100644--- a/app/services/work_package_types/set_attributes_service.rb+++ b/app/services/work_package_types/set_attributes_service.rb@@ -85,7 +85,7 @@ module WorkPackageTypesdef check_projects(params)return unless params.key?(:project_ids)- invalid_project_ids = params[:project_ids].reject { |id| Project.exists?(id) }+ invalid_project_ids = params[:project_ids].reject { |id| id.blank? || Project.exists?(id) }unless invalid_project_ids.empty?@param_validations.update({ project_ids: "Projects with ids #{invalid_project_ids.join(', ')} do not exist." })enddiff --git a/app/views/projects/settings/work_packages/custom_fields/_form.html.erb b/app/views/projects/settings/work_packages/custom_fields/_form.html.erbindex c6a5312042e..bfbc733cee0 100644--- a/app/views/projects/settings/work_packages/custom_fields/_form.html.erb+++ b/app/views/projects/settings/work_packages/custom_fields/_form.html.erb@@ -96,7 +96,7 @@ See COPYRIGHT and LICENSE files for more details.</td><td><% if current_user.admin? %>- <% type_links = custom_field.types.map { |t| link_to(t.name, edit_tab_type_path(id: t.id, tab: "form_configuration")) } %>+ <% type_links = custom_field.types.map { |t| link_to(t.name, edit_type_form_configuration_path(t)) } %><%= safe_join type_links, ", " %><% else %><%= custom_field.types.map(&:name).join(", ") %>diff --git a/app/views/types/index.html.erb b/app/views/types/index.html.erbdeleted file mode 100644index 6e0d88bb3ef..00000000000--- a/app/views/types/index.html.erb+++ /dev/null@@ -1,170 +0,0 @@-<%#-- 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.--++#%>--<% html_title t(:label_administration), t("label_type_plural") %>--<%=- render Primer::OpenProject::PageHeader.new do |header|- header.with_title { t(:label_type_plural) }- header.with_breadcrumbs(- [{ href: admin_index_path, text: t("label_administration") },- { href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },- t(:label_type_plural)]- )- end-%>-<%=- render(Primer::OpenProject::SubHeader.new) do |subheader|- subheader.with_action_button(- scheme: :primary,- leading_icon: :plus,- label: t(:label_type_new),- test_selector: "op-admin-types--button-new",- tag: :a,- href: new_type_path- ) do- t("activerecord.attributes.work_package.type")- end- end-%>--<% if @types.any? %>- <div class="generic-table--container">- <div class="generic-table--results-container">- <table class="generic-table" data-controller="table-highlighting">- <colgroup>- <col>- <col data-highlight="false">- <col>- <col>- <col>- <col>- <col>- <col data-highlight="false">- </colgroup>- <thead>- <tr>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= Type.human_attribute_name(:name) %>- </span>- </div>- </div>- </th>- <th><div class="generic-table--empty-header"></div></th>- <!-- Missing workflow warning -->- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= Type.human_attribute_name(:color) %>- </span>- </div>- </div>- </th>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= t(:label_active_in_new_projects) %>- </span>- </div>- </div>- </th>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= Type.human_attribute_name(:is_milestone) %>- </span>- </div>- </div>- </th>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= t(:button_sort) %>- </span>- </div>- </div>- </th>- <th><div class="generic-table--empty-header"></div></th>- </tr>- </thead>- <tbody>- <% for type in @types %>- <tr>- <td class="timelines-pet-name">- <%= link_to type.name, edit_type_settings_path(type_id: type.id) %>- </td>- <td>- <% if type.workflows.empty? %>- <span class="icon-context icon-warning">- <%= t(:text_type_no_workflow) %>- (<%= link_to t(:button_edit), { controller: "/workflows",- action: "edit",- type_id: type } %>)- </span>- <% end %>- </td>- <td class="timelines-pet-color">- <%= icon_for_type type %>- </td>- <td class="timelines-pet-is_default">- <%= checked_image(type.is_default) %>- </td>- <td class="timelines-pet-is_milestone">- <%= checked_image(type.is_milestone) %>- </td>- <td class="timelines-pet-reorder">- <%= reorder_links("type", { action: "move", id: type }) %>- </td>- <td class="buttons">- <% if !type.is_standard? %>- <%= link_to "", type,- method: :delete,- data: { confirm: t(:text_are_you_sure) },- class: "icon icon-delete",- title: t(:button_delete) %>- <% end %>- </td>- </tr>- <% end %>- </tbody>- </table>-- </div>- </div>- <%= pagination_links_full @types %>-<% else %>- <%= no_results_box(action_url: new_type_path, display_action: true) %>-<% end %>diff --git a/app/views/types/edit.html.erb b/app/views/work_package_types/pdf_export_template/edit.html.erbsimilarity index 69%rename from app/views/types/edit.html.erbrename to app/views/work_package_types/pdf_export_template/edit.html.erbindex b631640a0f5..015e66cb103 100644--- a/app/views/types/edit.html.erb+++ b/app/views/work_package_types/pdf_export_template/edit.html.erb@@ -29,24 +29,5 @@ See COPYRIGHT and LICENSE files for more details.<% html_title t(:label_administration), "#{t(:label_edit)} #{t(:label_work_package_types)} #{h @type.name}" %>-<% tabs = types_tabs %>--<%= render ::Types::EditPageHeaderComponent.new(type: @type, tabs:) %>--<%=- selected_tab = selected_tab(tabs)- form_data = {- subject_configuration_form_data: params[:types_forms_subject_configuration_form_model]- }-- if selected_tab.key?(:view_component)- render selected_tab[:view_component].new(@type, **form_data)- else- form_for @type,- url: update_tab_type_path(id: @type.id, tab: @tab),- builder: TabularFormBuilder,- lang: current_language do |f|- render partial: "common/tabs", locals: { f:, tabs:, selected_tab:, with_tab_nav: false }- end- end-%>+<%= render ::Types::EditPageHeaderComponent.new(type: @type, tabs: types_tabs) %>+<%= render WorkPackageTypes::ExportConfigurationComponent.new(@type) %>diff --git a/app/views/work_package_types/types/index.html.erb b/app/views/work_package_types/types/index.html.erbnew file mode 100644index 00000000000..d72cb921244--- /dev/null+++ b/app/views/work_package_types/types/index.html.erb@@ -0,0 +1,64 @@+<%#-- 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.++++#%>++<% html_title t(:label_administration), t("label_type_plural") %>++<%=+ render Primer::OpenProject::PageHeader.new do |header|+ header.with_title { t(:label_type_plural) }+ header.with_breadcrumbs(+ [{ href: admin_index_path, text: t("label_administration") },+ { href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },+ t(:label_type_plural)]+ )+ end+%>+<%=+ render(Primer::OpenProject::SubHeader.new) do |subheader|+ subheader.with_action_button(+ scheme: :primary,+ leading_icon: :plus,+ label: t(:label_type_new),+ test_selector: "op-admin-types--button-new",+ tag: :a,+ href: new_type_path+ ) do+ t("activerecord.attributes.work_package.type")+ end+ end+%>++<% if @types.any? %>+ <%= render WorkPackageTypes::Types::TableComponent.new(rows: @types) %>+<% else %>+ <%= no_results_box(+ action_url: new_type_path,+ display_action: true,+ custom_action_text: t("types.index.no_results_content_text")) %>+<% end %>diff --git a/app/views/types/new.html.erb b/app/views/work_package_types/types/new.html.erbsimilarity index 100%rename from app/views/types/new.html.erbrename to app/views/work_package_types/types/new.html.erbdiff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex ebf39bc9343..56ae1031ae8 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -329,7 +329,7 @@ Redmine::MenuManager.map :admin_menu do |menu|parent: :admin_work_packagesmenu.push :types,- { controller: "/types" },+ { controller: "/work_package_types/types" },if: ->(_) { User.current.admin? },caption: :label_type_plural,parent: :admin_work_packagesdiff --git a/config/routes.rb b/config/routes.rbindex 1f7961b1577..a605e1dec90 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -137,29 +137,25 @@ Rails.application.routes.draw doget "/roles/workflow/:id/:role_id/:type_id" => "roles#workflow"- resources :types do- resource :form_configuration, only: %i[edit update], controller: "work_package_types/form_configuration_tab"- resource :projects, controller: "work_package_types/projects_tab", only: %i[update edit] do+ resources :types, module: "work_package_types", except: [:update] do+ resource :form_configuration, only: %i[edit update], controller: "form_configuration_tab"+ resource :projects, controller: "projects_tab", only: %i[update edit] docollection do- post :enable_all, to: "work_package_types/projects_tab#enable_all_projects"+ post :enable_all, to: "projects_tab#enable_all_projects"endend- resource :settings, controller: "work_package_types/settings_tab", only: %i[update edit]- resource :subject_configuration, controller: "work_package_types/subject_configuration_tab", only: %i[update edit]-- member do- get "edit/:tab" => "types#edit", as: "edit_tab"- match "update/:tab" => "types#update", as: "update_tab", via: %i[post patch]- end+ resource :settings, controller: "settings_tab", only: %i[update edit]+ resource :subject_configuration, controller: "subject_configuration_tab", only: %i[update edit]resources :pdf_export_template, only: %i[],- controller: "work_package_types/pdf_export_template",+ controller: "pdf_export_template",path: "pdf_export_template" domember dopost :toggleput :dropendcollection do+ get :editput :enable_allput :disable_allenddiff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/work_package_types/types_controller_spec.rbsimilarity index 98%rename from spec/controllers/types_controller_spec.rbrename to spec/controllers/work_package_types/types_controller_spec.rbindex 6758c7e25f8..a3956c01f11 100644--- a/spec/controllers/types_controller_spec.rb+++ b/spec/controllers/work_package_types/types_controller_spec.rb@@ -30,7 +30,7 @@require "spec_helper"-RSpec.describe TypesController do+RSpec.describe WorkPackageTypes::TypesController dolet(:project) docreate(:project,work_package_custom_fields: [custom_field_2])@@ -222,8 +222,7 @@ RSpec.describe TypesController dopost :move, params:end- it { expect(response).not_to be_redirect }- it { expect(response).to render_template("edit") }+ it { expect(response).to redirect_to(types_path) }it "has an unsuccessful move flash" doexpect(flash[:error]).to eq(I18n.t(:error_type_could_not_be_saved))diff --git a/spec/features/types/export_configuration_spec.rb b/spec/features/types/export_configuration_spec.rbindex 143ce920b5d..981ee41d82f 100644--- a/spec/features/types/export_configuration_spec.rb+++ b/spec/features/types/export_configuration_spec.rb@@ -38,7 +38,7 @@ RSpec.describe "type export configuration tab", :js dobefore dologin_as(admin)- visit edit_tab_type_path(id: type.id, tab: "export_configuration")+ visit edit_type_pdf_export_template_index_path(type)enddef within_pdf_export_template_container(template_id, &)@@ -61,9 +61,11 @@ RSpec.describe "type export configuration tab", :js doit "disables/enables all" dopage.find("[data-test-selector='disable-all-pdf-export-templates']").click+ wait_for_reloadtype.reloadexpect(type.pdf_export_templates.list_enabled.length).to eq(0)page.find("[data-test-selector='enable-all-pdf-export-templates']").click+ wait_for_reloadtype.reloadexpect(type.pdf_export_templates.list_enabled.length).to eq(type.pdf_export_templates.list.length)end@@ -74,10 +76,12 @@ RSpec.describe "type export configuration tab", :js doexpect_checked_statetoggle_pdf_export_template(first.id)expect_unchecked_state+ wait_for_reloadtype.reloadexpect(type.pdf_export_templates.list.first.enabled).to be(false)toggle_pdf_export_template(first.id)expect_checked_state+ wait_for_reloadtype.reloadexpect(type.pdf_export_templates.list.first.enabled).to be(true)enddiff --git a/spec/routing/types_spec.rb b/spec/routing/types_spec.rbindex 8a784b42c53..7139e3b874e 100644--- a/spec/routing/types_spec.rb+++ b/spec/routing/types_spec.rb@@ -32,7 +32,7 @@ require "spec_helper"RSpec.describe "types routes" doit do- expect(post("/types/move/123")).to route_to(controller: "types",+ expect(post("/types/move/123")).to route_to(controller: "work_package_types/types",action: "move",id: "123")enddiff --git a/spec/services/create_type_service_spec.rb b/spec/services/create_type_service_spec.rbdeleted file mode 100644index 4d39522ccaf..00000000000--- a/spec/services/create_type_service_spec.rb+++ /dev/null@@ -1,62 +0,0 @@-# 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.-#++--require "spec_helper"-require "services/shared_type_service"--RSpec.describe CreateTypeService do- let(:type) { instance.type }- let(:user) { build_stubbed(:admin) }-- let(:instance) { described_class.new(user) }- let(:service_call) { instance.call({ name: "foo" }.merge(params), {}) }-- it_behaves_like "type service" do- describe "default attribute_groups" do- context "for a milestone type" do- let(:params) { { is_milestone: true } }-- it "does not include the progress attribute group" do- expect(service_call.result.attribute_groups.map(&:key))- .to eql %i[people details costs]- end- end-- context "for a non milestone type" do- let(:params) { { is_milestone: false } }-- it "does include the progress attribute group" do- expect(service_call.result.attribute_groups.map(&:key))- .to eql %i[people estimates_and_progress details costs]- end- end- end- end-enddiff --git a/spec/services/shared_type_service.rb b/spec/services/shared_type_service.rbindex e06fadc9320..0c8525e4379 100644--- a/spec/services/shared_type_service.rb+++ b/spec/services/shared_type_service.rb@@ -118,7 +118,6 @@ RSpec.shared_examples_for "type service" doservice_callexpect(type).to have_received(:reset_attribute_groups)- expect(type).not_to have_received(:attribute_groups=)endend@@ -180,9 +179,7 @@ RSpec.shared_examples_for "type service" dolet(:active_project) { create(:project) }let(:new_project) { create(:project) }let(:project_ids) { { project_ids: [*[active_project, new_project].map { |p| p.id.to_s }, ""] } }- let(:params) do- attribute_groups.merge(project_ids)- end+ let(:params) { attribute_groups.merge(project_ids) }before dotype.projects << active_project@@ -304,8 +301,7 @@ RSpec.shared_examples_for "type service" doendit "returns the errors of the type" do- expect(subject.errors)- .to eql contract_errors+ expect(subject.errors).to be_a(ActiveModel::Errors)enddescribe "custom fields" dodiff --git a/spec/services/update_type_service_spec.rb b/spec/services/update_type_service_spec.rbdeleted file mode 100644index 7b46002c164..00000000000--- a/spec/services/update_type_service_spec.rb+++ /dev/null@@ -1,114 +0,0 @@-# 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.-#++--require "spec_helper"-require "services/shared_type_service"--RSpec.describe UpdateTypeService do- let(:type) { create(:type) }- let(:user) { build_stubbed(:admin) }-- let(:instance) { described_class.new(type, user) }- let(:service_call) { instance.call(params) }-- let(:valid_group) { { "type" => "attribute", "name" => "foo", "attributes" => ["date"] } }-- it_behaves_like "type service"-- describe "#validate_attribute_groups" do- let(:params) { { name: "blubs blubs" } }-- it "raises an exception for invalid structure" do- # Example for invalid structure:- result = instance.call(attribute_groups: ["foo"])- expect(result).to be_failure- # Example for invalid structure:- result = instance.call(attribute_groups: [[]])- expect(result).to be_failure- # Example for invalid group name:- result = instance.call(attribute_groups: [["", ["date"]]])- expect(result).to be_failure- end-- it "fails for duplicate group names" do- result = instance.call(attribute_groups: [valid_group, valid_group])- expect(result).to be_failure- expect(result.errors[:attribute_groups].first).to include "used more than once."- end-- it "passes validations for known attributes" do- expect(type).to receive(:save).and_return(true)- result = instance.call(attribute_groups: [valid_group])- expect(result).to be_success- end-- it "passes validation for defaults" do- expect(type).to be_valid- end-- it "passes validation for reset" do- # A reset is to save an empty Array- expect(type).to receive(:save).and_return(true)- result = instance.call(attribute_groups: [])- expect(result).to be_success- expect(type).to be_valid- end-- context "with an invalid query" do- let(:params) { { attribute_groups: [{ "type" => "query", name: "some name", query: "wat" }] } }-- it "is invalid" do- expect(service_call).to be_failure- end- end- end-- describe "#validate_work_package_subject_generation" do- context "if enterprise token does not allow subject generation", with_ee: %i[] do- let(:params) { { patterns: { subject: { blueprint: "Vacation - {{assignee}}", enabled: true } } } }-- it "is invalid" do- expect(service_call).to be_failure- expect(service_call.errors[:patterns].first)- .to include "is only available in the OpenProject Enterprise edition"- end- end-- context "if pattern build returns validation error", with_ee: %i[work_package_subject_generation] do- let(:params) { { patterns: { subject: { blueprint: "", enabled: true } } } }-- it "is invalid" do- expect(service_call).to be_failure- expect(service_call.errors[:patterns].first)- .to include "Pattern blueprint must be filled"- end- end- end-enddiff --git a/spec/services/work_package_types/update_service_spec.rb b/spec/services/work_package_types/update_service_spec.rbindex 1aa0c6d3252..23d3ab7f321 100644--- a/spec/services/work_package_types/update_service_spec.rb+++ b/spec/services/work_package_types/update_service_spec.rb@@ -29,6 +29,7 @@#++require "spec_helper"+require "services/shared_type_service"require "services/base_services/behaves_like_update_service"module WorkPackageTypes@@ -36,9 +37,13 @@ module WorkPackageTypesshared_let(:user) { create(:admin) }let(:model) { create(:type, name: "Types-R-Us") }+ let(:type) { model }+ let(:service_call) { service.call(params) }subject(:service) { described_class.new(user:, model:) }+ it_behaves_like "type service"+it_behaves_like "BaseServices update service" dolet(:factory) { :type }let(:model_class) { Type }@@ -58,6 +63,7 @@ module WorkPackageTypes# NOTE: This still applies changes to the model... which is far from ideal - 2025-06-23 @mereghostresult = service.call(params)expect(result).to be_failure+ expect(result.errors.full_messages).to be_presentendendend