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

Fixed OneDrive Drive ID not beeing a UUID

Andreas Pfohl1231c12e1e6c
diff --git a/modules/storages/app/contracts/storages/storages/one_drive_contract.rb b/modules/storages/app/contracts/storages/storages/one_drive_contract.rb
index ce08c56bf23..fb293f0aaf0 100644
--- a/modules/storages/app/contracts/storages/storages/one_drive_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/one_drive_contract.rb
@@ -35,6 +35,6 @@ module Storages::Storages
attribute :tenant_id
validates :tenant_id, format: { with: /\A(?:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}|consumers)\z/i }
attribute :drive_id
- validates :drive_id, format: { with: /\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\z/i }, allow_nil: true
+ validates :drive_id, presence: true, allow_nil: true
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 02a7e13aad7..639b723b75a 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -42,7 +42,6 @@ class Storages::Admin::StoragesController < ApplicationController
# and set the @<controller_name> variable to the object referenced in the URL.
before_action :require_admin
before_action :find_model_object, only: %i[show destroy edit edit_host update replace_oauth_application]
- before_action :prepare_update_params, only: %i[update]
# menu_item is defined in the Redmine::MenuManager::MenuController
# module, included from ApplicationController.
@@ -114,7 +113,7 @@ class Storages::Admin::StoragesController < ApplicationController
def update
service_result = ::Storages::Storages::UpdateService
.new(user: current_user, model: @storage)
- .call(@storage_params)
+ .call(permitted_storage_params)
@storage = service_result.result
if service_result.success?
@@ -178,16 +177,6 @@ class Storages::Admin::StoragesController < ApplicationController
private
- def prepare_update_params
- @storage_params = permitted_storage_params
-
- if @storage.provider_type_one_drive? && @storage.drive_id.nil?
- parts = @storage_params[:drive_id].split(',')
-
- @storage_params[:drive_id] = parts.count > 1 ? parts[1] : parts[0]
- end
- end
-
def oauth_application(service_result)
service_result.dependent_results&.first&.result
end
diff --git a/modules/storages/spec/controller/storages_controller_spec.rb b/modules/storages/spec/controller/storages_controller_spec.rb
index d97822ec099..a94e300a51e 100644
--- a/modules/storages/spec/controller/storages_controller_spec.rb
+++ b/modules/storages/spec/controller/storages_controller_spec.rb
@@ -49,13 +49,10 @@ RSpec.describe Storages::Admin::StoragesController, type: :controller, webmock:
login_as admin
mock_server_capabilities_response(host)
mock_server_config_check_response(host)
+ post :create, params:
end
describe 'with valid storage attributes' do
- before do
- post :create, params:
- end
-
it 'is successful' do
expect(response).to be_successful
expect(response.body).not_to include('Host is not providing a &quot;Secure Context&quot;.')
@@ -66,35 +63,9 @@ RSpec.describe Storages::Admin::StoragesController, type: :controller, webmock:
describe 'with invalid storage attributes' do
let(:schema) { 'http' }
- before do
- post :create, params:
- end
-
it 'shows the errors of the dependent service result, complaining about HTTP being invalid' do
expect(response).to be_successful # you get a 200 response despite errors...
expect(response.body).to include('Host is not providing a &quot;Secure Context&quot;.')
end
end
-
- describe 'with drive ID triple' do
- let(:storage) { create(:one_drive_storage) }
- let(:drive_id) { "1b4b6576-906d-4d94-8f49-6d00a9507b50" }
- let(:params) do
- {
- id: storage.id,
- storages_storage: {
- drive_id: "example.sharepoint.com,#{drive_id},7ef259e8-8eed-4645-920a-8b367bb0d8e0"
- }
- }
- end
-
- before do
- put :update, params:
- end
-
- it 'drive ID must be parsed down to a single UUID' do
- storage.reload
- expect(storage.drive_id).to eq(drive_id)
- end
- end
end