Skip to content

Commit

Permalink
Merge pull request #2159 from samvera/remove_autocreate
Browse files Browse the repository at this point in the history
Remove autocreate_fields! it makes it impossible to set required fields
  • Loading branch information
cjcolvar authored Nov 13, 2017
2 parents 78e44e3 + 02e24bf commit 0a032be
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 24 deletions.
34 changes: 31 additions & 3 deletions app/change_sets/hyrax/batch_upload_change_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,44 @@ module Hyrax
class BatchUploadChangeSet < WorkChangeSet
# include HydraEditor::Form::Permissions

self.exclude_fields = [:title, :resource_type]
property :creator, multiple: true, required: true
property :keyword, multiple: true, required: true
property :rights_statement, required: true

property :created_at
property :updated_at
property :depositor
property :date_uploaded
property :date_modified
property :proxy_depositor
property :on_behalf_of
property :label
property :relative_path
property :contributor
property :description
property :license
property :publisher
property :date_created
property :subject
property :language
property :identifier
property :related_url
property :source
property :based_near
property :arkivo_checksum

property :admin_set_id
property :member_of_collection_ids
property :member_ids
property :thumbnail_id
property :representative_id

attr_accessor :payload_concern # a Class name: what is form creating a batch of?

def self.work_klass
::BatchUploadItem
end

autocreate_fields!

# On the batch upload, title is set per-file.
def primary_terms
super - [:title]
Expand Down
9 changes: 1 addition & 8 deletions app/change_sets/hyrax/work_change_set.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Hyrax
class WorkChangeSet < Valkyrie::ChangeSet
class_attribute :workflow_class, :exclude_fields, :primary_terms, :secondary_terms
class_attribute :workflow_class, :primary_terms, :secondary_terms
delegate :human_readable_type, to: :resource

# Which fields show above the fold.
Expand All @@ -9,9 +9,6 @@ class WorkChangeSet < Valkyrie::ChangeSet
:date_created, :subject, :language, :identifier,
:based_near, :related_url, :source]

# Don't create accessors for these fields
self.exclude_fields = [:internal_resource, :id, :read_groups, :read_users, :edit_users, :edit_groups]

# Used for searching
property :search_context, virtual: true, multiple: false, required: false

Expand Down Expand Up @@ -44,10 +41,6 @@ class << self
def work_klass
name.sub(/ChangeSet$/, '').constantize
end

def autocreate_fields!
self.fields = work_klass.schema.keys + [:resource_type] - [:internal_resource, :id, :read_groups, :read_users, :edit_users, :edit_groups]
end
end

def prepopulate!
Expand Down
34 changes: 33 additions & 1 deletion lib/generators/hyrax/work/templates/change_set.rb.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Generated via
# `rails generate hyrax:work <%= class_name %>`
class <%= class_name %>ChangeSet < Hyrax::WorkChangeSet
self.autocreate_fields!
property :title, multiple: true, required: true
property :creator, multiple: true, required: true
property :keyword, multiple: true, required: true
property :rights_statement, required: true

property :created_at
property :updated_at
property :depositor
property :date_uploaded
property :date_modified
property :proxy_depositor
property :on_behalf_of
property :label
property :relative_path
property :resource_type
property :contributor
property :description
property :license
property :publisher
property :date_created
property :subject
property :language
property :identifier
property :related_url
property :source
property :based_near
property :arkivo_checksum

property :admin_set_id
property :member_of_collection_ids
property :member_ids
property :thumbnail_id
property :representative_id
end
44 changes: 32 additions & 12 deletions spec/change_sets/hyrax/generic_work_change_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,16 @@
describe "#fields" do
subject { change_set.fields.keys }

# rubocop:disable RSpec/ExampleLength
it do
is_expected.to eq ["created_at", "updated_at", "depositor", "title",
"date_uploaded", "date_modified", "admin_set_id",
"state", "proxy_depositor", "on_behalf_of",
"arkivo_checksum", "member_of_collection_ids",
"member_ids", "thumbnail_id", "representative_id",
"label", "relative_path", "resource_type", "creator",
"contributor", "description", "keyword", "license",
"rights_statement",
"publisher", "date_created", "subject", "language",
"identifier", "related_url", "source", "based_near"]
is_expected.to match_array ["created_at", "updated_at", "depositor", "title",
"date_uploaded", "date_modified", "admin_set_id",
"proxy_depositor", "on_behalf_of", "arkivo_checksum",
"member_of_collection_ids", "member_ids", "thumbnail_id",
"representative_id", "label", "relative_path", "resource_type",
"creator", "contributor", "description", "keyword", "license",
"rights_statement", "publisher", "date_created", "subject",
"language", "identifier", "related_url", "source", "based_near"]
end
# rubocop:enable RSpec/ExampleLength
end

describe "#primary_terms" do
Expand All @@ -394,6 +390,30 @@
end
end

describe "#title" do
it "is required" do
expect(change_set.required?('title')).to be true
end
end

describe "#creator" do
it "is required" do
expect(change_set.required?('creator')).to be true
end
end

describe "#keyword" do
it "is required" do
expect(change_set.required?('keyword')).to be true
end
end

describe "#rights_statement" do
it "is required" do
expect(change_set.required?('rights_statement')).to be true
end
end

describe "#permissions" do
let(:work) do
GenericWork.new(edit_users: ['bob'],
Expand Down

0 comments on commit 0a032be

Please sign in to comment.