-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2746 from sul-dlss/decommission-collections#2629
Allow collections to be decommissioned
- Loading branch information
Showing
31 changed files
with
480 additions
and
41 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
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,15 @@ | ||
<section class="admin-section p-3 mb-5"> | ||
<div class="row"> | ||
<div class="col"> | ||
<label for="adminFunctionsSelect" class="form-label admin-functions">Admin functions</label> | ||
</div> | ||
<div class="col"> | ||
<select id="adminFunctionsSelect" class="form-select" onchange="this.value !== 'select' ? document.querySelector('#collectionAdminSection').src = this.value : document.querySelector('#collectionAdminSection').innerHTML = ''"> | ||
<%= options %> | ||
</select> | ||
</div> | ||
</div> | ||
<div class="row pt-3"> | ||
<turbo-frame id="collectionAdminSection"></turbo-frame> | ||
</div> | ||
</section> |
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Collections | ||
# Renders the admin functions for a collection | ||
class AdminComponent < ApplicationComponent | ||
def initialize(collection:) | ||
@collection = collection | ||
end | ||
|
||
attr_reader :collection | ||
|
||
def render? | ||
helpers.user_with_groups.administrator? | ||
end | ||
|
||
def options | ||
opts = [ | ||
['Select...', 'select'] | ||
] | ||
opts << ['Decommission collection', edit_collection_decommission_path(collection)] unless collection.head.decommissioned? # rubocop:disable Layout/LineLength | ||
options_for_select(opts, 'select') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
# a controller for decommissioning a collection. | ||
class CollectionDecommissionController < ApplicationController | ||
before_action :authenticate_user! | ||
verify_authorized | ||
|
||
def edit | ||
authorize! :collection_decommission | ||
end | ||
|
||
def update | ||
authorize! :collection_decommission | ||
|
||
collection = Collection.find(params[:id]) | ||
# Check that collection contains only NO items or ONLY DECOMMISSIONED items | ||
if collection.works_without_decommissioned.any? | ||
flash[:error] = I18n.t('collection.flash.decommission_failed') | ||
else | ||
decommission!(collection) | ||
flash[:success] = I18n.t('collection.flash.decommissioned') | ||
end | ||
redirect_to collection_path(collection) | ||
end | ||
|
||
private | ||
|
||
def decommission!(collection) | ||
Collection.transaction do | ||
# NOTE: You might think the `head.collection` bit here is not needed... | ||
# but it is. Why? Because when the event is created in the | ||
# CollectionVersion class, we access the collection **via** the | ||
# collection version. And that in-memory collection instance is a | ||
# different in-memory collection instance than the collection here. | ||
collection.head.collection.event_context = { | ||
user: current_user, | ||
description: I18n.t('collection.flash.decommissioned') | ||
} | ||
collection.head.decommission! | ||
collection.update!( | ||
managed_by: [], | ||
depositors: [], | ||
reviewed_by: [] | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
# Authorization policy for Collection decommission operations | ||
class CollectionDecommissionPolicy < ApplicationPolicy | ||
alias_rule :edit?, to: :update? | ||
|
||
def update? | ||
administrator? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<turbo-frame id='collectionAdminSection'> | ||
<%= form_with url: collection_decommission_path(params[:id]), method: :put, data: { turbo: false } do |form| %> | ||
<div data-controller="decommission"> | ||
<div class="form-check mt-3"> | ||
<input class="form-check-input" type="checkbox" value="" id="confirmCheckbox" data-decommission-target="confirm" data-action="decommission#change"> | ||
<label class="form-check-label" for="confirmCheckbox"> | ||
I confirm this collection has been decommissioned in Argo and <span class="text-danger">understand this cannot be undone</span>. | ||
</label> | ||
</div> | ||
<fieldset data-decommission-target="submit"> | ||
<%= form.submit "Decommission collection from H2", class: 'btn btn-primary mt-3' %> | ||
</fieldset> | ||
</div> | ||
<% end %> | ||
</turbo-frame> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<turbo-frame id="collectionAdminFrame"> | ||
<%= render Collections::AdminComponent.new(collection: @collection) %> | ||
</turbo-frame> |
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,15 +1,15 @@ | ||
<turbo-frame id='workAdminSection'> | ||
<%= form_with url: decommission_path(params[:id]), method: :put, data: {turbo: false} do |form| %> | ||
<%= form_with url: work_decommission_path(params[:id]), method: :put, data: {turbo: false} do |form| %> | ||
<div data-controller="decommission"> | ||
<div class="form-check mt-3"> | ||
<input class="form-check-input" type="checkbox" value="" id="confirmCheckbox" data-decommission-target="confirm" data-action="decommission#change"> | ||
<label class="form-check-label" for="confirmCheckbox"> | ||
I confirm this item has been decommissioned in Argo and <span class="text-danger">understand this cannot be undone</span>. | ||
I confirm this item has been decommissioned in Argo and <span class="text-danger">understand this cannot be undone</span>. | ||
</label> | ||
</div> | ||
<fieldset data-decommission-target="submit"> | ||
<%= form.submit "Decommission from H2", class: 'btn btn-primary mt-3' %> | ||
</fieldset> | ||
</div> | ||
<% end %> | ||
</turbo-frame> | ||
</turbo-frame> |
Oops, something went wrong.