Skip to content

Commit

Permalink
Add ability for HYACINTH config to specify the group and permissions …
Browse files Browse the repository at this point in the history
…for access copy files
  • Loading branch information
elohanlon committed Nov 10, 2023
1 parent 36b3c41 commit 9c3b043
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/models/concerns/digital_object/assets/file_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ def do_file_import
self.original_file_path = (@import_file_original_file_path || @import_file_import_path) # This also updates the 'content' datastream label
end

def copy_access_copy_to_save_destination(source_path, dest_path)
FileUtils.cp(source_path, dest_path)
# Optionally set file's group
FileUtils.chown(nil, HYACINTH['access_copy_file_group'], dest_path) if HYACINTH['access_copy_file_group'].present?
# Optionally set file's permissions
FileUtils.chmod(HYACINTH['access_copy_file_permissions'], dest_path) if HYACINTH['access_copy_file_permissions'].present?
end

def do_access_copy_import
access_filename = 'access' + File.extname(@access_copy_import_path)
dest_dir = Hyacinth::Utils::PathUtils.access_directory_path_for_uuid!(self.uuid)
dest_file_path = File.join(dest_dir, access_filename)
FileUtils.cp(@access_copy_import_path, dest_file_path)
# Make sure the new file's group permissions are set to rw (using 0660 permissions).
# When Derivativo 1.5 is released, this can change to 0640 permissions.
FileUtils.chmod(0660, dest_file_path)
copy_access_copy_to_save_destination(@access_copy_import_path, dest_file_path)

access_ds_location = Hyacinth::Utils::PathUtils.filesystem_path_to_ds_location(dest_file_path)

Expand Down
4 changes: 4 additions & 0 deletions config/templates/hyacinth.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ development:
default_asset_home: <%= Rails.root.join('tmp', 'development', 'asset_home') %>
default_service_copy_home: <%= Rails.root.join('tmp', 'development', 'service_copy_home') %>
access_copy_directory: <%= Rails.root.join('tmp', 'development', 'access') %>
# access_copy_file_group: digital-projects
# access_copy_file_permissions: 0640
upload_directory: <%= Rails.root.join('tmp', 'development', 'upload') %>
csv_export_directory: <%= Rails.root.join('tmp', 'development', 'csv_exports') %>
processed_csv_import_directory: <%= Rails.root.join('tmp', 'development', 'processed_csv_imports') %>
Expand All @@ -20,6 +22,8 @@ test:
default_asset_home: <%= Rails.root.join('tmp', 'test', 'asset_home') %>
default_service_copy_home: <%= Rails.root.join('tmp', 'test', 'service_copy_home') %>
access_copy_directory: <%= Rails.root.join('tmp', 'test', 'access') %>
# access_copy_file_group: digital-projects
# access_copy_file_permissions: 0640
upload_directory: <%= Rails.root.join('tmp', 'test', 'upload') %>
csv_export_directory: <%= Rails.root.join('tmp', 'test', 'csv_exports') %>
processed_csv_import_directory: <%= Rails.root.join('tmp', 'test', 'processed_csv_imports') %>
Expand Down
49 changes: 49 additions & 0 deletions spec/models/digital_object/assets/file_import_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'rails_helper'

RSpec.describe DigitalObject::Asset, :type => :model do
describe "#copy_access_copy_to_save_destination" do
let(:src_path) { '/path/to/src.png' }
let(:dest_path) { '/path/to/dest.png' }
let(:expected_file_group) { 'digital-projects' }
let(:expected_file_permissions) { 0640 }

context "when the HYACINTH config has values set for access_copy_file_group and access_copy_file_permissions" do
before do
stub_const(
"HYACINTH",
HYACINTH.dup.merge(
'access_copy_file_group' => expected_file_group,
'access_copy_file_permissions' => expected_file_permissions
)
)
end
it "performs the expected operations" do
expect(FileUtils).to receive(:cp).with(src_path, dest_path)
expect(FileUtils).to receive(:chown).with(nil, expected_file_group, dest_path)
expect(FileUtils).to receive(:chmod).with(expected_file_permissions, dest_path)

DigitalObject::Asset.new.copy_access_copy_to_save_destination(src_path, dest_path)
end
end

context "when the HYACINTH config has NO values set for access_copy_file_group and access_copy_file_permissions" do
before do
stub_const(
"HYACINTH",
HYACINTH.dup.merge(
'access_copy_file_group' => nil,
'access_copy_file_permissions' => nil
)
)
end
it "performs the expected operations" do
expect(FileUtils).to receive(:cp).with(src_path, dest_path)
expect(FileUtils).not_to receive(:chown)
expect(FileUtils).not_to receive(:chmod)

DigitalObject::Asset.new.copy_access_copy_to_save_destination(src_path, dest_path)
end
end
end
end

0 comments on commit 9c3b043

Please sign in to comment.