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
Edit state
Oliver Günther50c8b4c2b8a1
diff --git a/frontend/src/global_styles/openproject.sass b/frontend/src/global_styles/openproject.sassindex 6048a0657f7..bcede07f87e 100644--- a/frontend/src/global_styles/openproject.sass+++ b/frontend/src/global_styles/openproject.sass@@ -22,6 +22,7 @@@import "../../../modules/meeting/app/components/_index.sass"@import "../../../modules/overviews/app/components/_index.sass"@import "../../../modules/storages/app/components/_index.sass"+@import "../../../modules/auth_saml/app/components/_index.sass"// Component specific Styles@import "../../../app/components/_index.sass"diff --git a/frontend/src/global_styles/primer/_overrides.sass b/frontend/src/global_styles/primer/_overrides.sassindex 570bc7c9034..227f32c61b2 100644--- a/frontend/src/global_styles/primer/_overrides.sass+++ b/frontend/src/global_styles/primer/_overrides.sass@@ -52,6 +52,9 @@ action-menu@media screen and (min-width: $breakpoint-sm)scroll-behavior: smooth+ul.SegmentedControl+ margin-left: 0+/* Remove margin-left: 2rem from Breadcrumbs */#breadcrumb,page-header,diff --git a/frontend/src/stimulus/controllers/dynamic/admin/saml.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/saml.controller.tsnew file mode 100644index 00000000000..4286e476515--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/admin/saml.controller.ts@@ -0,0 +1,253 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2023 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.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class CustomFieldsController extends Controller {+ static targets = [+ 'format',+ 'dragContainer',++ 'customOptionDefaults',+ 'customOptionRow',++ 'allowNonOpenVersions',+ 'defaultBool',+ 'defaultLongText',+ 'defaultText',+ 'length',+ 'multiSelect',+ 'possibleValues',+ 'regexp',+ 'searchable',+ 'textOrientation',+ ];++ static values = {+ formatConfig: Array,+ };++ declare readonly formatConfigValue:[string, string, string[]][];++ declare readonly formatTarget:HTMLInputElement;+ declare readonly dragContainerTarget:HTMLElement;+ declare readonly hasDragContainerTarget:boolean;++ declare readonly customOptionDefaultsTargets:HTMLInputElement[];+ declare readonly customOptionRowTargets:HTMLTableRowElement[];++ declare readonly allowNonOpenVersionsTargets:HTMLElement[];+ declare readonly defaultBoolTargets:HTMLElement[];+ declare readonly defaultLongTextTargets:HTMLElement[];+ declare readonly defaultTextTargets:HTMLElement[];+ declare readonly lengthTargets:HTMLElement[];+ declare readonly multiSelectTargets:HTMLElement[];+ declare readonly possibleValuesTargets:HTMLElement[];+ declare readonly regexpTargets:HTMLElement[];+ declare readonly searchableTargets:HTMLInputElement[];+ declare readonly textOrientationTargets:HTMLElement[];++ connect() {+ if (this.hasDragContainerTarget) {+ this.setupDragAndDrop();+ }++ this.formatChanged();+ }++ formatChanged() {+ this.toggleFormat(this.formatTarget.value);+ }++ moveRowUp(event:{ target:HTMLElement }) {+ const row = event.target.closest('tr') as HTMLTableRowElement;+ const idx = this.customOptionRowTargets.indexOf(row);+ if (idx > 0) {+ this.customOptionRowTargets[idx - 1].before(row);+ }++ return false;+ }++ moveRowDown(event:{ target:HTMLElement }) {+ const row = event.target.closest('tr') as HTMLTableRowElement;+ const idx = this.customOptionRowTargets.indexOf(row);+ if (idx < this.customOptionRowTargets.length - 1) {+ this.customOptionRowTargets[idx + 1].after(row);+ }++ return false;+ }++ moveRowToTheTop(event:{ target:HTMLElement }) {+ const row = event.target.closest('tr') as HTMLTableRowElement;+ const first = this.customOptionRowTargets[0];++ if (first && first !== row) {+ first.before(row);+ }++ return false;+ }++ moveRowToTheBottom(event:{ target:HTMLElement }) {+ const row = event.target.closest('tr') as HTMLTableRowElement;+ const last = this.customOptionRowTargets[this.customOptionRowTargets.length - 1];++ if (last && last !== row) {+ last.after(row);+ }++ return false;+ }++ removeOption(event:MouseEvent) {+ const self = event.target as HTMLAnchorElement;+ if (self.href === '#' || self.href.endsWith('/0')) {+ const row = self.closest('tr');++ if (row && this.customOptionRowTargets.length > 1) {+ row.remove();+ }++ event.preventDefault();+ event.stopImmediatePropagation();+ }+ return true; // send off deletion+ }++ addOption() {+ const count = this.customOptionRowTargets.length;+ const last = this.customOptionRowTargets[count - 1];+ const dup = last.cloneNode(true) as HTMLElement;++ const input = dup.querySelector('.custom-option-value input') as HTMLInputElement;++ input.setAttribute('name', `custom_field[custom_options_attributes][${count}][value]`);+ input.setAttribute('id', `custom_field_custom_options_attributes_${count}_value`);+ input.value = '';++ dup+ .querySelector('.custom-option-id')+ ?.remove();++ const defaultValueCheckbox = dup.querySelector('input[type="checkbox"]') as HTMLInputElement;+ const defaultValueHidden = dup.querySelector('input[type="hidden"]') as HTMLInputElement;++ defaultValueHidden.setAttribute('name', `custom_field[custom_options_attributes][${count}][default_value]`);+ defaultValueHidden.removeAttribute('id');+ defaultValueCheckbox.setAttribute('name', `custom_field[custom_options_attributes][${count}][default_value]`);+ defaultValueCheckbox.setAttribute('id', `custom_field_custom_options_attributes_${count}_default_value`);+ defaultValueCheckbox.checked = false;++ last.insertAdjacentElement('afterend', dup);++ return false;+ }++ uncheckOtherDefaults(event:{ target:HTMLElement }) {+ const cb = event.target as HTMLInputElement;++ if (cb.checked) {+ const multi = this.multiSelectTargets[0] as HTMLInputElement|undefined;++ if (multi?.checked === false) {+ this.customOptionDefaultsTargets.forEach((el) => (el.checked = false));+ cb.checked = true;+ }+ }+ }++ checkOnlyOne(event:{ target:HTMLElement }) {+ const cb = event.target as HTMLInputElement;++ if (!cb.checked) {+ this.customOptionDefaultsTargets+ .filter((el) => el.checked)+ .slice(1)+ .forEach((el) => (el.checked = false));+ }+ }++ private setupDragAndDrop() {+ // Make custom fields draggable+ // eslint-disable-next-line no-undef+ const drake = dragula([this.dragContainerTarget], {+ isContainer: () => false,+ moves: (el, source, handle:HTMLElement) => handle.classList.contains('dragula-handle'),+ accepts: () => true,+ invalid: () => false,+ direction: 'vertical',+ copy: false,+ copySortSource: false,+ revertOnSpill: true,+ removeOnSpill: false,+ mirrorContainer: this.dragContainerTarget,+ ignoreInputTextSelection: true,+ });++ // Setup autoscroll+ void window.OpenProject.getPluginContext().then((pluginContext) => {+ // eslint-disable-next-line no-new+ new pluginContext.classes.DomAutoscrollService(+ [+ document.getElementById('content-body') as HTMLElement,+ ],+ {+ margin: 25,+ maxSpeed: 10,+ scrollWhenOutside: true,+ autoScroll: () => drake.dragging,+ },+ );+ });+ }++ private setActive(elements:HTMLElement[], active:boolean) {+ elements.forEach((element) => {+ element.hidden = !active;+ element+ .querySelectorAll<HTMLInputElement>('input, textarea')+ .forEach((input) => {+ input.disabled = !active;+ });+ });+ }++ private toggleFormat(format:string) {+ this.formatConfigValue.forEach(([targetsName, operator, formats]) => {+ const active = operator === 'only' ? formats.includes(format) : !formats.includes(format);+ const targets = this[`${targetsName}Targets` as keyof typeof this] as HTMLElement[];+ if (targets) {+ this.setActive(targets, active);+ }+ });+ }+}diff --git a/frontend/src/stimulus/controllers/show-when-checked.controller.ts b/frontend/src/stimulus/controllers/show-when-checked.controller.tsnew file mode 100644index 00000000000..1674cc7a527--- /dev/null+++ b/frontend/src/stimulus/controllers/show-when-checked.controller.ts@@ -0,0 +1,30 @@+import { ApplicationController } from 'stimulus-use';++export default class OpShowWhenCheckedController extends ApplicationController {+ static targets = ['cause', 'effect'];++ static values = {+ reversed: Boolean,+ };++ declare reversedValue:boolean;++ declare readonly hasReversedValue:boolean;++ 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 checked = (evt.target as HTMLInputElement).checked;+ this.effectTargets.forEach((el) => {+ el.hidden = (this.hasReversedValue && this.reversedValue) ? checked : !checked;+ });+ }+}diff --git a/frontend/src/stimulus/setup.ts b/frontend/src/stimulus/setup.tsindex a04e4bb5a18..9d46a67f5ec 100644--- a/frontend/src/stimulus/setup.ts+++ b/frontend/src/stimulus/setup.ts@@ -8,6 +8,7 @@ import RefreshOnFormChangesController from './controllers/refresh-on-form-changeimport 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";declare global {interface Window {@@ -26,6 +27,7 @@ instance.handleError = (error, message, detail) => {instance.register('application', OpApplicationController);instance.register('menus--main', MainMenuController);+instance.register('show-when-checked', OpShowWhenCheckedController);instance.register('disable-when-checked', OpDisableWhenCheckedController);instance.register('print', PrintController);instance.register('refresh-on-form-changes', RefreshOnFormChangesController);diff --git a/modules/auth_saml/app/components/_index.sass b/modules/auth_saml/app/components/_index.sassnew file mode 100644index 00000000000..49f9321ba2d--- /dev/null+++ b/modules/auth_saml/app/components/_index.sass@@ -0,0 +1 @@+@import "saml/providers/view_component"diff --git a/modules/auth_saml/app/components/saml/providers/sections/metadata_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/metadata_component.html.erbindex 8ef31fb231d..48b387774e1 100644--- a/modules/auth_saml/app/components/saml/providers/sections/metadata_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/sections/metadata_component.html.erb@@ -1,18 +1,34 @@<%=- flex_layout do |flex|- flex.with_column do- render(Primer::Beta::Text.new(font_weight: :semibold)) { t("saml.providers.label_metadata") }+ grid_layout('op-saml-view-row', tag: :div, align_items: :center) do |grid|+ grid.with_area(:title, mr: 3) do+ concat render(Primer::Beta::Text.new(font_weight: :bold)) { t("saml.providers.label_metadata") }+ if provider.has_metadata?+ concat render(Primer::Beta::Label.new(scheme: :success, ml: 1)) { t(:label_completed) }+ else+ concat render(Primer::Beta::Label.new(scheme: :secondary, ml: 1)) { t(:label_incomplete) }+ endend- if provider.metadata_url.present?- flex.with_column do- render(Primer::Beta::Label.new(scheme: :success, ml: 1)) { t(:label_completed) }+ grid.with_area(:description) do+ render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do+ t("saml.providers.section_texts.metadata")+ end+ end++ grid.with_area(:action) do+ flex_layout(justify_content: :flex_end) do |icons_container|+ icons_container.with_column do+ render(+ Primer::Beta::IconButton.new(+ icon: :pencil,+ tag: :a,+ scheme: :invisible,+ href: edit_saml_provider_path(provider, edit_state: :metadata),+ aria: { label: I18n.t(:label_edit) }+ )+ )+ endendend- end-%>-<%=- render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do- t("saml.providers.section_texts.metadata")end%>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.erbindex 1e8be68155e..09b26b4060e 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@@ -1,24 +1,35 @@<%=primer_form_with(model: provider,- url: saml_providers_path,+ url: import_metadata_saml_provider_path(provider),+ data: {+ controller: "show-when-checked"+ },method: :post,) do |form|flex_layout do |flex|flex.with_row do- render(Primer::Alpha::SegmentedControl.new("aria-label": "File view", full_width: full_width, hide_labels: hide_labels, size: size)) do |component|- component.with_item(label: "Preview", icon: icon, selected: true)- component.with_item(label: "Raw", icon: icon)- component.with_item(label: "Blame", icon: icon)+ render(Primer::Beta::Text.new(tag: :p, mb: 4, font_size: :small)) do+ t("saml.providers.section_texts.metadata_form")endendflex.with_row do+ render(Saml::Providers::MetadataCheckboxForm.new(form, provider:))+ end++ flex.with_row(mt: 2, hidden: !provider.has_metadata?, data: { 'show-when-checked-target': "effect" }) dorender(Saml::Providers::MetadataUrlForm.new(form))end+ flex.with_row(mt: 2, hidden: !provider.has_metadata?, data: { 'show-when-checked-target': "effect" }) do+ render(Saml::Providers::MetadataXmlForm.new(form))+ end+flex.with_row(mt: 4) do- render(Saml::Providers::SubmitOrCancelForm.new(form, provider:, state: :metadata))+ render(Saml::Providers::SubmitOrCancelForm.new(form,+ provider:,+ state: :metadata))endendenddiff --git a/modules/auth_saml/app/components/saml/providers/sections/name_component.html.erb b/modules/auth_saml/app/components/saml/providers/sections/name_component.html.erbindex a911047d0bb..9564ef43050 100644--- a/modules/auth_saml/app/components/saml/providers/sections/name_component.html.erb+++ b/modules/auth_saml/app/components/saml/providers/sections/name_component.html.erb@@ -1,15 +1,30 @@<%=- flex_layout do |flex|- flex.with_column do- render(Primer::Beta::Text.new(font_weight: :semibold)) { t("saml.providers.singular") }+ grid_layout('op-saml-view-row', tag: :div, align_items: :center) do |grid|+ grid.with_area(:title, mr: 3) do+ concat render(Primer::Beta::Text.new(font_weight: :bold)) { t("saml.providers.singular") }+ concat render(Primer::Beta::Label.new(scheme: :success, ml: 1)) { t(:label_completed) }end- flex.with_column do- render(Primer::Beta::Label.new(scheme: :success, ml: 1)) { t(:label_completed) }++ grid.with_area(:description) do+ render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do+ t("saml.providers.section_texts.display_name")+ end+ end++ grid.with_area(:action) do+ flex_layout(justify_content: :flex_end) do |icons_container|+ icons_container.with_column do+ render(+ Primer::Beta::IconButton.new(+ icon: :pencil,+ tag: :a,+ scheme: :invisible,+ href: edit_saml_provider_path(provider, edit_state: :name),+ aria: { label: I18n.t(:label_edit) }+ )+ )+ end+ endend- end-%>-<%=- render(Primer::Beta::Text.new(tag: :p, font_size: :small, color: :subtle)) do- t("saml.providers.section_texts.display_name")end%>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 6231524a526..58e9b882b0e 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@@ -12,7 +12,6 @@endend-component.with_row(scheme: :neutral, color: :muted) dorender(Primer::Beta::Text.new(font_weight: :semibold)) { I18n.t('saml.providers.label_automatic_configuration') }end@@ -24,56 +23,5 @@render(Saml::Providers::Sections::MetadataComponent.new(provider))endend- #- # component.with_row(scheme: :default) do- # render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))- # end- #- # component.with_row(scheme: :neutral, color: :muted) do- # grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|- # grid.with_area(:item, tag: :div) do- # render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.project_folders') }- # end- # end- # end- #- # component.with_row(scheme: :default) do- # if automatically_managed_project_folders_section_closed?- # render(Storages::Admin::AutomaticallyManagedProjectFoldersInfoComponent.new(storage))- # else- # render(Storages::Admin::Forms::AutomaticallyManagedProjectFoldersFormComponent.new(storage))- # end- # end- # end- #- # if storage.provider_type_one_drive?- # component.with_row(scheme: :neutral, color: :muted) do- # grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|- # grid.with_area(:item, tag: :div, mr: 3) do- # render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.access_management.title') }- # end- # end- # end- #- # component.with_row(scheme: :default) do- # render(Storages::Admin::AccessManagementComponent.new(storage))- # end- #- # component.with_row(scheme: :neutral, color: :muted) do- # grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|- # grid.with_area(:item, tag: :div, mr: 3) do- # render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_applications') }- # end- # end- # end- #- # component.with_row(scheme: :default) do- # render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))- # end- #- # component.with_row(scheme: :default) do- # render(Storages::Admin::RedirectUriComponent.new(oauth_client: storage.oauth_client, storage:))- # end- # endend%>diff --git a/modules/auth_saml/app/components/saml/providers/view_component.sass b/modules/auth_saml/app/components/saml/providers/view_component.sassnew file mode 100644index 00000000000..c17632077ee--- /dev/null+++ b/modules/auth_saml/app/components/saml/providers/view_component.sass@@ -0,0 +1,4 @@+.op-saml-view-row+ display: grid+ grid-template-columns: 3fr 1fr+ grid-template-areas: "title action" "description action"diff --git a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb b/modules/auth_saml/app/contracts/saml/providers/base_contract.rbindex 63a5c164f0b..617876207b3 100644--- a/modules/auth_saml/app/contracts/saml/providers/base_contract.rb+++ b/modules/auth_saml/app/contracts/saml/providers/base_contract.rb@@ -35,6 +35,7 @@ module Samlendattribute :display_name+ attribute :optionsendendenddiff --git a/modules/auth_saml/app/contracts/saml/providers/update_contract.rb b/modules/auth_saml/app/contracts/saml/providers/update_contract.rbindex 90e4bf6fd0f..17ade1f291f 100644--- a/modules/auth_saml/app/contracts/saml/providers/update_contract.rb+++ b/modules/auth_saml/app/contracts/saml/providers/update_contract.rb@@ -28,7 +28,10 @@module Samlmodule Providers- class UpdateContract < News::BaseContract+ class UpdateContract < BaseContract+ attribute :metadata_url+ validates :metadata_url,+ url: { allow_blank: true, allow_nil: true, schemes: %w[http https] }endendenddiff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rbindex 5a1086bd237..7cde74aade1 100644--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb@@ -5,27 +5,28 @@ module Samlbefore_action :require_adminbefore_action :check_ee- before_action :find_provider, only: %i[show edit update destroy]+ before_action :find_provider, only: %i[show edit import_metadata update destroy]def index@providers = Saml::Provider.allend- def edit; end+ def edit+ @edit_state = params[:edit_state].to_sym if params.key?(:edit_state)+ end+def show; enddef new@provider = ::Saml::Provider.newend- def import- @provider = ::Saml::Provider.new(name: import_params[:name])-- if import_params[:metadata_url].present?- import_metadata+ def import_metadata+ if import_params.present?+ update_provider_metadataend- render action: :edit+ redirect_to edit_saml_provider_path(@provider, edit_state: :configuration) unless performed?enddef create@@ -88,23 +89,59 @@ module Samlendend- def import_params- params.require(:saml_provider).permit(:name, :metadata_url)+ def update_provider_metadata+ call = Saml::Providers::UpdateService+ .new(model: @provider, user: User.current)+ .call(import_params)++ if call.success?+ load_and_apply_metadata+ else+ @provider = call.result+ @edit_state = :metadata++ flash[:error] = call.message+ render action: :edit+ endend- def import_metadata- call = Saml::MetadataParserService- .new(user: User.current)- .parse_url(import_params[:metadata_url])+ def load_and_apply_metadata+ call = Saml::UpdateMetadataService+ .new(provider: @provider, user: User.current)+ .call++ if call.success?+ apply_metadata(call.result)+ else+ @edit_state = :metadata++ flash[:error] = call.message+ render action: :edit+ end+ end++ def apply_metadata(params)+ call = Saml::Providers::UpdateService+ .new(model: @provider, user: User.current)+ .call({ options: params})if call.success?flash[:notice] = I18n.t("saml.metadata_parser.success")- @provider = ::Saml::Provider.new(**call.result.merge(name: import_params[:name]))else+ @provider = call.result+ @edit_state = :configuration+flash[:error] = call.message+ render action: :editendend+ def import_params+ params+ .require(:saml_provider)+ .permit(:metadata_url, :metadata_xml)+ end+def create_paramsparams.require(:saml_provider).permit(:display_name)enddiff --git a/modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rb b/modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rbnew file mode 100644index 00000000000..79a580d2ac0--- /dev/null+++ b/modules/auth_saml/app/forms/saml/providers/metadata_checkbox_form.rb@@ -0,0 +1,51 @@+#-- 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 Saml+ module Providers+ class MetadataCheckboxForm < ApplicationForm+ 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'+ }+ )+ end++ def initialize(provider:)+ super()+ @provider = provider+ end+ end+ end+enddiff --git a/modules/auth_saml/app/forms/saml/providers/metadata_xml_form.rb b/modules/auth_saml/app/forms/saml/providers/metadata_xml_form.rbnew file mode 100644index 00000000000..86a2718d51d--- /dev/null+++ b/modules/auth_saml/app/forms/saml/providers/metadata_xml_form.rb@@ -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 Saml+ module Providers+ class MetadataXmlForm < ApplicationForm+ form do |f|+ f.text_area(+ name: :metadata_xml,+ label: I18n.t("saml.settings.metadata_xml"),+ caption: I18n.t("saml.instructions.metadata_xml"),+ required: false,+ full_width: false,+ rows: 10,+ input_width: :medium+ )+ end+ end+ end+enddiff --git a/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rb b/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rbindex 519d287eb02..0dc350c9193 100644--- a/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rb+++ b/modules/auth_saml/app/forms/saml/providers/submit_or_cancel_form.rb@@ -33,6 +33,7 @@ module Samlif @statef.hidden(name: :edit_state,+ scope_name_to_model: false,value: @state)enddiff --git a/modules/auth_saml/app/models/saml/provider.rb b/modules/auth_saml/app/models/saml/provider.rbindex ff5db3dbd16..c5d678be92e 100644--- a/modules/auth_saml/app/models/saml/provider.rb+++ b/modules/auth_saml/app/models/saml/provider.rb@@ -27,14 +27,14 @@ module Saml"saml-#{id}"end- def assertion_consumer_service_url- URI.join(url_helpers.root_url, "/auth/#{name}/callback").to_s- end-def limit_self_registration?limit_self_registrationend+ def has_metadata?+ metadata_xml.present? || metadata_url.present?+ end+def to_hoptions.merge(@@ -43,8 +43,5 @@ module Samlassertion_consumer_service_url:,)end-- private-endenddiff --git a/modules/auth_saml/app/services/saml/metadata_parser_service.rb b/modules/auth_saml/app/services/saml/update_metadata_service.rbsimilarity index 71%rename from modules/auth_saml/app/services/saml/metadata_parser_service.rbrename to modules/auth_saml/app/services/saml/update_metadata_service.rbindex 1186204679a..6168077faac 100644--- a/modules/auth_saml/app/services/saml/metadata_parser_service.rb+++ b/modules/auth_saml/app/services/saml/update_metadata_service.rb@@ -27,35 +27,45 @@#++module Saml- class MetadataParserService- attr_reader :user+ class UpdateMetadataService+ attr_reader :user, :provider- def initialize(user:)+ def initialize(user:, provider:)@user = user+ @provider = providerend- def parse_url(url)- validate_url!(url)- parse_remote_metadata(url)- rescue URI::InvalidURIError- ServiceResult.failure(message: I18n.t('saml.metadata_parser.invalid_url'))- rescue OneLogin::RubySaml::HttpError => e- ServiceResult.failure(message: I18n.t('saml.metadata_parser.error', error: e.message))+ def call+ ServiceResult.success(result: updated_metadata)rescue StandardError => eOpenProject.logger.error(e)ServiceResult.failure(message: I18n.t('saml.metadata_parser.error', error: e.class.name))end- def parse_remote_metadata(metadata_url)- idp_metadata_parser = OneLogin::RubySaml::IdpMetadataParser.new- result = idp_metadata_parser.parse_remote_to_hash(metadata_url)+ private++ def updated_metadata+ if provider.metadata_url.present?+ parse_url+ elsif provider.metadata_xml.present?+ parse_xml+ else+ {}+ end+ end++ def parse_xml+ parser_instance.parse_to_hash(provider.metadata_xml)+ end- ServiceResult.success(result:)+ def parse_url+ parser.parse_remote_to_hash(metadata_url)+ rescue OneLogin::RubySaml::HttpError => e+ ServiceResult.failure(message: I18n.t('saml.metadata_parser.error', error: e.message))end- def validate_url!(url)- uri = URI.parse(url)- raise URI::InvalidURIError unless uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)+ def parser_instance+ OneLogin::RubySaml::IdpMetadataParser.newendendenddiff --git a/modules/auth_saml/app/views/saml/providers/edit.html.erb b/modules/auth_saml/app/views/saml/providers/edit.html.erbindex 25d092111a5..5859fc6f240 100644--- a/modules/auth_saml/app/views/saml/providers/edit.html.erb+++ b/modules/auth_saml/app/views/saml/providers/edit.html.erb@@ -1,19 +1,25 @@-<% page_title = t('saml.providers.label_edit', name: @provider.name) %>-<% local_assigns[:additional_breadcrumb] = @provider.name %>+<% page_title = t('saml.providers.label_edit', name: @provider.display_name) %>+<% local_assigns[:additional_breadcrumb] = @provider.display_name %><% html_title(t(:label_administration), page_title) -%>+<% content_controller "admin--saml", dynamic: true %>-<%= toolbar title: page_title %>+<%= render(Primer::OpenProject::PageHeader.new) do |header| %>+ <% header.with_title { page_title } %>-<%= error_messages_for @provider %>+ <% header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },+ { href: saml_providers_path, text: t('saml.providers.plural') },+ page_title]) %>-<%= @provider.assertion_consumer_service_url %>--<%= labelled_tabular_form_for @provider,- html: { class: 'form', autocomplete: 'off' } do |f| %>- <%= render partial: "form", locals: { f: f } %>- <p>- <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %>- <%= link_to t(:button_cancel), { action: :index }, class: 'button -with-icon icon-cancel' %>- </p>+ <% header.with_description do %>+ <%= link_translate(+ 'saml.instructions.new_description',+ links: {+ docs_url: ::OpenProject::Static::Links[:sysadmin_docs][:saml][:href],+ },+ target: "_blank"+ ) %>+ <% end %><% end %>++<%= render(Saml::Providers::ViewComponent.new(@provider, edit_state: @edit_state)) %>diff --git a/modules/auth_saml/config/locales/en.yml b/modules/auth_saml/config/locales/en.ymlindex 5baa6aeea47..b15892f3545 100644--- a/modules/auth_saml/config/locales/en.yml+++ b/modules/auth_saml/config/locales/en.yml@@ -17,7 +17,7 @@ en:description: >Use these parameters to configure your identity provider connection to OpenProject.metadata_parser:- success: "Successfully retrieved the identity provider metadata. Please review and save the configuration."+ success: "Successfully updated the configuration using the identity provider metadata. Please review and save the configuration."invalid_url: "Provided metadata URL is invalid. Provide a HTTP(s) URL."error: "Failed to retrieve the identity provider metadata: %{error}"providers:@@ -44,8 +44,11 @@ en:section_texts:display_name: "Configure the display name of the SAML provider."metadata: "Pre-fill configuration using a metadata URL or by pasting metadata XML"+ metadata_form: "If your identity provider has a metadata endpoint or XML download, add it below to pre-fill configuration."settings:- metadata_url: Identity provider metadata URL (Optional)+ metadata_checkbox: "I have metadata (optional)"+ metadata_url: "Metadata URL"+ metadata_xml: "Metadata XML"instructions:new_description: >Add a new SAML provider. Please refer to our [documentation on configuring SAML providers](docs_url).@@ -53,6 +56,7 @@ en:The name of the provider. This will be displayed as the login button and in the list of providers.metadata_url: >Enter the URL of the identity provider XML metadata endpoint.- If provided, OpenProject will try to prefill all available configuration options from your identity provider.+ metadata_xml: >+ Alternatively, enter the SAML metadata XML from your identity provider.limit_self_registration: >If enabled users can only register using this provider if the self registration setting allows for it.diff --git a/modules/auth_saml/config/routes.rb b/modules/auth_saml/config/routes.rbindex e09a10516a0..926f2427ae9 100644--- a/modules/auth_saml/config/routes.rb+++ b/modules/auth_saml/config/routes.rb@@ -2,8 +2,8 @@ Rails.application.routes.draw doscope :admin donamespace :saml doresources :providers do- collection do- post :import+ member do+ post :import_metadataendendend