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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
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.erbnew file mode 100644index 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.rbnew file mode 100644index 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+enddiff --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.erbindex 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) doflex_layout(justify_content: :flex_end) do |icons_container|+ if @action+ icons_container.with_column do+ render(@action)+ end+ end+icons_container.with_column dorender(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.rbindex 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::Sectionsclass ShowComponent < SectionComponentdef 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 = actionenddef 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.erbindex 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")+ ))+ endend- 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+ ))+ endend- 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,+ ))+ endend- 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")+ ))+ endend- 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+ ))+ endend- 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")+ ))+ endendend-end-%>+ %><% end %>diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex 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 Samlclass ProvidersController < ::ApplicationControllerinclude OpTurbo::ComponentStream+ include OpTurbo::DialogStreamHelperlayout "admin"menu_item :plugin_samlbefore_action :require_adminbefore_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 Samlendend+ def show_metadata+ respond_with_dialog(+ Saml::Providers::MetadataDialogComponent.new(@provider)+ )+ end+def createcall = ::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.rbindex 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 Samlmetadata_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.ymlindex 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 configurationlabel_metadata: Metadata+ label_show_metadata: Show OpenProject metadatalabel_metadata_endpoint: Metadata endpointlabel_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 providerare 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 providerrequest_attributes:diff --git a/modules/auth_saml/config/routes.rb b/modules/auth_saml/config/routes.rbindex 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 doresources :providers domember dopost :import_metadata+ get :show_metadataendendend