Skip to content

Commit

Permalink
Expand test and add clause so that new works can assign other visibil…
Browse files Browse the repository at this point in the history
…ities if specified
  • Loading branch information
bbpennel committed Oct 26, 2023
1 parent cc833f5 commit f177411
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Hydra::AccessControls::Visibility.module_eval do
alias_method :original_visibility, :visibility
def visibility
# [hyc-override] Default to the most permissive visibility for new records
return Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC if self.new_record?
# [hyc-override] Default to the most permissive visibility for new records if no read groups are specified
return Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC if new_record? && read_groups.blank?
original_visibility
end
end
37 changes: 33 additions & 4 deletions spec/models/hydra/access_controls/visibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@
context 'with a new article' do
let(:article) { Article.new }

it 'has default public visibility' do
it 'has default open visibility' do
expect(article.visibility).to eq 'open'
end
end

context 'with an existing article with no defined read groups' do
context 'with a new article with registered group' do
let(:article) { Article.new(read_groups: ['registered']) }

it 'has authenticated visibility' do
expect(article.visibility).to eq 'authenticated'
end
end

context 'with a new article with private group' do
let(:article) { Article.new(read_groups: ['private']) }

it 'has restricted visibility' do
expect(article.visibility).to eq 'restricted'
end
end

context 'with an existing article with empty read groups' do
let(:article) do
FactoryBot.create(
:article,
Expand All @@ -35,6 +51,19 @@
it 'has authenticated visibility' do
expect(article.visibility).to eq 'authenticated'
end
end
end

context 'with an existing article with public read group' do
let(:article) do
FactoryBot.create(
:article,
read_groups: ['public']
)
end

it 'has open visibility' do
expect(article.visibility).to eq 'open'
end
end
end
end
end

0 comments on commit f177411

Please sign in to comment.