Skip to content

Commit

Permalink
Rename project_folder_path
Browse files Browse the repository at this point in the history
  • Loading branch information
mereghost committed Feb 21, 2024
1 parent f29cac3 commit 644859c
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module OneDrive
class CreateFolderCommand
using ServiceResultRefinements

def self.call(storage:, folder_path:, parent_location: nil)
new(storage).call(folder_path:, parent_location:)
def self.call(storage:, folder_path:)
new(storage).call(folder_path:)
end

def initialize(storage)
Expand Down
6 changes: 3 additions & 3 deletions modules/storages/app/models/storages/project_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def automatic_management_possible?
storage.present? && storage.automatic_management_enabled?
end

def project_folder_path
def managed_project_folder_path
case storage.short_provider_type
when 'nextcloud'
"#{storage.group_folder}/#{project.name.tr('/', '|')} (#{project.id})/"
Expand All @@ -74,7 +74,7 @@ def project_folder_path
def project_folder_location
case storage.short_provider_type
when 'nextcloud'
project_folder_path
managed_project_folder_path
when 'one_drive'
project_folder_id
else
Expand All @@ -83,7 +83,7 @@ def project_folder_location
end

def project_folder_path_escaped
escape_path(project_folder_path)
escape_path(managed_project_folder_path)
end

def file_inside_project_folder?(escaped_file_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def copy_dependency(*)
file_ids: source_file_links.map(&:origin_id))
folder_files_file_ids_deep_query_result = folder_files_file_ids_deep_query(
storage:,
path: target_project_storage.project_folder_path
path: target_project_storage.managed_project_folder_path
)
source_file_links.each do |old_file_link|
attributes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def copy_dependency(*)

def copy_project_folder(source_project_storage, destination_project_storage)
source_folder_name = source_project_storage.project_folder_location
destination_folder_name = destination_project_storage.project_folder_path
destination_folder_name = destination_project_storage.managed_project_folder_path

Storages::Peripherals::Registry
.resolve("commands.#{source_project_storage.storage.short_provider_type}.copy_template_folder")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def set_folders_permissions(remote_admins, project_storage)
end

