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

Update error message to include links to archived projects

Aaron Contrerasfcfc66c90a8e
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb
index d2a62840334..1def471e953 100644
--- a/app/controllers/types_controller.rb
+++ b/app/controllers/types_controller.rb
@@ -178,11 +178,11 @@ class TypesController < ApplicationController
)
]
- archived_projects = @type.projects.filter(&:archived?)
- if !archived_projects.empty?
- error_message.push(
+ if archived_projects.any?
+ error_message << ApplicationController.helpers.sanitize(
t(:'error_can_not_delete_type.archived_projects',
- archived_projects: archived_projects.map(&:name).join(', '))
+ archived_projects_urls: helpers.archived_projects_urls_for(archived_projects)),
+ attributes: %w(href target)
)
end
@@ -193,4 +193,8 @@ class TypesController < ApplicationController
def belonging_wps_url(type_id)
work_packages_path query_props: "{\"f\":[{\"n\":\"type\",\"o\":\"=\",\"v\":[#{type_id}]}]}"
end
+
+ def archived_projects
+ @archived_projects ||= @type.projects.archived
+ end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 3733b2f8fa6..bb82a97d931 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -157,6 +157,7 @@ class Project < ApplicationRecord
scope :visible, ->(user = User.current) { where(id: Project.visible_by(user)) }
scope :newest, -> { order(created_at: :desc) }
scope :active, -> { where(active: true) }
+ scope :archived, -> { where(active: false) }
scope :with_member, ->(user = User.current) { where(id: user.memberships.select(:project_id)) }
scope :without_member, ->(user = User.current) { where.not(id: user.memberships.select(:project_id)) }
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 44d319d8c0b..8941930dd7b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1362,7 +1362,7 @@ en:
error_can_not_delete_custom_field: "Unable to delete custom field"
error_can_not_delete_type:
explanation: 'This type contains work packages and cannot be deleted. You can see all affected work packages in <a target="_blank" href="%{url}">this view</a>.'
- archived_projects: 'There are also work packages in archived projects. You need to reactivate the following projects first, before you can change the type of the respective work packages: %{archived_projects}'
+ archived_projects: 'There are also work packages in archived projects. You need to reactivate the following projects first, before you can change the type of the respective work packages: %{archived_projects_urls}'
error_can_not_delete_standard_type: "Standard types cannot be deleted."
error_can_not_invite_user: "Failed to send invitation to user."
error_can_not_remove_role: "This role is in use and cannot be deleted."
diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rb
index 4962c67b921..6956d23fdd1 100644
--- a/spec/controllers/types_controller_spec.rb
+++ b/spec/controllers/types_controller_spec.rb
@@ -367,9 +367,9 @@ RSpec.describe TypesController do
end
describe 'destroy type in use should fail' do
- let(:project2) do
+ let(:archived_project) do
create(:project,
- active: false,
+ :archived,
work_package_custom_fields: [custom_field_2],
types: [type2])
end
@@ -377,10 +377,20 @@ RSpec.describe TypesController do
create(:work_package,
author: current_user,
type: type2,
- project: project2)
+ project: archived_project)
end
let(:params) { { 'id' => type2.id } }
+ let(:error_message) do
+ archived_projects_urls = described_class
+ .helpers
+ .archived_projects_urls_for([archived_project])
+ [
+ I18n.t(:'error_can_not_delete_type.explanation'),
+ I18n.t(:'error_can_not_delete_type.archived_projects', archived_projects_urls:)
+ ]
+ end
+
before do
delete :destroy, params:
end
@@ -389,10 +399,6 @@ RSpec.describe TypesController do
it { expect(response).to redirect_to(types_path) }
it 'shows an error message' do
- error_message = [I18n.t(:'error_can_not_delete_type.explanation')]
- error_message.push(I18n.t(:'error_can_not_delete_type.archived_projects',
- archived_projects: project2.name))
-
expect(sanitize_string(flash[:error])).to eq(sanitize_string(error_message))
end