Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Metadata dialog

Oliver Günther98b0f4e4b88f
diff --git a/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.html.erb b/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.html.erb
new file mode 100644
index 00000000000..68b1fe14c03
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.html.erb
@@ -0,0 +1,40 @@
+<%=
+ render(Primer::Alpha::Dialog.new(
+ id:,
+ title: t("saml.providers.label_metadata_endpoint"),
+ size: :large
+ )) do |d|
+ d.with_header
+ d.with_body do
+ flex_layout do |flex|
+ flex.with_row(mb: 4) do
+ t("saml.providers.metadata.dialog")
+ end
+
+ flex.with_row do
+ render(Primer::OpenProject::InputGroup.new) do |input_group|
+ input_group.with_text_input(name: :metadata_endpoint,
+ label: t("saml.providers.label_metadata_endpoint"),
+ visually_hide_label: true,
+ value: provider.metadata_endpoint)
+ input_group.with_trailing_action_clipboard_copy_button(
+ value: provider.metadata_endpoint,
+ aria: {
+ label: I18n.t('button_copy_to_clipboard')
+ })
+ end
+ end
+
+ flex.with_row(justify_items: :flex_end) do
+
+ end
+ end
+ end
+
+ d.with_footer do
+ render(Primer::ButtonComponent.new(data: { 'close-dialog-id': id })) do
+ I18n.t("button_close")
+ end
+ end
+ end
+%>
diff --git a/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.rb b/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.rb
new file mode 100644
index 00000000000..016e9a5a755
--- /dev/null
+++ b/modules/auth_saml/app/components/saml/providers/metadata_dialog_component.rb
@@ -0,0 +1,15 @@
+module Saml
+ module Providers
+ class MetadataDialogComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ alias_method :provider, :model
+
+ def id
+ "saml-metadata-dialog"
+ end
+ end
+ end
+end
diff --git a/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb
index a7f95321cb5..ceb8ae5e22f 100644
--- a/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb
+++ b/modules/auth_saml/app/components/saml/providers/sections/show_component.html.erb
@@ -17,6 +17,12 @@
if show_edit?
grid.with_area(:action) do
flex_layout(justify_content: :flex_end) do |icons_container|
+ if @action
+ icons_container.with_column do
+ render(@action)
+ end
+ end
+
icons_container.with_column do
render(
Primer::Beta::IconButton.new(
diff --git a/modules/auth_saml/app/components/saml/providers/sections/show_component.rb b/modules/auth_saml/app/components/saml/providers/sections/show_component.rb
index e87e322cd3d..c6fdfa055e7 100644
--- a/modules/auth_saml/app/components/saml/providers/sections/show_component.rb
+++ b/modules/auth_saml/app/components/saml/providers/sections/show_component.rb
@@ -31,7 +31,7 @@
module Saml::Providers::Sections
class ShowComponent < SectionComponent
def initialize(provider, view_mode:, target_state:,
- heading:, description:, label: nil, label_scheme: :attention)
+ heading:, description:, action: nil, label: nil, label_scheme: :attention)
super(provider)
@target_state = target_state
@@ -40,6 +40,7 @@ module Saml::Providers::Sections
@description = description
@label = label
@label_scheme = label_scheme
+ @action = action
end
def show_edit?
diff --git a/modules/auth_saml/app/components/saml/providers/view_component.html.erb b/modules/auth_saml/app/components/saml/providers/view_component.html.erb
index 931e2dfa3a0..0e2c86ad2db 100644
--- a/modules/auth_saml/app/components/saml/providers/view_component.html.erb
+++ b/modules/auth_saml/app/components/saml/providers/view_component.html.erb
@@ -7,146 +7,159 @@
%>
<% end %>
-<%= render(border_box_container) do |component|
- component.with_header(color: :muted) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("activemodel.attributes.saml/provider.display_name") }
- end
+ <%= render(border_box_container) do |component|
+ component.with_header(color: :muted) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t("activemodel.attributes.saml/provider.display_name") }
+ end
- component.with_row(scheme: :default) do
- if edit_state == :name
- render(Saml::Providers::Sections::FormComponent.new(
- provider,
- form_class: Saml::Providers::NameInputForm,
- edit_state:,
- next_edit_state: :metadata,
- edit_mode:,
- heading: nil
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- view_mode:,
- target_state: :name,
- heading: t("saml.providers.singular"),
- description: t("saml.providers.section_texts.display_name")
- ))
+ component.with_row(scheme: :default) do
+ if edit_state == :name
+ render(Saml::Providers::Sections::FormComponent.new(
+ provider,
+ form_class: Saml::Providers::NameInputForm,
+ edit_state:,
+ next_edit_state: :metadata,
+ edit_mode:,
+ heading: nil
+ ))
+ else
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ view_mode:,
+ target_state: :name,
+ heading: t("saml.providers.singular"),
+ description: t("saml.providers.section_texts.display_name")
+ ))
+ end
end
- end
- component.with_row(scheme: :neutral, color: :muted) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.label_automatic_configuration') }
- end
+ component.with_row(scheme: :neutral, color: :muted) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.label_automatic_configuration') }
+ end
+
+ component.with_row(scheme: :default) do
+ if edit_state == :metadata
+ render(Saml::Providers::Sections::MetadataFormComponent.new(
+ provider,
+ edit_mode:,
+ ))
+ else
+ dialog_button =
+ if provider.persisted?
+ Primer::Beta::Button.new(
+ tag: :a,
+ href: show_metadata_saml_provider_path(provider),
+ scheme: :invisible,
+ color: :subtle,
+ 'aria-label': t('saml.providers.label_show_metadata'),
+ data: { turbo: true, 'turbo-stream': true }
+ ).with_content(t('saml.providers.label_show_metadata'))
+ end
- component.with_row(scheme: :default) do
- if edit_state == :metadata
- render(Saml::Providers::Sections::MetadataFormComponent.new(
- provider,
- edit_mode:,
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- target_state: :metadata,
- view_mode:,
- heading: t("saml.providers.label_metadata"),
- description: t("saml.providers.section_texts.metadata"),
- label: provider.has_metadata? ? t(:label_completed) : t(:label_not_configured),
- label_scheme: provider.has_metadata? ? :success : :secondary
- ))
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ target_state: :metadata,
+ view_mode:,
+ action: dialog_button,
+ heading: t("saml.providers.label_metadata"),
+ description: t("saml.providers.section_texts.metadata"),
+ label: provider.has_metadata? ? t(:label_completed) : t(:label_not_configured),
+ label_scheme: provider.has_metadata? ? :success : :secondary
+ ))
+ end
end
- end
- component.with_row(scheme: :neutral, color: :muted) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.configuration') }
- end
+ component.with_row(scheme: :neutral, color: :muted) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.configuration') }
+ end
- component.with_row(scheme: :default) do
- if edit_state == :configuration
- render(Saml::Providers::Sections::FormComponent.new(
- provider,
- form_class: Saml::Providers::ConfigurationForm,
- edit_state:,
- next_edit_state: :encryption,
- edit_mode:,
- banner: provider.last_metadata_update ? t("saml.providers.section_texts.configuration_metadata") : nil,
- banner_scheme: :default,
- heading: nil
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- target_state: :configuration,
- view_mode:,
- heading: t("saml.providers.label_configuration_details"),
- description: t("saml.providers.section_texts.configuration"),
- label: (provider.persisted? && !provider.configured?) ? t(:label_incomplete) : nil,
- ))
+ component.with_row(scheme: :default) do
+ if edit_state == :configuration
+ render(Saml::Providers::Sections::FormComponent.new(
+ provider,
+ form_class: Saml::Providers::ConfigurationForm,
+ edit_state:,
+ next_edit_state: :encryption,
+ edit_mode:,
+ banner: provider.last_metadata_update ? t("saml.providers.section_texts.configuration_metadata") : nil,
+ banner_scheme: :default,
+ heading: nil
+ ))
+ else
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ target_state: :configuration,
+ view_mode:,
+ heading: t("saml.providers.label_configuration_details"),
+ description: t("saml.providers.section_texts.configuration"),
+ label: (provider.persisted? && !provider.configured?) ? t(:label_incomplete) : nil,
+ ))
+ end
end
- end
- component.with_row(scheme: :default) do
- if edit_state == :encryption
- render(Saml::Providers::Sections::FormComponent.new(
- provider,
- form_class: Saml::Providers::EncryptionForm,
- edit_state:,
- next_edit_state: :mapping,
- edit_mode:,
- heading: t("saml.providers.section_texts.encryption_form")
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- target_state: :encryption,
- view_mode:,
- heading: t("saml.providers.label_configuration_encryption"),
- description: t("saml.providers.section_texts.encryption")
- ))
+ component.with_row(scheme: :default) do
+ if edit_state == :encryption
+ render(Saml::Providers::Sections::FormComponent.new(
+ provider,
+ form_class: Saml::Providers::EncryptionForm,
+ edit_state:,
+ next_edit_state: :mapping,
+ edit_mode:,
+ heading: t("saml.providers.section_texts.encryption_form")
+ ))
+ else
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ target_state: :encryption,
+ view_mode:,
+ heading: t("saml.providers.label_configuration_encryption"),
+ description: t("saml.providers.section_texts.encryption")
+ ))
+ end
end
- end
- component.with_row(scheme: :neutral, color: :muted) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.attributes') }
- end
+ component.with_row(scheme: :neutral, color: :muted) do
+ render(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.section_headers.attributes') }
+ end
- component.with_row(scheme: :default) do
- if edit_state == :mapping
- render(Saml::Providers::Sections::FormComponent.new(
- provider,
- form_class: Saml::Providers::MappingForm,
- edit_state:,
- next_edit_state: :requested_attributes,
- edit_mode:,
- heading: t("saml.instructions.mapping")
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- target_state: :mapping,
- view_mode:,
- heading: t("saml.providers.label_mapping"),
- description: t("saml.providers.section_texts.mapping"),
- label: provider.mapping_configured? ? t(:label_completed) : t(:label_incomplete),
- label_scheme: provider.mapping_configured? ? :success : :attention
- ))
+ component.with_row(scheme: :default) do
+ if edit_state == :mapping
+ render(Saml::Providers::Sections::FormComponent.new(
+ provider,
+ form_class: Saml::Providers::MappingForm,
+ edit_state:,
+ next_edit_state: :requested_attributes,
+ edit_mode:,
+ heading: t("saml.instructions.mapping")
+ ))
+ else
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ target_state: :mapping,
+ view_mode:,
+ heading: t("saml.providers.label_mapping"),
+ description: t("saml.providers.section_texts.mapping"),
+ label: provider.mapping_configured? ? t(:label_completed) : t(:label_incomplete),
+ label_scheme: provider.mapping_configured? ? :success : :attention
+ ))
+ end
end
- end
- component.with_row(scheme: :default) do
- if edit_state == :requested_attributes
- render(Saml::Providers::Sections::RequestAttributesFormComponent.new(
- provider,
- edit_mode:
- ))
- else
- render(Saml::Providers::Sections::ShowComponent.new(
- provider,
- target_state: :requested_attributes,
- view_mode:,
- heading: t("saml.providers.requested_attributes"),
- description: t("saml.providers.section_texts.requested_attributes")
- ))
+ component.with_row(scheme: :default) do
+ if edit_state == :requested_attributes
+ render(Saml::Providers::Sections::RequestAttributesFormComponent.new(
+ provider,
+ edit_mode:
+ ))
+ else
+ render(Saml::Providers::Sections::ShowComponent.new(
+ provider,
+ target_state: :requested_attributes,
+ view_mode:,
+ heading: t("saml.providers.requested_attributes"),
+ description: t("saml.providers.section_texts.requested_attributes")
+ ))
+ end
end
end
-end
-%>
+ %>
<% end %>
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
index c9caf20cd9a..e3762e79791 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -1,13 +1,14 @@
module Saml
class ProvidersController < ::ApplicationController
include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
layout "admin"
menu_item :plugin_saml
before_action :require_admin
before_action :check_ee
- before_action :find_provider, only: %i[show edit import_metadata update destroy]
+ before_action :find_provider, only: %i[show edit show_metadata import_metadata update destroy]
before_action :check_provider_writable, only: %i[update import_metadata]
before_action :set_edit_state, only: %i[create edit update import_metadata]
@@ -67,6 +68,12 @@ module Saml
end
end
+ def show_metadata
+ respond_with_dialog(
+ Saml::Providers::MetadataDialogComponent.new(@provider)
+ )
+ end
+
def create
call = ::Saml::Providers::CreateService
.new(user: User.current)
diff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rb
index 7747e7cee62..704fc6935f9 100644
--- a/modules/auth_saml/app/models/saml/provider.rb
+++ b/modules/auth_saml/app/models/saml/provider.rb
@@ -60,6 +60,10 @@ module Saml
metadata_xml_changed? || metadata_url_changed?
end
+ def metadata_endpoint
+ URI.join(auth_url, "metadata").to_s
+ end
+
def configured?
sp_entity_id.present? &&
idp_sso_service_url.present? &&
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index 26b56974d90..7a61e57311a 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -45,6 +45,7 @@ en:
label_empty_description: "Add a provider to see them here."
label_automatic_configuration: Automatic configuration
label_metadata: Metadata
+ label_show_metadata: Show OpenProject metadata
label_metadata_endpoint: Metadata endpoint
label_configuration_details: "Identity provider endpoints and certificates"
label_configuration_encryption: "Signatures and Encryption"
@@ -62,6 +63,8 @@ en:
attribute_mapping_text: >
The following fields control which attributes provided by the SAML identity provider
are used to provide user attributes in OpenProject
+ metadata:
+ dialog: "This is the URL where the OpenProject SAML metadata is available. Optionally use it to configure your identity provider:"
upsale:
description: Connect OpenProject to a SAML identity provider
request_attributes:
diff --git a/modules/auth_saml/config/routes.rb b/modules/auth_saml/config/routes.rb
index 926f2427ae9..6af0d120b4e 100644
--- a/modules/auth_saml/config/routes.rb
+++ b/modules/auth_saml/config/routes.rb
@@ -4,6 +4,7 @@ Rails.application.routes.draw do
resources :providers do
member do
post :import_metadata
+ get :show_metadata
end
end
end