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

Add missing property to storages API

Jan Sandbrinked8310840c02
diff --git a/docs/api/apiv3/components/schemas/storage_read_model.yml b/docs/api/apiv3/components/schemas/storage_read_model.yml
index 9beab56c8de..4fbfed50382 100644
--- a/docs/api/apiv3/components/schemas/storage_read_model.yml
+++ b/docs/api/apiv3/components/schemas/storage_read_model.yml
@@ -25,6 +25,13 @@ properties:
This is only required for authentication through single-sign-on and so far
only supported for provider type Nextcloud.
+ tokenExchangeScope:
+ type: string
+ description: |-
+ The scope that will be requested when requesting a token for the storage through token exchange. Has no effect if no
+ token exchange is performed.
+
+ This is only required for authentication through single-sign-on and so far only supported for provider type Nextcloud.
tenantId:
type: string
description: |-
diff --git a/docs/api/apiv3/components/schemas/storage_write_model.yml b/docs/api/apiv3/components/schemas/storage_write_model.yml
index c9526819795..c47b7673539 100644
--- a/docs/api/apiv3/components/schemas/storage_write_model.yml
+++ b/docs/api/apiv3/components/schemas/storage_write_model.yml
@@ -13,6 +13,13 @@ properties:
This is only required for authentication through single-sign-on and so far
only supported for provider type Nextcloud.
+ tokenExchangeScope:
+ type: string
+ description: |-
+ The scope that will be requested when requesting a token for the storage through token exchange. Has no effect if no
+ token exchange is performed.
+
+ This is only required for authentication through single-sign-on and so far only supported for provider type Nextcloud.
applicationPassword:
type:
- string
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index fbd945564e5..4eb134024ef 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -99,6 +99,11 @@ module API::V3::Storages
getter: ->(represented:, **) { represented.provider_type_nextcloud? && represented.storage_audience },
setter: ->(fragment:, represented:, **) { represented.storage_audience = fragment }
+ property :tokenExchangeScope,
+ skip_render: ->(represented:, **) { !represented.provider_type_nextcloud? },
+ getter: ->(represented:, **) { represented.provider_type_nextcloud? && represented.token_exchange_scope },
+ setter: ->(fragment:, represented:, **) { represented.token_exchange_scope = fragment }
+
property :applicationPassword,
skip_render: ->(*) { true },
getter: ->(*) {},
diff --git a/modules/storages/spec/lib/api/v3/storages/storages_representer_parsing_spec.rb b/modules/storages/spec/lib/api/v3/storages/storages_representer_parsing_spec.rb
index 17db7d8a901..f42f6056583 100644
--- a/modules/storages/spec/lib/api/v3/storages/storages_representer_parsing_spec.rb
+++ b/modules/storages/spec/lib/api/v3/storages/storages_representer_parsing_spec.rb
@@ -100,6 +100,7 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "parsing" do
"href" => "urn:openproject-org:api:v3:storages:authenticationMethod:OAuth2SSO"
}
parsed_hash["storageAudience"] = "the-new-storage-audience"
+ parsed_hash["tokenExchangeScope"] = "one-scope two-scope"
end
it "parses the authentication method" do
@@ -109,6 +110,10 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "parsing" do
it "parses the storage audience" do
expect(parsed.storage_audience).to eq("the-new-storage-audience")
end
+
+ it "parses the token exchange scope" do
+ expect(parsed.token_exchange_scope).to eq("one-scope two-scope")
+ end
end
describe "automatically managed project folders" do
diff --git a/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb
index ac82556cf45..2882b498481 100644
--- a/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb
+++ b/modules/storages/spec/lib/api/v3/storages/storages_representer_rendering_spec.rb
@@ -265,6 +265,26 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" do
end
end
end
+
+ describe "tokenExchangeScope" do
+ it_behaves_like "no property", :tokenExchangeScope
+
+ context "when the storage is configured for SSO authentication" do
+ let(:storage) { create(:nextcloud_storage, :oidc_sso_enabled, token_exchange_scope: "a-scope") }
+
+ it_behaves_like "property", :tokenExchangeScope do
+ let(:value) { "a-scope" }
+ end
+ end
+
+ context "when the storage is configured for SSO authentication, but has an empty scope" do
+ let(:storage) { create(:nextcloud_storage, :oidc_sso_enabled, token_exchange_scope: "") }
+
+ it_behaves_like "property", :tokenExchangeScope do
+ let(:value) { "" }
+ end
+ end
+ end
end
it_behaves_like "common file storage links"