Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1653,6 +1658,7 @@ DEPENDENCIES
openproject-bim!
openproject-boards!
openproject-calendar!
openproject-dev_tools!
openproject-documents!
openproject-gantt!
openproject-github_integration!
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.modules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ group :development, :test do
gem 'ladle'
end

group :development do
Copy link
Copy Markdown
Contributor

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_plugins seem to load it too early (fails to find OpenProject::Plugins) and will not be found as a plugin, maybe better to stop loading in non dev environment in the Engine?

gem 'openproject-dev_tools', path: 'modules/dev_tools'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is internal only gem, Maybe better to specify require: "open_project/dev_tools" to not create the modules/dev_tools/lib/openproject-dev_tools.rb file?

end

gem 'omniauth-openid_connect-providers',
git: 'https://github.com/opf/omniauth-openid_connect-providers.git',
ref: 'c7e2498a8b093cfc5693d4960cae2e903a5e10cd'
Expand Down
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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is possible to somehow add order: 1 style, this item will be rendered at the end of the flex box

menu_id: "op-dev-user-switcher-menu",
anchor_align: :end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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" } }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding select_variant: :single to Primer::Alpha::ActionMenu.new options and following allow showing current user in the list

Suggested change
content_arguments: { data: { "turbo-method": "post" } }
content_arguments: { data: { "turbo-method": "post" } },
active: user == User.current

)
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?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to allow logged out too, then with skip_before_action :check_if_login_required in controller it works

end

def users
@users ||= User.active
.not_builtin
.order(:lastname, :firstname)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ordering by id would be better on dev:

lastname, firstname firstname, lastname id
Image Image Image

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

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
9 changes: 9 additions & 0 deletions modules/dev_tools/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
en:
dev_tools:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at few other plugins, we seem to use plugin_openproject_XXX namespace, so plugin_openproject_dev_tools

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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. storages is not plugin_storages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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"
35 changes: 35 additions & 0 deletions modules/dev_tools/config/routes.rb
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
42 changes: 42 additions & 0 deletions modules/dev_tools/dev_tools.gemspec
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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative is to disable the rubocop rule # rubocop:disable Gemspec/RequireMFA for the gemspec block

end
64 changes: 64 additions & 0 deletions modules/dev_tools/lib/open_project/dev_tools.rb
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Loading
Loading