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
[#55158] Add complete attribute to storage representer
Eric Schubert064cfd6ff915
diff --git a/docs/api/apiv3/components/examples/storage-nextcloud-response-for-creation.yml b/docs/api/apiv3/components/examples/storage-nextcloud-response-for-creation.ymlnew file mode 100644index 00000000000..929a62a2fb8--- /dev/null+++ b/docs/api/apiv3/components/examples/storage-nextcloud-response-for-creation.yml@@ -0,0 +1,55 @@+# Example: Nextcloud storage on creation (includes client secret)+---+value:+ _type: Storage+ id: 1337+ name: My New DeathStar+ hasApplicationPassword: false+ createdAt: '2024-05-21T09:11:53.880Z'+ updatedAt: '2024-05-21T09:11:53.880Z'+ complete: false+ _embedded:+ oauthApplication:+ id: 42+ _type: OAuthApplication+ name: My New DeathStar (Nextcloud)+ clientId: gNQ-gi3VX59ruoft5B9aRmukEYbZOhKIsxXE9iT1tcQ+ confidential: true+ clientSecret: 79hIlb1Ezj5kPx8LgE6LI9L1-mb8g7jX1-u_a08RJlI+ createdAt: '2024-05-21T09:11:53.908Z'+ updatedAt: '2024-05-21T09:11:53.908Z'+ scopes:+ - api_v3+ _links:+ self:+ href: '/api/v3/oauth_applications/42'+ owner:+ href: '/api/v3/users/13'+ title: Darth Vader+ integration:+ href: '/api/v3/storages/1337'+ title: My New DeathStar+ redirectUri:+ - href: 'https://nextcloud.deathstar.rocks/index.php/apps/integration_openproject/oauth-redirect'+ _links:+ self:+ href: /api/v3/storages/1337+ title: My New DeathStar+ type:+ href: urn:openproject-org:api:v3:storages:Nextcloud+ title: Nextcloud+ origin:+ href: https://nextcloud.deathstar.rocks/+ open:+ href: /api/v3/storages/1337/open+ prepareUpload: []+ authorizationState:+ href: urn:openproject-org:api:v3:storages:authorization:FailedAuthorization+ title: Authorization failed+ projectStrages:+ href: /api/v3/project_storages?filters=[{"storageId":{"operator":"=","values":["1337"]}}]+ oauthApplication:+ href: /api/v3/oauth_application/42+ title: My New DeathStar (Nextcloud)+ oauthClientCredentials:+ href: nulldiff --git a/docs/api/apiv3/components/examples/storage-nextcloud-response.yml b/docs/api/apiv3/components/examples/storage-nextcloud-response.ymlnew file mode 100644index 00000000000..8cc42f3bfa8--- /dev/null+++ b/docs/api/apiv3/components/examples/storage-nextcloud-response.yml@@ -0,0 +1,86 @@+# Example: Nextcloud storage+---+value:+ _type: Storage+ id: 1337+ name: It's no moon+ hasApplicationPassword: true+ createdAt: '2021-12-20T13:37:00.211Z'+ updatedAt: '2021-12-20T13:37:00.211Z'+ complete: true+ _embedded:+ oauthApplication:+ id: 42+ _type: OAuthApplication+ name: It's no moon (Nextcloud)+ clientId: O5h6WObhMg1Z8IcLHRE3_LMh4jJYmmca2V6OTFSv8DA+ confidential: true+ createdAt: '2022-12-07T12:56:42.626Z'+ updatedAt: '2022-12-07T12:56:42.626Z'+ scopes:+ - api_v3+ _links:+ self:+ href: '/api/v3/oauth_applications/42'+ owner:+ href: '/api/v3/users/13'+ title: Darth Vader+ integration:+ href: '/api/v3/storages/1337'+ title: It's no moon+ redirectUri:+ - href: 'https://nextcloud.deathstar.rocks/index.php/apps/integration_openproject/oauth-redirect'+ oauthClientCredentials:+ _type: OAuthClientCredentials+ id: 42+ clientId: fGEFWxIpROrpci25TW6qWCZozDFEAKSkonMBkrf3LYvBXRljBbLajBf2vD2fjePm+ confidential: true+ createdAt: '2023-12-08T09:49:24.397Z'+ updatedAt: '2023-12-08T09:49:24.397Z'+ _links:+ self:+ href: /api/v3/oauth_client_credentials/42+ integration:+ href: /api/v3/storages/1337+ title: It's no moon+ _links:+ self:+ href: /api/v3/storages/1337+ title: It's no moon+ type:+ href: urn:openproject-org:api:v3:storages:Nextcloud+ title: Nextcloud+ origin:+ href: https://nextcloud.deathstar.rocks/+ prepareUpload:+ - href: /api/v3/storages/1337/files/prepare_upload+ method: post+ title: Upload file+ payload:+ projectId: 21+ fileName: '{fileName}'+ parent: '{parent}'+ templated: true+ - href: /api/v3/storages/95/files/prepare_upload+ method: post+ title: Upload file+ payload:+ projectId: 11+ fileName: '{fileName}'+ parent: '{parent}'+ templated: true+ open:+ href: /api/v3/storages/1337/open+ authorizationState:+ href: urn:openproject-org:api:v3:storages:authorization:Connected+ title: Connected+ # authorize:+ # href: https://nextcloud.deathstar.rocks/authorize/+ # title: Authorize+ projectStrages:+ href: /api/v3/project_storages?filters=[{"storageId":{"operator":"=","values":["1337"]}}]+ oauthApplication:+ href: /api/v3/oauth_application/42+ title: It's no moon (Nextcloud)+ oauthClientCredentials:+ href: /api/v3/oauth_client_credentials/42diff --git a/docs/api/apiv3/components/examples/storage-nextcloud-unauthorized-response.yml b/docs/api/apiv3/components/examples/storage-nextcloud-unauthorized-response.ymlnew file mode 100644index 00000000000..6a9ad6b4818--- /dev/null+++ b/docs/api/apiv3/components/examples/storage-nextcloud-unauthorized-response.yml@@ -0,0 +1,70 @@+# Example: Nextcloud storage+---+value:+ _type: Storage+ id: 1337+ name: It's no moon+ hasApplicationPassword: false+ createdAt: '2021-12-20T13:37:00.211Z'+ updatedAt: '2021-12-20T13:37:00.211Z'+ complete: true+ _embedded:+ oauthApplication:+ id: 42+ _type: OAuthApplication+ name: It's no moon (Nextcloud)+ clientId: O5h6WObhMg1Z8IcLHRE3_LMh4jJYmmca2V6OTFSv8DA+ confidential: true+ createdAt: '2022-12-07T12:56:42.626Z'+ updatedAt: '2022-12-07T12:56:42.626Z'+ scopes:+ - api_v3+ _links:+ self:+ href: '/api/v3/oauth_applications/42'+ owner:+ href: '/api/v3/users/13'+ title: Darth Vader+ integration:+ href: '/api/v3/storages/1337'+ title: It's no moon+ redirectUri:+ - href: 'https://nextcloud.deathstar.rocks/index.php/apps/integration_openproject/oauth-redirect'+ oauthClientCredentials:+ _type: OAuthClientCredentials+ id: 42+ clientId: fGEFWxIpROrpci25TW6qWCZozDFEAKSkonMBkrf3LYvBXRljBbLajBf2vD2fjePm+ confidential: true+ createdAt: '2023-12-08T09:49:24.397Z'+ updatedAt: '2023-12-08T09:49:24.397Z'+ _links:+ self:+ href: /api/v3/oauth_client_credentials/42+ integration:+ href: /api/v3/storages/1337+ title: It's no moon+ _links:+ self:+ href: /api/v3/storages/1337+ title: It's no moon+ type:+ href: urn:openproject-org:api:v3:storages:Nextcloud+ title: Nextcloud+ origin:+ href: https://nextcloud.deathstar.rocks/+ prepareUpload: []+ open:+ href: /api/v3/storages/1337/open+ authorizationState:+ href: urn:openproject-org:api:v3:storages:authorization:FailedAuthorization+ title: Authorization failed+ authorize:+ href: https://nextcloud25.local/index.php/apps/oauth2/authorize?client_id=fnrIeJZqqAKGQlejuDaGhSQfCAVtoayHLACWCYcPJ0w17Pp6daPPUktkM9QaGxca&redirect_uri=https://openproject.local/oauth_clients/fnrIeJZqqAKGQlejuDaGhSQfCAVtoayHLACWCYcPJ0w17Pp6daPPUktkM9QaGxca/callback&response_type=code+ title: Authorize+ projectStrages:+ href: /api/v3/project_storages?filters=[{"storageId":{"operator":"=","values":["1337"]}}]+ oauthApplication:+ href: /api/v3/oauth_application/42+ title: It's no moon (Nextcloud)+ oauthClientCredentials:+ href: /api/v3/oauth_client_credentials/42diff --git a/docs/api/apiv3/components/examples/storage-one-drive-incomplete-response.yml b/docs/api/apiv3/components/examples/storage-one-drive-incomplete-response.ymlnew file mode 100644index 00000000000..e5b63875491--- /dev/null+++ b/docs/api/apiv3/components/examples/storage-one-drive-incomplete-response.yml@@ -0,0 +1,28 @@+# Example: OneDrive storage+---+value:+ _type: Storage+ id: 1337+ name: It's no moon+ tenantId: e36f1dbc-fdae-427e-b61b-0d96ddfb81a4+ driveId: null+ createdAt: '2021-12-20T13:37:00.211Z'+ updatedAt: '2021-12-20T13:37:00.211Z'+ complete: true+ _links:+ self:+ href: /api/v3/storages/1337+ title: It's no moon+ type:+ href: urn:openproject-org:api:v3:storages:OneDrive+ title: OneDrive/SharePoint+ prepareUpload: []+ open:+ href: /api/v3/storages/1337/open+ authorizationState:+ href: urn:openproject-org:api:v3:storages:authorization:FailedAuthorization+ title: Authorization failed+ projectStrages:+ href: /api/v3/project_storages?filters=[{"storageId":{"operator":"=","values":["1337"]}}]+ oauthClientCredentials:+ href: /api/v3/oauth_client_credentials/42diff --git a/docs/api/apiv3/components/examples/storage-one-drive-response.yml b/docs/api/apiv3/components/examples/storage-one-drive-response.ymlnew file mode 100644index 00000000000..2fa7543ff19--- /dev/null+++ b/docs/api/apiv3/components/examples/storage-one-drive-response.yml@@ -0,0 +1,50 @@+# Example: OneDrive storage+---+value:+ _type: Storage+ id: 1337+ name: It's no moon+ tenantId: e36f1dbc-fdae-427e-b61b-0d96ddfb81a4+ driveId: b!FeOZEMfQx0eGQKqVBLcP__BG8mq-4-9FuRqOyk3MXY8Qconfm2i6SKEoCmuGYqQK+ createdAt: '2021-12-20T13:37:00.211Z'+ updatedAt: '2021-12-20T13:37:00.211Z'+ complete: true+ _embedded:+ oauthClientCredentials:+ _type: OAuthClientCredentials+ id: 42+ clientId: b8a5bb54-5fb2-4e0e-9427-9d24dbac32ff+ confidential: true+ createdAt: '2023-12-08T09:49:24.397Z'+ updatedAt: '2023-12-08T09:49:24.397Z'+ _links:+ self:+ href: /api/v3/oauth_client_credentials/42+ integration:+ href: /api/v3/storages/1337+ title: It's no moon+ _links:+ self:+ href: /api/v3/storages/1337+ title: It's no moon+ type:+ href: urn:openproject-org:api:v3:storages:OneDrive+ title: OneDrive/SharePoint+ prepareUpload:+ - href: /api/v3/storages/1337/files/prepare_upload+ method: post+ title: Upload file+ payload:+ projectId: 33+ fileName: '{fileName}'+ parent: '{parent}'+ templated: true+ open:+ href: /api/v3/storages/1337/open+ authorizationState:+ href: urn:openproject-org:api:v3:storages:authorization:Connected+ title: Connected+ projectStrages:+ href: /api/v3/project_storages?filters=[{"storageId":{"operator":"=","values":["1337"]}}]+ oauthClientCredentials:+ href: /api/v3/oauth_client_credentials/42diff --git a/docs/api/apiv3/components/schemas/oauth_application_read_model.yml b/docs/api/apiv3/components/schemas/oauth_application_read_model.ymlindex 8a7b98d3f02..bd63d469814 100644--- a/docs/api/apiv3/components/schemas/oauth_application_read_model.yml+++ b/docs/api/apiv3/components/schemas/oauth_application_read_model.yml@@ -71,16 +71,18 @@ properties:**Resource**: StorageredirectUri:- allOf:- - $ref: './link.yml'- - description: |-- The redirect URI of the OAuth application-- **Resource**: N/A+ type: array+ items:+ allOf:+ - $ref: './link.yml'+ - description: |-+ A redirect URI of the OAuth application++ **Resource**: N/Aexample:id: 1337- _type: OauthClientCredentials+ _type: OAuthApplicationname: Vader's secure OAuth appclientId: O5h6WObhMg1Z8IcLHRE3_LMh4jJYmmca2V6OTFSv8DAconfidential: true@@ -98,4 +100,4 @@ example:href: '/api/v3/storages/42'title: Death Star CloudredirectUri:- href: 'https://death-star.cloud.tools/index.php/apps/integration_openproject/oauth-redirect'+ - href: 'https://death-star.cloud.tools/index.php/apps/integration_openproject/oauth-redirect'diff --git a/docs/api/apiv3/components/schemas/storage_read_model.yml b/docs/api/apiv3/components/schemas/storage_read_model.ymlindex 4ebcfaf19a1..80060d7f737 100644--- a/docs/api/apiv3/components/schemas/storage_read_model.yml+++ b/docs/api/apiv3/components/schemas/storage_read_model.yml@@ -17,12 +17,24 @@ properties:name:type: stringdescription: Storage name+ tenantId:+ type: string+ description: |-+ The tenant id of a file storage of type OneDrive/SharePoint.++ Ignored if the provider type is not OneDrive/SharePoint.+ driveId:+ type: string+ description: |-+ The drive id of a file storage of type OneDrive/SharePoint.++ Ignored if the provider type is not OneDrive/SharePoint.hasApplicationPassword:type: booleandescription: |-Whether the storage has the application password to use for the Nextcloud storage.- Ignored if the provider type is not Nextcloud+ Ignored if the provider type is not Nextcloud.createdAt:type: stringformat: date-time@@ -31,11 +43,11 @@ properties:type: stringformat: date-timedescription: Time of the most recent change to the storage+ complete:+ type: boolean+ description: Indication, if the storage is fully configured_embedded:type: object- required:- - oauthApplication- - oauthClientCredentialsproperties:oauthApplication:$ref: './oauth_application_read_model.yml'@@ -46,7 +58,6 @@ properties:required:- self- type- - origin- open- authorizationStateproperties:@@ -68,7 +79,8 @@ properties:allOf:- $ref: './link.yml'- description: |-- Web URI of the storage instance.+ Web URI of the storage instance. This link is ignored, if the storage is hosted in a cloud and has no own+ URL, like file storages of type OneDrive/SharePoint.**Resource**: N/Aopen:@@ -124,32 +136,3 @@ properties:- User has role `admin`**Resource**: OAuthClientCredentials-example:- id: 1337- _type: Storage- name: It's no moon- hasApplicationPassword: true- createdAt: '2021-12-20T13:37:00.211Z'- updatedAt: '2021-12-20T13:37:00.211Z'- _links:- self:- href: /api/v3/storages/1337- title: It's no moon- type:- href: urn:openproject-org:api:v3:storages:nextcloud- title: Nextcloud- origin:- href: https://nextcloud.deathstar.rocks/- open:- href: https://nextcloud.deathstar.rocks/apps/files- authorizationState:- href: urn:openproject-org:api:v3:storages:authorization:FailedAuthorization- title: Failed Authorization- authorize:- href: https://nextcloud.deathstar.rocks/authorize/- title: Authorize- oauthApplication:- href: /api/v3/oauth_application/42- title: It's no moon (Nextcloud)- oauthClientCredentials:- href: /api/v3/oauth_client_credentials/42diff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex be010effa5c..38b8112aea8 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -513,6 +513,16 @@ components:$ref: "./components/examples/project_body.yml"ProjectCollection:$ref: "./components/examples/project_collection.yml"+ StorageNextcloudResponse:+ $ref: "./components/examples/storage-nextcloud-response.yml"+ StorageNextcloudResponseForCreation:+ $ref: "./components/examples/storage-nextcloud-response-for-creation.yml"+ StorageNextcloudUnauthorizedResponse:+ $ref: "./components/examples/storage-nextcloud-unauthorized-response.yml"+ StorageOneDriveIncompleteResponse:+ $ref: "./components/examples/storage-one-drive-incomplete-response.yml"+ StorageOneDriveResponse:+ $ref: "./components/examples/storage-one-drive-response.yml"QueriesModel:$ref: "./components/examples/queries.yml"QueryModel:diff --git a/docs/api/apiv3/paths/storage.yml b/docs/api/apiv3/paths/storage.ymlindex 630565bc9f2..f93ccd7738e 100644--- a/docs/api/apiv3/paths/storage.yml+++ b/docs/api/apiv3/paths/storage.yml@@ -23,6 +23,17 @@ get:application/hal+json:schema:$ref: '../components/schemas/storage_read_model.yml'+ examples:+ 'Nextcloud storage':+ $ref: '../components/examples/storage-nextcloud-response.yml'+ 'Freshly created Nextcloud storage':+ $ref: '../components/examples/storage-nextcloud-response-for-creation.yml'+ 'OneDrive storage':+ $ref: '../components/examples/storage-one-drive-response.yml'+ 'Incomplete OneDrive storage':+ $ref: '../components/examples/storage-one-drive-incomplete-response.yml'+ 'Unauthorized Nextcloud storage':+ $ref: '../components/examples/storage-nextcloud-unauthorized-response.yml''404':content:application/hal+json:diff --git a/lib/api/v3/oauth/oauth_applications_representer.rb b/lib/api/v3/oauth/oauth_applications_representer.rbindex 440984d241a..6740d526960 100644--- a/lib/api/v3/oauth/oauth_applications_representer.rb+++ b/lib/api/v3/oauth/oauth_applications_representer.rb@@ -76,10 +76,8 @@ module API::V3::OAuth}end- link :redirectUri do- {- href: represented.redirect_uri- }+ links :redirectUri do+ represented.redirect_uri.split(/[\r\n]+/).map { |href| { href: } }enddef _typediff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rbindex 4dc51c9f8eb..728eb983d6e 100644--- a/modules/storages/lib/api/v3/storages/storage_representer.rb+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb@@ -90,14 +90,28 @@ module API::V3::Storagesend}+ property :tenant_id,+ skip_render: ->(represented:, **) { !represented.provider_type_one_drive? },+ render_nil: true,+ getter: ->(represented:, **) { represented.tenant_id if represented.provider_type_one_drive? },+ setter: ->(fragment:, represented:, **) { represented.tenant_id = fragment }++ property :drive_id,+ skip_render: ->(represented:, **) { !represented.provider_type_one_drive? },+ render_nil: true,+ getter: ->(represented:, **) { represented.drive_id if represented.provider_type_one_drive? },+ setter: ->(fragment:, represented:, **) { represented.drive_id = fragment }++ property :complete,+ skip_parse: true,+ getter: ->(represented:, **) { represented.configured? }+property :hasApplicationPassword,skip_parse: true,skip_render: ->(represented:, **) { !represented.provider_type_nextcloud? },- getter: ->(represented:, **) {- break unless represented.provider_type_nextcloud?-- represented.automatic_management_enabled?- },+ getter: ->(represented:, **) do+ represented.automatic_management_enabled? if represented.provider_type_nextcloud?+ end,setter: ->(*) {}date_time_property :created_at@@ -120,7 +134,7 @@ module API::V3::Storages}link_without_resource :origin,- getter: ->(*) { { href: represented.host } },+ getter: ->(*) { { href: represented.host } if represented.host.present? },setter: ->(fragment:, **) {break if fragment["href"].blank?diff --git a/modules/storages/spec/factories/storage_factory.rb b/modules/storages/spec/factories/storage_factory.rbindex eedac36bc0e..fa71537c4e8 100644--- a/modules/storages/spec/factories/storage_factory.rb+++ b/modules/storages/spec/factories/storage_factory.rb@@ -163,6 +163,7 @@ FactoryBot.define dohost { nil }tenant_id { SecureRandom.uuid }drive_id { SecureRandom.uuid }+ automatically_managed { false }trait :as_automatically_managed doautomatically_managed { true }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.rbindex e4fe4281275..96f947a634a 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@@ -32,14 +32,41 @@ require "spec_helper"require_module_spec_helperRSpec.describe API::V3::Storages::StorageRepresenter, "parsing" do- let(:storage) { build_stubbed(:nextcloud_storage) }let(:current_user) { build_stubbed(:user) }+ let(:representer) { described_class.new(storage, current_user:) }- describe "parsing" do- subject(:parsed) { representer.from_hash parsed_hash }+ subject(:parsed) { representer.from_hash parsed_hash }- let(:representer) { described_class.new(storage, current_user:) }+ describe "OneDrive/SharePoint" do+ let(:storage) { build_stubbed(:one_drive_storage) }+ let(:parsed_hash) do+ {+ "name" => "My SharePoint",+ "tenantId" => "e36f1dbc-fdae-427e-b61b-0d96ddfb81a4",+ "_links" => {+ "type" => {+ "href" => API::V3::Storages::URN_STORAGE_TYPE_ONE_DRIVE+ }+ }+ }+ end++ context "with basic attributes" do+ it "is parsed correctly" do+ expect(parsed).to have_attributes(name: "My SharePoint",+ tenant_id: "e36f1dbc-fdae-427e-b61b-0d96ddfb81a4",+ provider_type: "Storages::OneDriveStorage")++ aggregate_failures "honors provider fields defaults" do+ expect(parsed).not_to be_automatically_managed+ expect(parsed).to be_health_notifications_enabled+ end+ end+ end+ end+ describe "Nextcloud" do+ let(:storage) { build_stubbed(:nextcloud_storage) }let(:parsed_hash) do{"name" => "Nextcloud Local",@@ -56,7 +83,8 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "parsing" docontext "with basic attributes" doit "is parsed correctly" do- expect(parsed).to have_attributes(name: "Nextcloud Local", host: storage.host,+ expect(parsed).to have_attributes(name: "Nextcloud Local",+ host: storage.host,provider_type: "Storages::NextcloudStorage")aggregate_failures "honors provider fields defaults" dodiff --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.rbindex 529e52ffc5c..4f0a733d8b0 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@@ -32,9 +32,7 @@ require "spec_helper"require_module_spec_helperRSpec.describe API::V3::Storages::StorageRepresenter, "rendering" do- let(:oauth_application) { build_stubbed(:oauth_application) }let(:oauth_client_credentials) { build_stubbed(:oauth_client) }- let(:storage) { build_stubbed(:nextcloud_storage, oauth_application:, oauth_client: oauth_client_credentials) }let(:user) { build_stubbed(:user) }let(:auth_check_result) { ServiceResult.success }let(:representer) { described_class.new(storage, current_user: user, embed_links: true) }@@ -48,7 +46,33 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" do)end- describe "_links" do+ shared_examples_for "common file storage properties" do+ it_behaves_like "property", :_type do+ let(:value) { "Storage" }+ end++ it_behaves_like "property", :id do+ let(:value) { storage.id }+ end++ it_behaves_like "property", :name do+ let(:value) { storage.name }+ end++ it_behaves_like "property", :complete do+ let(:value) { true }+ end++ it_behaves_like "datetime property", :createdAt do+ let(:value) { storage.created_at }+ end++ it_behaves_like "datetime property", :updatedAt do+ let(:value) { storage.updated_at }+ end+ end++ shared_examples_for "common file storage links" dodescribe "self" doit_behaves_like "has a titled link" dolet(:link) { "self" }@@ -57,19 +81,32 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" doendend- describe "origin" do- it_behaves_like "has an untitled link" do- let(:link) { "origin" }- let(:href) { storage.host }- end- end-- describe "connectionState" do+ describe "authorizationState" doit_behaves_like "has a titled link" dolet(:link) { "authorizationState" }let(:href) { "urn:openproject-org:api:v3:storages:authorization:Connected" }let(:title) { "Connected" }end++ context "if authentication check returns unauthorized" do+ let(:auth_check_result) { ServiceResult.failure(errors: Storages::StorageError.new(code: :unauthorized)) }++ it_behaves_like "has a titled link" do+ let(:link) { "authorizationState" }+ let(:href) { "urn:openproject-org:api:v3:storages:authorization:FailedAuthorization" }+ let(:title) { "Authorization failed" }+ end+ end++ context "if authentication check returns error" do+ let(:auth_check_result) { ServiceResult.failure(errors: Storages::StorageError.new(code: :error)) }++ it_behaves_like "has a titled link" do+ let(:link) { "authorizationState" }+ let(:href) { "urn:openproject-org:api:v3:storages:authorization:Error" }+ let(:title) { "Error" }+ end+ endenddescribe "prepareUpload" do@@ -130,31 +167,6 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" doendend- describe "oauthApplication" do- it_behaves_like "has no link" do- let(:link) { "oauthApplication" }- end-- context "as admin" do- let(:user) { build_stubbed(:admin) }-- it_behaves_like "has a titled link" do- let(:link) { "oauthApplication" }- let(:href) { "/api/v3/oauth_applications/#{oauth_application.id}" }- let(:title) { oauth_application.name }- end-- context "with invalid configured storage with missing oauth application" do- let(:oauth_application) { nil }-- it_behaves_like "has an untitled link" do- let(:link) { "oauthApplication" }- let(:href) { nil }- end- end- end- end-describe "oauthClientCredentials" doit_behaves_like "has no link" dolet(:link) { "oauthClientCredentials" }@@ -181,17 +193,7 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" doendend- describe "_embedded" do- describe "oauthApplication" do- it { is_expected.not_to have_json_path("_embedded/oauthApplication") }-- context "as admin" do- let(:user) { build_stubbed(:admin) }-- it { is_expected.to be_json_eql(oauth_application.id).at_path("_embedded/oauthApplication/id") }- end- end-+ shared_examples_for "common file storage embedded resources" dodescribe "oauthClientCredentials" doit { is_expected.not_to have_json_path("_embedded/oauthClientCredentials") }@@ -210,86 +212,102 @@ RSpec.describe API::V3::Storages::StorageRepresenter, "rendering" doendend- describe "properties" do- it_behaves_like "property", :_type do- let(:value) { "Storage" }- end+ context "if file storage has provider type Nextcloud" do+ let(:oauth_application) { build_stubbed(:oauth_application) }+ let(:storage) { build_stubbed(:nextcloud_storage, oauth_application:, oauth_client: oauth_client_credentials) }- it_behaves_like "property", :id do- let(:value) { storage.id }- end+ it_behaves_like "common file storage properties"- it_behaves_like "datetime property", :createdAt do- let(:value) { storage.created_at }- end+ describe "properties (Nextcloud only)" do+ it_behaves_like "property", :hasApplicationPassword do+ let(:value) { false }+ end- it_behaves_like "datetime property", :updatedAt do- let(:value) { storage.updated_at }- end+ describe "hasApplicationPassword" do+ it_behaves_like "property", :hasApplicationPassword do+ let(:value) { false }+ end- describe "Automatically managed project folders" do- shared_examples "protects applicationPassword" do- it "does not render the applicationPassword" do- expect(generated).not_to have_json_path("applicationPassword")+ context "if file storage is configured as 'automatically managed project folders'" do+ let(:storage) do+ build(:nextcloud_storage, :as_automatically_managed, oauth_application:, oauth_client: oauth_client_credentials)+ end++ it_behaves_like "property", :hasApplicationPassword do+ let(:value) { true }+ endendend+ end- context "with automatic project folder management enabled" do- let(:storage) do- build(:nextcloud_storage, :as_automatically_managed, oauth_application:, oauth_client: oauth_client_credentials)- end+ it_behaves_like "common file storage links"- it_behaves_like "property", :hasApplicationPassword do- let(:value) { true }+ describe "_links (Nextcloud only)" do+ describe "origin" do+ it_behaves_like "has an untitled link" do+ let(:link) { "origin" }+ let(:href) { storage.host }end-- it_behaves_like "protects applicationPassword"end- context "with automatic project folder management disabled" do- let(:storage) do- build(:nextcloud_storage, :as_not_automatically_managed, oauth_application:, oauth_client: oauth_client_credentials)+ describe "oauthApplication" do+ it_behaves_like "has no link" do+ let(:link) { "oauthApplication" }end- it_behaves_like "property", :hasApplicationPassword do- let(:value) { false }- end+ context "as admin" do+ let(:user) { build_stubbed(:admin) }- it_behaves_like "protects applicationPassword"- end+ it_behaves_like "has a titled link" do+ let(:link) { "oauthApplication" }+ let(:href) { "/api/v3/oauth_applications/#{oauth_application.id}" }+ let(:title) { oauth_application.name }+ end- context "when automatic project folder management is not configured" do- let(:storage) do- build(:nextcloud_storage,- provider_fields: { automatically_managed: false },- oauth_application:, oauth_client: oauth_client_credentials)- end+ context "with invalid configured storage with missing oauth application" do+ let(:oauth_application) { nil }- it "hasApplicationPassword is false" do- expect(generated).to be_json_eql(false).at_path("hasApplicationPassword")+ it_behaves_like "has an untitled link" do+ let(:link) { "oauthApplication" }+ let(:href) { nil }+ end+ endend-- it_behaves_like "protects applicationPassword"end+ end- context "with a non-Nextcloud storage" do- let(:storage) do- build(:one_drive_storage, oauth_application:, oauth_client: oauth_client_credentials)- end+ it_behaves_like "common file storage embedded resources"- before do- Storages::Peripherals::Registry.stub(- "one_drive.queries.open_storage",- ->(_) { ServiceResult.success(result: "https://my.sharepoint.com/sites/DeathStar/Documents") }- )- end+ describe "_embedded (Nextcloud only)" do+ describe "oauthApplication" do+ it { is_expected.not_to have_json_path("_embedded/oauthApplication") }++ context "as admin" do+ let(:user) { build_stubbed(:admin) }- it "does not include the property hasApplicationPassword" do- expect(generated).not_to have_json_path("hasApplicationPassword")+ it { is_expected.to be_json_eql(oauth_application.id).at_path("_embedded/oauthApplication/id") }end+ end+ end+ end- it_behaves_like "protects applicationPassword"+ context "if file storage has provider type OneDrive/SharePoint" do+ let(:storage) { build_stubbed(:one_drive_storage, oauth_client: oauth_client_credentials) }++ it_behaves_like "common file storage properties"++ describe "properties (OneDrive/SharePoint only)" do+ it_behaves_like "property", :tenantId do+ let(:value) { storage.tenant_id }+ end++ it_behaves_like "property", :driveId do+ let(:value) { storage.drive_id }endend++ it_behaves_like "common file storage links"++ it_behaves_like "common file storage embedded resources"endend