Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1708
- Loading branch information
Showing
15 changed files
with
179 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Sufia | ||
# Creates a work and attaches files to the work | ||
class CreateWithCollectionsActor | ||
attr_reader :work_actor, :collection_ids | ||
|
||
def initialize(work_actor, collection_ids) | ||
@work_actor = work_actor | ||
@collection_ids = collection_ids | ||
end | ||
|
||
delegate :visibility_changed?, to: :work_actor | ||
|
||
def create | ||
validate_collections && work_actor.create && add_to_collections | ||
end | ||
|
||
def update | ||
validate_collections && work_actor.update && add_to_collections | ||
end | ||
|
||
protected | ||
|
||
# ensure that the collections we are given are owned by the depositor of the work | ||
def validate_collections | ||
expected_user_id = work_actor.user.id | ||
uploaded_files.each do |file| | ||
if file.user_id != expected_user_id | ||
Rails.logger.error "User #{work_actor.user.user_key} attempted to ingest uploaded_file #{file.id}, but it belongs to a different user" | ||
return false | ||
end | ||
end | ||
true | ||
end | ||
|
||
# @return [TrueClass] | ||
def attach_files | ||
AddWorkToCollectionJob.perform_later(work_actor.curation_concern, uploaded_files) | ||
true | ||
end | ||
|
||
# Fetch collections from Fedora | ||
def collections | ||
return [] unless collection_ids | ||
@collections ||= Collection.find(collection_ids) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/views/curation_concerns/base/_form_relationships.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h3>This Work in Collections</h3> | ||
<div id="collection-widget"> | ||
<%= f.input :collection_ids, as: :select, | ||
collection: available_collections(nil), | ||
input_html: { class: 'form-control', multiple: true } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
:visibility_after_lease, | ||
:visibility, | ||
:ordered_member_ids, | ||
:collection_ids, | ||
:resource_type] } | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,62 @@ | ||
require 'spec_helper' | ||
|
||
describe Sufia::Forms::WorkForm do | ||
describe CurationConcerns::GenericWorkForm do | ||
let(:form) { described_class.new(GenericWork.new, nil) } | ||
|
||
describe "#rendered_terms" do | ||
subject { form.rendered_terms } | ||
it { is_expected.not_to include(:visibilty, :visibility_during_embargo, | ||
:embargo_release_date, :visibility_after_embargo, | ||
:visibility_during_lease, :lease_expiration_date, | ||
:visibility_after_lease) } | ||
:visibility_after_lease, :collection_ids) } | ||
end | ||
|
||
describe "#[]" do | ||
subject { form[term] } | ||
context "for collection_ids" do | ||
let(:term) { :collection_ids } | ||
it { is_expected.to eq [] } | ||
end | ||
end | ||
|
||
describe '.model_attributes' do | ||
let(:params) { ActionController::Parameters.new( | ||
title: ['foo'], | ||
description: [''], | ||
visibility: 'open', | ||
admin_set_id: '123', | ||
representative_id: '456', | ||
thumbnail_id: '789', | ||
tag: ['derp'], | ||
rights: ['http://creativecommons.org/licenses/by/3.0/us/'], | ||
collection_ids: ['123456', 'abcdef']) } | ||
|
||
subject { described_class.model_attributes(params) } | ||
|
||
it 'permits parameters' do | ||
expect(subject['title']).to eq ['foo'] | ||
expect(subject['description']).to be_empty | ||
expect(subject['visibility']).to eq 'open' | ||
expect(subject['rights']).to eq ['http://creativecommons.org/licenses/by/3.0/us/'] | ||
expect(subject['tag']).to eq ['derp'] | ||
expect(subject['collection_ids']).to eq ['123456', 'abcdef'] | ||
end | ||
|
||
context '.model_attributes' do | ||
let(:params) { ActionController::Parameters.new( | ||
title: [''], | ||
description: [''], | ||
tag: [''], | ||
rights: [''], | ||
collection_ids: ['']) } | ||
|
||
it 'removes blank parameters' do | ||
expect(subject['title']).to be_empty | ||
expect(subject['description']).to be_empty | ||
expect(subject['rights']).to be_empty | ||
expect(subject['tag']).to be_empty | ||
expect(subject['collection_ids']).to be_empty | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters