Skip to content

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

Primerize and separate enumerations

Oliver Günther03a96eefb4dc
diff --git a/Gemfile.modules b/Gemfile.modules
index 0407226c7d6..0992e008fa9 100644
--- a/Gemfile.modules
+++ b/Gemfile.modules
@@ -23,7 +23,6 @@ group :opf_plugins do
gem 'openproject-auth_plugins', path: 'modules/auth_plugins'
gem 'openproject-auth_saml', path: 'modules/auth_saml'
gem 'openproject-openid_connect', path: 'modules/openid_connect'
- gem 'openproject-documents', path: 'modules/documents'
gem 'openproject-xls_export', path: 'modules/xls_export'
gem 'costs', path: 'modules/costs'
gem 'openproject-reporting', path: 'modules/reporting'
@@ -48,6 +47,7 @@ group :opf_plugins do
gem 'openproject-gantt', path: 'modules/gantt'
gem 'openproject-calendar', path: 'modules/calendar'
gem 'openproject-storages', path: 'modules/storages'
+ gem 'openproject-documents', path: 'modules/documents'
gem 'openproject-bim', path: 'modules/bim'
end
diff --git a/app/components/admin/enumerations/index_component.html.erb b/app/components/admin/enumerations/index_component.html.erb
new file mode 100644
index 00000000000..9145f180e87
--- /dev/null
+++ b/app/components/admin/enumerations/index_component.html.erb
@@ -0,0 +1,37 @@
+<%=
+component_wrapper do
+ flex_layout(data: wrapper_data_attributes) do |flex|
+ flex.with_row do
+ render(Primer::OpenProject::SubHeader.new) do |subheader|
+ subheader.with_action_button(
+ scheme: :primary,
+ tag: :a,
+ href: helpers.url_for(action: :new),
+ test_selector: "add-enumeration-button"
+ ) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t(:button_add)
+ end
+ end
+ end
+
+ flex.with_row do
+ render(border_box_container(data: drop_target_config)) do |component|
+ component.with_header(font_weight: :bold) { enumeration_class.model_name.human(count: :other) }
+
+ if enumerations.empty?
+ component.with_row do
+ render(Primer::Beta::Text.new(color: :subtle)) { t(:no_results_title_text) }
+ end
+ else
+ enumerations.each do |enumeration|
+ component.with_row(test_selector: "enumeration-row-#{enumeration.id}", data: draggable_item_config(enumeration)) do
+ render(item_component_class.new(enumeration: enumeration, max_position: max_position))
+ end
+ end
+ end
+ end
+ end
+ end
+end
+%>
diff --git a/modules/costs/app/components/admin/time_entry_activities/index_component.rb b/app/components/admin/enumerations/index_component.rb
similarity index 78%
rename from modules/costs/app/components/admin/time_entry_activities/index_component.rb
rename to app/components/admin/enumerations/index_component.rb
index 74bb76c0ca9..fe4f84d853a 100644
--- a/modules/costs/app/components/admin/time_entry_activities/index_component.rb
+++ b/app/components/admin/enumerations/index_component.rb
@@ -29,18 +29,18 @@
# ++
module Admin
- module TimeEntryActivities
+ module Enumerations
class IndexComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- options :time_entry_activities
+ options :enumerations
private
- def max_activity_position
- time_entry_activities.map(&:position).max
+ def max_position
+ enumerations.map(&:position).max
end
def wrapper_data_attributes
@@ -54,17 +54,25 @@ module Admin
{
"is-drag-and-drop-target": true,
"target-container-accessor": "& > ul",
- "target-allowed-drag-type": "time-entry-activity"
+ "target-allowed-drag-type": "enumeration"
}
end
- def draggable_item_config(activity)
+ def draggable_item_config(enumeration)
{
- "draggable-id": activity.id,
- "draggable-type": "time-entry-activity",
- "drop-url": move_admin_time_entry_activity_path(activity)
+ "draggable-id": enumeration.id,
+ "draggable-type": "enumeration",
+ "drop-url": helpers.url_for(action: :move, id: enumeration.id)
}
end
+
+ def enumeration_class
+ enumerations.klass
+ end
+
+ def item_component_class
+ ItemComponent
+ end
end
end
end
diff --git a/app/components/admin/enumerations/item_component.html.erb b/app/components/admin/enumerations/item_component.html.erb
new file mode 100644
index 00000000000..9882d422f8b
--- /dev/null
+++ b/app/components/admin/enumerations/item_component.html.erb
@@ -0,0 +1,39 @@
+<%=
+ component_wrapper do
+ flex_layout(align_items: :center, justify_content: :space_between) do |enumeration_container|
+ enumeration_container.with_column(flex_layout: true) do |enumeration_info|
+ enumeration_info.with_column(mr: 2) do
+ render(Primer::OpenProject::DragHandle.new(draggable: true))
+ end
+
+ if colored?
+ enumeration_info.with_column(mr: 2) do
+ helpers.icon_for_color enumeration.color
+ end
+ end
+
+ enumeration_info.with_column(mr: 2) do
+ render(Primer::Beta::Link.new(href: helpers.url_for(action: :edit, id: enumeration), underline: false)) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) { enumeration.name }
+ end
+ end
+
+ enumeration_info.with_column(mr: 2) do
+ render(Primer::Beta::Text.new(color: :subtle)) { enumeration.active? ? "Active" : "Inactive" }
+ end
+ end
+
+ enumeration_container.with_column do
+ render(Primer::Alpha::ActionMenu.new(test_selector: "op-time-entry-acrtivity--action-menu")) do |menu|
+ menu.with_show_button(
+ icon: "kebab-horizontal",
+ scheme: :invisible,
+ "aria-label": "Actions"
+ )
+
+ build_enumeration_menu(menu)
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/costs/app/components/admin/time_entry_activities/activity_component.rb b/app/components/admin/enumerations/item_component.rb
similarity index 75%
rename from modules/costs/app/components/admin/time_entry_activities/activity_component.rb
rename to app/components/admin/enumerations/item_component.rb
index 16e9c4ec6e9..28308898c04 100644
--- a/modules/costs/app/components/admin/time_entry_activities/activity_component.rb
+++ b/app/components/admin/enumerations/item_component.rb
@@ -29,106 +29,107 @@
# ++
module Admin
- module TimeEntryActivities
- class ActivityComponent < ApplicationComponent
+ module Enumerations
+ class ItemComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- options :activity
- options :max_activity_position
+ options :enumeration
+ options :max_position
+
+ delegate :colored?, to: :enumeration
private
def wrapper_uniq_by
- activity.id
+ enumeration.id
end
def first_item?
- activity.position == 1
+ enumeration.position == 1
end
def last_item?
- activity.position == max_activity_position
+ enumeration.position == max_position
end
- def build_activity_menu(menu)
- edit_activity(menu)
+ def build_enumeration_menu(menu)
+ edit_enumeration(menu)
menu.with_divider
if !first_item?
- move_to_top_activity(menu)
- move_up_activity(menu)
+ move_to_top_enumeration(menu)
+ move_up_enumeration(menu)
end
if !last_item?
- move_down_activity(menu)
- move_to_bottom_activity(menu)
+ move_down_enumeration(menu)
+ move_to_bottom_enumeration(menu)
end
menu.with_divider
- deletion_activity(menu)
+ deletion_enumeration(menu)
end
- def edit_activity(menu)
+ def edit_enumeration(menu)
menu.with_item(label: I18n.t(:button_edit),
tag: :a,
- href: edit_admin_time_entry_activity_path(activity)) do |item|
+ href: helpers.url_for(action: :edit, id: enumeration)) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
end
- def move_to_top_activity(menu)
+ def move_to_top_enumeration(menu)
form_inputs = [{ name: "move_to", value: "highest" }]
menu.with_item(label: I18n.t(:label_sort_highest),
tag: :button,
- href: move_admin_time_entry_activity_path(activity),
+ href: helpers.url_for(action: :move, id: enumeration),
# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :put, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "move-to-top")
end
end
- def move_up_activity(menu)
+ def move_up_enumeration(menu)
form_inputs = [{ name: "move_to", value: "higher" }]
menu.with_item(label: I18n.t(:label_sort_higher),
tag: :button,
- href: move_admin_time_entry_activity_path(activity),
+ href: helpers.url_for(action: :move, id: enumeration),
# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :put, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "chevron-up")
end
end
- def move_down_activity(menu)
+ def move_down_enumeration(menu)
form_inputs = [{ name: "move_to", value: "lower" }]
menu.with_item(label: I18n.t(:label_sort_lower),
tag: :button,
- href: move_admin_time_entry_activity_path(activity),
+ href: helpers.url_for(action: :move, id: enumeration),
# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :put, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "chevron-down")
end
end
- def move_to_bottom_activity(menu)
+ def move_to_bottom_enumeration(menu)
form_inputs = [{ name: "move_to", value: "lowest" }]
menu.with_item(label: I18n.t(:label_sort_lowest),
tag: :button,
- href: move_admin_time_entry_activity_path(activity),
+ href: helpers.url_for(action: :move, id: enumeration),
# content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
form_arguments: { method: :put, inputs: form_inputs }) do |item|
item.with_leading_visual_icon(icon: "move-to-bottom")
end
end
- def deletion_activity(menu)
+ def deletion_enumeration(menu)
menu.with_item(label: I18n.t(:button_delete),
tag: :button,
scheme: :danger,
- href: admin_time_entry_activity_path(activity),
- # content_arguments: { data: { turbo_frame: ItemsComponent.wrapper_key } },
+ href: helpers.url_for(action: :destroy, id: enumeration),
form_arguments: { method: :delete }) do |item|
item.with_leading_visual_icon(icon: :trash)
end
diff --git a/modules/costs/app/components/admin/time_entry_activities/activity_form.rb b/app/components/admin/enumerations/item_form.rb
similarity index 76%
rename from modules/costs/app/components/admin/time_entry_activities/activity_form.rb
rename to app/components/admin/enumerations/item_form.rb
index 67d5cc36fcf..da9b0a7c1c6 100644
--- a/modules/costs/app/components/admin/time_entry_activities/activity_form.rb
+++ b/app/components/admin/enumerations/item_form.rb
@@ -29,18 +29,30 @@
#++
module Admin
- module TimeEntryActivities
- class ActivityForm < ApplicationForm
+ module Enumerations
+ class ItemForm < ApplicationForm
+ delegate :object, to: :@builder
+
form do |form|
form.text_field(
name: :name,
- label: TimeEntryActivity.human_attribute_name(:name),
+ label: object.class.human_attribute_name(:name),
required: true,
- input_width: :large
+ input_width: :medium
)
+
+ if object.colored?
+ form.color_select_list(
+ label: attribute_name(:color_id),
+ name: :color_id,
+ caption: object.color_label,
+ input_width: :medium
+ )
+ end
+
form.check_box(
name: :active,
- label: TimeEntryActivity.human_attribute_name(:active)
+ label: object.class.human_attribute_name(:active)
)
form.submit(
diff --git a/modules/costs/app/components/admin/time_entry_activities/reassign_form.rb b/app/components/admin/enumerations/reassign_form.rb
similarity index 91%
rename from modules/costs/app/components/admin/time_entry_activities/reassign_form.rb
rename to app/components/admin/enumerations/reassign_form.rb
index 6cb909fa2ad..c4636f62e91 100644
--- a/modules/costs/app/components/admin/time_entry_activities/reassign_form.rb
+++ b/app/components/admin/enumerations/reassign_form.rb
@@ -29,16 +29,16 @@
#++
module Admin
- module TimeEntryActivities
+ module Enumerations
class ReassignForm < ApplicationForm
include OpenProject::StaticRouting::UrlHelpers
- attr_reader :other_activities
+ attr_reader :other_enumerations
- def initialize(other_activities:)
+ def initialize(other_enumerations:)
super()
- @other_activities = other_activities
+ @other_enumerations = other_enumerations
end
form do |form|
@@ -48,7 +48,7 @@ module Admin
required: true,
input_width: :large
) do |select|
- other_activities.each do |activity|
+ other_enumerations.each do |activity|
select.option(value: activity.id, label: activity.name)
end
end
diff --git a/app/controllers/admin/settings/work_package_priorities_controller.rb b/app/controllers/admin/settings/work_package_priorities_controller.rb
new file mode 100644
index 00000000000..5c4169d3280
--- /dev/null
+++ b/app/controllers/admin/settings/work_package_priorities_controller.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Admin::Settings
+ class WorkPackagePrioritiesController < ApplicationController
+ include ::Admin::EnumerationsController
+
+ menu_item :priorities
+
+ private
+
+ def enumeration_class
+ IssuePriority
+ end
+ end
+end
diff --git a/app/controllers/concerns/admin/enumerations_controller.rb b/app/controllers/concerns/admin/enumerations_controller.rb
new file mode 100644
index 00000000000..0afe3ffb771
--- /dev/null
+++ b/app/controllers/concerns/admin/enumerations_controller.rb
@@ -0,0 +1,154 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Admin
+ module EnumerationsController
+ extend ActiveSupport::Concern
+ include OpTurbo::ComponentStream
+
+ included do
+ before_action :require_admin
+ before_action :find_enumeration, only: %i[edit update destroy move reassign]
+ layout "admin"
+
+ helper_method :index_component_class
+ end
+
+ def index
+ @enumerations = enumeration_class.all
+ end
+
+ def new
+ @enumeration = enumeration_class.new
+ end
+
+ def edit; end
+
+ def create
+ @enumeration = enumeration_class.new(enumeration_permitted_params)
+
+ if @enumeration.save
+ flash[:notice] = I18n.t(:notice_successful_update)
+ redirect_to(action: :index)
+ else
+ render action: :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ if @enumeration.update(enumeration_permitted_params)
+ flash[:notice] = I18n.t(:notice_successful_update)
+ redirect_to(action: :index)
+ else
+ render action: :edit, status: :unprocessable_entity
+ end
+ end
+
+ def destroy
+ if @enumeration.in_use?
+ handle_reassignment_on_deletion
+ elsif @enumeration.destroy
+ flash[:notice] = I18n.t(:notice_successful_delete)
+ redirect_to(action: :index)
+ else
+ flash.now[:error] = I18n.t(:error_can_not_delete_entry)
+ redirect_to(action: :index)
+ end
+ end
+
+ def move
+ if @enumeration.update(move_params)
+ render_success_flash_message_via_turbo_stream(
+ message: I18n.t(:enumeration_caption_order_changed)
+ )
+ else
+ render_error_flash_message_via_turbo_stream(
+ message: I18n.t(:enumeration_could_not_be_moved)
+ )
+ end
+
+ replace_via_turbo_stream(
+ component: index_component_class.new(enumerations: enumeration_class.all)
+ )
+
+ respond_with_turbo_streams
+ end
+
+ def reassign
+ @other_enumerations = enumeration_class.all - [@enumeration]
+ end
+
+ def default_breadcrumb; end
+
+ private
+
+ def move_params
+ move_to = params[:move_to]
+ position = Integer(params[:position], exception: false)
+
+ if move_to.in? %w(highest higher lower lowest)
+ { move_to: move_to }
+ elsif position
+ { position: position }
+ else
+ {}
+ end
+ end
+
+ def handle_reassignment_on_deletion
+ reassign_to_id = params.dig(:enumeration, :reassign_to_id)
+
+ if reassign_to_id.present?
+ reassign_to = enumeration_class.find_by(id: reassign_to_id)
+ @enumeration.destroy(reassign_to)
+ flash[:notice] = I18n.t(:notice_successful_delete)
+ redirect_to(action: :index)
+ else
+ redirect_to(action: :reassign, id: @enumeration.id)
+ end
+ end
+
+ def find_enumeration
+ @enumeration = enumeration_class.find(params[:id])
+ end
+
+ def enumeration_class
+ raise NotImplementedError
+ end
+
+ def enumeration_permitted_params
+ permitted_params.enumerations
+ end
+
+ def index_component_class
+ ::Admin::Enumerations::IndexComponent
+ end
+ end
+end
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
deleted file mode 100644
index e466bebf1f4..00000000000
--- a/app/controllers/enumerations_controller.rb
+++ /dev/null
@@ -1,126 +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.
-#++
-
-class EnumerationsController < ApplicationController
- layout "admin"
-
- before_action :require_admin
- before_action :find_enumeration, only: %i[edit update move destroy]
-
- helper_method :enumeration_classes
-
- include CustomFieldsHelper
-
- def index; end
-
- def new
- enum_class = enumeration_class(permitted_params.enumeration_type)
- if enum_class
- @enumeration = enum_class.new
- else
- render_400 # bad request
- end
- end
-
- def edit; end
-
- def create
- enum_params = permitted_params.enumerations
- type = permitted_params.enumeration_type
- @enumeration = (enumeration_class(type) || Enumeration).new do |e|
- e.attributes = enum_params
- end
-
- if @enumeration.save
- flash[:notice] = I18n.t(:notice_successful_create)
- redirect_to action: "index", type: @enumeration.type
- else
- render action: :new, status: :unprocessable_entity
- end
- end
-
- def update
- enum_params = permitted_params.enumerations
- type = permitted_params.enumeration_type
- @enumeration.type = enumeration_class(type).try(:name) || @enumeration.type
- if @enumeration.update enum_params
- flash[:notice] = I18n.t(:notice_successful_update)
- redirect_to enumerations_path(type: @enumeration.type)
- else
- render action: :edit, status: :unprocessable_entity
- end
- end
-
- def destroy
- # No associated objects
- @enumeration.destroy
- redirect_to action: "index"
- return
- elsif params[:reassign_to_id]
- if reassign_to = @enumeration.class.find_by(id: params[:reassign_to_id])
- @enumeration.destroy(reassign_to)
- redirect_to action: "index"
- return
- end
- end
- @enumerations = @enumeration.class.all - [@enumeration]
- end
-
- def move
- if @enumeration.update(permitted_params.enumerations_move)
- flash[:notice] = I18n.t(:notice_successful_update)
- redirect_to enumerations_path
- else
- flash.now[:error] = I18n.t(:error_type_could_not_be_saved)
- render action: :edit, status: :unprocessable_entity
- end
- end
-
- protected
-
- def enumeration_classes
- [DocumentCategory, IssuePriority]
- end
-
- def show_local_breadcrumb
- false
- end
-
- def default_breadcrumb; end
-
- def find_enumeration
- @enumeration = Enumeration.find(params[:id])
- end
-
- ##
- # Find an enumeration class with the given name
- def enumeration_class(type)
- Enumeration.registered_subclasses.detect { |cls| cls.name == type }
- end
-end
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 34e99d76ad0..f1a7546fc57 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -48,26 +48,12 @@ class Enumeration < ApplicationRecord
scope :shared, -> { where(project_id: nil) }
scope :active, -> { where(active: true) }
- # let all child classes have Enumeration as its model name
- # used to not having to create another route for every subclass of Enumeration
- def self.inherited(child)
- # in the long run we probably want to have seperate pages, time entry activities are first so we skipt it here
- enumerations_with_own_settings = %w(TimeEntryActivity)
-
- unless child.name.in?(enumerations_with_own_settings)
- child.instance_eval do
- def model_name
- Enumeration.model_name
- end
- end
- end
- super
- end
-
def self.colored?
false
end
+ delegate :colored?, to: :class
+
def self.default
# Creates a fake default scope so Enumeration.default will check
# its type. STI subclasses will automatically add their own
diff --git a/app/views/admin/settings/work_package_priorities/edit.html.erb b/app/views/admin/settings/work_package_priorities/edit.html.erb
new file mode 100644
index 00000000000..48ae3a3131b
--- /dev/null
+++ b/app/views/admin/settings/work_package_priorities/edit.html.erb
@@ -0,0 +1,48 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% priorities_label = IssuePriority.model_name.human(count: :other) %>
+<% html_title t(:label_administration), priorities_label %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { @enumeration.name }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
+ { href: url_for(action: :index), text: @enumeration.class.model_name.human(count: :other) },
+ @enumeration.name
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
+<% end %>
diff --git a/app/views/admin/settings/work_package_priorities/index.html.erb b/app/views/admin/settings/work_package_priorities/index.html.erb
new file mode 100644
index 00000000000..85786b9e843
--- /dev/null
+++ b/app/views/admin/settings/work_package_priorities/index.html.erb
@@ -0,0 +1,46 @@
+<%#-- 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.
+
+++#%>
+
+<% priorities_label = IssuePriority.model_name.human(count: :other) %>
+<% html_title t(:label_administration), priorities_label %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { priorities_label }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
+ priorities_label
+ ]
+ )
+ end
+%>
+
+<%= render(index_component_class.new(enumerations: @enumerations)) %>
diff --git a/app/views/admin/settings/work_package_priorities/new.html.erb b/app/views/admin/settings/work_package_priorities/new.html.erb
new file mode 100644
index 00000000000..31a3b54415f
--- /dev/null
+++ b/app/views/admin/settings/work_package_priorities/new.html.erb
@@ -0,0 +1,46 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% html_title t(:label_administration), I18n.t("projects.settings.work_package_priorities.new_label") %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { I18n.t("projects.settings.work_package_priorities.new_label") }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_work_package_priorities_path, text: IssuePriority.model_name.human(count: :other) },
+ I18n.t("projects.settings.work_package_priorities.new_label")
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
+<% end %>
diff --git a/app/views/admin/settings/work_package_priorities/reassign.html.erb b/app/views/admin/settings/work_package_priorities/reassign.html.erb
new file mode 100644
index 00000000000..c8ec79750eb
--- /dev/null
+++ b/app/views/admin/settings/work_package_priorities/reassign.html.erb
@@ -0,0 +1,48 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% priorities_label = IssuePriority.model_name.human(count: :other) %>
+<% html_title t(:label_administration), priorities_label %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { @enumeration.name }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
+ { href: url_for(action: :index), text: @enumeration.class.model_name.human(count: :other) },
+ @enumeration.name
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :destroy, id: @enumeration), method: :delete) do |f| %>
+ <%= render(Admin::Enumerations::ReassignForm.new(f, other_enumerations: @other_enumerations)) %>
+<% end %>
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 60d74aaa7e1..355c4285192 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -323,6 +323,12 @@ Redmine::MenuManager.map :admin_menu do |menu|
caption: :label_status,
parent: :admin_work_packages
+ menu.push :priorities,
+ { controller: "/admin/settings/work_package_priorities" },
+ if: ->(_) { User.current.admin? },
+ caption: IssuePriority.model_name.human(count: :other),
+ parent: :admin_work_packages
+
menu.push :progress_tracking,
{ controller: "/admin/settings/progress_tracking", action: :show },
if: ->(_) { User.current.admin? },
@@ -391,11 +397,6 @@ Redmine::MenuManager.map :admin_menu do |menu|
icon: "question",
if: ->(_) { User.current.allowed_globally?(:edit_attribute_help_texts) }
- menu.push :enumerations,
- { controller: "/enumerations" },
- if: ->(_) { User.current.admin? },
- icon: "multi-select"
-
menu.push :calendars_and_dates,
{ controller: "/admin/settings/working_days_and_hours_settings", action: :show },
if: ->(_) { User.current.admin? },
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 91474282b91..ef4b98853b3 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -431,6 +431,8 @@ en:
no_results_content_text: Create a new version
storage:
no_results_title_text: There is no additional recorded disk space consumed by this project.
+ work_package_priorities:
+ new_label: "New priority"
project_stage:
working_days_count:
one: "Duration: %{count} working day"
@@ -1533,6 +1535,9 @@ en:
forum: "Forum"
global_role: "Global role"
group: "Group"
+ issue_priority:
+ one: "Priority"
+ other: "Priorities"
member: "Member"
news: "News"
notification:
@@ -2006,6 +2011,9 @@ en:
enumeration_activities: "Time tracking activities"
enumeration_work_package_priorities: "Work package priorities"
enumeration_reported_project_statuses: "Reported project status"
+ enumeration_caption_order_changed: "Order successfully changed."
+ enumeration_could_not_be_moved: "Enumeration could not be moved."
+
error_auth_source_sso_failed: "Single Sign-On (SSO) for user '%{value}' failed"
error_can_not_archive_project: "This project cannot be archived: %{errors}"
diff --git a/config/routes.rb b/config/routes.rb
index c42f124de9a..9cc53f2e81e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -460,9 +460,6 @@ Rails.application.routes.draw do
delete "enterprise/delete_trial_key" => "enterprises#delete_trial_key"
end
end
- resources :enumerations do
- post "move/:id", action: "move", on: :collection
- end
delete "design/logo" => "custom_styles#logo_delete", as: "custom_style_logo_delete"
delete "design/export_logo" => "custom_styles#export_logo_delete", as: "custom_style_export_logo_delete"
@@ -538,6 +535,13 @@ Rails.application.routes.draw do
# It is important to have this named something else than "work_packages".
# Otherwise the angular ui-router will also recognize that as a WorkPackage page and apply according classes.
resource :work_packages_general, controller: "/admin/settings/work_packages_general", only: %i[show update]
+ resources :work_package_priorities, except: [:show] do
+ member do
+ put :move
+ get :reassign
+ end
+ end
+
resource :progress_tracking, controller: "/admin/settings/progress_tracking", only: %i[show update]
resource :projects, controller: "/admin/settings/projects_settings", only: %i[show update]
resource :new_project, controller: "/admin/settings/new_project_settings", only: %i[show update]
diff --git a/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb b/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb
deleted file mode 100644
index cd5930dd03e..00000000000
--- a/modules/costs/app/components/admin/time_entry_activities/activity_component.html.erb
+++ /dev/null
@@ -1,33 +0,0 @@
-<%=
- component_wrapper do
- flex_layout(align_items: :center, justify_content: :space_between) do |activity_container|
- activity_container.with_column(flex_layout: true) do |activity_info|
- activity_info.with_column(mr: 2) do
- render(Primer::OpenProject::DragHandle.new(draggable: true))
- end
-
- activity_info.with_column(mr: 2) do
- render(Primer::Beta::Link.new(href: edit_admin_time_entry_activity_path(activity), underline: false)) do
- render(Primer::Beta::Text.new(font_weight: :bold)) { activity.name }
- end
- end
-
- activity_info.with_column(mr: 2) do
- render(Primer::Beta::Text.new(color: :subtle)) { activity.active? ? "Active" : "Inactive" }
- end
- end
-
- activity_container.with_column do
- render(Primer::Alpha::ActionMenu.new(test_selector: "op-time-entry-acrtivity--action-menu")) do |menu|
- menu.with_show_button(
- icon: "kebab-horizontal",
- scheme: :invisible,
- "aria-label": "Actions"
- )
-
- build_activity_menu(menu)
- end
- end
- end
- end
-%>
diff --git a/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb b/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb
deleted file mode 100644
index 961d515081e..00000000000
--- a/modules/costs/app/components/admin/time_entry_activities/index_component.html.erb
+++ /dev/null
@@ -1,37 +0,0 @@
-<%=
-component_wrapper do
- flex_layout(data: wrapper_data_attributes) do |flex|
- flex.with_row do
- render(Primer::OpenProject::SubHeader.new) do |subheader|
- subheader.with_action_button(
- scheme: :primary,
- tag: :a,
- href: new_admin_time_entry_activity_path,
- test_selector: "add-activity-button"
- ) do |button|
- button.with_leading_visual_icon(icon: :plus)
- I18n.t(:button_add_activity)
- end
- end
- end
-
- flex.with_row do
- render(border_box_container(data: drop_target_config)) do |component|
- component.with_header(font_weight: :bold) { TimeEntryActivity.model_name.human(count: :other) }
-
- if time_entry_activities.empty?
- component.with_row do
- render(Primer::Beta::Text.new(color: :subtle)) { "No activities exist" }
- end
- else
- time_entry_activities.each do |activity|
- component.with_row(test_selector: "time-entry-activity-row-#{activity.id}", data: draggable_item_config(activity)) do
- render(Admin::TimeEntryActivities::ActivityComponent.new(activity: activity, max_activity_position: max_activity_position))
- end
- end
- end
- end
- end
- end
-end
-%>
diff --git a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb b/modules/costs/app/controllers/admin/time_entry_activities_controller.rb
index c0c76b5a03d..e63d1e02992 100644
--- a/modules/costs/app/controllers/admin/time_entry_activities_controller.rb
+++ b/modules/costs/app/controllers/admin/time_entry_activities_controller.rb
@@ -30,109 +30,18 @@
module Admin
class TimeEntryActivitiesController < ApplicationController
- include OpTurbo::ComponentStream
-
- # Allow only admins here
- before_action :require_admin
- before_action :find_time_entry_activity, only: %i[edit update destroy move reassign]
- layout "admin"
+ include EnumerationsController
menu_item :time_entry_activities
- def index
- @time_entry_activities = TimeEntryActivity.all
- end
-
- def new
- @time_entry_activity = TimeEntryActivity.new
- end
-
- def edit; end
-
- def create
- @time_entry_activity = TimeEntryActivity.new(permitted_params.time_entry_activities)
-
- if @time_entry_activity.save
- flash[:notice] = I18n.t(:notice_successful_update)
- redirect_to(action: :index)
- else
- render action: :new, status: :unprocessable_entity
- end
- end
-
- def update
- if @time_entry_activity.update(permitted_params.time_entry_activities)
- flash[:notice] = I18n.t(:notice_successful_update)
- redirect_to(action: :index)
- else
- render action: :edit, status: :unprocessable_entity
- end
- end
-
- def destroy
- if @time_entry_activity.in_use?
- handle_reassignment_on_deletion
- elsif @time_entry_activity.destroy
- flash[:notice] = I18n.t(:notice_successful_delete)
- redirect_to(action: :index)
- else
- flash.now[:error] = I18n.t(:error_can_not_delete_entry)
- redirect_to(action: :index)
- end
- end
-
- def move
- if @time_entry_activity.update(move_params)
- render_success_flash_message_via_turbo_stream(
- message: I18n.t(:caption_activity_order_changed)
- )
- else
- render_error_flash_message_via_turbo_stream(
- message: I18n.t(:error_activity_could_not_be_moved)
- )
- end
-
- replace_via_turbo_stream(
- component: Admin::TimeEntryActivities::IndexComponent.new(time_entry_activities: TimeEntryActivity.all)
- )
-
- respond_with_turbo_streams
- end
-
- def reassign
- @other_activities = TimeEntryActivity.all - [@time_entry_activity]
- end
-
private
- def move_params
- move_to = params[:move_to]
- position = Integer(params[:position], exception: false)
-
- if move_to.in? %w(highest higher lower lowest)
- { move_to: move_to }
- elsif position
- { position: position }
- else
- {}
- end
- end
-
- def handle_reassignment_on_deletion
- reassign_to_id = params.dig(:time_entry_activity, :reassign_to_id)
-
- if reassign_to_id.present?
- reassign_to = TimeEntryActivity.find_by(id: reassign_to_id)
- @time_entry_activity.destroy(reassign_to)
- flash[:notice] = I18n.t(:notice_successful_delete)
- redirect_to(action: :index)
- else
- redirect_to(action: :reassign, id: @time_entry_activity.id)
- end
+ def enumeration_class
+ TimeEntryActivity
end
- def find_time_entry_activity
- @time_entry_activity = TimeEntryActivity.find(params[:id])
+ def enumeration_param_key
+ enumeration_class.model_name.param_key
end
end
end
diff --git a/modules/costs/app/views/admin/time_entry_activities/edit.html.erb b/modules/costs/app/views/admin/time_entry_activities/edit.html.erb
index 36a5d748f67..7262cec808d 100644
--- a/modules/costs/app/views/admin/time_entry_activities/edit.html.erb
+++ b/modules/costs/app/views/admin/time_entry_activities/edit.html.erb
@@ -30,19 +30,19 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
- header.with_title { @time_entry_activity.name }
+ header.with_title { @enumeration.name }
header.with_description { I18n.t(:label_time_entry_activity_form_description) }
header.with_breadcrumbs(
[
{ href: admin_index_path, text: t("label_administration") },
{ href: admin_costs_settings_path, text: t(:project_module_costs) },
{ href: admin_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },
- @time_entry_activity.name
+ @enumeration.name
]
)
end
%>
-<%= primer_form_with(model: @time_entry_activity, url: admin_time_entry_activity_path(@time_entry_activity)) do |f| %>
- <%= render(Admin::TimeEntryActivities::ActivityForm.new(f)) %>
+<%= primer_form_with(model: @enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>
diff --git a/modules/costs/app/views/admin/time_entry_activities/index.html.erb b/modules/costs/app/views/admin/time_entry_activities/index.html.erb
index 0e6c902e0d6..ab1000d3619 100644
--- a/modules/costs/app/views/admin/time_entry_activities/index.html.erb
+++ b/modules/costs/app/views/admin/time_entry_activities/index.html.erb
@@ -42,4 +42,4 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= render(Admin::TimeEntryActivities::IndexComponent.new(time_entry_activities: @time_entry_activities)) %>
+<%= render(index_component_class.new(enumerations: @enumerations)) %>
diff --git a/modules/costs/app/views/admin/time_entry_activities/new.html.erb b/modules/costs/app/views/admin/time_entry_activities/new.html.erb
index a8458e5cae4..cc6ec6f721f 100644
--- a/modules/costs/app/views/admin/time_entry_activities/new.html.erb
+++ b/modules/costs/app/views/admin/time_entry_activities/new.html.erb
@@ -43,6 +43,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= primer_form_with(model: @time_entry_activity, url: admin_time_entry_activities_path) do |f| %>
- <%= render(Admin::TimeEntryActivities::ActivityForm.new(f)) %>
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>
diff --git a/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb b/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb
index e6512464997..d12f07b93c9 100644
--- a/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb
+++ b/modules/costs/app/views/admin/time_entry_activities/reassign.html.erb
@@ -30,19 +30,19 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Primer::OpenProject::PageHeader.new) do |header|
- header.with_title { @time_entry_activity.name }
- header.with_description { t(:text_enumeration_destroy_question, count: @time_entry_activity.objects_count) }
+ header.with_title { @enumeration.name }
+ header.with_description { t(:text_enumeration_destroy_question, count: @enumeration.objects_count) }
header.with_breadcrumbs(
[
{ href: admin_index_path, text: t("label_administration") },
{ href: admin_costs_settings_path, text: t(:project_module_costs) },
{ href: admin_time_entry_activities_path, text: TimeEntryActivity.model_name.human(count: :other) },
- @time_entry_activity.name
+ @enumeration.name
]
)
end
%>
-<%= primer_form_with(model: @time_entry_activity, url: admin_time_entry_activity_path(@time_entry_activity), method: :delete) do |f| %>
- <%= render(Admin::TimeEntryActivities::ReassignForm.new(f, other_activities: @other_activities)) %>
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :destroy, id: @enumeration), method: :delete) do |f| %>
+ <%= render(Admin::Enumerations::ReassignForm.new(f, other_enumerations: @other_enumerations)) %>
<% end %>
diff --git a/modules/costs/config/locales/en.yml b/modules/costs/config/locales/en.yml
index f9a4fbb5871..de58218636e 100644
--- a/modules/costs/config/locales/en.yml
+++ b/modules/costs/config/locales/en.yml
@@ -109,13 +109,11 @@ en:
caption_set_rate: "Set current rate"
caption_show_locked: "Show locked types"
caption_log_time_dialog: "Log time"
- caption_activity_order_changed: "Order successfully changed."
description_date_for_new_rate: "Date for new rate"
description_costs_settings: "Define the desired format for the costs in all projects."
description_time_settings: "Define which fields are mandatory to fill when logging time in all projects."
- error_activity_could_not_be_moved: "Activity could not be moved."
group_by_others: "not in any group"
diff --git a/modules/costs/lib/costs/patches/permitted_params_patch.rb b/modules/costs/lib/costs/patches/permitted_params_patch.rb
index aeb7cf493d6..c3d4d269c68 100644
--- a/modules/costs/lib/costs/patches/permitted_params_patch.rb
+++ b/modules/costs/lib/costs/patches/permitted_params_patch.rb
@@ -86,9 +86,5 @@ module Costs::Patches::PermittedParamsPatch
)
.merge(custom_field_values(:time_entry))
end
-
- def time_entry_activities
- params.require(:time_entry_activity).permit(:name, :active)
- end
end
end
diff --git a/modules/costs/spec/features/time_entry/activity_spec.rb b/modules/costs/spec/features/time_entry/activity_spec.rb
index 69c305c4612..33377a8273d 100644
--- a/modules/costs/spec/features/time_entry/activity_spec.rb
+++ b/modules/costs/spec/features/time_entry/activity_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe "Time entry activity" do
it "allows creating new activities and activating them on projects" do
visit admin_time_entry_activities_path
- page.find_test_selector("add-activity-button").click
+ page.find_test_selector("add-enumeration-button").click
fill_in "Name", with: "A new activity"
click_on("Save")
diff --git a/modules/documents/app/controllers/admin/settings/document_categories_controller.rb b/modules/documents/app/controllers/admin/settings/document_categories_controller.rb
new file mode 100644
index 00000000000..342febef3ba
--- /dev/null
+++ b/modules/documents/app/controllers/admin/settings/document_categories_controller.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Admin
+ module Settings
+ class DocumentCategoriesController < ApplicationController
+ include EnumerationsController
+
+ menu_item :document_categories
+
+ private
+
+ def enumeration_class
+ DocumentCategory
+ end
+ end
+ end
+end
diff --git a/modules/documents/app/views/admin/settings/document_categories/edit.html.erb b/modules/documents/app/views/admin/settings/document_categories/edit.html.erb
new file mode 100644
index 00000000000..61242a48df3
--- /dev/null
+++ b/modules/documents/app/views/admin/settings/document_categories/edit.html.erb
@@ -0,0 +1,47 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% html_title t(:label_administration), t("documents.categories") %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { @enumeration.name }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_storages_path, text: t("project_module_storages") },
+ { href: url_for(action: :index), text: t("documents.categories") },
+ @enumeration.name
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
+<% end %>
diff --git a/modules/documents/app/views/admin/settings/document_categories/index.html.erb b/modules/documents/app/views/admin/settings/document_categories/index.html.erb
new file mode 100644
index 00000000000..e4abe0827dc
--- /dev/null
+++ b/modules/documents/app/views/admin/settings/document_categories/index.html.erb
@@ -0,0 +1,45 @@
+<%#-- 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("documents.label_categories") %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { t("documents.label_categories") }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_storages_path, text: t("project_module_storages") },
+ t("documents.label_categories")
+ ]
+ )
+ end
+%>
+
+<%= render(index_component_class.new(enumerations: @enumerations)) %>
diff --git a/modules/documents/app/views/admin/settings/document_categories/new.html.erb b/modules/documents/app/views/admin/settings/document_categories/new.html.erb
new file mode 100644
index 00000000000..ff084d218ec
--- /dev/null
+++ b/modules/documents/app/views/admin/settings/document_categories/new.html.erb
@@ -0,0 +1,46 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% html_title t(:label_administration), t("documents.new_category") %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { I18n.t("documents.new_category") }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_storages_path, text: t("project_module_storages") },
+ t("documents.new_category")
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %>
+ <%= render(Admin::Enumerations::ItemForm.new(f)) %>
+<% end %>
diff --git a/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb b/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb
new file mode 100644
index 00000000000..e5b5c67cbb8
--- /dev/null
+++ b/modules/documents/app/views/admin/settings/document_categories/reassign.html.erb
@@ -0,0 +1,47 @@
+<%#-- 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.v
+See COPYRIGHT and LICENSE files for more details.
+
+++#%>
+
+<% html_title t(:label_administration), t("documents.categories") %>
+
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { @enumeration.name }
+ header.with_breadcrumbs(
+ [
+ { href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_storages_path, text: t("project_module_storages") },
+ { href: url_for(action: :index), text: t("documents.categories") },
+ @enumeration.name
+ ]
+ )
+ end
+%>
+
+<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :delete, id: @enumeration), method: :delete) do |f| %>
+ <%= render(Admin::Enumerations::ReassignForm.new(f, other_enumerations: @other_enumerations)) %>
+<% end %>
diff --git a/modules/documents/config/locales/en.yml b/modules/documents/config/locales/en.yml
index a64cba91932..f51cac5d8e8 100644
--- a/modules/documents/config/locales/en.yml
+++ b/modules/documents/config/locales/en.yml
@@ -46,6 +46,8 @@ en:
documents:
label_attachment_author: "Attachment author"
+ label_categories: "Categories"
+ new_category: "New category"
label_document_added: "Document added"
label_document_new: "New document"
diff --git a/modules/documents/config/routes.rb b/modules/documents/config/routes.rb
index 42104f8af97..de24a3b3768 100644
--- a/modules/documents/config/routes.rb
+++ b/modules/documents/config/routes.rb
@@ -32,4 +32,15 @@ Rails.application.routes.draw do
end
resources :documents, except: %i[create new index]
+
+ namespace :admin do
+ namespace :settings do
+ resources :document_categories, except: [:show] do
+ member do
+ put :move
+ get :reassign
+ end
+ end
+ end
+ end
end
diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb
index c8d6e1e85d5..f8aae7c5b3e 100644
--- a/modules/documents/lib/open_project/documents/engine.rb
+++ b/modules/documents/lib/open_project/documents/engine.rb
@@ -52,6 +52,13 @@ module OpenProject::Documents
require: :loggedin
end
+ menu :admin_menu,
+ :document_categories,
+ { controller: "/admin/settings/document_categories", action: :index },
+ if: ->(_) { User.current.admin? },
+ caption: :"documents.label_categories",
+ parent: :files
+
Redmine::Search.register :documents
end
diff --git a/spec/features/admin/enumerations_spec.rb b/modules/documents/spec/features/document_categories_spec.rb
similarity index 74%
rename from spec/features/admin/enumerations_spec.rb
rename to modules/documents/spec/features/document_categories_spec.rb
index d0b568c6cc4..dc32243c452 100644
--- a/spec/features/admin/enumerations_spec.rb
+++ b/modules/documents/spec/features/document_categories_spec.rb
@@ -28,21 +28,24 @@
require "spec_helper"
-RSpec.describe "Enumerations" do
+RSpec.describe "Document categories" do
shared_let(:admin) { create(:admin) }
before do
login_as(admin)
- visit enumerations_path
end
- it "contains all defined enumerations" do
- classes = Enumeration.subclasses - [TimeEntryActivity]
+ it "allows creating new document categories" do
+ visit admin_settings_document_categories_path
- classes.each do |enumeration|
- expect(page).to have_css("h3", text: I18n.t(enumeration::OptionName))
- expect(page).to have_link(I18n.t(:label_enumeration_new),
- href: new_enumeration_path(type: enumeration.name))
- end
+ page.find_test_selector("add-enumeration-button").click
+
+ fill_in "Name", with: "Documentation"
+ click_on("Save")
+
+ # we are redirected back to the index page
+ expect(page).to have_current_path(admin_settings_document_categories_path)
+
+ expect(page).to have_content("Documentation")
end
end
diff --git a/modules/documents/spec/requests/admin/settings/document_categories_spec.rb b/modules/documents/spec/requests/admin/settings/document_categories_spec.rb
new file mode 100644
index 00000000000..8225ba50b0f
--- /dev/null
+++ b/modules/documents/spec/requests/admin/settings/document_categories_spec.rb
@@ -0,0 +1,91 @@
+# 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"
+
+RSpec.describe "Document categories",
+ :aggregate_failures,
+ :skip_csrf,
+ type: :rails_request do
+ shared_let(:admin) { create(:admin) }
+ shared_let(:category) { create(:document_category, name: "Technical") }
+ shared_let(:other_category) { create(:document_category, name: "Other") }
+
+ before do
+ login_as(admin)
+ end
+
+ describe "GET /admin/settings/document_categories" do
+ it "renders the index template" do
+ get admin_settings_document_categories_path
+ expect(response).to have_http_status(:ok)
+ expect(response.body).to include "Technical"
+ expect(response.body).to include "Other"
+ end
+ end
+
+ describe "DELETE /admin/settings/document_categories/:id" do
+ let(:params) { {} }
+
+ context "without documents assigned" do
+ it "redirects to the categories index" do
+ delete(admin_settings_document_category_path(category), params:)
+ expect(response).to redirect_to admin_settings_document_categories_path
+ expect { category.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context "with documents assigned" do
+ shared_let(:document) { create(:document, category:) }
+
+ it "renders the reassign template" do
+ delete(admin_settings_document_category_path(category), params:)
+ expect(response).to redirect_to reassign_admin_settings_document_category_path(category)
+ expect { category.reload }.not_to raise_error
+ expect(document.reload.category).to eq category
+ end
+
+ context "with documents assigned and reassigning" do
+ let(:params) do
+ {
+ enumeration: { reassign_to_id: other_category.id }
+ }
+ end
+
+ it "reassigns the category" do
+ delete(admin_settings_document_category_path(category), params:)
+ expect(response).to redirect_to admin_settings_document_categories_path
+ expect { category.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ expect(document.reload.category).to eq other_category
+ end
+ end
+ end
+ end
+end
diff --git a/spec/routing/enumerations_spec.rb b/modules/documents/spec/routing/document_categories_spec.rb
similarity index 50%
rename from spec/routing/enumerations_spec.rb
rename to modules/documents/spec/routing/document_categories_spec.rb
index f3e09fdf24a..993da4d15a3 100644
--- a/spec/routing/enumerations_spec.rb
+++ b/modules/documents/spec/routing/document_categories_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -28,39 +30,36 @@
require "spec_helper"
-RSpec.describe EnumerationsController, "routing" do
- context "admin scoped" do
+RSpec.describe Admin::Settings::DocumentCategoriesController, "routing" do
+ describe "document categories" do
it {
- expect(subject).to route(:get, "admin/enumerations").to(controller: "enumerations",
- action: "index")
+ expect(subject).to route(:get, "admin/settings/document_categories")
+ .to(controller: "admin/settings/document_categories", action: "index")
}
it {
- expect(subject).to route(:get, "admin/enumerations/new").to(controller: "enumerations",
- action: "new")
+ expect(subject).to route(:get, "admin/settings/document_categories/new")
+ .to(controller: "admin/settings/document_categories", action: "new")
}
it {
- expect(subject).to route(:post, "admin/enumerations").to(controller: "enumerations",
- action: "create")
+ expect(subject).to route(:post, "admin/settings/document_categories")
+ .to(controller: "admin/settings/document_categories", action: "create")
}
it {
- expect(subject).to route(:get, "admin/enumerations/1/edit").to(controller: "enumerations",
- action: "edit",
- id: "1")
+ expect(subject).to route(:get, "admin/settings/document_categories/1/edit")
+ .to(controller: "admin/settings/document_categories", action: "edit", id: "1")
}
it {
- expect(subject).to route(:put, "admin/enumerations/1").to(controller: "enumerations",
- action: "update",
- id: "1")
+ expect(subject).to route(:put, "admin/settings/document_categories/1")
+ .to(controller: "admin/settings/document_categories", action: "update", id: "1")
}
it {
- expect(subject).to route(:delete, "admin/enumerations/1").to(controller: "enumerations",
- action: "destroy",
- id: "1")
+ expect(subject).to route(:delete, "admin/settings/document_categories/1")
+ .to(controller: "admin/settings/document_categories", action: "destroy", id: "1")
}
end
end
diff --git a/spec/controllers/enumerations_controller_spec.rb b/spec/controllers/enumerations_controller_spec.rb
deleted file mode 100644
index fd76e5b054f..00000000000
--- a/spec/controllers/enumerations_controller_spec.rb
+++ /dev/null
@@ -1,110 +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.
-#++
-
-require "spec_helper"
-
-RSpec.describe EnumerationsController do
- shared_let(:admin) { create(:admin) }
-
- current_user do
- admin
- end
-
- describe "#index" do
- before do
- get :index
- end
-
- it "is successful" do
- expect(response)
- .to have_http_status(:ok)
- end
-
- it "renders the index template" do
- expect(response)
- .to render_template "index"
- end
- end
-
- describe "#destroy" do
- let(:enum) { create(:priority) }
- let(:params) { { id: enum.id } }
- let(:work_packages) { [] }
-
- before do
- work_packages
-
- delete :destroy, params:
- end
-
- it "redirects" do
- expect(response)
- .to redirect_to enumerations_path
- end
-
- it "destroys the enum" do
- expect(Enumeration.where(id: enum.id))
- .not_to exist
- end
-
- context "when in use" do
- let(:work_packages) { [create(:work_package, priority: enum)] }
-
- it "keeps the enum (as it needs to be reassigned)" do
- expect(Enumeration.where(id: enum.id))
- .to exist
- end
-
- it "keeps the usage" do
- expect(work_packages.first.reload.priority)
- .to eql enum
- end
-
- it "renders destroy template" do
- expect(response)
- .to render_template :destroy
- end
- end
-
- context "when in use and reassigning" do
- let(:work_packages) { [create(:work_package, priority: enum)] }
- let!(:other_enum) { create(:priority) }
- let(:params) { { id: enum.id, reassign_to_id: other_enum.id } }
-
- it "destroys the enum" do
- expect(Enumeration.where(id: enum.id))
- .not_to exist
- end
-
- it "reassigns the usage" do
- expect(work_packages.first.reload.priority)
- .to eql other_enum
- end
- end
- end
-end
diff --git a/spec/features/admin/settings/work_package_priorities_spec.rb b/spec/features/admin/settings/work_package_priorities_spec.rb
new file mode 100644
index 00000000000..847690abdd9
--- /dev/null
+++ b/spec/features/admin/settings/work_package_priorities_spec.rb
@@ -0,0 +1,53 @@
+# 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"
+
+RSpec.describe "Work package priorities" do
+ shared_let(:admin) { create(:admin) }
+
+ before do
+ login_as(admin)
+ end
+
+ it "allows creating new priorities" do
+ visit admin_settings_work_package_priorities_path
+
+ page.find_test_selector("add-enumeration-button").click
+
+ fill_in "Name", with: "Immediate"
+ click_on("Save")
+
+ # we are redirected back to the index page
+ expect(page).to have_current_path(admin_settings_work_package_priorities_path)
+
+ expect(page).to have_content("Immediate")
+ end
+end
diff --git a/spec/features/menu_items/admin_menu_item_spec.rb b/spec/features/menu_items/admin_menu_item_spec.rb
index 2f73efd158c..5bb505e0fc3 100644
--- a/spec/features/menu_items/admin_menu_item_spec.rb
+++ b/spec/features/menu_items/admin_menu_item_spec.rb
@@ -44,8 +44,8 @@ RSpec.describe "Admin menu items",
context "without having any menu items hidden in configuration" do
it "must display all menu items" do
expect(page).to have_test_selector("menu-blocks--container")
- expect(page).to have_test_selector("menu-block", count: 21)
- expect(page).to have_test_selector("op-menu--item-action", count: 22) # All plus 'overview'
+ expect(page).to have_test_selector("menu-block", count: 20)
+ expect(page).to have_test_selector("op-menu--item-action", count: 21) # All plus 'overview'
end
end
@@ -55,10 +55,10 @@ RSpec.describe "Admin menu items",
} do
it "must not display the hidden menu items and blocks" do
expect(page).to have_test_selector("menu-blocks--container")
- expect(page).to have_test_selector("menu-block", count: 20)
+ expect(page).to have_test_selector("menu-block", count: 19)
expect(page).not_to have_test_selector("menu-block", text: I18n.t(:label_color_plural))
- expect(page).to have_test_selector("op-menu--item-action", count: 21) # All plus 'overview'
+ expect(page).to have_test_selector("op-menu--item-action", count: 20) # All plus 'overview'
expect(page).not_to have_test_selector("op-menu--item-action", text: I18n.t(:label_color_plural))
end
end
diff --git a/spec/requests/admin/settings/work_package_priorities_spec.rb b/spec/requests/admin/settings/work_package_priorities_spec.rb
new file mode 100644
index 00000000000..56630e8371d
--- /dev/null
+++ b/spec/requests/admin/settings/work_package_priorities_spec.rb
@@ -0,0 +1,91 @@
+# 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"
+
+RSpec.describe "Work package priorities",
+ :aggregate_failures,
+ :skip_csrf,
+ type: :rails_request do
+ shared_let(:admin) { create(:admin) }
+ shared_let(:priority) { create(:issue_priority, name: "High") }
+ shared_let(:other_priority) { create(:issue_priority, name: "Other") }
+
+ before do
+ login_as(admin)
+ end
+
+ describe "GET /admin/settings/work_package_priorities" do
+ it "renders the index template" do
+ get admin_settings_work_package_priorities_path
+ expect(response).to have_http_status(:ok)
+ expect(response.body).to include "High"
+ expect(response.body).to include "Other"
+ end
+ end
+
+ describe "DELETE /admin/settings/work_package_priorities/:id" do
+ let(:params) { {} }
+
+ context "without work packages assigned" do
+ it "redirects to the priorities index" do
+ delete(admin_settings_work_package_priority_path(priority), params:)
+ expect(response).to redirect_to admin_settings_work_package_priorities_path
+ expect { priority.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
+ context "with work packages assigned" do
+ shared_let(:work_package) { create(:work_package, priority:) }
+
+ it "renders the reassign template" do
+ delete(admin_settings_work_package_priority_path(priority), params:)
+ expect(response).to redirect_to reassign_admin_settings_work_package_priority_path(priority)
+ expect { priority.reload }.not_to raise_error
+ expect(work_package.reload.priority).to eq priority
+ end
+
+ context "with work packages assigned and reassigning" do
+ let(:params) do
+ {
+ enumeration: { reassign_to_id: other_priority.id }
+ }
+ end
+
+ it "reassigns the priority" do
+ delete(admin_settings_work_package_priority_path(priority), params:)
+ expect(response).to redirect_to admin_settings_work_package_priorities_path
+ expect { priority.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ expect(work_package.reload.priority).to eq other_priority
+ end
+ end
+ end
+ end
+end
diff --git a/spec/routing/admin/settings/work_package_priorities_spec.rb b/spec/routing/admin/settings/work_package_priorities_spec.rb
new file mode 100644
index 00000000000..8e224969816
--- /dev/null
+++ b/spec/routing/admin/settings/work_package_priorities_spec.rb
@@ -0,0 +1,63 @@
+#-- 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"
+
+RSpec.describe Admin::Settings::WorkPackagePrioritiesController, "routing" do
+ describe "work package priorities" do
+ it {
+ expect(subject).to route(:get, "admin/settings/work_package_priorities")
+ .to(controller: "admin/settings/work_package_priorities", action: "index")
+ }
+
+ it {
+ expect(subject).to route(:get, "admin/settings/work_package_priorities/new")
+ .to(controller: "admin/settings/work_package_priorities", action: "new")
+ }
+
+ it {
+ expect(subject).to route(:post, "admin/settings/work_package_priorities")
+ .to(controller: "admin/settings/work_package_priorities", action: "create")
+ }
+
+ it {
+ expect(subject).to route(:get, "admin/settings/work_package_priorities/1/edit")
+ .to(controller: "admin/settings/work_package_priorities", action: "edit", id: "1")
+ }
+
+ it {
+ expect(subject).to route(:put, "admin/settings/work_package_priorities/1")
+ .to(controller: "admin/settings/work_package_priorities", action: "update", id: "1")
+ }
+
+ it {
+ expect(subject).to route(:delete, "admin/settings/work_package_priorities/1")
+ .to(controller: "admin/settings/work_package_priorities", action: "destroy", id: "1")
+ }
+ end
+end