-
Notifications
You must be signed in to change notification settings - Fork 0
Extract dev_tools from OP monorepo module #2
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -1,2 +1,19 @@ | ||
| # openproject-dev_tools | ||
| OpenProject plugin adding tools helping with local development of OpenProject | ||
|
|
||
| An OpenProject plugin that adds development tools to make local development easier. | ||
|
|
||
| > **:warning: This plugin is intended for local development only. Do not use it in production.** | ||
|
|
||
| ## Tools | ||
|
|
||
| - **User switcher**: A dropdown in the top navigation bar listing all active users. Click any user to immediately switch to them. | ||
|
|
||
| ## Installation | ||
|
|
||
| Add it like this to the `Gemfile.local` file: | ||
|
|
||
| ```ruby | ||
| group :development do | ||
| gem 'openproject-dev_tools', github: 'opf/openproject-dev_tools' | ||
| end | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| <%#-- 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", | ||||||
| style: "order: 1", | ||||||
|
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 have a feeling that some people would ask you to not use inline styles if it would be in the main project, but I don't mind in dev module, up to you |
||||||
| menu_id: "op-dev-user-switcher-menu", | ||||||
| select_variant: :single | ||||||
|
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. In some cases the menu renders narrower wrapping user names, so I think it is better to set size (probably to :small, as it is enough and the smallest one), this also resolves it jumping from bottom to side when user list doesn't fit vertically |
||||||
| ) | ||||||
| ) 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 | ||||||
|
|
||||||
|
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. Not sure about this, but maybe first user should be «Anonymous», as a quick way to see things logged out, also next menu has sign out |
||||||
| users.each do |user| | ||||||
| menu .with_item( | ||||||
|
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.
Suggested change
|
||||||
| href: dev_tools_switch_user_path(user_id: user.id), | ||||||
| label: user.name, | ||||||
| content_arguments: { data: { "turbo-method": "post" } }, | ||||||
| active: user == User.current | ||||||
| ) | ||||||
| end | ||||||
| end | ||||||
| %> | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # 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 users | ||
| @users ||= User.active | ||
| .not_builtin | ||
| .order(:id) | ||
| end | ||
|
|
||
| def current_user_name | ||
| User.current.name | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # 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! :switch | ||
| skip_before_action :check_if_login_required | ||
|
|
||
| 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) | ||
|
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 assume it is not important, but logging in from logged out state doesn't show the notice |
||
| 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: | ||
| 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" | ||
|
Comment on lines
+6
to
+9
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 see only |
||
| 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 | ||||||
|
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 using
Suggested change
|
||||||
| 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" | ||
| 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 | ||
|
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 |
||
| 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. | ||||
| #++ | ||||
|
|
||||
| require "open_project/plugins" | ||||
|
|
||||
| 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: false, | ||||
|
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. Doesn't need to be explicitly specified
Suggested change
|
||||
| name: "OpenProject Dev Tools" | ||||
|
|
||||
| config.to_prepare do | ||||
| OpenProject::DevTools::Hooks::LayoutHook | ||||
| end | ||||
| end | ||||
| end | ||||
| end | ||||
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.
Thought for future additions - it may be nice to be able to easily switch them on/off, like if they conflict with something or someone prefers to not have them all on