Skip to content

Commit

Permalink
Update OIDC configuration UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ba1ash committed Oct 14, 2024
1 parent f2f94d6 commit 4082d8e
Show file tree
Hide file tree
Showing 56 changed files with 2,085 additions and 789 deletions.
10 changes: 5 additions & 5 deletions app/components/op_primer/border_box_table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ See COPYRIGHT and LICENSE files for more details.

if rows.empty?
component.with_row(scheme: :default) { render_blank_slate }
end

rows.each do |row|
component.with_row(scheme: :default) do
render(row_class.new(row:, table: self))
else
rows.each do |row|
component.with_row(scheme: :default) do
render(row_class.new(row:, table: self))
end
end
end
end
Expand Down
71 changes: 71 additions & 0 deletions db/migrate/20240829140616_migrate_oidc_settings_to_providers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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.
#++

class MigrateOidcSettingsToProviders < ActiveRecord::Migration[7.1]
def up
providers = Hash(Setting.plugin_openproject_openid_connect).with_indifferent_access[:providers]
return if providers.blank?

providers.each do |name, configuration|
configuration.delete(:name)
migrate_provider!(name, configuration)
end
end

def down
# This migration does not yet remove Setting.plugin_openproject_openid_connect
# so it can be retried.
end

private

def migrate_provider!(name, configuration)
Rails.logger.debug { "Trying to migrate OpenID provider #{name} from previous settings format..." }
call = ::OpenIDConnect::SyncService.new(name, configuration).call

if call.success
Rails.logger.debug { <<~SUCCESS }
Successfully migrated OpenID provider #{name} from previous settings format.
You can now manage this provider in the new administrative UI within OpenProject under
the "Administration -> Authentication -> OpenID providers" section.
SUCCESS
else
raise <<~ERROR
Failed to create or update OpenID provider #{name} from previous settings format.
The error message was: #{call.message}
Please check the logs for more information and open a bug report in our community:
https://www.openproject.org/docs/development/report-a-bug/
If you would like to skip migrating the OpenID provider setting and discard them instead, you can use our documentation
to unset any previous OpenID provider settings:
https://www.openproject.org/docs/system-admin-guide/authentication/openid-providers/
ERROR
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<% OpenProject::Plugins::AuthPlugin.providers.each do |pro| %>
<% OpenProject::Plugins::AuthPlugin.providers.each do |provider| %>
<%
opts = { script_name: OpenProject::Configuration.rails_relative_url_root }

Expand All @@ -36,8 +36,8 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
<a
href="<%= omni_auth_start_path(pro[:name], opts) %>"
class="auth-provider auth-provider-<%= pro[:name] %> <%= pro[:icon] ? 'auth-provider--imaged' : '' %> button">
<span class="auth-provider-name"><%= pro[:display_name] || pro[:name] %></span>
href="<%= omni_auth_start_path(provider[:name], opts) %>"
class="auth-provider auth-provider-<%= provider[:name] %> <%= provider[:icon] ? 'auth-provider--imaged' : '' %> button">
<span class="auth-provider-name"><%= provider[:display_name] || provider[:name] %></span>
</a>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ See COPYRIGHT and LICENSE files for more details.
++#%>

