Skip to content

Commit

Permalink
provide default PermissionBadge presenter behavior when nil
Browse files Browse the repository at this point in the history
if visibility wasn't indexed for any item, the `PermissionBadge` presenter will
cause any relevant page not to render.

this fixes that issue by providing a reasonable default display badge in the
case that we can't identify the visibility from the indexed data.
  • Loading branch information
tamsin johnson authored and dunn committed Aug 23, 2022
1 parent 3e08ab3 commit 4f8b5de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/presenters/hyrax/permission_badge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def render
private

def dom_label_class
VISIBILITY_LABEL_CLASS.fetch(@visibility.to_sym, 'badge-info')
VISIBILITY_LABEL_CLASS.fetch(@visibility&.to_sym, 'badge-info')
end

def text
if registered?
Institution.name
else
I18n.t("hyrax.visibility.#{@visibility}.text")
visibility_key = @visibility || 'unknown'
I18n.t("hyrax.visibility.#{visibility_key}.text")
end
end

Expand Down
2 changes: 2 additions & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,8 @@ en:
note_html: Keep to myself with option to share.
text: Private
restricted_title_attr: Change the visibility of this resource
unknown:
text: Unknown
work_button_row:
attach_child: Attach Child
workflow:
Expand Down
7 changes: 7 additions & 0 deletions spec/presenters/hyrax/permission_badge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
context "when private" do
it { is_expected.to eq "<span class=\"badge badge-danger\">Private</span>" }
end

# solr document can have no visibility indexed
it "does not fail when nil is passed" do
badge = described_class.new(nil)

expect(badge.render).to eq "<span class=\"badge badge-info\">Unknown</span>"
end
end
end

Expand Down

0 comments on commit 4f8b5de

Please sign in to comment.