diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 77f5454f767..3f32fa18afb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -308,8 +308,6 @@ module ApplicationHelper css << "ee-banners-#{EnterpriseToken.show_banners? ? 'visible' : 'hidden'}" - css << "bcf-#{@project&.module_enabled?(:bcf) ? 'activated' : 'deactivated'}" - # Add browser specific classes to aid css fixes css += browser_specific_classes diff --git a/app/helpers/work_packages_filter_helper.rb b/app/helpers/work_packages_filter_helper.rb index f259705b529..5e03fa2e719 100644 --- a/app/helpers/work_packages_filter_helper.rb +++ b/app/helpers/work_packages_filter_helper.rb @@ -214,20 +214,6 @@ module WorkPackagesFilterHelper project_work_packages_with_query_path(version.project, query, options) end - def project_work_packages_bcf_issues_path(project) - query = { - f: [ - filter_object('status_id', 'o') - ], - hi: true, - hl: 'priority', - t: 'created_at:desc', - dr: 'card' - } - - project_work_packages_with_query_path(project, query) - end - private def default_sort diff --git a/frontend/src/app/components/wp-query-select/wp-static-queries.service.ts b/frontend/src/app/components/wp-query-select/wp-static-queries.service.ts index 5a52d59f6a7..c7e935a573a 100644 --- a/frontend/src/app/components/wp-query-select/wp-static-queries.service.ts +++ b/frontend/src/app/components/wp-query-select/wp-static-queries.service.ts @@ -59,7 +59,6 @@ export class WorkPackageStaticQueriesService { recently_created: this.I18n.t('js.work_packages.default_queries.recently_created'), all_open: this.I18n.t('js.work_packages.default_queries.all_open'), summary: this.I18n.t('js.work_packages.default_queries.summary'), - bcf_issues: this.I18n.t('js.bcf.work_packages.default_queries.bcf'), }; // Create all static queries manually @@ -81,14 +80,24 @@ export class WorkPackageStaticQueriesService { identifier: 'recently_created', label: this.text.recently_created, query_props: '{"c":["id","subject","type","status","assignee","createdAt"],"hi":false,"g":"","t":"createdAt:desc","f":[{"n":"status","o":"o","v":[]}]}' - }, - { - identifier: 'all_open', - label: this.text.all_open, - query_props: null } ] as IAutocompleteItem[]; + // Modify default "all open" query for BCF + if (this.BcfDetectorService.isBcfActivated) { + items.push({ + identifier: 'all_open', + label: this.text.all_open, + query_props: '{"hi":true,"hl":"priority","f":[{"n":"status","o":"o","v":[]}],"dr":"card"}' + }); + } else { + items.push({ + identifier: 'all_open', + label: this.text.all_open, + query_props: null + }); + } + const projectIdentifier = this.CurrentProject.identifier; if (projectIdentifier) { items.push({ @@ -113,14 +122,6 @@ export class WorkPackageStaticQueriesService { ]); } - if (this.BcfDetectorService.isBcfActivated) { - items.push({ - identifier: 'bcf_issues', - label: this.text.bcf_issues, - query_props: '{"hi":true,"hl":"priority","g":"","t":"createdAt:desc","f":[{"n":"status","o":"o","v":[]}],"dr":"card"}' - }); - } - return items; } diff --git a/lib/redmine/menu_manager/menu_controller.rb b/lib/redmine/menu_manager/menu_controller.rb index c522eb367fe..e9bdd87efb6 100644 --- a/lib/redmine/menu_manager/menu_controller.rb +++ b/lib/redmine/menu_manager/menu_controller.rb @@ -93,8 +93,8 @@ module Redmine::MenuManager::MenuController # Returns false if user is not authorized def redirect_to_project_menu_item(project, name) item = Redmine::MenuManager.items(:project_menu).detect { |i| i.name.to_s == name.to_s } - if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project)) - redirect_to({ item.param => project }.merge(item.url)) + if item && User.current.allowed_to?(item.url(project), project) && (item.condition.nil? || item.condition.call(project)) + redirect_to({ item.param => project }.merge(item.url(project))) return true end false diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb index 976860743f4..da1d6344717 100644 --- a/lib/redmine/menu_manager/menu_helper.rb +++ b/lib/redmine/menu_manager/menu_helper.rb @@ -201,9 +201,9 @@ module Redmine::MenuManager::MenuHelper def render_unattached_menu_item(menu_item, project) raise Redmine::MenuManager::MenuError, ':child_menus must be an array of MenuItems' unless menu_item.is_a? Redmine::MenuManager::MenuItem - if User.current.allowed_to?(menu_item.url, project) + if User.current.allowed_to?(menu_item.url(project), project) link_to(menu_item.caption, - menu_item.url, + menu_item.url(project), menu_item.html_options) end end @@ -244,13 +244,13 @@ module Redmine::MenuManager::MenuHelper def extract_node_details(node, project = nil) item = node - url = case item.url + url = case item.url(project) when Hash - project.nil? ? item.url : { item.param => project }.merge(item.url) + project.nil? ? item.url(project) : { item.param => project }.merge(item.url(project)) when Symbol - main_app.send(item.url) + main_app.send(item.url(project)) else - item.url + item.url(project) end caption = item.caption(project) @@ -271,7 +271,7 @@ module Redmine::MenuManager::MenuHelper end if project - user && user.allowed_to?(node.url, project) + user && user.allowed_to?(node.url(project), project) else # outside a project, all menu items allowed true diff --git a/lib/redmine/menu_manager/menu_item.rb b/lib/redmine/menu_manager/menu_item.rb index b474ae6d1ea..62dd2240191 100644 --- a/lib/redmine/menu_manager/menu_item.rb +++ b/lib/redmine/menu_manager/menu_item.rb @@ -29,7 +29,7 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode include Redmine::I18n - attr_reader :name, :url, :param, :icon_after, :context, :condition, :parent, :child_menus, :last, :partial + attr_reader :name, :param, :icon_after, :context, :condition, :parent, :child_menus, :last, :partial def initialize(name, url, options) raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) @@ -99,6 +99,18 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode @badge = new_badge end + def url(project = nil) + if @url.is_a?(Proc) + @url.call(project) + else + @url + end + end + + def url=(new_url) + @url = new_url + end + def html_options(options = {}) if options[:selected] o = @html_options.dup diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index 20e75a67683..d3fcb0f9580 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -279,7 +279,7 @@ module Redmine #:nodoc: menu_item.caption = options[:caption] menu_item.icon = options[:icon] menu_item.badge = options[:badge] - + menu_item.url = options[:url] end end diff --git a/modules/bcf/app/controllers/bcf/issues_controller.rb b/modules/bcf/app/controllers/bcf/issues_controller.rb index ab12220f550..9126dfc1e27 100644 --- a/modules/bcf/app/controllers/bcf/issues_controller.rb +++ b/modules/bcf/app/controllers/bcf/issues_controller.rb @@ -30,8 +30,9 @@ module ::Bcf class IssuesController < BaseController - include WorkPackagesFilterHelper include PaginationHelper + include WorkPackagesFilterHelper + include BcfWorkPackagesFilterHelper before_action :find_project_by_project_id before_action :authorize @@ -88,6 +89,10 @@ module ::Bcf @bcf_attachment.destroy end + def redirect_to_bcf_issues_list + redirect_to project_work_packages_bcf_issues_path(@project) + end + private def import_canceled? @@ -97,7 +102,7 @@ module ::Bcf unknown_mails_action non_members_action].map { |key| params.dig(:import_options, key) }.include? 'cancel' flash[:notice] = I18n.t('bcf.bcf_xml.import_canceled') - redirect_to project_work_packages_bcf_issues_path(@project) + redirect_to_bcf_issues_list end end diff --git a/modules/bcf/app/helpers/bcf_application_helper.rb b/modules/bcf/app/helpers/bcf_application_helper.rb new file mode 100644 index 00000000000..0566903b529 --- /dev/null +++ b/modules/bcf/app/helpers/bcf_application_helper.rb @@ -0,0 +1,27 @@ +#-- copyright +# OpenProject Costs Plugin +# +# Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 3. +# +# 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. +#++ +# +module BcfApplicationHelper + def body_css_classes + classes = super + classes = classes + " bcf-#{@project&.module_enabled?(:bcf) ? 'activated' : 'deactivated'}" + + classes + end +end diff --git a/modules/bcf/app/helpers/bcf_work_packages_filter_helper.rb b/modules/bcf/app/helpers/bcf_work_packages_filter_helper.rb new file mode 100644 index 00000000000..a3e710333b2 --- /dev/null +++ b/modules/bcf/app/helpers/bcf_work_packages_filter_helper.rb @@ -0,0 +1,44 @@ +#-- encoding: UTF-8 + +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) +# +# 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-2017 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 docs/COPYRIGHT.rdoc for more details. +#++ + +module BcfWorkPackagesFilterHelper + def project_work_packages_bcf_issues_path(project) + query = { + f: [ + filter_object('status_id', 'o') + ], + hi: true, + hl: 'priority', + dr: 'card' + } + + project_work_packages_with_query_path(project, query) + end +end diff --git a/modules/bcf/config/locales/js-en.yml b/modules/bcf/config/locales/js-en.yml index 22aa9ee97bd..92292fad057 100644 --- a/modules/bcf/config/locales/js-en.yml +++ b/modules/bcf/config/locales/js-en.yml @@ -4,6 +4,3 @@ en: bcf: import: 'Import' export: 'Export' - work_packages: - default_queries: - bcf: 'BCF issues' diff --git a/modules/bcf/config/routes.rb b/modules/bcf/config/routes.rb index cf691e533cb..b0fa5833459 100644 --- a/modules/bcf/config/routes.rb +++ b/modules/bcf/config/routes.rb @@ -42,6 +42,8 @@ OpenProject::Application.routes.draw do post :configure_import, action: :configure_import, on: :collection post :import, action: :perform_import, on: :collection end + + get 'bcf_issues', to: 'bcf/issues#redirect_to_bcf_issues_list', as: :work_packages end end end diff --git a/modules/bcf/lib/open_project/bcf/engine.rb b/modules/bcf/lib/open_project/bcf/engine.rb index 01a348ff980..9a424cfde9c 100644 --- a/modules/bcf/lib/open_project/bcf/engine.rb +++ b/modules/bcf/lib/open_project/bcf/engine.rb @@ -45,7 +45,10 @@ module OpenProject::Bcf project_module :bcf do permission :view_linked_issues, - 'bcf/issues': :index + 'bcf/issues': %i[index redirect_to_bcf_issues_list] + + permission :view_work_packages, + 'bcf/issues': :redirect_to_bcf_issues_list permission :manage_bcf, 'bcf/issues': %i[index upload prepare_import configure_import perform_import] @@ -53,8 +56,11 @@ module OpenProject::Bcf rename_menu_item :project_menu, :work_packages, - { caption: Proc.new { |project| project.module_enabled?(:bcf) ? I18n.t(:'bcf.label_bcf') : I18n.t(:label_work_package_plural) }, - icon: Proc.new { |project| project.module_enabled?(:bcf) ? 'icon2 icon-bcf' : 'icon2 icon-view-timeline' }, + { url: Proc.new { |project| project.module_enabled?(:bcf) ? + { controller: 'bcf/issues', action: 'redirect_to_bcf_issues_list' } : + { controller: 'work_packages', action: 'index' } }, + caption: Proc.new { |project| project.module_enabled?(:bcf) ? I18n.t(:'bcf.label_bcf') : I18n.t(:label_work_package_plural) }, + icon: Proc.new { |project| project.module_enabled?(:bcf) ? 'icon2 icon-bcf' : 'icon2 icon-view-timeline' }, badge: Proc.new { |project| project.module_enabled?(:bcf) ? 'bcf.experimental_badge' : nil } } end