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

show warning bar if workflow is missing

ulferts535198c8d72c
diff --git a/app/helpers/warning_bar_helper.rb b/app/helpers/warning_bar_helper.rb
index 206e6075fae..e945572c73c 100644
--- a/app/helpers/warning_bar_helper.rb
+++ b/app/helpers/warning_bar_helper.rb
@@ -39,6 +39,11 @@ module WarningBarHelper
(setting_protocol_mismatched? || setting_hostname_mismatched?)
end
+ def render_workflow_missing_warning?
+ current_user.admin? &&
+ no_workflow_for_wp_edit_role?
+ end
+
def setting_protocol_mismatched?
request.ssl? != OpenProject::Configuration.https?
end
@@ -47,6 +52,17 @@ module WarningBarHelper
Setting.host_name.gsub(/:\d+$/, '') != request.host
end
+ def no_workflow_for_wp_edit_role?
+ workflow_exists = OpenProject::Cache.read('no_wp_share_editor_workflow')
+
+ if workflow_exists.nil?
+ workflow_exists = Workflow.exists?(role_id: Role.where(builtin: Role::BUILTIN_WORK_PACKAGE_EDITOR).select(:id))
+ OpenProject::Cache.write('no_wp_share_editor_workflow', workflow_exists) if workflow_exists
+ end
+
+ !workflow_exists
+ end
+
##
# By default, never show a warning bar in the
# test mode due to overshadowing other elements.
diff --git a/app/views/warning_bar/_missing_wp_edit_role_workflows.html.erb b/app/views/warning_bar/_missing_wp_edit_role_workflows.html.erb
new file mode 100644
index 00000000000..832eef70956
--- /dev/null
+++ b/app/views/warning_bar/_missing_wp_edit_role_workflows.html.erb
@@ -0,0 +1,9 @@
+<div class="warning-bar--item">
+ <p>
+ <strong><%= t('work_packages.sharing.missing_workflow_waring.title') %></strong><br>
+
+ <%= t('work_packages.sharing.missing_workflow_waring.message') %>
+ <%= link_to t('work_packages.sharing.missing_workflow_waring.link_message'),
+ copy_workflows_path %>
+ </p>
+</div>
diff --git a/app/views/warning_bar/_warning_bar.html.erb b/app/views/warning_bar/_warning_bar.html.erb
index fc369ea217e..952abc2fc83 100644
--- a/app/views/warning_bar/_warning_bar.html.erb
+++ b/app/views/warning_bar/_warning_bar.html.erb
@@ -3,5 +3,6 @@
<%= render partial: 'warning_bar/host_and_protocol_mismatch' if render_host_and_protocol_mismatch? %>
<%= render partial: 'warning_bar/pending_migrations' if render_pending_migrations_warning? %>
<%= render partial: 'warning_bar/unsupported_browser' if unsupported_browser? %>
+ <%= render partial: 'warning_bar/missing_wp_edit_role_workflows' if render_workflow_missing_warning? %>
</div>
<% end %>
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index 4c9f031867a..d8c07116942 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -912,7 +912,8 @@ module Settings
},
show_warning_bars: {
description: 'Render warning bars (pending migrations, deprecation, unsupported browsers)',
- default: true,
+ # Hide warning bars by default in tests as they might overlay other elements
+ default: -> { !Rails.env.test? },
writable: false
},
smtp_authentication: {
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 3e69e844065..1ec8c1ceb2d 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -446,6 +446,12 @@ en:
no_common_statuses_exists: "There is no status available for all selected work packages. Their status cannot be changed."
unsupported_for_multiple_projects: "Bulk move/copy is not supported for work packages from multiple projects"
+ sharing:
+ missing_workflow_waring:
+ title: "Workflow missing for work package sharing"
+ message: "No workflow configured for the 'Work package editor' role. Without a workflow, the status of a shared work package cannot be changed."
+ link_message: "Configure a workflow in the administration."
+
summary:
reports:
category:
diff --git a/lib/open_project/cache.rb b/lib/open_project/cache.rb
index b291d218b2b..9f6259e4350 100644
--- a/lib/open_project/cache.rb
+++ b/lib/open_project/cache.rb
@@ -30,8 +30,16 @@ require_relative 'cache/cache_key'
module OpenProject
module Cache
- def self.fetch(*parts, **options, &)
- Rails.cache.fetch(CacheKey.key(*parts), **options, &)
+ def self.fetch(*, **, &)
+ Rails.cache.fetch(CacheKey.key(*), **, &)
+ end
+
+ def self.read(name, **, &)
+ Rails.cache.read(CacheKey.key(name), **, &)
+ end
+
+ def self.write(name, value, **, &)
+ Rails.cache.write(CacheKey.key(name), value, **, &)
end
def self.clear
diff --git a/spec/features/workflows/missing_for_sharing_wp_spec.rb b/spec/features/workflows/missing_for_sharing_wp_spec.rb
new file mode 100644
index 00000000000..54269bcfaab
--- /dev/null
+++ b/spec/features/workflows/missing_for_sharing_wp_spec.rb
@@ -0,0 +1,86 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 'Configuring the workflow for work package sharing',
+ with_config: { show_warning_bars: true } do
+ let!(:role) { create(:project_role) }
+ let!(:work_package_role) { create(:edit_work_package_role) }
+ let!(:type) { create(:type) }
+ let!(:start_status) { create(:status) }
+ let!(:end_status) { create(:status) }
+ let!(:workflow) do
+ create(:workflow,
+ role_id: role.id,
+ type_id: type.id,
+ old_status_id: start_status.id,
+ new_status_id: end_status.id,
+ author: false,
+ assignee: false)
+ end
+
+ current_user { create(:admin) }
+
+ before do
+ visit home_url
+ end
+
+ it 'shows a warning until a workflow is configured for the work package edit role' do
+ # There is a warning bar at the bottom informing of the missing workflow
+ within '.warning-bar--item' do
+ expect(page)
+ .to have_content("No workflow configured for the '#{work_package_role.name}' role. " \
+ "Without a workflow, the status of a shared work package cannot be changed.")
+
+ click_link "Configure a workflow"
+ end
+
+ # On the copy workflow form, select the already existing workflow for copying
+ select type.name, from: 'source_type_id'
+ select role.name, from: 'source_role_id'
+ select type.name, from: 'target_type_ids'
+ select work_package_role.name, from: 'target_role_ids'
+
+ click_button 'Copy'
+
+ # Copying succeeds which results in the edit role having a workflow and the warning disappearing.
+ expect(page)
+ .to have_content 'Successful update'
+
+ expect(Workflow.where(role_id: work_package_role.id,
+ type_id: type.id,
+ old_status_id: start_status.id,
+ new_status_id: end_status.id,
+ author: false,
+ assignee: false).count).to eq(1)
+
+ expect(page)
+ .not_to have_css('.warning-bar--item')
+ end
+end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 0bf0d78bf4b..56d6a2921d8 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -103,7 +103,4 @@ RSpec.configure do |config|
config.include ActiveJob::TestHelper
OpenProject::Configuration['attachments_storage_path'] = 'tmp/files'
-
- # Hide warning bars by default
- OpenProject::Configuration['show_warning_bars'] = false
end