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
[#51033] Enable OAuth Client Form submit button and show validation errors in case of invalid submission (#14354)
Kabiru Mwenja6f0e184d9a3c
diff --git a/app/contracts/oauth_clients/create_contract.rb b/app/contracts/oauth_clients/create_contract.rbindex 72646e3a087..f367479e5b6 100644--- a/app/contracts/oauth_clients/create_contract.rb+++ b/app/contracts/oauth_clients/create_contract.rb@@ -31,7 +31,7 @@ module OAuthClientsinclude ActiveModel::Validationsattribute :client_id, writable: true- validates :client_id, presence: true, length: { maximum: 255 }+ validates :client_id, presence: { message: I18n.t('oauth_client.errors.client_id_blank') }, length: { maximum: 255 }attribute :client_secret, writable: truevalidates :client_secret, presence: true, length: { maximum: 255 }diff --git a/app/services/oauth_clients/create_service.rb b/app/services/oauth_clients/create_service.rbindex 35d75686e6c..62ef02892ae 100644--- a/app/services/oauth_clients/create_service.rb+++ b/app/services/oauth_clients/create_service.rb@@ -36,10 +36,9 @@ module OAuthClientsclass CreateService < ::BaseServices::Createprotected- def before_perform(params, _service_result)- OAuthClient.where(integration: params[:integration]).delete_all-- super+ def after_validate(params, contract_call)+ OAuthClient.where(integration: params[:integration]).delete_all if contract_call.success?+ super(params, contract_call)endendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 0a685ec15cd..e7549218da3 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3127,7 +3127,7 @@ en:help_texts:views:project: >- %{plural} are always attached to a project.+ %{plural} are always attached to a project.You can only select projects here where the %{plural} module is active.After creating a %{singular} you can add work packages from other projects to it.public: "Publish this view, allowing other users to access your view. Users with the 'Manage public views' permission can modify or remove public query. This does not affect the visibility of work package results in that view and depending on their permissions, users may see different results."@@ -3512,6 +3512,7 @@ en:oauth_returned_json_error: "OAuth2 returned a JSON error"oauth_returned_http_error: "OAuth2 returned a network error"oauth_returned_standard_error: "OAuth2 returned an internal error"+ client_id_blank: "ID can't be blank."wrong_token_type_returned: "OAuth2 returned a wrong type of token, expecting AccessToken::Bearer"oauth_issue_contact_admin: "OAuth2 reported an error. Please contact your system administrator."oauth_client_not_found: "OAuth2 client not found in 'callback' endpoint (redirect_uri)."diff --git a/frontend/src/stimulus/controllers/dynamic/storages/oauth-client-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/storages/oauth-client-form.controller.tsdeleted file mode 100644index 717aa0dc177..00000000000--- a/frontend/src/stimulus/controllers/dynamic/storages/oauth-client-form.controller.ts+++ /dev/null@@ -1,64 +0,0 @@-/*- * -- 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 OAuthClientFormController extends Controller {- static targets = [- 'clientId',- 'clientSecret',- 'submitButton',- ];-- declare readonly hasClientIdTarget:boolean;- declare readonly hasClientSecretTarget:boolean;- declare readonly hasSubmitButtonTarget:boolean;- declare readonly clientIdTarget:HTMLInputElement;- declare readonly clientSecretTarget:HTMLInputElement;- declare readonly submitButtonTarget:HTMLInputElement;-- connect():void {- this.toggleSubmitButtonDisabled();- }-- public toggleSubmitButtonDisabled():void {- const targetsConfigured = this.hasClientIdTarget && this.hasClientSecretTarget && this.hasSubmitButtonTarget;-- if (!targetsConfigured) {- return;- }-- if (this.clientIdTarget.value === '' || this.clientSecretTarget.value === '') {- this.submitButtonTarget.disabled = true;- } else {- this.submitButtonTarget.disabled = false;- }- }-}diff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erbindex 351293b98d5..0ce74a15d84 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.html.erb@@ -3,11 +3,7 @@primer_form_with(model: oauth_client,url: admin_settings_storage_oauth_client_path(storage),- method: form_method,- data: {- controller: 'storages--oauth-client-form',- application_target: 'dynamic'- }+ method: form_method) do |form|flex_layout do |oauth_client_row|oauth_client_row.with_row(mb: 3) do@@ -19,24 +15,7 @@endoauth_client_row.with_row(mb: 3) do- render(- Storages::Admin::OAuthClientForm.new(- form,- storage:,- client_id_input_options: {- data: {- 'storages--oauth-client-form-target': 'clientId',- action: 'input->storages--oauth-client-form#toggleSubmitButtonDisabled'- }- },- client_secret_input_options: {- data: {- 'storages--oauth-client-form-target': 'clientSecret',- action: 'input->storages--oauth-client-form#toggleSubmitButtonDisabled'- }- }- )- )+ render(Storages::Admin::OAuthClientForm.new(form,storage:,))endoauth_client_row.with_row do@@ -45,10 +24,6 @@form,storage:,submit_button_options: {- disabled: submit_button_disabled?,- data: {- 'storages--oauth-client-form-target': 'submitButton',- },test_selector: 'storage-oauth-client-submit-button'},cancel_button_options: {diff --git a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rbindex e38599d1151..202d58b9189 100644--- a/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb+++ b/modules/storages/app/components/storages/admin/forms/oauth_client_form_component.rb@@ -48,10 +48,6 @@ module Storages::Admin::Formsstorage.persisted? ? edit_admin_settings_storage_path(storage) : admin_settings_storages_pathend- def submit_button_disabled?- !oauth_client_configured?- end-def storage_provider_credentials_instructionsI18n.t("storages.instructions.#{storage.short_provider_type}.oauth_configuration",application_link_text: send(:"#{storage.short_provider_type}_integration_link")).html_safe@@ -77,9 +73,5 @@ module Storages::Admin::Formsdef default_form_methodfirst_time_configuration? ? :post : :patchend-- def oauth_client_configured?- oauth_client.present? && oauth_client.client_id.present? && oauth_client.client_secret.present?- endendenddiff --git a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erbindex cbeefce49e9..6ae3d36d530 100644--- a/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb+++ b/modules/storages/app/components/storages/admin/forms/redirect_uri_form_component.html.erb@@ -3,11 +3,7 @@primer_form_with(model: oauth_client,url: finish_setup_admin_settings_storage_oauth_client_path(storage),- method: :post,- data: {- controller: 'storages--oauth-client-form',- application_target: 'dynamic'- }+ method: :post) do |form|flex_layout do |oauth_client_row|oauth_client_row.with_row(mb: 3) do@@ -44,10 +40,7 @@submit_button_options: {disabled: submit_button_disabled? || @options[:is_complete],label: I18n.t('storages.buttons.done_complete_setup'),- data: {- 'storages--oauth-client-form-target': 'submitButton',- turbo: false- },+ data: { turbo: false },test_selector: 'storage-oauth-client-submit-button'},cancel_button_options: {diff --git a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rbindex 2bf6f2432b4..705e8fed8e1 100644--- a/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb+++ b/modules/storages/app/components/storages/admin/oauth_application_info_copy_component.rb@@ -61,7 +61,7 @@ module Storages::Adminprivatedef submit_button_path- options[:submit_button_path] || edit_admin_settings_storage_path(storage)+ options[:submit_button_path] || show_oauth_application_admin_settings_storage_path(storage)endendenddiff --git a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb b/modules/storages/app/components/storages/admin/oauth_client_info_component.rbindex 735f15a54d9..1026081b3f3 100644--- a/modules/storages/app/components/storages/admin/oauth_client_info_component.rb+++ b/modules/storages/app/components/storages/admin/oauth_client_info_component.rb@@ -58,6 +58,7 @@ module Storages::Admindef edit_icon_button_data_options{}.tap do |data_h|data_h[:confirm] = I18n.t("storages.confirm_replace_oauth_client") if oauth_client_configured?+ data_h[:turbo_stream] = trueendenddiff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erbindex cbabc5e57de..12c8930ca8c 100644--- a/modules/storages/app/components/storages/admin/storage_view_component.html.erb+++ b/modules/storages/app/components/storages/admin/storage_view_component.html.erb@@ -28,13 +28,7 @@if storage.new_record? || openproject_oauth_application_section_closed?render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application:, storage:))else- render(- Storages::Admin::OAuthApplicationInfoCopyComponent.new(- oauth_application:,- storage:,- submit_button_path: show_oauth_application_admin_settings_storage_path(storage)- )- )+ render(Storages::Admin::OAuthApplicationInfoCopyComponent.new(oauth_application:, storage:))endendenddiff --git a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rbindex 7550f9c24d9..8e1f649b464 100644--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb@@ -37,7 +37,6 @@ class Storages::Admin::OAuthClientsController < ApplicationControllerbefore_action :require_adminbefore_action :find_storage- before_action :delete_current_oauth_client, only: %i[create update]# menu_item is defined in the Redmine::MenuManager::MenuController# module, included from ApplicationController.@@ -54,7 +53,6 @@ class Storages::Admin::OAuthClientsController < ApplicationController.resultrespond_to do |format|- format.htmlformat.turbo_streamendend@@ -67,7 +65,7 @@ class Storages::Admin::OAuthClientsController < ApplicationControllerservice_result.on_failure dorespond_to do |format|- format.html { render :new }+ format.turbo_stream { render :new }endend@@ -155,8 +153,4 @@ class Storages::Admin::OAuthClientsController < ApplicationControllerdef find_storage@storage = ::Storages::Storage.find(params[:storage_id])end-- def delete_current_oauth_client- ::OAuthClients::DeleteService.new(user: User.current, model: @storage.oauth_client).call if @storage.oauth_client- endenddiff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rbindex f845ac9b540..59a256e2709 100644--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb@@ -188,8 +188,7 @@ class Storages::Admin::StoragesController < ApplicationController@oauth_application = service_result.resultif service_result.success?- flash[:notice] = I18n.t('storages.notice_oauth_application_replaced')- render :show_oauth_application+ render :replace_oauth_applicationelserender :editenddiff --git a/modules/storages/app/views/storages/admin/oauth_clients/new.turbo_stream.erb b/modules/storages/app/views/storages/admin/oauth_clients/new.turbo_stream.erbindex c0ff300b0b5..ecf0c510001 100644--- a/modules/storages/app/views/storages/admin/oauth_clients/new.turbo_stream.erb+++ b/modules/storages/app/views/storages/admin/oauth_clients/new.turbo_stream.erb@@ -27,23 +27,6 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%= turbo_stream.update :storage_openproject_oauth_section do %>- <%=- render(- Storages::Admin::OAuthApplicationInfoComponent.new(- oauth_application: @oauth_application,- storage: @storage,- )- )- %>-<% end %>--<%= turbo_stream.update :storage_redirect_uri_section do %>- <%= render(Storages::Admin::RedirectUriComponent.new(oauth_client: @oauth_client, storage: @storage)) %>-<% end %>--<% if @storage.provider_type_nextcloud? && @storage.oauth_client.blank? %>- <%= turbo_stream.update :storage_oauth_client_section do %>- <%= render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client, storage: @storage)) %>- <% end %>+<%= turbo_stream.update :storage_oauth_client_section do %>+ <%= render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client, storage: @storage)) %><% end %>diff --git a/modules/storages/app/views/storages/admin/storages/create.turbo_stream.erb b/modules/storages/app/views/storages/admin/storages/create.turbo_stream.erbindex 155a9b7fd5c..72326bd6547 100644--- a/modules/storages/app/views/storages/admin/storages/create.turbo_stream.erb+++ b/modules/storages/app/views/storages/admin/storages/create.turbo_stream.erb@@ -31,7 +31,6 @@ See COPYRIGHT and LICENSE files for more details.<%= render(Storages::Admin::GeneralInfoComponent.new(@storage)) %><% end %>-<% if @storage.provider_type_nextcloud? %><%= turbo_stream.update :storage_openproject_oauth_section do %><%=@@ -41,8 +40,7 @@ See COPYRIGHT and LICENSE files for more details.storage: @storage,submit_button_options: {data: { turbo_stream: true }- },- submit_button_path: new_admin_settings_storage_oauth_client_path(@storage)+ }))%>diff --git a/modules/storages/app/views/storages/admin/oauth_clients/new.html.erb b/modules/storages/app/views/storages/admin/storages/replace_oauth_application.turbo_stream.erbsimilarity index 71%rename from modules/storages/app/views/storages/admin/oauth_clients/new.html.erbrename to modules/storages/app/views/storages/admin/storages/replace_oauth_application.turbo_stream.erbindex 13d13af21f8..fbaa8255d23 100644--- a/modules/storages/app/views/storages/admin/oauth_clients/new.html.erb+++ b/modules/storages/app/views/storages/admin/storages/replace_oauth_application.turbo_stream.erb@@ -27,10 +27,20 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<% html_title t(:label_administration), t("project_module_storages"), @storage.name, "#{t("storages.provider_types.#{@storage.short_provider_type}.name")} #{t("storages.label_oauth_client_details")}" %>--<%=- render(OpTurbo::FrameComponent.new(id: :storage_oauth_client_section)) do- render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @oauth_client, storage: @storage))- end-%>+<%= turbo_stream.update :storage_general_info_section do %>+ <%= render(Storages::Admin::GeneralInfoComponent.new(@storage)) %>+<% end %>++<%= turbo_stream.update :storage_openproject_oauth_section do %>+ <%=+ render(+ Storages::Admin::OAuthApplicationInfoCopyComponent.new(+ oauth_application: @oauth_application,+ storage: @storage,+ submit_button_options: {+ data: { turbo_stream: true }+ }+ )+ )+ %>+<% end %>diff --git a/modules/storages/app/views/storages/admin/storages/show_oauth_application.turbo_stream.erb b/modules/storages/app/views/storages/admin/storages/show_oauth_application.turbo_stream.erbindex 95531304160..8c833bccd44 100644--- a/modules/storages/app/views/storages/admin/storages/show_oauth_application.turbo_stream.erb+++ b/modules/storages/app/views/storages/admin/storages/show_oauth_application.turbo_stream.erb@@ -27,21 +27,12 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%= turbo_stream.update :storage_general_info_section do %>- <%= render(Storages::Admin::GeneralInfoComponent.new(@storage)) %>+<%= turbo_stream.update :storage_openproject_oauth_section do %>+ <%= render(Storages::Admin::OAuthApplicationInfoComponent.new(oauth_application: @oauth_application, storage: @storage)) %><% end %>-<%= turbo_stream.update :storage_openproject_oauth_section do %>- <%=- render(- Storages::Admin::OAuthApplicationInfoCopyComponent.new(- oauth_application: @oauth_application,- storage: @storage,- submit_button_options: {- data: { turbo_stream: true }- },- submit_button_path: new_admin_settings_storage_oauth_client_path(@storage)- )- )- %>+<% if @storage.oauth_client.blank? %>+ <%= turbo_stream.update :storage_oauth_client_section do %>+ <%= render(Storages::Admin::Forms::OAuthClientFormComponent.new(oauth_client: @storage.build_oauth_client, storage: @storage)) %>+ <% end %><% end %>diff --git a/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rbindex 82806801892..fc6a09cf358 100644--- a/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb+++ b/modules/storages/spec/components/storages/admin/oauth_client_info_component_spec.rb@@ -36,10 +36,9 @@ RSpec.describe Storages::Admin::OAuthClientInfoComponent, type: :component do #storage = build_stubbed(:nextcloud_storage,oauth_client: build_stubbed(:oauth_client))component = described_class.new(storage:, oauth_client: storage.oauth_client)-expect(component.edit_icon_button_options).to include(icon: :sync,- data: { confirm: "Are you sure? All users will have to authorize again against the storage." }+ data: { confirm: "Are you sure? All users will have to authorize again against the storage.", turbo_stream: true })endend@@ -50,7 +49,7 @@ RSpec.describe Storages::Admin::OAuthClientInfoComponent, type: :component do #component = described_class.new(storage:, oauth_client: nil)edit_icon_button_data_options = component.edit_icon_button_options- expect(edit_icon_button_data_options).to include(icon: :pencil)+ expect(edit_icon_button_data_options).to include(icon: :pencil, data: { turbo_stream: true })expect(edit_icon_button_data_options[:data]).not_to include(:confirm)endenddiff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rbindex b9ecaa9cfe9..adee62c4686 100644--- a/modules/storages/spec/features/admin_storages_spec.rb+++ b/modules/storages/spec/features/admin_storages_spec.rb@@ -134,13 +134,13 @@ RSpec.describe 'Admin storages',expect(page).to have_test_selector('storage-new-page-header--title', text: 'New Nextcloud storage')expect(page).to have_test_selector('storage-new-page-header--description',text: "Read our documentation on setting up a Nextcloud file storage " \- "integration for more information.")+ "integration for more information.")# General informationexpect(page).to have_test_selector('storage-provider-configuration-instructions',text: "Please make sure you have administration privileges in your " \- "Nextcloud instance and the application “Integration OpenProject” " \- "is installed before doing the setup.")+ "Nextcloud instance and the application “Integration OpenProject” " \+ "is installed before doing the setup.")# OAuth applicationexpect(page).to have_test_selector('storage-openproject-oauth-label', text: 'OpenProject OAuth')@@ -181,8 +181,8 @@ RSpec.describe 'Admin storages',within_test_selector('storage-openproject-oauth-application-form') dowarning_section = find_test_selector('storage-openproject_oauth_application_warning')expect(warning_section).to have_text('The client secret value will not be accessible again after you close ' \- 'this window. Please copy these values into the Nextcloud ' \- 'OpenProject Integration settings.')+ 'this window. Please copy these values into the Nextcloud ' \+ 'OpenProject Integration settings.')expect(warning_section).to have_link('Nextcloud OpenProject Integration settings',href: "https://example.com/settings/admin/openproject")@@ -201,15 +201,17 @@ RSpec.describe 'Admin storages',expect(page).to have_test_selector('storage-provider-credentials-instructions',text: 'Copy these values from Nextcloud Administration / OpenProject.')- # With null values, submit button should be disabled+ # With null values, form should render inline errorsexpect(page).to have_css('#oauth_client_client_id', value: '')expect(page).to have_css('#oauth_client_client_secret', value: '')- expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled+ click_button 'Save and continue'++ expect(page).to have_text("Client ID can't be blank.")+ expect(page).to have_text("Client secret can't be blank.")# Happy path - Submit valid valuesfill_in 'oauth_client_client_id', with: '1234567890'fill_in 'oauth_client_client_secret', with: '0987654321'- expect(find_test_selector('storage-oauth-client-submit-button')).not_to be_disabledclick_button 'Save and continue'end@@ -231,7 +233,7 @@ RSpec.describe 'Admin storages',# Test the error path for an invalid storage password.# Mock a valid response (=401) for example.com, so the password validation should failmock_nextcloud_application_credentials_validation('https://example.com', password: "1234567890",- response_code: 401)+ response_code: 401)automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')expect(automatically_managed_switch).to be_checkedfill_in 'storages_nextcloud_storage_password', with: "1234567890"@@ -251,10 +253,10 @@ RSpec.describe 'Admin storages',expect(page).to have_current_path(admin_settings_storages_path)expect(page).to have_test_selector(- "primer-banner-message-component",- text: "Storage connected successfully! Remember to activate the module and the specific " \- "storage in the project settings of each desired project to use it."- )+ "primer-banner-message-component",+ text: "Storage connected successfully! Remember to activate the module and the specific " \+ "storage in the project settings of each desired project to use it."+ )endendend@@ -288,21 +290,21 @@ RSpec.describe 'Admin storages',expect(page).to have_test_selector('storage-new-page-header--title', text: 'New OneDrive/SharePoint storage')expect(page).to have_test_selector('storage-new-page-header--description',text: "Read our documentation on setting up a OneDrive/SharePoint " \- "file storage integration for more information.")+ "file storage integration for more information.")# General informationexpect(page).to have_test_selector('storage-provider-configuration-instructions',text: "Please make sure you have administration privileges in the " \- "Azure portal or contact your Microsoft administrator before " \- "doing the setup. In the portal, you also need to register an " \- "Azure application or use an existing one for authentication.")+ "Azure portal or contact your Microsoft administrator before " \+ "doing the setup. In the portal, you also need to register an " \+ "Azure application or use an existing one for authentication.")# OAuth clientwait_for(page).to have_test_selector('storage-oauth-client-label', text: 'Azure OAuth')expect(page).not_to have_test_selector('label-storage_oauth_client_configured-status')expect(page).to have_test_selector('storage-oauth-client-id-description',text: "Allow OpenProject to access Azure data using OAuth " \- "to connect OneDrive/Sharepoint.")+ "to connect OneDrive/Sharepoint.")expect(page).to have_test_selector('storage-redirect-uri-description',text: "Complete the setup with the correct URI redirection.")end@@ -328,12 +330,15 @@ RSpec.describe 'Admin storages',within_test_selector('storage-oauth-client-form') doexpect(page).to have_test_selector('storage-provider-credentials-instructions',text: 'Copy these values from the desired application in the ' \- 'Azure portal.')+ 'Azure portal.')- # With null values, submit button should be disabled+ # With null values, upon submit validation errors are showexpect(page).to have_css('#oauth_client_client_id', value: '')expect(page).to have_css('#oauth_client_client_secret', value: '')- expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled+ click_button 'Save and continue'++ expect(page).to have_text("Client ID can't be blank.")+ expect(page).to have_text("Client secret can't be blank.")# Happy path - Submit valid valuesfill_in 'oauth_client_client_id', with: '1234567890'@@ -348,10 +353,10 @@ RSpec.describe 'Admin storages',expect(page).to have_current_path(admin_settings_storages_path)wait_for(page).to have_test_selector(- "primer-banner-message-component",- text: "Storage connected successfully! Remember to activate the module and the specific " \- "storage in the project settings of each desired project to use it."- )+ "primer-banner-message-component",+ text: "Storage connected successfully! Remember to activate the module and the specific " \+ "storage in the project settings of each desired project to use it."+ )endendend@@ -478,8 +483,8 @@ RSpec.describe 'Admin storages',within_test_selector('storage-openproject-oauth-application-form') dowarning_section = find_test_selector('storage-openproject_oauth_application_warning')expect(warning_section).to have_text('The client secret value will not be accessible again after you close ' \- 'this window. Please copy these values into the Nextcloud ' \- 'OpenProject Integration settings.')+ 'this window. Please copy these values into the Nextcloud ' \+ 'OpenProject Integration settings.')expect(warning_section).to have_link('Nextcloud OpenProject Integration settings',href: "#{storage.host}/settings/admin/openproject")@@ -498,10 +503,13 @@ RSpec.describe 'Admin storages',endwithin_test_selector('storage-oauth-client-form') do- # With null values, submit button should be disabled+ # With null values, form should render inline errorsexpect(page).to have_css('#oauth_client_client_id', value: '')expect(page).to have_css('#oauth_client_client_secret', value: '')- expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled+ click_button 'Save and continue'++ expect(page).to have_text("Client ID can't be blank.")+ expect(page).to have_text("Client secret can't be blank.")# Happy path - Submit valid valuesfill_in 'oauth_client_client_id', with: '1234567890'@@ -512,6 +520,7 @@ RSpec.describe 'Admin storages',expect(page).to have_test_selector('label-storage_oauth_client_configured-status', text: 'Completed')expect(page).to have_test_selector('storage-oauth-client-id-description', text: "OAuth Client ID: 1234567890")+ expect(OAuthClient.where(integration: storage).count).to eq(1)endaggregate_failures 'Automatically managed project folders' do@@ -530,7 +539,7 @@ RSpec.describe 'Admin storages',# Test the error path for an invalid storage password.# Mock a valid response (=401) for example.com, so the password validation should failmock_nextcloud_application_credentials_validation(storage.host, password: "1234567890",- response_code: 401)+ response_code: 401)automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')expect(automatically_managed_switch).to be_checkedfill_in 'storages_nextcloud_storage_password', with: "1234567890"@@ -609,15 +618,17 @@ RSpec.describe 'Admin storages',endwithin_test_selector('storage-oauth-client-form') do- # With null values, submit button should be disabled+ # With null values, form should render inline errorsexpect(page).to have_css('#oauth_client_client_id', value: '')expect(page).to have_css('#oauth_client_client_secret', value: '')- expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled+ click_button 'Save and continue'++ expect(page).to have_text("Client ID can't be blank.")+ expect(page).to have_text("Client secret can't be blank.")# Happy path - Submit valid valuesfill_in 'oauth_client_client_id', with: '1234567890'fill_in 'oauth_client_client_secret', with: '0987654321'- expect(find_test_selector('storage-oauth-client-submit-button')).not_to be_disabledclick_button 'Save and continue'enddiff --git a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rbindex 649840dcfb4..ce487547501 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_api_spec.rb@@ -492,7 +492,7 @@ RSpec.describe 'API v3 storages resource', :webmock, content_type: :json doendit_behaves_like 'constraint violation' do- let(:message) { 'Client can\'t be blank.' }+ let(:message) { 'Client ID can\'t be blank.' }endendenddiff --git a/spec/contracts/oauth_clients/create_contract_spec.rb b/spec/contracts/oauth_clients/create_contract_spec.rbindex 80e81a1e724..a64a257ecdc 100644--- a/spec/contracts/oauth_clients/create_contract_spec.rb+++ b/spec/contracts/oauth_clients/create_contract_spec.rb@@ -72,6 +72,16 @@ RSpec.describe OAuthClients::CreateContract doendend+ context 'with blank client ID' do+ let(:client_id) { '' }++ it 'is invalid, includes `ID` in error message' do+ expect(contract).not_to be_valid++ expect(contract.errors[:client_id]).to eq(["ID can't be blank."])+ end+ end+context 'with integration (polymorphic attribute) linked' dolet(:integration) { create(:nextcloud_storage) }