diff --git a/Gemfile.lock b/Gemfile.lock index 54235568b402..417c921e67aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,6 +114,11 @@ PATH specs: costs (1.0.0) +PATH + remote: modules/dev_tools + specs: + openproject-dev_tools (1.0.0) + PATH remote: modules/documents specs: @@ -1653,6 +1658,7 @@ DEPENDENCIES openproject-bim! openproject-boards! openproject-calendar! + openproject-dev_tools! openproject-documents! openproject-gantt! openproject-github_integration! @@ -2031,6 +2037,7 @@ CHECKSUMS openproject-bim (1.0.0) openproject-boards (1.0.0) openproject-calendar (1.0.0) + openproject-dev_tools (1.0.0) openproject-documents (1.0.0) openproject-gantt (1.0.0) openproject-github_integration (1.0.0) diff --git a/Gemfile.modules b/Gemfile.modules index bf1f2f7b5b93..7a8daa7c86c0 100644 --- a/Gemfile.modules +++ b/Gemfile.modules @@ -2,6 +2,10 @@ group :development, :test do gem 'ladle' end +group :development do + gem 'openproject-dev_tools', path: 'modules/dev_tools' +end + gem 'omniauth-openid_connect-providers', git: 'https://github.com/opf/omniauth-openid_connect-providers.git', ref: 'c7e2498a8b093cfc5693d4960cae2e903a5e10cd' diff --git a/modules/dev_tools/app/components/dev_tools_user_switcher/component.html.erb b/modules/dev_tools/app/components/dev_tools_user_switcher/component.html.erb new file mode 100644 index 000000000000..bd63271cf33e --- /dev/null +++ b/modules/dev_tools/app/components/dev_tools_user_switcher/component.html.erb @@ -0,0 +1,60 @@ +<%#-- 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. + +++#%> + +<%= + render( + Primer::Alpha::ActionMenu.new( + classes: "op-app-menu--item", + menu_id: "op-dev-user-switcher-menu", + anchor_align: :end + ) + ) do |menu| + menu.with_show_button( + scheme: :invisible, + classes: "op-app-header--primer-button" + ) do |button| + button.with_leading_visual_icon(icon: :"person-add") + button.with_tooltip(text: I18n.t("dev_tools.user_switcher.tooltip")) + + current_user_name + end + + menu.with_group do |group| + group.with_heading(title: I18n.t("dev_tools.user_switcher.active_users")) + + users.each do |user| + group.with_item( + href: dev_tools_switch_user_path(user_id: user.id), + label: user.name, + content_arguments: { data: { "turbo-method": "post" } } + ) + end + end + end +%> diff --git a/modules/dev_tools/app/components/dev_tools_user_switcher/component.rb b/modules/dev_tools/app/components/dev_tools_user_switcher/component.rb new file mode 100644 index 000000000000..38030b1fe510 --- /dev/null +++ b/modules/dev_tools/app/components/dev_tools_user_switcher/component.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +module DevToolsUserSwitcher + class Component < ApplicationComponent + def render? + User.current.logged? + end + + def users + @users ||= User.active + .not_builtin + .order(:lastname, :firstname) + end + + def current_user_name + User.current.name + end + end +end diff --git a/modules/dev_tools/app/controllers/dev_tools/user_switcher_controller.rb b/modules/dev_tools/app/controllers/dev_tools/user_switcher_controller.rb new file mode 100644 index 000000000000..ae1aaf57d23c --- /dev/null +++ b/modules/dev_tools/app/controllers/dev_tools/user_switcher_controller.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +module DevTools + class UserSwitcherController < ApplicationController + # No authorization required - this module only loads in development + # Non-admin users need to be able to switch back to admin + no_authorization_required! :switch + + def switch + user = User.find_by(id: params[:user_id]) + + if user&.active? + login_user(user) + flash[:notice] = I18n.t("dev_tools.user_switcher.switched", name: user.name) + else + flash[:error] = I18n.t("dev_tools.user_switcher.user_not_found") + end + + redirect_back_or_to root_path + end + end +end diff --git a/modules/dev_tools/config/locales/en.yml b/modules/dev_tools/config/locales/en.yml new file mode 100644 index 000000000000..8863a8dff74b --- /dev/null +++ b/modules/dev_tools/config/locales/en.yml @@ -0,0 +1,9 @@ +en: + dev_tools: + user_switcher: + switched: "Switched to user: %{name}" + user_not_found: "User not found or inactive" + title: "Switch User (Dev Only)" + tooltip: "Switch User (Dev Only)" + heading: "Switch User (Dev Only)" + active_users: "Active Users" diff --git a/modules/dev_tools/config/routes.rb b/modules/dev_tools/config/routes.rb new file mode 100644 index 000000000000..8403a8519642 --- /dev/null +++ b/modules/dev_tools/config/routes.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +OpenProject::Application.routes.draw do + scope module: :dev_tools, path: "dev_tools", as: :dev_tools do + match "switch_user", to: "user_switcher#switch", via: %i[get post] + end +end diff --git a/modules/dev_tools/dev_tools.gemspec b/modules/dev_tools/dev_tools.gemspec new file mode 100644 index 000000000000..b3cb51c65584 --- /dev/null +++ b/modules/dev_tools/dev_tools.gemspec @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +Gem::Specification.new do |s| + s.name = "openproject-dev_tools" + s.version = "1.0.0" + s.authors = "OpenProject GmbH" + s.email = "info@openproject.com" + s.summary = "OpenProject Development Tools" + s.description = "Development only tools for OpenProject (user switcher, custom styles, etc.)" + s.license = "GPL-3.0" + + s.files = Dir["{app,config,lib}/**/*"] + s.metadata["rubygems_mfa_required"] = "true" +end diff --git a/modules/dev_tools/lib/open_project/dev_tools.rb b/modules/dev_tools/lib/open_project/dev_tools.rb new file mode 100644 index 000000000000..a8f896cd8fa0 --- /dev/null +++ b/modules/dev_tools/lib/open_project/dev_tools.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +#-- 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. +#++# frozen_string_literal: true +# +# #-- 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 "open_project/dev_tools/engine" + +module OpenProject + module DevTools + end +end diff --git a/modules/dev_tools/lib/open_project/dev_tools/engine.rb b/modules/dev_tools/lib/open_project/dev_tools/engine.rb new file mode 100644 index 000000000000..5e7d09d6a0fa --- /dev/null +++ b/modules/dev_tools/lib/open_project/dev_tools/engine.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +module OpenProject + module DevTools + class Engine < ::Rails::Engine + engine_name :openproject_dev_tools + + include OpenProject::Plugins::ActsAsOpEngine + + register "openproject-dev_tools", + author_url: "https://www.openproject.org", + bundled: true, + name: "OpenProject Dev Tools" + + config.to_prepare do + OpenProject::DevTools::Hooks::LayoutHook + end + end + end +end diff --git a/modules/dev_tools/lib/open_project/dev_tools/hooks/layout_hook.rb b/modules/dev_tools/lib/open_project/dev_tools/hooks/layout_hook.rb new file mode 100644 index 000000000000..e12900c5cd80 --- /dev/null +++ b/modules/dev_tools/lib/open_project/dev_tools/hooks/layout_hook.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +#-- 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. +#++ + +module OpenProject + module DevTools + module Hooks + class LayoutHook < OpenProject::Hook::ViewListener + def view_layouts_base_top_menu(context = {}) + context[:controller].send( + :render_to_string, + DevToolsUserSwitcher::Component.new, + layout: false + ) + end + end + end + end +end diff --git a/modules/dev_tools/lib/openproject-dev_tools.rb b/modules/dev_tools/lib/openproject-dev_tools.rb new file mode 100644 index 000000000000..71b7c9e2732c --- /dev/null +++ b/modules/dev_tools/lib/openproject-dev_tools.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +#-- 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 "open_project/dev_tools"