Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display withdrawn work versions in the dashboard #889

Merged
merged 4 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ GEM
cocoon (1.2.14)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.1.7)
concurrent-ruby (1.1.8)
connection_pool (2.2.3)
content_disposition (1.0.0)
crack (0.4.3)
Expand Down Expand Up @@ -182,7 +182,7 @@ GEM
hashdiff (1.0.1)
hashie (4.1.0)
html_tokenizer (0.0.7)
i18n (1.8.5)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
jbuilder (2.10.0)
activesupport (>= 5.0.0)
Expand Down Expand Up @@ -242,7 +242,7 @@ GEM
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.2)
minitest (5.14.4)
msgpack (1.3.3)
multi_json (1.15.0)
multi_xml (0.6.0)
Expand Down Expand Up @@ -457,15 +457,15 @@ GEM
thor (1.0.1)
thread_safe (0.3.6)
timecop (0.9.2)
tzinfo (1.2.8)
tzinfo (1.2.9)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
uppy-s3_multipart (0.3.4)
aws-sdk-s3 (~> 1.0)
content_disposition (~> 1.0)
roda (>= 2.27, < 4)
vcr (6.0.0)
view_component (2.18.0)
view_component (2.26.1)
activesupport (>= 5.0.0, < 7.0)
warden (1.2.8)
rack (>= 2.0.6)
Expand All @@ -491,7 +491,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.4.1)
zeitwerk (2.4.2)

PLATFORMS
ruby
Expand Down
9 changes: 5 additions & 4 deletions app/components/back_to_work_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ def initialize(work:)
@work = work
end

# If the work has not been published, that is if it _only_ has a draft
# version, then we want to go to the resource page for that draft version.
# Otherwise, we want to to the resoure page of the work itself.
# If the work has not been published, that is if it _only_ has a draft version, then we want to go to the resource
# page for that draft version. If the work is withdrawn, or for some reason there's no draft version, we'll go to the
# resource page for the first (likely withdrawn) version. Otherwise, we want to to the resource page of the work
# itself.
def path
resource = if work.latest_published_version.nil?
work.draft_version
work.draft_version || work.versions[0]
else
work
end
Expand Down
15 changes: 0 additions & 15 deletions app/components/embargo_detail_component.html.erb

This file was deleted.

26 changes: 9 additions & 17 deletions app/components/embargo_detail_component.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
# frozen_string_literal: true

class EmbargoDetailComponent < ApplicationComponent
attr_reader :work_version
class EmbargoDetailComponent < FilesMessageComponent
def render?
work_version.embargoed?
end

# @param [WorkVersion]
# @todo We can avoid raising errors on unembargoed works with `render?` when it becomes available.
def initialize(work_version:)
raise ArgumentError, 'component must be used with an embargoed work' unless work_version.embargoed?
def heading
I18n.t('embargo.heading', date: embargo_release_date)
end

@work_version = work_version
def i18n_key
'embargo'
end

private

def embargo_release_date
work_version.work.embargoed_until.strftime('%Y-%m-%d')
end

def download?
Pundit.policy(controller.current_user, work_version).download?
end

def display_sharable_link?
return false unless work_version.published?

controller.controller_name == 'work_versions'
end
end
15 changes: 15 additions & 0 deletions app/components/files_message_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="alert alert-warning" role="alert">
<h2><%= heading %></h2>

<p>
<% if download? %>
<%= t("#{i18n_key}.edit_message") %>
<% else %>
<%= t("#{i18n_key}.public_message") %>
<% end %>
</p>

<% if display_sharable_link? %>
<%= link_to t("#{i18n_key}.link_text"), resource_path(work_version.work.uuid) %>
<% end %>
</div>
23 changes: 23 additions & 0 deletions app/components/files_message_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class FilesMessageComponent < ApplicationComponent
attr_reader :work_version

# @param [WorkVersion]
def initialize(work_version:)
@work_version = work_version
end

private

def download?
Pundit.policy(controller.current_user, work_version).download?
end

# @deprecated This can be removed in 4.4.0
def display_sharable_link?
return false unless work_version.published?

controller.controller_name == 'work_versions'
end
end
15 changes: 15 additions & 0 deletions app/components/withdrawn_detail_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class WithdrawnDetailComponent < FilesMessageComponent
def render?
work_version.withdrawn?
end

def heading
I18n.t('withdrawn.heading')
end

def i18n_key
'withdrawn'
end
end
17 changes: 13 additions & 4 deletions app/components/work_histories/work_version_change_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ def diff_id
end

def action
return translate('publish') if publish?

super
if publish?
translate('publish')
elsif withdrawn?
translate('withdrawn')
else
super
end
end

def changed_attributes
Expand Down Expand Up @@ -46,8 +50,13 @@ def publish?
paper_trail_version.object_changes.fetch('aasm_state', []).last.to_s == WorkVersion::STATE_PUBLISHED.to_s
end

def withdrawn?
paper_trail_version.event == 'update' &&
paper_trail_version.object_changes.fetch('aasm_state', []).last.to_s == WorkVersion::STATE_WITHDRAWN.to_s
end

def update?
super && !publish?
super && (!publish? || !withdrawn?)
end

