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
[#44841] added api spec for oauth credentials
Eric Schubert35908313107d
diff --git a/app/models/oauth_credentials_representer.rb b/app/models/oauth_credentials_representer.rbnew file mode 100644index 00000000000..c9055dd5af4--- /dev/null+++ b/app/models/oauth_credentials_representer.rb@@ -0,0 +1,3 @@+class OAuthCredentialsRepresenter++enddiff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rbindex e0b8ce4d8f9..a5ea5a876a3 100644--- a/config/initializers/zeitwerk.rb+++ b/config/initializers/zeitwerk.rb@@ -2,41 +2,33 @@ require Rails.root.join('config/constants/open_project/inflector')OpenProject::Inflector.rule do |_, abspath|if abspath.match?(/open_project\/version(\.rb)?\z/) ||- abspath.match?(/lib\/open_project\/\w+\/version(\.rb)?\z/)+ abspath.match?(/lib\/open_project\/\w+\/version(\.rb)?\z/)"VERSION"endend+# The order of the matchers is relevant, as less specific matcher could exclude more specific matchers.+# I.e. `/\Afoo_(.*)_bar\z/` must be specified before `/\Afoo_(.*)\z/` and `/\A(.*)_bar\z/`,+# as only the first matching rule wil be applied.OpenProject::Inflector.rule do |basename, abspath|case basename+ when /\Aoauth_(.*)_api\z/+ 'OAuth' + default_inflect($1, abspath) + 'API'when /\Aapi_(.*)\z/'API' + default_inflect($1, abspath)when /\A(.*)_api\z/default_inflect($1, abspath) + 'API'when 'api''API'- end-end--OpenProject::Inflector.rule do |basename, abspath|- if basename =~ /\Aar_(.*)\z/+ when /\Aar_(.*)\z/'AR' + default_inflect($1, abspath)- end-end--OpenProject::Inflector.rule do |basename, abspath|- case basenamewhen /\Aoauth_(.*)\z/'OAuth' + default_inflect($1, abspath)when /\A(.*)_oauth\z/default_inflect($1, abspath) + 'OAuth'when 'oauth''OAuth'- end-end--OpenProject::Inflector.rule do |basename, abspath|- if basename =~ /\A(.*)_sso\z/+ when /\A(.*)_sso\z/default_inflect($1, abspath) + 'SSO'endenddiff --git a/docs/api/apiv3/components/schemas/file_link_read_model.yml b/docs/api/apiv3/components/schemas/file_link_read_model.ymlindex bcf06bb1d80..b4a0c2e4f82 100644--- a/docs/api/apiv3/components/schemas/file_link_read_model.yml+++ b/docs/api/apiv3/components/schemas/file_link_read_model.yml@@ -31,7 +31,7 @@ properties:- containerproperties:storage:- $ref: './storage_model.yml'+ $ref: './storage_read_model.yml'container:$ref: './work_package_model.yml'_links:diff --git a/docs/api/apiv3/components/schemas/oauth_credentials_read_model.yml b/docs/api/apiv3/components/schemas/oauth_credentials_read_model.ymlnew file mode 100644index 00000000000..a7002976210--- /dev/null+++ b/docs/api/apiv3/components/schemas/oauth_credentials_read_model.yml@@ -0,0 +1,28 @@+# Schema: OauthCredentialsReadModel+---+type: object+required:+ - id+ - _type+ - clientId+ - confidential+properties:+ id:+ type: integer+ minimum: 1+ _type:+ type: string+ enum:+ - OauthCredentials+ clientId:+ type: string+ description: OAuth 2 client id+ confidential:+ type: boolean+ description: true, if OAuth 2 credentials are confidential, false, if no secret is stored++example:+ id: 1337+ _type: OauthCredentials+ clientId: O5h6WObhMg1Z8IcLHRE3_LMh4jJYmmca2V6OTFSv8DA+ confidential: truediff --git a/docs/api/apiv3/components/schemas/oauth_credential_model.yml b/docs/api/apiv3/components/schemas/oauth_credentials_write_model.ymlsimilarity index 72%rename from docs/api/apiv3/components/schemas/oauth_credential_model.ymlrename to docs/api/apiv3/components/schemas/oauth_credentials_write_model.ymlindex 8966fc75cbb..3f295ce3dec 100644--- a/docs/api/apiv3/components/schemas/oauth_credential_model.yml+++ b/docs/api/apiv3/components/schemas/oauth_credentials_write_model.yml@@ -1,15 +1,10 @@-# Schema: OauthCredentialModel+# Schema: OauthCredentialsWriteModel---type: objectrequired:- - _type- clientId- clientSecretproperties:- _type:- type: string- enum:- - OauthCredentialsclientId:type: stringdescription: OAuth 2 client id@@ -18,6 +13,5 @@ properties:description: OAuth 2 client secretexample:- _type: OauthCredentialsclientId: O5h6WObhMg1Z8IcLHRE3_LMh4jJYmmca2V6OTFSv8DAclientSecret: LSk52mn4jmtSYTgH0NzDj-u2z5LMpT8bsS0BouwJQQwdiff --git a/docs/api/apiv3/components/schemas/storage_read_model.yml b/docs/api/apiv3/components/schemas/storage_read_model.ymlindex 697d51e8e55..97121dd6e5d 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:type: stringformat: date-timedescription: Time of the most recent change to the storage+ _embedded:+ type: object+ required:+ - oauthCredentials+ properties:+ oauthCredentials:+ $ref: './oauth_credentials_read_model.yml'_links:type: objectrequired:@@ -86,6 +93,17 @@ properties:- urn:openproject-org:api:v3:storages:authorization:FailedAuthorization**Resource**: N/A+ oauthCredentials:+ allOf:+ - $ref: './link.yml'+ - description: |-+ The OAuth 2 credentials resource linked to the storage.++ # Conditions++ - User has role `admin`++ **Resource**: OauthCredentialsexample:id: 1337_type: Storage@@ -109,3 +127,5 @@ example:authorize:href: https://nextcloud.deathstar.rocks/authorize/title: Authorize+ oauthCredentials:+ href: /api/v3/oauth_credentials/42diff --git a/docs/api/apiv3/components/schemas/storage_update_model.yml b/docs/api/apiv3/components/schemas/storage_update_model.ymldeleted file mode 100644index 0d4d24ee4ed..00000000000--- a/docs/api/apiv3/components/schemas/storage_update_model.yml+++ /dev/null@@ -1,42 +0,0 @@-# Schema: StorageUpdateModel-----type: object-properties:- name:- type: string- description: Storage name- storageOauthClientId:- type: string- description: The client id of the oauth provider created on the storage.- storageOauthClientServer:- type: string- description: The client server of the oauth provider created on the storage.- _links:- type: object- properties:- url:- allOf:- - $ref: './link.yml'- - description: |-- The storage's host URL.-- **Resource**: N/A- type:- allOf:- - $ref: './link.yml'- - description: |-- The urn of the storage type. Currently only nextcloud storages are supported.-- - urn:openproject-org:api:v3:storages:nextcloud-- **Resource**: N/A--example:- name: Coruscant- storageOauthClientId: VTqcnqHPs1eXdKF6jtgAbe6KKwCKczBqOKr20DGHgdlN1uqK8qnHa88eTyhabxXj- storageOauthClientServer: OqdcHKaSfRh1En09PqOJRCfx7iKt98qvp0paJWYrDXzgAaDBiVnhurI71bhxUGF2- _links:- url:- href: https://nextcloud.deathstar.rocks- type:- href: urn:openproject-org:api:v3:storages:nextclouddiff --git a/docs/api/apiv3/components/schemas/storage_write_model.yml b/docs/api/apiv3/components/schemas/storage_write_model.ymlindex afa5a400359..c542eeec583 100644--- a/docs/api/apiv3/components/schemas/storage_write_model.yml+++ b/docs/api/apiv3/components/schemas/storage_write_model.yml@@ -1,17 +1,12 @@# Schema: StorageWriteModel---type: object-required:- - _linksproperties:name:type: stringdescription: Storage name, if not provided, falls back to a default._links:type: object- required:- - origin- - typeproperties:origin:allOf:diff --git a/docs/api/apiv3/components/schemas/update_membership.yml b/docs/api/apiv3/components/schemas/update_membership.ymldeleted file mode 100644index a8bbde0cff4..00000000000--- a/docs/api/apiv3/components/schemas/update_membership.yml+++ /dev/null@@ -1,2 +0,0 @@-# Schema: Update_membership---- {}diff --git a/docs/api/apiv3/components/schemas/update_project.yml b/docs/api/apiv3/components/schemas/update_project.ymldeleted file mode 100644index a3425acfbe5..00000000000--- a/docs/api/apiv3/components/schemas/update_project.yml+++ /dev/null@@ -1,2 +0,0 @@-# Schema: Update_project---- {}diff --git a/docs/api/apiv3/components/schemas/update_time_entry.yml b/docs/api/apiv3/components/schemas/update_time_entry.ymldeleted file mode 100644index 12dfe4fa292..00000000000--- a/docs/api/apiv3/components/schemas/update_time_entry.yml+++ /dev/null@@ -1,2 +0,0 @@-# Schema: Update_time_entry---- {}diff --git a/docs/api/apiv3/components/schemas/user_preference_model.yml b/docs/api/apiv3/components/schemas/user_preference_model.ymldeleted file mode 100644index 31c201c4572..00000000000--- a/docs/api/apiv3/components/schemas/user_preference_model.yml+++ /dev/null@@ -1,43 +0,0 @@-# Schema: User_PreferenceModel-----type: object-properties:- autoHidePopups:- type: boolean- description: Whether to hide popups (e.g. success messages) after 5 seconds- hideMail:- type: boolean- description: Hide mail address from other users- notifications:- $ref: "./notification_settings_model.yml"- timeZone:- type: string- description: Current selected time zone- commentSortDescending:- type: boolean- description: Sort comments in descending order- warnOnLeavingUnsaved:- type: boolean- description: Issue warning when leaving a page with unsaved text- _links:- type: object- required:- - self- - user- properties:- self:- allOf:- - "$ref": "./link.yml"- - description: |-- This UserPreferences-- **Resource**: UserPreferences- readOnly: true- user:- allOf:- - "$ref": "./link.yml"- - description: |-- The user that this preference belongs to-- **Resource**: User- readOnly: truediff --git a/docs/api/apiv3/openapi-spec.yml b/docs/api/apiv3/openapi-spec.ymlindex 2279726af28..fdae53228cb 100644--- a/docs/api/apiv3/openapi-spec.yml+++ b/docs/api/apiv3/openapi-spec.yml@@ -251,6 +251,8 @@ paths:"$ref": "./paths/notification_read.yml""/api/v3/notifications/{id}/unread_ian":"$ref": "./paths/notification_unread.yml"+ "/api/v3/oauth_credentials/{id}":+ "$ref": "./paths/oauth_credentials.yml""/api/v3/posts/{id}":"$ref": "./paths/post.yml""/api/v3/posts/{id}/attachments":@@ -359,6 +361,8 @@ paths:"$ref": "./paths/storage.yml""/api/v3/storages/{id}/files":"$ref": "./paths/storage_files.yml"+ "/api/v3/storages/{id}/oauth_credentials":+ "$ref": "./paths/storage_oauth_credentials.yml""/api/v3/time_entries":"$ref": "./paths/time_entries.yml""/api/v3/time_entries/{id}/form":@@ -654,8 +658,10 @@ components:"$ref": "./components/schemas/notification_settings_model.yml"Offset_based_pagination:"$ref": "./components/schemas/offset_based_pagination.yml"- OauthCredentialModel:- "$ref": "./components/schemas//oauth_credential_model.yml"+ OauthCredentialsReadModel:+ "$ref": "./components/schemas/oauth_credentials_read_model.yml"+ OauthCredentialsWriteModel:+ "$ref": "./components/schemas/oauth_credentials_write_model.yml"Plain_Text:"$ref": "./components/schemas/plain_text.yml"Plain_TextModel:@@ -742,8 +748,6 @@ components:"$ref": "./components/schemas/storage_file_location_model.yml"StorageReadModel:"$ref": "./components/schemas/storage_read_model.yml"- StorageUpdateModel:- "$ref": "./components/schemas/storage_update_model.yml"StorageWriteModel:"$ref": "./components/schemas/storage_write_model.yml"Time_EntryModel:@@ -768,12 +772,6 @@ components:"$ref": "./components/schemas/update_user.yml"Update_group:"$ref": "./components/schemas/update_group.yml"- Update_membership:- "$ref": "./components/schemas/update_membership.yml"- Update_project:- "$ref": "./components/schemas/update_project.yml"- Update_time_entry:- "$ref": "./components/schemas/update_time_entry.yml"UserCollectionModel:"$ref": "./components/schemas/user_collection_model.yml"UserCreateModel:@@ -782,8 +780,6 @@ components:"$ref": "./components/schemas/user_model.yml"UserPreferencesModel:"$ref": "./components/schemas/user_preferences_model.yml"- User_PreferenceModel:- "$ref": "./components/schemas/user_preference_model.yml"ValuesPropertyModel:"$ref": "./components/schemas/values_property_model.yml"VersionModel:diff --git a/docs/api/apiv3/paths/oauth_credentials.yml b/docs/api/apiv3/paths/oauth_credentials.ymlnew file mode 100644index 00000000000..93aa5226308--- /dev/null+++ b/docs/api/apiv3/paths/oauth_credentials.yml@@ -0,0 +1,53 @@+# /api/v3/oauth_credentials/{id}+---+get:+ summary: Get the oauth credentials object.+ operationId: get_storage_oauth_credentials+ tags:+ - File links+ description: |-+ Retrieves the OAuth 2 credentials for the given storage. The secret will not be part of the response, instead a+ `confidential` flag is indicating, whether there is a secret or not.+ parameters:+ - name: id+ description: Storage id+ in: path+ required: true+ schema:+ type: integer+ example: 1337+ responses:+ '200':+ description: OK+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/oauth_credentials_read_model.yml'+ '403':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not authorized to access this resource.+ description: |-+ Returned if the client does not have sufficient permissions.++ **Required permission:** admin+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The requested resource could not be found.+ description: |-+ Returned if the storage does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view file linksdiff --git a/docs/api/apiv3/paths/storage.yml b/docs/api/apiv3/paths/storage.ymlindex 64b7dfa0963..583e78fdd44 100644--- a/docs/api/apiv3/paths/storage.yml+++ b/docs/api/apiv3/paths/storage.yml@@ -57,7 +57,7 @@ put:content:application/json:schema:- $ref: '../components/schemas/storage_update_model.yml'+ $ref: '../components/schemas/storage_write_model.yml'responses:'200':description: OKdiff --git a/docs/api/apiv3/paths/storage_oauth_credentials.yml b/docs/api/apiv3/paths/storage_oauth_credentials.ymlnew file mode 100644index 00000000000..349ad17aff7--- /dev/null+++ b/docs/api/apiv3/paths/storage_oauth_credentials.yml@@ -0,0 +1,58 @@+# /api/v3/storages/{id}/oauth_credentials+---+post:+ summary: Creates an oauth credentials object for a storage.+ operationId: create_storage_oauth_credentials+ tags:+ - File links+ description: |-+ Inserts the OAuth 2 credentials into the storage, to allow the storage to act as an OAuth 2 client. Calling this+ endpoint on a storage that already contains OAuth 2 client credentials will replace them.+ parameters:+ - name: id+ description: Storage id+ in: path+ required: true+ schema:+ type: integer+ example: 1337+ requestBody:+ content:+ application/json:+ schema:+ $ref: '../components/schemas/oauth_credentials_write_model.yml'+ responses:+ '201':+ description: Created+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/oauth_credentials_read_model.yml'+ '403':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ examples:+ response:+ value:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission+ message: You are not authorized to access this resource.+ description: |-+ Returned if the client does not have sufficient permissions.++ **Required permission:** admin+ '404':+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:NotFound+ message: The requested resource could not be found.+ description: |-+ Returned if the storage does not exist or the client does not have sufficient permissions to see it.++ **Required permission:** view file linksdiff --git a/docs/api/apiv3/paths/storages.yml b/docs/api/apiv3/paths/storages.ymlindex 31db5eaa26c..cc5660bed7c 100644--- a/docs/api/apiv3/paths/storages.yml+++ b/docs/api/apiv3/paths/storages.yml@@ -22,4 +22,4 @@ post:content:application/hal+json:schema:- $ref: '../components/schemas/oauth_credential_model.yml'+ $ref: '../components/schemas/oauth_credentials_write_model.yml'diff --git a/lib/api/v3/oauth/oauth_applications_api.rb b/lib/api/v3/oauth/oauth_applications_api.rbnew file mode 100644index 00000000000..cc09f327a02--- /dev/null+++ b/lib/api/v3/oauth/oauth_applications_api.rb@@ -0,0 +1,44 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 API::V3::OAuth+ class OAuthApplicationsAPI < ::API::OpenProjectAPI+ resources :oauth_applications do+ route_param :oauth_application_id, type: Integer, desc: 'OAuth application id' do+ after_validation do+ @application = ::Doorkeeper::Application.find(params[:oauth_application_id])+ end++ get &::API::V3::Utilities::Endpoints::Show+ .new(model: ::Doorkeeper::Application,+ render_representer: ::API::V3::OAuth::OAuthApplicationsRepresenter)+ .mount+ end+ end+ end+enddiff --git a/lib/api/v3/oauth/oauth_applications_representer.rb b/lib/api/v3/oauth/oauth_applications_representer.rbnew file mode 100644index 00000000000..40cf7eff35f--- /dev/null+++ b/lib/api/v3/oauth/oauth_applications_representer.rb@@ -0,0 +1,78 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 API::V3::OAuth+ class OAuthApplicationsRepresenter < ::API::Decorators::Single+ include API::Decorators::LinkedResource+ include API::Decorators::DateProperty++ property :id++ property :uid, as: :client_id++ property :confidential++ property :client_secret,+ getter: ->(*) { plaintext_secret },+ skip_render: ->(*) { plaintext_secret.blank? }++ date_time_property :created_at++ date_time_property :updated_at++ property :scopes++ link :owner do+ next if represented.owner.blank?++ {+ href: api_v3_paths.user(represented.owner.id),+ title: represented.owner.name+ }+ end++ link :integration do+ next if represented.integration.blank?++ {+ href: api_v3_paths.storage(represented.integration.id),+ title: represented.integration.name+ }+ end++ link :redirect_uri do+ {+ href: represented.redirect_uri+ }+ end++ def _type+ 'OAuthApplication'+ end+ end+enddiff --git a/lib/api/v3/oauth/oauth_client_credentials_api.rb b/lib/api/v3/oauth/oauth_client_credentials_api.rbnew file mode 100644index 00000000000..8faf67b11c2--- /dev/null+++ b/lib/api/v3/oauth/oauth_client_credentials_api.rb@@ -0,0 +1,44 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 API::V3::OAuth+ class OAuthClientCredentialsAPI < ::API::OpenProjectAPI+ resources :oauth_client_credentials do+ route_param :oauth_client_credentials_id, type: Integer, desc: 'OAuth Client Credentials id' do+ after_validation do+ @oauth_client = ::OAuthClient.find(params[:oauth_client_credentials_id])+ end++ get &::API::V3::Utilities::Endpoints::Show+ .new(model: ::OAuthClient,+ render_representer: ::API::V3::OAuth::OAuthClientCredentialsRepresenter)+ .mount+ end+ end+ end+enddiff --git a/lib/api/v3/oauth/oauth_client_credentials_representer.rb b/lib/api/v3/oauth/oauth_client_credentials_representer.rbnew file mode 100644index 00000000000..61f67571244--- /dev/null+++ b/lib/api/v3/oauth/oauth_client_credentials_representer.rb@@ -0,0 +1,47 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 API::V3::OAuth+ class OAuthClientCredentialsRepresenter < ::API::Decorators::Single+ include API::Decorators::LinkedResource++ property :id++ property :client_id++ property :client_secret,+ skip_render: true++ property :confidential,+ getter: ->(*) { client_secret.present? }++ def _type+ 'OAuthClientCredentials'+ end+ end+enddiff --git a/lib/api/v3/root.rb b/lib/api/v3/root.rbindex 8cbf58a123e..f1a8c63a966 100644--- a/lib/api/v3/root.rb+++ b/lib/api/v3/root.rb@@ -58,6 +58,8 @@ module APImount ::API::V3::HelpTexts::HelpTextsAPImount ::API::V3::Memberships::MembershipsAPImount ::API::V3::News::NewsAPI+ mount ::API::V3::OAuth::OAuthApplicationsAPI+ mount ::API::V3::OAuth::OAuthClientCredentialsAPImount ::API::V3::Posts::PostsAPImount ::API::V3::Principals::PrincipalsAPImount ::API::V3::Priorities::PrioritiesAPIdiff --git a/modules/storages/lib/api/v3/o_auth_credentials/o_auth_credentials_api.rb b/modules/storages/lib/api/v3/o_auth_credentials/o_auth_credentials_api.rbnew file mode 100644index 00000000000..9c2fbe7d033--- /dev/null+++ b/modules/storages/lib/api/v3/o_auth_credentials/o_auth_credentials_api.rb@@ -0,0 +1,42 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 API::V3::OAuthCredentials+ class OAuthCredentialsAPI < ::API::OpenProjectAPI+ resources :oauth_credentials do+ post &::API::V3::Utilities::Endpoints::Create+ .new(model: ::OAuthClient,+ parse_representer: ::API::V3::OAuth::OAuthClientCredentialsRepresenter,+ render_representer: ::API::V3::OAuth::OAuthClientCredentialsRepresenter,+ params_modifier: ->(params) do+ params.merge(integration: @storage)+ end)+ .mount+ end+ end+enddiff --git a/modules/storages/lib/api/v3/storages/create_endpoint.rb b/modules/storages/lib/api/v3/storages/create_endpoint.rbindex 8687155fb2b..78952baa714 100644--- a/modules/storages/lib/api/v3/storages/create_endpoint.rb+++ b/modules/storages/lib/api/v3/storages/create_endpoint.rb@@ -31,9 +31,11 @@ class API::V3::Storages::CreateEndpoint < API::Utilities::Endpoints::Createinclude ::API::V3::Utilities::Endpoints::V3PresentSingledef present_success(request, service_call)- API::V3::Storages::OAuthCredentialsRepresenter.create(- service_call.dependent_results.first.result,- current_user: request.current_user+ API::V3::Storages::StorageRepresenter.create(+ service_call.result,+ current_user: request.current_user,+ embed_links: true,+ created_oauth_application: service_call.dependent_results.first.result)endenddiff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rbindex dfec895091f..4f1ff350d91 100644--- a/modules/storages/lib/api/v3/storages/storage_representer.rb+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb@@ -62,11 +62,12 @@ module API::V3::Storagesextend ClassMethods- def initialize(model, current_user:, embed_links: nil)+ def initialize(model, current_user:, embed_links: nil, created_oauth_application: nil)@connection_manager =::OAuthClients::ConnectionManager.new(user: current_user, oauth_client: model.oauth_client)+ @oauth_application = created_oauth_application || model.oauth_application- super+ super(model, current_user:, embed_links:)endproperty :id@@ -125,6 +126,18 @@ module API::V3::Storages{ href: @connection_manager.get_authorization_uri, title: 'Authorize' }end+ associated_resource :oauth_application,+ getter: ->(*) {+ ::API::V3::OAuth::OAuthApplicationsRepresenter.create(@oauth_application, current_user:)+ },+ # representer: ::API::V3::OAuth::OAuthApplicationsRepresenter,+ link: ->(*) {+ {+ href: "/api/v3/oauth_applications/#{@oauth_application.id}",+ title: @oauth_application.name+ }+ }+def _type'Storage'enddiff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rbindex 4250a9693fb..061a3b786ff 100644--- a/modules/storages/lib/api/v3/storages/storages_api.rb+++ b/modules/storages/lib/api/v3/storages/storages_api.rb@@ -40,6 +40,7 @@ class API::V3::Storages::StoragesAPI < ::API::OpenProjectAPI# The `:resources` keyword defines the API namespace -> /api/v3/storages/...resources :storages dopost &::API::V3::Storages::CreateEndpoint.new(model: ::Storages::Storage).mount+ # post &::API::V3::Utilities::Endpoints::Create.new(model: ::Storages::Storage).mount# `route_param` extends the route by a route parameter of the endpoint.# The input parameter value is parsed into the `:storage_id` symbol.@@ -65,6 +66,7 @@ class API::V3::Storages::StoragesAPI < ::API::OpenProjectAPIdelete &::API::V3::Utilities::Endpoints::Delete.new(model: ::Storages::Storage).mountmount API::V3::StorageFiles::StorageFilesAPI+ mount API::V3::OAuthCredentials::OAuthCredentialsAPIendendenddiff --git a/script/api/validate_spec b/script/api/validate_specindex bf6f89d4af1..d1d3a0a040a 100755--- a/script/api/validate_spec+++ b/script/api/validate_spec@@ -18,7 +18,7 @@ beginfile.puts full_specend- `npx @redocly/openapi-cli lint #{openapi_yaml_spec_path}`+ `npx @redocly/openapi-cli lint #{openapi_yaml_spec_path} --max-problems 200`status = $?.exitstatusensure