-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add dev env user switcher #22016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dev env user switcher #22016
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ group :development, :test do | |
| gem 'ladle' | ||
| end | ||
|
|
||
| group :development do | ||
| gem 'openproject-dev_tools', path: 'modules/dev_tools' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is internal only gem, Maybe better to specify |
||
| end | ||
|
|
||
| gem 'omniauth-openid_connect-providers', | ||
| git: 'https://github.com/opf/omniauth-openid_connect-providers.git', | ||
| ref: 'c7e2498a8b093cfc5693d4960cae2e903a5e10cd' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -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", | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is possible to somehow add |
||||||||
| menu_id: "op-dev-user-switcher-menu", | ||||||||
| anchor_align: :end | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. anchor_align doesn't seem to be needed, all items are aligned to the end on container level |
||||||||
| ) | ||||||||
| ) 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 | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe better to leave only the icon, for the item not to change size, and current user can be partially identified by the login icon |
||||||||
| end | ||||||||
|
|
||||||||
| menu.with_group do |group| | ||||||||
| group.with_heading(title: I18n.t("dev_tools.user_switcher.active_users")) | ||||||||
|
Comment on lines
+48
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is only one group, I think it is not needed and items can be added directly on the menu level |
||||||||
|
|
||||||||
| 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" } } | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding
Suggested change
|
||||||||
| ) | ||||||||
| end | ||||||||
| end | ||||||||
| end | ||||||||
| %> | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to allow logged out too, then with |
||
| end | ||
|
|
||
| def users | ||
| @users ||= User.active | ||
| .not_builtin | ||
| .order(:lastname, :firstname) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| def current_user_name | ||
| User.current.name | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
mrmir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| en: | ||
| dev_tools: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at few other plugins, we seem to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am pretty sure that we don't do this consistently. E.g.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw that it was inconsistent, but longer namespace reduces the chance of conflict |
||
| 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternative is to disable the rubocop rule |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Comment on lines
+61
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to create empty modules, as they will be created already in required file |
||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it to development group instead of
opf_pluginsseem to load it too early (fails to findOpenProject::Plugins) and will not be found as a plugin, maybe better to stop loading in non dev environment in theEngine?