Files
openproject/app/controllers/admin_controller.rb
T
Henriette Darge ee8452282a [63485] Remove show_local_breadcrumb and default_breadcrumb (#18663)
* add a new helper for breadcrumb in wiki page

* set page header in destroy page

* set page header in edit page

* set page header in history and rename and edit parent pages

* change toolbar items into page header items

* add new wiki action to sub header

* remove version edit page which is not in use any more

* add export as a menu item of the header

* fix rubocup errors

* fix failing tests

* replace page header in annotate page

* replace page header in diff page

* add page header in select menu page

* fix rubocup errors

* fix errors on rename test

* fix errors on selecting items from toolbar

* fix errors on tests for child pages

* set correct permission for configure menu item

* replace page header in summary page

* replace page header in summary details page

* edit docs of sub header

* add page header in wiki new page

* remove controller and a route for edit method

* undo changes for docs of sub header

* extract header in show page into a new component

* use helper method in header component

* add wiki module to the breadcrumb

* rename page header component for wiki page

* simplify how lock and lock implemented

* extract sub header

* remove wiki title from header of history page

* fix page header in new page

* use page.find_test_selector in test

* fix failing test for summary page

* fix failing test for wiki child pages

* change the summary test

* use test selector for page header title

* undo changes for activate user in admin

* use test selector in adding editing history test

* use test selector in attachment upload test

* use test selector in child pages tests

* use test selector in wiki menu items tests

* change test selector for breadcrumbs

* extract conditions to show edit button into a method

* extract conditions to show rollback action menu item into a method

* extract conditions to show create button into a method

* fix duplicated code in test

* Remove outdated `show_local_breadcrumb` method which is replaced by the Primer::PageHeader breadcrumb

* Remove `default_breadcrumb` method as it serves no prupose any more

* Remove the old breadcrumb and its hook completely

* remove breadcrumbs path from rename

* fix translations errors in storages

* undo changes on translations

* remove default breadcrumbs in time tracking controller

---------

Co-authored-by: Behrokh Satarnejad <b.satarnejad@openproject.com>
Co-authored-by: Behrokh Satarnejad <62008897+bsatarnejad@users.noreply.github.com>
2025-04-23 10:40:43 +02:00

150 lines
4.8 KiB
Ruby

#-- 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 "open3"
class AdminController < ApplicationController
layout "admin"
before_action :require_admin, except: %i[index]
before_action :authorize_global, only: %i[index]
menu_item :plugins, only: [:plugins]
menu_item :info, only: [:info]
menu_item :admin_overview, only: [:index]
def index
@menu_nodes = Redmine::MenuManager.items(:admin_menu).children.reject do |node|
name = node.name
condition = node.condition
name === :admin_overview ||
(condition && !condition.call(nil)) ||
hidden_admin_menu_items.include?(name.to_s)
end
if @menu_nodes.count == 1
redirect_to @menu_nodes.first.url
end
end
def projects
redirect_to controller: "projects", action: "index"
end
def plugins
@plugins = Redmine::Plugin.not_bundled.sort
end
def test_email
raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
# Force ActionMailer to raise delivery errors so we can catch it
ActionMailer::Base.raise_delivery_errors = true
begin
@test = UserMailer.test_mail(User.current).deliver_now
flash[:notice] = I18n.t(:notice_email_sent, value: User.current.mail)
rescue StandardError => e
flash[:error] = I18n.t(:notice_email_error, value: Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup))
end
ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
redirect_to admin_settings_mail_notifications_path
end
def info
@db_version = OpenProject::Database.version
@checklist = [
[:text_default_administrator_account_changed, User.default_admin_account_changed?],
[:text_database_allows_tsv, OpenProject::Database.allows_tsv?]
]
@checklist += file_storage_checks
@checklist += plaintext_extraction_checks
@checklist += admin_information_hook_checks
@checklist += image_conversion_checks
@checklist += jemalloc_active_checks
@storage_information = OpenProject::Storage.mount_information
end
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.tesseract", Plaintext::ImageHandler.available?]
]
else
[]
end
end
def image_conversion_checks
[[:"image_conversion.imagemagick", image_conversion_libs_available?]]
end
def jemalloc_active_checks
[[:"admin.jemalloc_allocator", jemalloc_libs_active?]]
end
def jemalloc_libs_active?
Open3.capture2e({ "MALLOC_CONF" => "true" }, "ruby", "-e", "exit").first.include?("jemalloc")
rescue StandardError
false
end
def image_conversion_libs_available?
Open3.capture2e("convert", "-version").first.include?("ImageMagick")
rescue StandardError
false
end
def file_storage_checks
# Add local directory test if we're not using fog
if OpenProject::Configuration.file_storage?
repository_writable = File.writable?(OpenProject::Configuration.attachments_storage_path)
[[:text_file_repository_writable, repository_writable]]
else
[]
end
end
def admin_information_hook_checks
call_hook(:admin_information_checklist).flat_map do |result|
result
end
end
end