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

[#41945] fixed rubocop issues

Eric Schubert81d526c2c503
diff --git a/.gitignore b/.gitignore
index 32109fc042a..6ebfeccbc26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -115,6 +115,7 @@ structure.sql
# Local development docker
/.env
+/docker-compose.override.yml
# Local development direnv files
/.envrc
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb
index b35b6afa771..332de760c54 100644
--- a/app/controllers/admin_controller.rb
+++ b/app/controllers/admin_controller.rb
@@ -38,9 +38,14 @@ class AdminController < ApplicationController
menu_item :admin_overview, only: [:index]
def index
- @menu_nodes = Redmine::MenuManager.items(:admin_menu).children
- @menu_nodes.delete_if { |node| node.name === :admin_overview }
- @menu_nodes.delete_if { |node| node.condition && !node.condition.call }
+ @menu_nodes = Redmine::MenuManager.items(:admin_menu).children.reject do |node|
+ name = node.name
+ condition = node.condition
+
+ name === :admin_overview ||
+ (condition && !condition.call) ||
+ hidden_admin_menu_items.include?(name.to_s)
+ end
if @menu_nodes.count == 1
redirect_to @menu_nodes.first.url
@@ -71,7 +76,7 @@ class AdminController < ApplicationController
def force_user_language
available_languages = Setting.find_by(name: 'available_languages').value
- User.where(['language not in (?)', available_languages]).each do |u|
+ User.where.not(language: available_languages).each do |u|
u.language = Setting.default_language
u.save
end
@@ -109,14 +114,18 @@ class AdminController < ApplicationController
private
+ def hidden_admin_menu_items
+ (OpenProject::Configuration.hidden_menu_items[:admin_menu.to_s] || [])
+ end
+
def plaintext_extraction_checks
if OpenProject::Database.allows_tsv?
[
[:'extraction.available.pdftotext', Plaintext::PdfHandler.available?],
- [:'extraction.available.unrtf', Plaintext::RtfHandler.available?],
- [:'extraction.available.catdoc', Plaintext::DocHandler.available?],
- [:'extraction.available.xls2csv', Plaintext::XlsHandler.available?],
- [:'extraction.available.catppt', Plaintext::PptHandler.available?],
+ [:'extraction.available.unrtf', Plaintext::RtfHandler.available?],
+ [:'extraction.available.catdoc', Plaintext::DocHandler.available?],
+ [:'extraction.available.xls2csv', Plaintext::XlsHandler.available?],
+ [:'extraction.available.catppt', Plaintext::PptHandler.available?],
[:'extraction.available.tesseract', Plaintext::ImageHandler.available?]
]
else
diff --git a/app/views/admin/index.html.erb b/app/views/admin/index.html.erb
index 6e5e694aa65..26eb10a8c7b 100644
--- a/app/views/admin/index.html.erb
+++ b/app/views/admin/index.html.erb
@@ -31,9 +31,9 @@ See COPYRIGHT and LICENSE files for more details.
<%= toolbar title: t(:label_overview) %>
-<div class="menu-blocks--container">
+<div class="menu-blocks--container" data-qa-selector="menu-blocks--container">
<% @menu_nodes.each do |menu_node| -%>
- <%= link_to menu_node.url, { class: 'menu-block' } do %>
+ <%= link_to menu_node.url, { class: 'menu-block', 'data-qa-selector': 'menu-block' } do %>
<%= op_icon('menu-block--icon ' + (menu_node.icon || '').gsub(/icon2/, "icon3")) %>
<span class="menu-block--title"> <%= menu_node.caption %> </span>
<% end %>
diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb
index 52ea06b4ac9..16fb69484bd 100644
--- a/lib/redmine/menu_manager/menu_helper.rb
+++ b/lib/redmine/menu_manager/menu_helper.rb
@@ -31,10 +31,7 @@ module Redmine::MenuManager::MenuHelper
include ::Redmine::MenuManager::WikiMenuHelper
include AccessibilityHelper
- # Returns the current menu item name
- def current_menu_item
- controller.current_menu_item
- end
+ delegate :current_menu_item, to: :controller
# Renders the application main menu
def render_main_menu(menu, project = nil)
@@ -67,7 +64,7 @@ module Redmine::MenuManager::MenuHelper
first_level = any_item_selected?(select_leafs(menu_items)) || !current_menu_item_part_of_menu?(menu, project)
classes = first_level ? 'open' : 'closed'
- links.empty? ? nil : content_tag('ul', safe_join(links, "\n"), class: 'menu_root ' + classes)
+ links.empty? ? nil : content_tag('ul', safe_join(links, "\n"), class: "menu_root #{classes}")
end
def select_leafs(items)
@@ -82,7 +79,7 @@ module Redmine::MenuManager::MenuHelper
selected = any_item_selected?(items)
label_node = render_drop_down_label_node(label, selected, label_options)
- options[:drop_down_class] = 'op-menu ' + options.fetch(:drop_down_class, '')
+ options[:drop_down_class] = "op-menu #{options.fetch(:drop_down_class, '')}"
render_menu_dropdown(label_node, options) do
items.each do |item|
concat render_menu_node(item, project)
@@ -104,7 +101,7 @@ module Redmine::MenuManager::MenuHelper
concat(content_tag(:ul,
style: 'display:none',
id: options[:drop_down_id],
- class: 'op-app-menu--dropdown ' + options.fetch(:drop_down_class, ''),
+ class: "op-app-menu--dropdown #{options.fetch(:drop_down_class, '')}",
&block))
end
end
@@ -155,7 +152,7 @@ module Redmine::MenuManager::MenuHelper
unless standard_children_list.empty?
node << content_tag(:ul, standard_children_list, class: 'main-menu--children')
end
- unless unattached_children_list.blank?
+ if unattached_children_list.present?
node << content_tag(:ul, unattached_children_list, class: 'main-menu--children unattached')
end
@@ -173,10 +170,11 @@ module Redmine::MenuManager::MenuHelper
lang: menu_item_locale(item)) do
''.html_safe + caption + badge_for(item)
end
- link_text << ' '.html_safe + op_icon(item.icon_after) if item.icon_after.present?
+ link_text << (' '.html_safe + op_icon(item.icon_after)) if item.icon_after.present?
html_options = item.html_options(selected: selected)
html_options[:title] ||= selected ? t(:description_current_position) + caption : caption
html_options[:class] = "#{html_options[:class]} #{menu_class}--item-action"
+ html_options['data-qa-selector'] = "#{menu_class}--item-action"
link_to link_text, url, html_options
end
@@ -342,7 +340,7 @@ module Redmine::MenuManager::MenuHelper
@hidden_menu_items ||= OpenProject::Configuration.hidden_menu_items
if @hidden_menu_items.length.positive?
hidden_nodes = @hidden_menu_items[menu.to_s] || []
- !hidden_nodes.include? node.name.to_s
+ hidden_nodes.exclude? node.name.to_s
else
true
end
diff --git a/spec/features/menu_items/admin_menu_item_spec.rb b/spec/features/menu_items/admin_menu_item_spec.rb
index 020526cecda..a558b958ef7 100644
--- a/spec/features/menu_items/admin_menu_item_spec.rb
+++ b/spec/features/menu_items/admin_menu_item_spec.rb
@@ -28,39 +28,53 @@
require 'spec_helper'
-feature 'Admin menu items' do
+describe 'Admin menu items', js: true do
let(:user) { create :admin }
before do
- allow(User).to receive(:current).and_return user
+ login_as user
end
after do
OpenProject::Configuration['hidden_menu_items'] = []
end
- describe 'displaying all the menu items' do
- it 'hides the specified admin menu items' do
+ context 'without having any menu items hidden in configuration' do
+ it 'must display all menu items' do
visit admin_index_path
- expect(page).to have_selector('a', text: I18n.t('label_user_plural'))
- expect(page).to have_selector('a', text: I18n.t('label_role_plural'))
- expect(page).to have_selector('a', text: I18n.t('label_type_plural'))
+ expect(page).to have_selector('[data-qa-selector="menu-blocks--container"]')
+ expect(page).to have_selector('[data-qa-selector="menu-block"]', count: 17)
+ expect(page).to have_selector('[data-qa-selector="op-menu--item-action"]', count: 18) # All plus 'overview'
end
end
- describe 'hiding menu items' do
- before do
- OpenProject::Configuration['hidden_menu_items'] = { 'admin_menu' => ['roles', 'types'] }
+ context 'with having custom hidden menu items',
+ with_config: {
+ 'hidden_menu_items' => { 'admin_menu' => ['colors'] }
+ } do
+ it 'must not display the hidden menu items and blocks' do
+ visit admin_index_path
+
+ expect(page).to have_selector('[data-qa-selector="menu-blocks--container"]')
+ expect(page).to have_selector('[data-qa-selector="menu-block"]', count: 16)
+ expect(page).not_to have_selector('[data-qa-selector="menu-block"]', text: I18n.t('timelines.admin_menu.colors'))
+
+ expect(page).to have_selector('[data-qa-selector="op-menu--item-action"]', count: 17) # All plus 'overview'
+ expect(page).not_to have_selector('[data-qa-selector="op-menu--item-action"]', text: I18n.t('timelines.admin_menu.colors'))
end
+ end
- it 'hides the specified admin menu items' do
- visit admin_index_path
+ context 'when logged in with a non-admin user with specific admin permissions' do
+ let(:user) { create :user, global_permission: %i[manage_user create_backup] }
- expect(page).to have_selector('a', text: I18n.t('label_user_plural'))
+ it 'must display only the actions allowed by global permissions' do
+ visit admin_index_path
- expect(page).not_to have_selector('a', text: I18n.t('label_role_plural'))
- expect(page).not_to have_selector('a', text: I18n.t('label_type_plural'))
+ expect(page).to have_selector('[data-qa-selector="menu-block"]', text: I18n.t('label_user_plural'))
+ expect(page).to have_selector('[data-qa-selector="menu-block"]', text: I18n.t('label_backup'))
+ expect(page).to have_selector('[data-qa-selector="op-menu--item-action"]', text: I18n.t('label_user_plural'))
+ expect(page).to have_selector('[data-qa-selector="op-menu--item-action"]', text: I18n.t('label_backup'))
end
end
end