def diff
Expand Down
6 changes: 4 additions & 2 deletions app/components/work_versions/status_badge_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
class WorkVersions::StatusBadgeComponent < ApplicationComponent
STATE_CLASSES = {
WorkVersion::STATE_DRAFT => %w(badge--dark-blue badge--outline),
WorkVersion::STATE_PUBLISHED => %w(badge--dark-blue)
WorkVersion::STATE_PUBLISHED => %w(badge--dark-blue),
WorkVersion::STATE_WITHDRAWN => %w(badge--dark-red)
}.with_indifferent_access.freeze

INVERTED_STATE_CLASSES = {
WorkVersion::STATE_DRAFT => %w(badge-light badge--outline),
WorkVersion::STATE_PUBLISHED => %w(badge-light)
WorkVersion::STATE_PUBLISHED => %w(badge-light),
WorkVersion::STATE_WITHDRAWN => %w(badge--light-red)
}.with_indifferent_access.freeze

def initialize(work_version:, invert: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def version
def state_classes
{
WorkVersion::STATE_DRAFT => %w(badge--dark-blue badge--outline),
WorkVersion::STATE_PUBLISHED => %w(badge--dark-blue)
WorkVersion::STATE_PUBLISHED => %w(badge--dark-blue),
WorkVersion::STATE_WITHDRAWN => %w(badge--dark-red)
}.with_indifferent_access.fetch(work_version.aasm_state)
end
end
2 changes: 2 additions & 0 deletions app/indexers/work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def self.call(work, commit: false)

if work.latest_published_version.present?
IndexingService.add_document(work.to_solr, commit: commit)
elsif work.withdrawn?
IndexingService.delete_document(work.uuid, commit: commit)
elsif commit
Blacklight.default_index.connection.commit
end
Expand Down
22 changes: 22 additions & 0 deletions app/javascript/frontend/styles/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,17 @@ h4,
}
}

&--dark-red {
background: $dark-red;
color: $white;

&.badge--outline {
background: transparent;
border: 1px solid $dark-red;
color: $dark-red;
}
}

&--gray-800 {
background: $gray-800;
color: $white;
Expand Down Expand Up @@ -1114,6 +1125,17 @@ h4,
}
}

&--light-red {
background: $white;
color: $dark-red;

&.badge--outline {
background: transparent;
border: 1px solid $light;
color: $light;
}
}

&--icon {
position: relative;
padding: .55rem .5rem .55rem 2.25rem;
Expand Down
4 changes: 4 additions & 0 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def draft_version
versions.draft.last
end

def withdrawn?
versions.withdrawn.any? && versions.published.none?
end

def resource_with_doi
self
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/resources/_work_version.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<div class="container-fluid">

<% unless (work_version.latest_published_version? || work_version.draft?) %>
<% unless (work_version.latest_published_version? || work_version.draft? || work_version.withdrawn?) %>
<div class="alert alert-warning" role="alert">
<%= t 'resources.old_version.message' %>
<%= link_to t('resources.old_version.link'),
Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_work_version_files.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= render(EmbargoDetailComponent.new(work_version: work_version)) if work_version.embargoed? %>
<%= render(EmbargoDetailComponent.new(work_version: work_version)) %>
<%= render(WithdrawnDetailComponent.new(work_version: work_version)) %>

<% if policy(work_version).download? %>
<ul class="file-card">
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ en:
public_message: "Files are not available during the embargo."
edit_message: "You have permission to access the files during the embargo."
link_text: "Public link"
withdrawn:
heading: "Withdrawn"
public_message: "Files are not available for works that have been withdrawn."
edit_message: "You have permission to access the files."
link_text: "Public link"
errors:
messages:
invalid_edtf: is not a valid date in EDTF format
Expand Down Expand Up @@ -426,6 +431,7 @@ en:
publish: Published
update: Updated
destroy: Deleted
withdrawn: Withdrawn
truncated_attributes: "and %{count} more"
omniauth:
login_error: 'There was a problem logging you in. We have been notified of the issue and will work to fix it. Please try again later.'
Expand Down
12 changes: 10 additions & 2 deletions spec/components/back_to_work_button_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:component) { described_class.new(work: work) }
let(:result) { render_inline(component).css('a').first }

context 'when the Work has a latest published version' do
context 'when the work has a latest published version' do
let(:work) { create :work, has_draft: false, versions_count: 1 }

it "renders a link back to the _Work's_ resource page" do
Expand All @@ -17,11 +17,19 @@
end
end

context 'when the has only a draft' do
context 'when the work has only a draft' do
let(:work) { create :work, has_draft: true, versions_count: 1 }

it "renders a link back to the _draft Version's_ resource page" do
expect(result[:href]).to eq resource_path(work.draft_version.uuid)
end
end

context 'when the work is withdrawn' do
let(:work) { create :work, :withdrawn, has_draft: false }

it "renders a link back to the withdrawn work version's resource page" do
expect(result[:href]).to eq resource_path(work.versions[0].uuid)
end
end
end
2 changes: 1 addition & 1 deletion spec/components/embargo_detail_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
let(:work) { build(:work) }

specify do
expect { content }.to raise_error(ArgumentError, 'component must be used with an embargoed work')
expect(content).to be_empty
end
end
end
Loading