Skip to content

Commit

Permalink
Add an option to set all files public
Browse files Browse the repository at this point in the history
This sets the preserve, shelve and publish to 'yes'
  • Loading branch information
jcoyne committed Mar 17, 2020
1 parent 7042701 commit b80b6c5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/controllers/bundle_contexts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def show

def bundle_contexts_params
params.require(:bundle_context)
.permit(:project_name, :content_structure, :staging_style_symlink, :content_metadata_creation, :bundle_dir, job_runs_attributes: [:job_type])
.permit(:project_name, :content_structure, :staging_style_symlink,
:content_metadata_creation, :bundle_dir, :all_files_public,
job_runs_attributes: [:job_type])
.merge(user: current_user)
end
end
8 changes: 3 additions & 5 deletions app/lib/pre_assembly/bundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def digital_objects
@digital_objects ||= discover_containers_via_manifest.each_with_index.map do |c, i|
stageable_items = discover_items_via_crawl(c)
row = manifest_rows[i]

DigitalObject.new(self,
container: c,
stageable_items: stageable_items,
Expand Down Expand Up @@ -202,10 +201,9 @@ def all_object_files

# @return [PreAssembly::ObjectFile]
def new_object_file(stageable, file_path)
ObjectFile.new(
file_path,
relative_path: relative_path(get_base_dir(stageable), file_path)
)
options = { relative_path: relative_path(get_base_dir(stageable), file_path) }
options[:file_attributes] = { preserve: 'yes', shelve: 'yes', publish: 'yes' } if bundle_context.all_files_public?
ObjectFile.new(file_path, options)
end

####
Expand Down
6 changes: 6 additions & 0 deletions app/views/bundle_contexts/_new_bc_form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</div>
</div>

<div class="row">
<div class="col-5">
<%= form.input :all_files_public %>
</div>
</div>

<div class="row">
<div class="col-5">
<%= form.input :content_metadata_creation, collection:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
activerecord:
attributes:
bundle_context:
all_files_public: "Make all files public?"
helpers:
submit:
bundle_context:
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20200317201845_add_public_to_bundle_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPublicToBundleContext < ActiveRecord::Migration[5.2]
def change

add_column :bundle_contexts, :all_files_public, :boolean, default: false, null: false
end
end
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_10_01_182157) do
ActiveRecord::Schema.define(version: 2020_03_17_201845) do

create_table "bundle_contexts", force: :cascade do |t|
t.string "project_name", null: false
t.integer "content_structure", null: false
t.string "bundle_dir", null: false
t.boolean "staging_style_symlink", default: false, null: false
t.integer "content_metadata_creation", null: false
t.bigint "user_id", null: false
t.integer "user_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "all_files_public", default: false, null: false
t.index ["user_id", "project_name"], name: "index_bundle_contexts_on_user_id_and_project_name", unique: true
t.index ["user_id"], name: "index_bundle_contexts_on_user_id"
end

create_table "job_runs", force: :cascade do |t|
t.string "output_location"
t.integer "job_type", null: false
t.bigint "bundle_context_id", null: false
t.integer "bundle_context_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bundle_context_id"], name: "index_job_runs_on_bundle_context_id"
Expand Down
18 changes: 18 additions & 0 deletions spec/factories/bundle_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@
Dir.delete(bc.output_dir) if Dir.exist?(bc.output_dir)
end
end

trait :flat_dir_images do
bundle_dir { 'spec/test_data/flat_dir_images' }
content_metadata_creation { 'default' }
content_structure { 'simple_image' }
project_name { 'Flat_Dir_Images' }
end

trait :folder_manifest do
bundle_dir { 'spec/test_data/obj_dirs_images' }
content_metadata_creation { 'default' }
content_structure { 'simple_image' }
project_name { 'FolderManifest' }
end

trait :public_files do
all_files_public { true }
end
end
end
15 changes: 15 additions & 0 deletions spec/lib/pre_assembly/bundle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@
expect(dobj.source_id).to be_a(String)
end
end

context 'when all_files_public is true' do
let(:bundle_context) do
build(:bundle_context, :folder_manifest, :public_files)
end
let(:bundle) { described_class.new(bundle_context) }

it 'sets the file attributes to public' do
bundle.digital_objects.each do |dobj|
dobj.object_files.each do |object_file|
expect(object_file.file_attributes).to eq(preserve: 'yes', shelve: 'yes', publish: 'yes')
end
end
end
end
end

describe '#load_checksums' do
Expand Down

0 comments on commit b80b6c5

Please sign in to comment.