<% OpenProject::Plugins::AuthPlugin.providers.each do |pro| %>
<% if pro[:icon] %>
<% OpenProject::Plugins::AuthPlugin.providers.each do |provider| %>
<% if provider[:icon] %>
<style type="text/css">
#content .login-auth-providers a.auth-provider.auth-provider-<%= pro[:name] %> {
background-image: url('<%= asset_path(pro[:icon]) %>');
#content .login-auth-providers a.auth-provider.auth-provider-<%= provider[:name] %> {
background-image: url('<%= asset_path(provider[:icon]) %>');
}
.op-app-header #nav-login-content .login-auth-providers a.auth-provider.auth-provider-<%= pro[:name] %> {
background-image: url('<%= asset_path(pro[:icon]) %>') ;
.op-app-header #nav-login-content .login-auth-providers a.auth-provider.auth-provider-<%= provider[:name] %> {
background-image: url('<%= asset_path(provider[:icon]) %>') ;
}
.login-auth-providers a.auth-provider.auth-provider-<%= pro[:name] %> {
background-image: url('<%= asset_path(pro[:icon]) %>') ;
.login-auth-providers a.auth-provider.auth-provider-<%= provider[:name] %> {
background-image: url('<%= asset_path(provider[:icon]) %>') ;
}
</style>
<% end -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create
def update
call = Saml::Providers::UpdateService
.new(model: @provider, user: User.current)
.call(options: update_params)
.call(update_params)

if call.success?
flash[:notice] = I18n.t(:notice_successful_update) unless @edit_mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
expect(provider.private_key.strip.gsub("\r\n", "\n")).to eq CertificateHelper.private_key.private_to_pem.strip
expect(provider.idp_sso_service_url).to eq "https://example.com/sso"
expect(provider.idp_slo_service_url).to eq "https://example.com/slo"
expect(provider.mapping_login).to eq "login\nmail"
expect(provider.mapping_login).to eq "login\r\nmail"
expect(provider.mapping_mail).to eq "mail"
expect(provider.mapping_firstname).to eq "myName"
expect(provider.mapping_lastname).to eq "myLastName"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 OpenIDConnect
module Providers
class BaseForm < ApplicationForm
attr_reader :provider

def initialize(provider:)
super()
@provider = provider
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 OpenIDConnect
module Providers
class ClientDetailsForm < BaseForm
form do |f|
%i[client_id client_secret].each do |attr|
f.text_field(
name: attr,
label: I18n.t("activemodel.attributes.openid_connect/provider.#{attr}"),
caption: I18n.t("openid_connect.instructions.#{attr}"),
disabled: provider.seeded_from_env?,
required: true,
input_width: :large
)
end
f.check_box(
name: :limit_self_registration,
label: I18n.t("activemodel.attributes.openid_connect/provider.limit_self_registration"),
caption: I18n.t("openid_connect.instructions.limit_self_registration"),
disabled: provider.seeded_from_env?,
required: true
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 OpenIDConnect
module Providers
class MetadataDetailsForm < BaseForm
form do |f|
OpenIDConnect::Provider::DISCOVERABLE_ATTRIBUTES_ALL.each do |attr|
f.text_field(
name: attr,
label: I18n.t("activemodel.attributes.openid_connect/provider.#{attr}"),
disabled: provider.seeded_from_env?,
required: OpenIDConnect::Provider::DISCOVERABLE_ATTRIBUTES_MANDATORY.include?(attr),
input_width: :large
)
end
end
end
end
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) 2012-2024 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 OpenIDConnect
module Providers
class MetadataOptionsForm < BaseForm
form do |f|
f.radio_button_group(
name: "metadata",
scope_name_to_model: false,
disabled: provider.seeded_from_env?,
visually_hide_label: true
) do |radio_group|
radio_group.radio_button(
value: "none",
checked: @provider.metadata_url.blank?,
label: I18n.t("openid_connect.settings.metadata_none"),
disabled: provider.seeded_from_env?,
data: { "show-when-value-selected-target": "cause" }
)

radio_group.radio_button(
value: "url",
checked: @provider.metadata_url.present?,
label: I18n.t("openid_connect.settings.metadata_url"),
disabled: provider.seeded_from_env?,
data: { "show-when-value-selected-target": "cause" }
)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 OpenIDConnect
module Providers
class MetadataUrlForm < BaseForm
form do |f|
f.text_field(
name: :metadata_url,
label: I18n.t("openid_connect.settings.endpoint_url"),
required: false,
disabled: provider.seeded_from_env?,
caption: I18n.t("openid_connect.instructions.endpoint_url"),
input_width: :xlarge
)
end
end
end
end
Loading

0 comments on commit 4082d8e

Please sign in to comment.