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 form

Oliver Günther9b663a8cf37c
diff --git a/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts b/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts
new file mode 100644
index 00000000000..6c28e08c22c
--- /dev/null
+++ b/frontend/src/stimulus/controllers/show-when-value-selected.controller.ts
@@ -0,0 +1,22 @@
+import { ApplicationController } from 'stimulus-use';
+
+export default class OpShowWhenValueSelectedController extends ApplicationController {
+ static targets = ['cause', 'effect'];
+
+ declare readonly effectTargets:HTMLInputElement[];
+
+ causeTargetConnected(target:HTMLElement) {
+ target.addEventListener('change', this.toggleDisabled.bind(this));
+ }
+
+ causeTargetDisconnected(target:HTMLElement) {
+ target.removeEventListener('change', this.toggleDisabled.bind(this));
+ }
+
+ private toggleDisabled(evt:InputEvent):void {
+ const value = (evt.target as HTMLInputElement).value;
+ this.effectTargets.forEach((el) => {
+ el.hidden = !(el.dataset.value === value);
+ });
+ }
+}
diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.ts
index 9d46a67f5ec..eb160bfe694 100644
--- a/frontend/src/stimulus/setup.ts
+++ b/frontend/src/stimulus/setup.ts
@@ -9,6 +9,7 @@ import AsyncDialogController from './controllers/async-dialog.controller';
import PollForChangesController from './controllers/poll-for-changes.controller';
import TableHighlightingController from './controllers/table-highlighting.controller';
import OpShowWhenCheckedController from "./controllers/show-when-checked.controller";
+import OpShowWhenValueSelectedController from "./controllers/show-when-value-selected.controller";
declare global {
interface Window {
@@ -29,6 +30,7 @@ instance.register('menus--main', MainMenuController);
instance.register('show-when-checked', OpShowWhenCheckedController);
instance.register('disable-when-checked', OpDisableWhenCheckedController);
+instance.register('show-when-value-selected', OpShowWhenValueSelectedController);
instance.register('print', PrintController);
instance.register('refresh-on-form-changes', RefreshOnFormChangesController);
instance.register('async-dialog', AsyncDialogController);
diff --git a/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb
index d51dbe4ef8b..86a2ed28470 100644
--- a/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb
+++ b/modules/auth_saml/app/components/saml/providers/sections/metadata_form_component.html.erb
@@ -3,7 +3,7 @@
model: provider,
url: import_metadata_saml_provider_path(provider),
data: {
- controller: "show-when-checked"
+ controller: "show-when-value-selected"
},
method: :post,
) do |form|
@@ -15,14 +15,22 @@
end
flex.with_row do
- render(Saml::Providers::MetadataCheckboxForm.new(form, provider:))
+ render(Saml::Providers::MetadataOptionsForm.new(form, provider:))
end
- flex.with_row(mt: 2, hidden: !provider.has_metadata?, data: { 'show-when-checked-target': "effect" }) do
+ flex.with_row(
+ mt: 2,
+ hidden: provider.metadata_url.blank?,
+ data: { value: :url, 'show-when-value-selected-target': "effect" }
+ ) do
render(Saml::Providers::MetadataUrlForm.new(form, provider:))
end
- flex.with_row(mt: 2, hidden: !provider.has_metadata?, data: { 'show-when-checked-target': "effect" }) do
+ flex.with_row(
+ mt: 2,
+ hidden: provider.metadata_xml.blank?,
+ data: { value: :xml, 'show-when-value-selected-target': "effect" }
+ ) do
render(Saml::Providers::MetadataXmlForm.new(form, provider:))
end
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
index 5206ed737f3..7189d988b02 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -22,7 +22,7 @@ module Saml
end
def import_metadata
- if import_params.present?
+ if params[:saml_provider][:metadata] != "none"
update_provider_metadata
end
diff --git a/modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rb b/modules/auth_saml/app/forms/saml/providers/metadata_options_form.rb
similarity index 52%
rename from modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rb
rename to modules/auth_saml/app/forms/saml/providers/metadata_options_form.rb
index 7dc4448092f..c27bb36ef2b 100644
--- a/modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rb
+++ b/modules/auth_saml/app/forms/saml/providers/metadata_options_form.rb
@@ -28,18 +28,37 @@
module Saml
module Providers
- class MetadataCheckboxForm < BaseForm
+ class MetadataOptionsForm < BaseForm
form do |f|
- f.check_box(
- name: :metadata_url,
- checked: @provider.has_metadata?,
- label: I18n.t("saml.settings.metadata_checkbox"),
- required: false,
- input_width: :medium,
- data: {
- "show-when-checked-target": "cause"
- }
- )
+ f.radio_button_group(
+ name: "metadata",
+ scope_name_to_model: false,
+ label: I18n.t("saml.providers.label_metadata")
+ ) do |radio_group|
+ radio_group.radio_button(
+ value: "none",
+ checked: [email protected]_metadata?,
+ label: I18n.t("saml.settings.metadata_none"),
+ caption: I18n.t("saml.instructions.metadata_none"),
+ data: { "show-when-value-selected-target": "cause" }
+ )
+
+ radio_group.radio_button(
+ value: "url",
+ checked: @provider.metadata_url.present?,
+ label: I18n.t("saml.settings.metadata_url"),
+ caption: I18n.t("saml.instructions.metadata_url"),
+ data: { "show-when-value-selected-target": "cause" }
+ )
+
+ radio_group.radio_button(
+ value: "xml",
+ checked: @provider.metadata_xml.present?,
+ label: I18n.t("saml.settings.metadata_xml"),
+ caption: I18n.t("saml.instructions.metadata_xml"),
+ data: { "show-when-value-selected-target": "cause" }
+ )
+ end
end
end
end
diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.yml
index ed7b17260da..4db7d521758 100644
--- a/modules/auth_saml/config/locales/en.yml
+++ b/modules/auth_saml/config/locales/en.yml
@@ -81,7 +81,7 @@ en:
mapping: "Manually adjust the mapping between the SAML response and user attributes in OpenProject."
requested_attributes: "Define the set of attributes to be requested in the SAML request sent to your identity provider."
settings:
- metadata_checkbox: "I have metadata (optional)"
+ metadata_none: "I don't have metadata"
metadata_url: "Metadata URL"
metadata_xml: "Metadata XML"
instructions:
@@ -89,10 +89,12 @@ en:
Please refer to our [documentation on configuring SAML providers](docs_url) for more information on these configuration options.
display_name: >
The name of the provider. This will be displayed as the login button and in the list of providers.
+ metadata_none: >
+ Your identity provider does not have a metadata endpoint or XML download option. You can the configuration manually.
metadata_url: >
- Enter the URL of the identity provider XML metadata endpoint.
+ Your identity provider provides a metadata URL.
metadata_xml: >
- Alternatively, enter the SAML metadata XML from your identity provider.
+ Your identity provider provides a metadata XML download.
limit_self_registration: >
If enabled users can only register using this provider if the self registration setting allows for it.
sp_entity_id: >