Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #914
- Loading branch information
Showing
12 changed files
with
228 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module CurationConcerns | ||
class AdminSetIndexer < ActiveFedora::IndexingService | ||
include IndexesThumbnails | ||
|
||
def generate_solr_document | ||
super.tap do |solr_doc| | ||
# Makes Admin Sets show under the "Admin Sets" tab | ||
Solrizer.set_field(solr_doc, 'generic_type', 'Admin Set', :facetable) | ||
solr_doc['thumbnail_path_ss'] = thumbnail_path | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class AdminSet < ActiveFedora::Base | ||
include CurationConcerns::AdminSetBehavior | ||
end |
29 changes: 29 additions & 0 deletions
29
app/models/concerns/curation_concerns/admin_set_behavior.rb
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,29 @@ | ||
module CurationConcerns | ||
module AdminSetBehavior | ||
extend ActiveSupport::Concern | ||
|
||
include Hydra::AccessControls::WithAccessRight | ||
include CurationConcerns::Noid | ||
include CurationConcerns::HumanReadableType | ||
include CurationConcerns::HasRepresentative | ||
|
||
included do | ||
validates_with HasOneTitleValidator | ||
class_attribute :human_readable_short_description, :indexer | ||
self.indexer = CurationConcerns::AdminSetIndexer | ||
property :title, predicate: ::RDF::Vocab::DC.title do |index| | ||
index.as :stored_searchable, :facetable | ||
end | ||
property :description, predicate: ::RDF::Vocab::DC.description do |index| | ||
index.as :stored_searchable | ||
end | ||
has_many :members, | ||
predicate: ::RDF::Vocab::DC.isPartOf, | ||
class_name: 'ActiveFedora::Base' | ||
end | ||
|
||
def to_s | ||
title.present? ? title : 'No Title' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module CurationConcerns | ||
module InAdminSet | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
belongs_to :admin_set, predicate: ::RDF::Vocab::DC.isPartOf | ||
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
8 changes: 8 additions & 0 deletions
8
app/search_builders/curation_concerns/admin_set_search_builder.rb
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,8 @@ | ||
module CurationConcerns | ||
class AdminSetSearchBuilder < ::SearchBuilder | ||
# This overrides the filter_models in FilterByType | ||
def filter_models(solr_parameters) | ||
solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::AdminSet.to_class_uri) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module CurationConcerns | ||
class AdminSetService | ||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def select_options | ||
search_results.map do |element| | ||
[element.to_s, element.id] | ||
end | ||
end | ||
|
||
def blacklight_config | ||
::CatalogController.blacklight_config | ||
end | ||
|
||
def current_ability | ||
::Ability.new(@user) | ||
end | ||
|
||
private | ||
|
||
def search_results | ||
builder = AdminSetSearchBuilder.new(self) | ||
response = repository.search(builder) | ||
response.documents | ||
end | ||
|
||
def repository | ||
::CatalogController.new.repository | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper' | ||
require 'cancan/matchers' | ||
|
||
describe 'User Abilities' do | ||
subject { ability } | ||
let(:ability) { Ability.new(current_user) } | ||
let(:user) { create(:user) } | ||
let(:current_user) { user } | ||
let(:admin_set) { create(:admin_set, edit_users: [user]) } | ||
|
||
it "allows the edit_users to edit and read" do | ||
is_expected.to be_able_to(:read, admin_set) | ||
is_expected.to be_able_to(:edit, admin_set) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FactoryGirl.define do | ||
factory :admin_set do | ||
title ['Test admin set title'] | ||
|
||
trait :public do | ||
read_groups ['public'] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe AdminSet, type: :model do | ||
let(:gf1) { create(:generic_work, user: user) } | ||
let(:gf2) { create(:generic_work, user: user) } | ||
let(:gf3) { create(:generic_work, user: user) } | ||
|
||
let(:user) { create(:user) } | ||
|
||
before do | ||
subject.title = ['Some title'] | ||
end | ||
|
||
describe "#to_solr" do | ||
let(:admin_set) { build(:admin_set, title: ['A good title']) } | ||
let(:solr_document) { admin_set.to_solr } | ||
|
||
it "has title information" do | ||
expect(solr_document).to include 'title_tesim' => ['A good title'], | ||
'title_sim' => ['A good title'] | ||
end | ||
end | ||
|
||
describe "#members" do | ||
it "is empty by default" do | ||
expect(subject.members).to be_empty | ||
end | ||
|
||
context "adding members" do | ||
context "using assignment" do | ||
subject { described_class.create!(title: ['Some title'], members: [gf1, gf2]) } | ||
|
||
it "has many files" do | ||
expect(subject.reload.members).to match_array [gf1, gf2] | ||
end | ||
end | ||
|
||
context "using append" do | ||
before do | ||
subject.members = [gf1] | ||
subject.save | ||
end | ||
it "allows new files to be added" do | ||
subject.reload | ||
subject.members << gf2 | ||
subject.save | ||
expect(subject.reload.members).to match_array [gf1, gf2] | ||
end | ||
end | ||
end | ||
end | ||
|
||
it "has a title" do | ||
subject.title = ["title"] | ||
subject.save | ||
expect(subject.reload.title).to eq ["title"] | ||
end | ||
|
||
it "has a description" do | ||
subject.title = ["title"] | ||
subject.description = ["description"] | ||
subject.save | ||
expect(subject.reload.description).to eq ["description"] | ||
end | ||
|
||
describe "#destroy" do | ||
before do | ||
subject.members = [gf1, gf2] | ||
subject.save | ||
subject.destroy | ||
end | ||
|
||
it "does not delete member files when deleted" do | ||
expect(GenericWork.exists?(gf1.id)).to be true | ||
expect(GenericWork.exists?(gf2.id)).to be true | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
spec/search_builders/curation_concerns/admin_set_search_builder_spec.rb
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,17 @@ | ||
require 'spec_helper' | ||
|
||
describe CurationConcerns::AdminSetSearchBuilder do | ||
let(:processor_chain) { [:filter_models] } | ||
let(:context) { double('context') } | ||
let(:user) { double('user') } | ||
let(:solr_params) { { fq: [] } } | ||
|
||
subject { described_class.new(context) } | ||
describe '#filter_models' do | ||
before { subject.filter_models(solr_params) } | ||
|
||
it 'adds AdminSet to query' do | ||
expect(solr_params[:fq].first).to include('{!field f=has_model_ssim}AdminSet') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CurationConcerns::AdminSetService do | ||
describe ".select_options" do | ||
let(:service) { described_class.new(user) } | ||
let(:user) { create(:user) } | ||
let!(:as1) { create(:admin_set, :public, title: ['foo']) } | ||
let!(:as2) { create(:admin_set, :public, title: ['bar']) } | ||
subject { service.select_options } | ||
it { is_expected.to eq [['foo', as1.id], | ||
['bar', as2.id]] } | ||
end | ||
end |