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

feat[Op#50737]: Extend OAuthClient components to account for OneDrive storage

Kabiru Mwenja9795321d99df
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.ts
index d203493adcb..e1e82369c31 100644
--- a/frontend/src/stimulus/controllers/dynamic/storages/oauth-client-form.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/storages/oauth-client-form.controller.ts
@@ -33,15 +33,22 @@ import { Controller } from '@hotwired/stimulus';
export default class OAuthClientFormController extends Controller {
static targets = [
'clientId',
+ 'clientSecret',
'redirectUri',
+ 'submitButton',
];
static values = {
clientIdMissing: String,
};
+ declare readonly hasClientIdTarget:boolean;
+ declare readonly hasClientSecretTarget:boolean;
+ declare readonly hasSubmitButtonTarget:boolean;
declare readonly clientIdTarget:HTMLInputElement;
+ declare readonly clientSecretTarget:HTMLInputElement;
declare readonly redirectUriTarget:HTMLInputElement;
+ declare readonly submitButtonTarget:HTMLInputElement;
declare readonly clientIdMissingValue:string;
@@ -51,6 +58,21 @@ export default class OAuthClientFormController extends Controller {
});
this.redirectUriTarget.value = this.redirectUri();
+ 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;
+ }
}
private redirectUri():string {
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.erb
index a4a76c47af8..65105c6de02 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
@@ -2,7 +2,12 @@
render(Primer::Beta::Text.new(tag: :div, test_selector: 'storage-oauth-client-form')) do
primer_form_with(
model: oauth_client,
- url: admin_settings_storage_oauth_client_path(storage)
+ url: admin_settings_storage_oauth_client_path(storage),
+ data: {
+ controller: 'storages--oauth-client-form',
+ application_target: 'dynamic',
+ 'storages--oauth-client-form-client-id-missing-value': t(:"storages.instructions.#{storage.short_provider_type}.missing_client_id_for_redirect_uri")
+ }
) do |form|
flex_layout do |oauth_client_row|
oauth_client_row.with_row(mb: 3) do
@@ -14,7 +19,43 @@
end
oauth_client_row.with_row(mb: 3) do
- render(Storages::Admin::OAuthClientForm.new(form, storage:))
+ 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'
+ }
+ }
+ )
+ )
+ end
+
+ if storage.provider_type_one_drive?
+ oauth_client_row.with_row(mb: 3) do
+ render(
+ OpenProject::Common::ClipboardCopyComponent.new(
+ name: :oauth_client_redirect_uri,
+ visually_hide_label: false,
+ value_to_copy: redirect_uri_or_instructions,
+ label: I18n.t('storages.label_redirect_uri'),
+ required: true,
+ input_group_options: {
+ data: {
+ 'storages--oauth-client-form-target': 'redirectUri'
+ }
+ },
+ )
+ )
+ end
end
oauth_client_row.with_row do
@@ -22,6 +63,12 @@
Storages::Admin::SubmitOrCancelForm.new(
form,
storage:,
+ submit_button_options: {
+ disabled: submit_button_disabled?,
+ data: {
+ 'storages--oauth-client-form-target': 'submitButton'
+ }
+ },
cancel_button_options: {
href: cancel_button_path
}
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.rb
index b8ab502027c..682c6a3bc87 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
@@ -44,7 +44,17 @@ module Storages::Admin::Forms
storage.persisted? ? edit_admin_settings_storage_path(storage) : admin_settings_storages_path
end
- private
+ def submit_button_disabled?
+ !storage_oauth_client_configured?
+ end
+
+ def redirect_uri_or_instructions
+ if storage_oauth_client_configured?
+ oauth_client.redirect_uri
+ else
+ I18n.t("storages.instructions.one_drive.missing_client_id_for_redirect_uri")
+ end
+ end
def storage_provider_credentials_copy_instructions
"#{I18n.t('storages.instructions.copy_from')}: #{provider_credentials_instructions_link}".html_safe
@@ -59,5 +69,11 @@ module Storages::Admin::Forms
)
) { I18n.t("storages.instructions.#{@storage.short_provider_type}.integration") }
end
+
+ private
+
+ def storage_oauth_client_configured?
+ oauth_client.present? && oauth_client.client_id.present? && oauth_client.client_secret.present?
+ end
end
end
diff --git a/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb b/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
index 37fa98e4e8d..90251d0be5b 100644
--- a/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
+++ b/modules/storages/app/components/storages/admin/oauth_client_info_component.html.erb
@@ -1,7 +1,11 @@
<%=
grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
grid.with_area(:item, tag: :div, mr: 3) do
- concat(render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1, test_selector: 'storage-oauth-client-label')) { I18n.t('storages.file_storage_view.nextcloud_oauth') })
+ concat(
+ render(
+ Primer::Beta::Text.new(font_weight: :semibold, mr: 1, test_selector: 'storage-oauth-client-label')
+ ) { I18n.t("storages.file_storage_view.#{storage.short_provider_type}_oauth") }
+ )
concat(configuration_check_label_for(:storage_oauth_client_configured))
end
diff --git a/modules/storages/app/components/storages/admin/storage_view_component.html.erb b/modules/storages/app/components/storages/admin/storage_view_component.html.erb
index 5f256409e4c..088a1b9f099 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
@@ -65,5 +65,21 @@
end
end
end
+
+ if storage.provider_type_one_drive?
+ component.with_row(scheme: :neutral) do
+ grid_layout('op-storage-view--row', tag: :div, align_items: :center) do |grid|
+ grid.with_area(:item, tag: :div, mr: 3) do
+ render(Primer::Beta::Text.new(font_weight: :semibold, mr: 1)) { I18n.t('storages.file_storage_view.oauth_applications') }
+ end
+ end
+ end
+
+ component.with_row(scheme: :default) do
+ render(OpTurbo::FrameComponent.new(id: :storage_oauth_client_section)) do
+ render(Storages::Admin::OAuthClientInfoComponent.new(oauth_client: storage.oauth_client, storage:))
+ end
+ end
+ end
end
%>
diff --git a/modules/storages/app/components/storages/admin/storage_view_information.rb b/modules/storages/app/components/storages/admin/storage_view_information.rb
index 109b89a8155..2b2669d0f4d 100644
--- a/modules/storages/app/components/storages/admin/storage_view_information.rb
+++ b/modules/storages/app/components/storages/admin/storage_view_information.rb
@@ -48,7 +48,7 @@ module Storages::Admin
if storage.oauth_client
"#{I18n.t('storages.label_oauth_client_id')}: #{storage.oauth_client.client_id}"
else
- I18n.t('storages.configuration_checks.oauth_client_incomplete', provider: storage.short_provider_type.capitalize)
+ I18n.t("storages.configuration_checks.oauth_client_incomplete.#{storage.short_provider_type}")
end
end
end
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 7fa853d82af..6cab7d6845c 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -111,9 +111,7 @@ class Storages::Admin::StoragesController < ApplicationController
service_result.on_success do
if OpenProject::FeatureDecisions.storage_primer_design_active?
- respond_to do |format|
- format.turbo_stream { render :show_oauth_application }
- end
+ respond_to { |format| format.turbo_stream }
else
case @storage.provider_type
when ::Storages::Storage::PROVIDER_TYPE_ONE_DRIVE
diff --git a/modules/storages/app/forms/storages/admin/oauth_client_form.rb b/modules/storages/app/forms/storages/admin/oauth_client_form.rb
index 8bad45364cd..53568462b5c 100644
--- a/modules/storages/app/forms/storages/admin/oauth_client_form.rb
+++ b/modules/storages/app/forms/storages/admin/oauth_client_form.rb
@@ -29,22 +29,35 @@
module Storages::Admin
class OAuthClientForm < ApplicationForm
form do |oauth_client_form|
- oauth_client_form.text_field(name: :client_id,
- label: label_client_id,
- required: true)
-
- oauth_client_form.text_field(name: :client_secret,
- label: label_client_secret,
- required: true)
+ oauth_client_form.text_field(**@client_id_input_options)
+ oauth_client_form.text_field(**@client_secret_input_options)
end
- def initialize(storage:)
+ def initialize(storage:, client_id_input_options: {}, client_secret_input_options: {})
super()
@storage = storage
+ @client_id_input_options = default_client_id_input_options.merge(client_id_input_options)
+ @client_secret_input_options = default_client_secret_input_options.merge(client_secret_input_options)
end
private
+ def default_client_id_input_options
+ {
+ name: :client_id,
+ label: label_client_id,
+ required: true
+ }
+ end
+
+ def default_client_secret_input_options
+ {
+ name: :client_secret,
+ label: label_client_secret,
+ required: true
+ }
+ end
+
def label_client_id
[label_provider_name, I18n.t('storages.label_oauth_client_id')].join(' ')
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.erb
new file mode 100644
index 00000000000..f15990f2c5d
--- /dev/null
+++ b/modules/storages/app/views/storages/admin/storages/create.turbo_stream.erb
@@ -0,0 +1,58 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-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.
+
+++#%>
+
+<%= turbo_stream.update :storage_general_info_section do %>
+ <%= render(Storages::Admin::GeneralInfoComponent.new(@storage)) %>
+<% end %>
+
+
+<% if @storage.provider_type_nextcloud? %>
+ <%= 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),
+ cancel_button_path: admin_settings_storages_path,
+ cancel_button_should_break_from_frame: true
+ )
+ )
+ %>
+ <% end %>
+<% end %>
+
+<% if @storage.provider_type_one_drive? %>
+ <%= 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/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 842850af44a..51af55ffb94 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -89,6 +89,7 @@ en:
project_folders: "Project folders"
storage_provider: "Storage provider"
openproject_oauth: "OpenProject OAuth"
+ one_drive_oauth: "Azure OAuth"
nextcloud_oauth: "Nextcloud OAuth"
automatically_managed_folders: "Automatically managed folders"
page_titles:
@@ -143,7 +144,7 @@ en:
oauth_client_secret: >
Copy the client secret from the Azure portal. For a newly created application the secret first needs to be
created manually. For authorization of web applications a secret is mandatory.
- missing_client_id_for_redirect_uri: "Client ID missing to provide redirect URI."
+ missing_client_id_for_redirect_uri: "Please fill the OAuth values to generate a URI"
tenant_id: "Please copy the tenant from your Azure application."
tenant_id_placeholder: "Name or UUID"
drive_id: "Please copy the drive ID from your Azure application."
@@ -154,7 +155,9 @@ en:
Users can nevertheless still upload files to other locations.
configuration_checks:
incomplete: "The setup of this storage is incomplete."
- oauth_client_incomplete: "Allow OpenProject to access %{provider} data using OAuth."
+ oauth_client_incomplete:
+ nextcloud: "Allow OpenProject to access Nextcloud data using OAuth."
+ one_drive: "Allow OpenProject to access Azure data using OAuth to connect OneDrive/Sharepoint."
delete_warning:
storage: >
Are you sure you want to delete this storage? This will also delete the storage from all projects where it is used.
@@ -200,6 +203,7 @@ en:
label_information: "Additional information"
label_provider_type: "Provider type"
label_project_folder: "Project folder"
+ label_redirect_uri: "Redirect URI"
label_new_storage: "New storage"
label_new_file_storage: "New file storage"
label_edit_storage: "Edit storage"