command_params = {
path: project_storage.project_folder_path,
path: project_storage.managed_project_folder_path,
permissions: {
users: admin_permissions.to_h.merge(users_permissions),
groups: { "#{@storage.group}": NO_PERMISSIONS }
Expand All @@ -143,7 +143,7 @@ def set_folders_permissions(remote_admins, project_storage)
.resolve("commands.nextcloud.set_permissions")
.call(storage: @storage, **command_params)
.result_or do |error|
format_and_log_error(error, folder: project_storage.project_folder_path)
format_and_log_error(error, folder: project_storage.managed_project_folder_path)
end
end

Expand Down Expand Up @@ -186,11 +186,11 @@ def ensure_folders_exist(remote_folders)
next create_folder(project_storage) unless id_folder_map.key?(project_storage.project_folder_id)

current_path = id_folder_map[project_storage.project_folder_id]
if current_path != project_storage.project_folder_path
if current_path != project_storage.managed_project_folder_path
rename_folder(project_storage, current_path).on_failure do |service_result|
format_and_log_error(service_result.errors,
source: current_path,
target: project_storage.project_folder_path)
target: project_storage.managed_project_folder_path)

# we need to stop as this would mess with the other processes
return service_result
Expand All @@ -205,11 +205,11 @@ def ensure_folders_exist(remote_folders)
def rename_folder(project_storage, current_name)
Peripherals::Registry
.resolve("commands.nextcloud.rename_file")
.call(storage: @storage, source: current_name, target: project_storage.project_folder_path)
.call(storage: @storage, source: current_name, target: project_storage.managed_project_folder_path)
end

def create_folder(project_storage)
folder_path = project_storage.project_folder_path
folder_path = project_storage.managed_project_folder_path
Peripherals::Registry
.resolve("commands.nextcloud.create_folder")
.call(storage: @storage, folder_path:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def ensure_folders_exist(folder_map)
active_project_storages_scope.includes(:project).find_each do |project_storage|
next create_folder(project_storage) unless folder_map.key?(project_storage.project_folder_id)

if folder_map[project_storage.project_folder_id] != project_storage.project_folder_path
rename_folder(project_storage.project_folder_id, project_storage.project_folder_path)
if folder_map[project_storage.project_folder_id] != project_storage.managed_project_folder_path
rename_folder(project_storage.project_folder_id, project_storage.managed_project_folder_path)
end
end

Expand Down Expand Up @@ -117,8 +117,8 @@ def rename_folder(source, target)
def create_folder(project_storage)
Peripherals::Registry
.resolve('commands.one_drive.create_folder')
.call(storage: @storage, folder_path: project_storage.project_folder_path)
.match(on_failure: ->(error) { format_and_log_error(error, folder_path: project_storage.project_folder_path) },
.call(storage: @storage, folder_path: project_storage.managed_project_folder_path)
.match(on_failure: ->(error) { format_and_log_error(error, folder_path: project_storage.managed_project_folder_path) },
on_success: ->(folder_info) do
last_project_folder = ::Storages::LastProjectFolder
.find_by(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,11 @@ def create_base_folder
def setup_template_folder
raise if source_path.nil?

Storages::Peripherals::Registry
.resolve('commands.one_drive.create_folder')
.call(storage:, folder_path: 'Empty Subfolder', parent_location: source_path)

subfolder = Storages::Peripherals::Registry
.resolve('commands.one_drive.create_folder')
.call(storage:, folder_path: 'Subfolder with File', parent_location: source_path).result
command = Storages::Peripherals::Registry
.resolve('commands.one_drive.create_folder').new(storage)
command.call(folder_path: 'Empty Subfolder', parent_location: source_path)

subfolder = command.call(folder_path: 'Subfolder with File', parent_location: source_path).result
file_name = 'files_query_root.yml'
token = OAuthClientToken.last

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
expect(described_class).to respond_to(:call)

method = described_class.method(:call)
expect(method.parameters).to contain_exactly(%i[keyreq storage], %i[keyreq folder_path], %i[key parent_location])
expect(method.parameters).to contain_exactly(%i[keyreq storage], %i[keyreq folder_path])
end

it 'is registered as create_folder' do
Expand All @@ -67,7 +67,7 @@

it 'creates a sub folder', vcr: 'one_drive/create_folder_sub_folder' do
folder = described_class.call(storage:, folder_path:).result
sub_folder = described_class.call(storage:, folder_path: "Another Folder", parent_location: folder.id).result
sub_folder = described_class.new(storage).call(folder_path: "Another Folder", parent_location: folder.id).result

expect(sub_folder.name).to eq("Another Folder")
expect(sub_folder.location).to eq("/#{folder_path}/Another Folder")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
let(:file_link) { create(:file_link, storage:, container: work_package) }
let(:second_file_link) { create(:file_link, container: work_package, storage:) }
let(:delete_folder_url) do
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.project_folder_path.chop}/"
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.managed_project_folder_path.chop}/"
end

before do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
describe 'DELETE /api/v3/storages/:storage_id' do
let(:path) { api_v3_paths.storage(storage.id) }
let(:delete_folder_url) do
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.project_folder_path.chop}/"
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.managed_project_folder_path.chop}/"
end
let(:deletion_request_stub) do
stub_request(:delete, delete_folder_url).to_return(status: 204, body: nil, headers: {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@
expect(OpenProject.logger)
.to have_received(:warn)
.with(source: "OpenProject/Lost Jedi Project Folder #3/",
target: project_storage2.project_folder_path,
target: project_storage2.managed_project_folder_path,
command: Storages::Peripherals::StorageInteraction::Nextcloud::RenameFileCommand,
message: 'Outbound request destination not found',
data: { status: 404, body: '' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def project_folder_info(project_storage)
end

def create_folder_for(project_storage, folder_override = nil)
folder_path = folder_override || project_storage.project_folder_path
folder_path = folder_override || project_storage.managed_project_folder_path

Storages::Peripherals::Registry.resolve('commands.one_drive.create_folder')
.call(storage: project_storage.storage, folder_path:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
let(:factory) { :project_storage }
let(:host) { model_instance.storage.host }
let(:username) { model_instance.storage.username }
let(:path) { model_instance.project_folder_path.chop }
let(:path) { model_instance.managed_project_folder_path.chop }
let(:delete_folder_url) do
"#{host}/remote.php/dav/files/#{username}/#{path}/"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/services/projects/delete_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
work_package = create(:work_package, project:)
create(:file_link, container: work_package, storage:)
delete_folder_url =
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.project_folder_path.chop}/"
"#{storage.host}/remote.php/dav/files/#{storage.username}/#{project_storage.managed_project_folder_path.chop}/"

stub_request(:delete, delete_folder_url).to_return(status: 204, body: nil, headers: {})

Expand Down

0 comments on commit 644859c

Please sign in to comment.