Skip to content

Commit

Permalink
Lease managment UI should match embargo management UI. Fixes #391
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 12, 2015
1 parent b937df5 commit 5e2cbab
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
padding-left: 8px;
}

.extra-embargo-info {
.extra-embargo-info, .extra-lease-info {
td {
border-top: none;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ def destroy
def update
filter_docs_with_edit_access!
copy_visibility = params[:embargoes].values.map { |h| h[:copy_visibility] }
batch.each do |id|
ActiveFedora::Base.find(id).tap do |curation_concern|
EmbargoActor.new(curation_concern).destroy
curation_concern.copy_visibility_to_files if copy_visibility.include?(id)
end
ActiveFedora::Base.find(batch).each do |curation_concern|
EmbargoActor.new(curation_concern).destroy
curation_concern.copy_visibility_to_files if copy_visibility.include?(curation_concern.id)
end
redirect_to embargoes_path
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def index
authorize! :index, Hydra::AccessControls::Lease
end

# Removes a single lease
def destroy
LeaseActor.new(curation_concern).destroy
flash[:notice] = curation_concern.lease_history.last
Expand All @@ -24,11 +25,10 @@ def destroy

def update
filter_docs_with_edit_access!
batch.each do |id|
ActiveFedora::Base.find(id).tap do |curation_concern|
curation_concern.deactivate_lease!
curation_concern.save
end
copy_visibility = params[:leases].values.map { |h| h[:copy_visibility] }
ActiveFedora::Base.find(batch).each do |curation_concern|
LeaseActor.new(curation_concern).destroy
curation_concern.copy_visibility_to_files if copy_visibility.include?(curation_concern.id)
end
redirect_to leases_path
end
Expand Down
7 changes: 6 additions & 1 deletion app/views/leases/_list_expired_active_leases.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</tr>
</thead>
<tbody>
<% assets_with_expired_leases.each do |curation_concern| %>
<% assets_with_expired_leases.each_with_index do |curation_concern, i| %>
<tr>
<td><%= button_for_add_to_batch curation_concern%></td>
<td class="human-readable-type"><%= curation_concern.human_readable_type %></td>
Expand All @@ -31,6 +31,11 @@
<td class="visibility-after-lease"><%= visibility_badge(curation_concern.visibility_after_lease) %></td>
<td class="actions"><%= link_to 'Deactivate Lease', embargo_path(curation_concern), method: :delete, class: 'btn btn-primary' %></td>
</tr>
<tr data-behavior="extra" data-id="<%= curation_concern.id %>" class="extra-lease-info">
<td></td>
<td colspan=5>
<%= check_box_tag "leases[#{i}][copy_visibility]", curation_concern.id, true %> Change all files within <%= curation_concern %> to <%= visibility_badge(curation_concern.visibility_after_lease) %>?</td>
</tr>
<% end %>
</tbody>
</table>
Expand Down
25 changes: 19 additions & 6 deletions spec/controllers/leases_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,27 @@

describe '#update' do
context 'when I have permission to edit the object' do
let(:file_set) { create(:file_set, visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) }
let(:expiration_date) { Date.today + 2 }

before do
expect(ActiveFedora::Base).to receive(:find).with(a_work.id).and_return(a_work)
a_work.file_sets << file_set
a_work.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
a_work.visibility_during_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
a_work.visibility_after_lease = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
a_work.lease_expiration_date = expiration_date.to_s
a_work.lease.save(validate: false)
a_work.save(validate: false)
end
it 'deactivates lease and redirect' do
expect(a_work).to receive(:deactivate_lease!)
expect(a_work).to receive(:save)
patch :update, batch_document_ids: [a_work.id]
expect(response).to redirect_to leases_path

context 'with an expired lease' do
let(:expiration_date) { Date.today - 2 }
it 'deactivates lease, update the visibility and redirect' do
patch :update, batch_document_ids: [a_work.id], leases: { '0' => { copy_visibility: a_work.id } }
expect(a_work.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
expect(file_set.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
expect(response).to redirect_to leases_path
end
end
end
end
Expand Down

0 comments on commit 5e2cbab

Please sign in to comment.