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

Added spec for StorageController drive_id parsing

Andreas Pfohld5a3c39e450b
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 450b612431d..acff8804ba9 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -42,6 +42,7 @@ 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 update replace_oauth_application]
+ before_action :parse_drive_id, only: %i[update]
# menu_item is defined in the Redmine::MenuManager::MenuController
# module, included from ApplicationController.
@@ -111,14 +112,9 @@ class Storages::Admin::StoragesController < ApplicationController
# See also: create above
# Called by: Global app/config/routes.rb to serve Web page
def update
- storage_params = permitted_storage_params
- parts = storage_params[:drive_id].split(',')
-
- storage_params[:drive_id] = parts.count > 1 ? parts[1] : parts[0]
-
service_result = ::Storages::Storages::UpdateService
.new(user: current_user, model: @storage)
- .call(storage_params)
+ .call(@storage_params)
if service_result.success?
flash[:notice] = I18n.t(:notice_successful_update)
@@ -176,6 +172,16 @@ class Storages::Admin::StoragesController < ApplicationController
private
+ def parse_drive_id
+ @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 a94e300a51e..d97822ec099 100644
--- a/modules/storages/spec/controller/storages_controller_spec.rb
+++ b/modules/storages/spec/controller/storages_controller_spec.rb
@@ -49,10 +49,13 @@ 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;.')
@@ -63,9 +66,35 @@ 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