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
Allow admins to choose not exchanging for specific SSO token
Jan Sandbrink18b7ebf77c45
diff --git a/frontend/src/stimulus/controllers/dynamic/storages/storage-audience.controller.ts b/frontend/src/stimulus/controllers/dynamic/storages/storage-audience.controller.tsnew file mode 100644index 00000000000..ecbf280edcc--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/storages/storage-audience.controller.ts@@ -0,0 +1,58 @@+/*+ * -- 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.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class StorageAudienceController extends Controller {+ static targets = [+ 'audienceInput',+ 'audienceInputWrapper',+ 'idpRadio',+ ];++ declare readonly audienceInputTarget:HTMLInputElement;+ declare readonly audienceInputWrapperTarget:HTMLDivElement;+ declare readonly idpRadioTarget:HTMLInputElement;++ connect() {+ if (this.idpRadioTarget.checked) {+ this.hideAudienceInput();+ }+ }++ showAudienceInput() {+ this.audienceInputTarget.value = '';+ this.audienceInputWrapperTarget.classList.remove('d-none');+ }++ hideAudienceInput() {+ this.audienceInputWrapperTarget.classList.add('d-none');+ }+}diff --git a/modules/storages/app/components/storages/admin/forms/nextcloud_audience_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/nextcloud_audience_form_component.html.erbindex b720fe418f7..939cdd5aeda 100644--- a/modules/storages/app/components/storages/admin/forms/nextcloud_audience_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/nextcloud_audience_form_component.html.erb@@ -34,7 +34,11 @@ See COPYRIGHT and LICENSE files for more details.model:,url: form_url,method: :patch,- data: { turbo_frame: "page-content" }+ data: {+ turbo_frame: "page-content",+ application_target: "dynamic",+ controller: "storages--storage-audience"+ }) do |form|flex_layout do |general_info_row|general_info_row.with_row(mb: 3) dodiff --git a/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.erb b/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.erbindex 8046080c048..4688465bc30 100644--- a/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.erb+++ b/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.erb@@ -36,13 +36,7 @@ See COPYRIGHT and LICENSE files for more details.endgrid.with_area(:description, tag: :div, color: :subtle, test_selector: 'nextcloud-audience-description') do- concat(render(Primer::Beta::Text.new) {- if storage.nextcloud_audience.present?- I18n.t('storages.file_storage_view.nextcloud_audience_description', audience: storage.nextcloud_audience)- else- I18n.t('storages.file_storage_view.nextcloud_audience_blank')- end- })+ concat(render(Primer::Beta::Text.new) { audience_summary })endif editable_storage?diff --git a/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.rb b/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.rbindex dc2d030d2dc..6c0ff21cad7 100644--- a/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.rb+++ b/modules/storages/app/components/storages/admin/nextcloud_audience_info_component.rb@@ -32,6 +32,17 @@ module Storagesmodule Adminclass NextcloudAudienceInfoComponent < StorageInfoComponentdef self.wrapper_key = :storage_nextcloud_audience_section++ def audience_summary+ case storage.nextcloud_audience+ when ""+ I18n.t("storages.file_storage_view.nextcloud_audience_blank")+ when OpenIDConnect::UserToken::IDP_AUDIENCE+ I18n.t("storages.file_storage_view.nextcloud_audience_idp")+ else+ I18n.t("storages.file_storage_view.nextcloud_audience_description", audience: storage.nextcloud_audience)+ end+ endendendenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex cd90f2138f9..fed0763d292 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -252,6 +252,7 @@ class Storages::Admin::StoragesController < ApplicationController"provider_type","host","authentication_method",+ "audience_configuration","nextcloud_audience","oauth_client_id","oauth_client_secret",diff --git a/modules/storages/app/forms/storages/admin/nextcloud_audience_input_form.rb b/modules/storages/app/forms/storages/admin/nextcloud_audience_input_form.rbindex ffd6fd6fb1c..266037c3b7a 100644--- a/modules/storages/app/forms/storages/admin/nextcloud_audience_input_form.rb+++ b/modules/storages/app/forms/storages/admin/nextcloud_audience_input_form.rb@@ -31,14 +31,41 @@module Storages::Adminclass NextcloudAudienceInputForm < ApplicationFormform do |storage_form|- storage_form.text_field(- name: :nextcloud_audience,- label: I18n.t("activerecord.attributes.storages/nextcloud_storage.nextcloud_audience"),- required: true,- caption: I18n.t("storages.instructions.nextcloud.nextcloud_audience"),- placeholder: I18n.t("storages.instructions.nextcloud.nextcloud_audience_placeholder"),- input_width: :large- )+ storage_form.radio_button_group(name: :audience_configuration) do |group|+ group.radio_button(+ value: :idp,+ checked: idp?,+ label: I18n.t("storages.storage_audience.idp.label"),+ caption: I18n.t("storages.storage_audience.idp.helptext"),+ data: { action: "storages--storage-audience#hideAudienceInput", "storages--storage-audience-target": "idpRadio" }+ )++ group.radio_button(+ value: :manual,+ checked: !idp?,+ label: I18n.t("storages.storage_audience.manual.label"),+ caption: I18n.t("storages.storage_audience.manual.helptext"),+ data: { action: "storages--storage-audience#showAudienceInput" }+ )+ end++ storage_form.group(data: { "storages--storage-audience-target": "audienceInputWrapper" }) do |toggleable_group|+ toggleable_group.text_field(+ name: :nextcloud_audience,+ label: I18n.t("activerecord.attributes.storages/nextcloud_storage.nextcloud_audience"),+ required: true,+ caption: I18n.t("storages.instructions.nextcloud.nextcloud_audience"),+ placeholder: I18n.t("storages.instructions.nextcloud.nextcloud_audience_placeholder"),+ input_width: :large,+ data: { "storages--storage-audience-target": "audienceInput" }+ )+ end+ end++ private++ def idp?+ model.nextcloud_audience == OpenIDConnect::UserToken::IDP_AUDIENCEendendenddiff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rbindex 63adc6f51e6..3f2eb6a90ef 100644--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb@@ -40,8 +40,12 @@ module Storages::Storagesprivatedef set_attributes(params)+ audience_config = params.delete(:audience_configuration)+super+unset_nextcloud_application_credentials if nextcloud_storage?+ set_idp_audience if audience_config == "idp"enddef sanitize_host@@ -72,5 +76,9 @@ module Storages::Storagesdef nextcloud_storage?storage.is_a?(Storages::NextcloudStorage)end++ def set_idp_audience+ storage.nextcloud_audience = OpenIDConnect::UserToken::IDP_AUDIENCE+ endendenddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 90a3ddf3106..29f14a8d370 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -212,7 +212,8 @@ en:general_information: General informationnextcloud_audience: Nextcloud Audiencenextcloud_audience_blank: No audience has been configured- nextcloud_audience_description: Using audience %{audience}+ nextcloud_audience_description: Obtaining tokens for audience "%{audience}".+ nextcloud_audience_idp: Using first access token received by identity provider, regardless of audience.nextcloud_oauth: Nextcloud OAuthoauth_configuration: OAuth configurationone_drive_oauth: Azure OAuth@@ -405,6 +406,13 @@ en:'label: Show attachments in the work packages files tab+ storage_audience:+ idp:+ helptext: OpenProject will use the first access token received by the identity provider to authenticate requests to the storage. It will not try to obtain another token.+ label: Use first access token obtained by identity provider+ manual:+ helptext: Allows you to set the audience of the storage. OpenProject will try to obtain a token for the given audience from the identity provider.+ label: Define storage audience manuallystorage_list_blank_slate:description: Add a storage to see them here.heading: You don't have any storages yet.diff --git a/modules/storages/spec/features/storages/admin/create_storage_spec.rb b/modules/storages/spec/features/storages/admin/create_storage_spec.rbindex 4f49bef352b..4f80abc2704 100644--- a/modules/storages/spec/features/storages/admin/create_storage_spec.rb+++ b/modules/storages/spec/features/storages/admin/create_storage_spec.rb@@ -220,7 +220,7 @@ RSpec.describe "Admin Create a new file storage",endexpect(page).to have_test_selector("label-nextcloud_audience_configured-status", text: "Completed")- expect(page).to have_test_selector("nextcloud-audience-description", text: "Using audience nextcloud")+ expect(page).to have_test_selector("nextcloud-audience-description", text: "Obtaining tokens for audience \"nextcloud\"")endaggregate_failures "Automatically managed project folders" do