Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Sep 21, 2016
1 parent 4085914 commit f85cf0e
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 79 deletions.
Expand Up @@ -10,12 +10,16 @@ module AdminControllerBehavior
before_action :load_configuration
layout "admin"
copy_blacklight_config_from ::CatalogController
configure_blacklight do |config|
config.view.aggregate.partials = [:aggregate_information]
end
def index
render "index"
end

def search
(@response, @document_list) = search_results(params)
@search_builder = search_builder.with(params)

respond_to do |format|
format.html do
Expand All @@ -30,8 +34,11 @@ def search
def _prefixes
@_prefixes ||= super + ['catalog/']
end
end

def search_action_url(options = {})
admin_catalog_url(options.except(:controller, :action))
end
end

private

Expand Down
118 changes: 67 additions & 51 deletions app/sources/curation_concerns/resource_statistics_source.rb
@@ -1,67 +1,83 @@
module CurationConcerns
class ResourceStatisticsSource
class << self
def open_concerns_count
# TODO: verify that this is not pulling all records and then counting
relation.where(Hydra.config.permissions.read.group => 'public').count
end

def authenticated_concerns_count
relation.where(Hydra.config.permissions.read.group => 'registered').count
end
attr_accessor :search_builder, :repository
def initialize(search_builder: nil, repository: nil)
@search_builder = search_builder || ::CatalogController.new.search_builder
@repository = repository || ::CatalogController.new.repository
# Remove gated discovery.
@search_builder = self.search_builder.except(:add_access_controls_to_solr_params)
solr_arguments[:fq] ||= []
solr_arguments[:rows] = 0
end

def restricted_concerns_count
# TODO: Replace this with a query that that returns all documents that
# either lack the `read_access_group_ssim` key, or have the key
# without the values of `public` or `registered`
relation.count - (authenticated_concerns_count + open_concerns_count)
end
def open_concerns_count
search_with_query("#{Hydra.config.permissions.read.group}:public")
end

def expired_embargo_now_authenticated_concerns_count
relation.where(Hydra.config.permissions.read.group => 'registered').where("embargo_history_ssim:*").count
end
def authenticated_concerns_count
search_with_query("#{Hydra.config.permissions.read.group}:registered")
end

def expired_embargo_now_open_concerns_count
relation.where(Hydra.config.permissions.read.group => 'public').where("embargo_history_ssim:*").count
end
def restricted_concerns_count
# TODO: Replace this with a query that that returns all documents that
# either lack the `read_access_group_ssim` key, or have the key
# without the values of `public` or `registered`
repository.search(solr_arguments)["response"]["numFound"] - (authenticated_concerns_count + open_concerns_count)
end

def active_embargo_now_authenticated_concerns_count
relation.where(Hydra.config.permissions.read.group => 'registered').where("embargo_release_date_dtsi:[NOW TO *]").count
end
def expired_embargo_now_authenticated_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:registered", "embargo_history_ssim:*"])
end

def active_embargo_now_restricted_concerns_count
# TODO: Replace the subtraction with another `#where` query that returns
# all actively embargoed documents that either lack the
# `read_access_group_ssim` key, or have the key without the values
# of `public` or `registered`
relation.where("embargo_release_date_dtsi:[NOW TO *]").count - active_embargo_now_authenticated_concerns_count
end
def expired_embargo_now_open_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:public", "embargo_history_ssim:*"])
end

def expired_lease_now_authenticated_concerns_count
relation.where(Hydra.config.permissions.read.group => 'registered').where("lease_history_ssim:*").count
end
def active_embargo_now_authenticated_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:registered", "embargo_release_date_dtsi:[NOW TO *]"])
end

def expired_lease_now_restricted_concerns_count
# TODO: Replace the subtraction with another `#where` query that returns
# all expired lease documents that either lack the
# `read_access_group_ssim` key, or have the key without the values
# of `public` or `registered`
relation.where("lease_history_ssim:*").count - expired_lease_now_authenticated_concerns_count
end
def active_embargo_now_restricted_concerns_count
# TODO: Replace the subtraction with another `#where` query that returns
# all actively embargoed documents that either lack the
# `read_access_group_ssim` key, or have the key without the values
# of `public` or `registered`
all_expired_embargos = search_with_query("embargo_release_date_dtsi:[NOW TO *]")
all_expired_embargos - active_embargo_now_authenticated_concerns_count
end

def active_lease_now_authenticated_concerns_count
relation.where(Hydra.config.permissions.read.group => 'registered').where("lease_expiration_date_dtsi:[NOW TO *]").count
end
def expired_lease_now_authenticated_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:registered", "lease_history_ssim:*"])
end

def active_lease_now_open_concerns_count
relation.where(Hydra.config.permissions.read.group => 'public').where("lease_expiration_date_dtsi:[NOW TO *]").count
end
def expired_lease_now_restricted_concerns_count
# TODO: Replace the subtraction with another `#where` query that returns
# all expired lease documents that either lack the
# `read_access_group_ssim` key, or have the key without the values
# of `public` or `registered`
all_leased_documents = search_with_query("lease_history_ssim:*")
all_leased_documents - expired_lease_now_authenticated_concerns_count
end

private
def active_lease_now_authenticated_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:registered", "lease_expiration_date_dtsi:[NOW TO *]"])
end

def relation
CurationConcerns::WorkRelation.new
end
def active_lease_now_open_concerns_count
search_with_query(["#{Hydra.config.permissions.read.group}:public", "lease_expiration_date_dtsi:[NOW TO *]"])
end

private

def solr_arguments
@solr_arguments ||= search_builder.to_h
end

def search_with_query(query)
q = { fq: Array.wrap(query) }
repository.search(solr_arguments.merge(q) do |_key, v1, v2|
v1 + v2
end)["response"]["numFound"]
end
end
end
@@ -0,0 +1,5 @@
Aggregate Information:

<% resource_stats = @configuration[:data_sources][:resource_stats] %>
<% resource_stats = resource_stats.new(search_builder: @search_builder) %>
<%= render "resource_stats", resource_stats: resource_stats %>
14 changes: 14 additions & 0 deletions app/views/curation_concerns/admin/_resource_stats.html.erb
@@ -0,0 +1,14 @@
<h4>Totals by Visibility</h4>
<ul>
<li><%= t("curation_concerns.visibility.open.text") %> <span class="count">(<%= resource_stats.open_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.authenticated.text") %> <span class="count">(<%= resource_stats.authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.restricted.text") %> <span class="count">(<%= resource_stats.restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.expired.authenticated.text") %> <span class="count">(<%= resource_stats.expired_embargo_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.expired.open.text") %> <span class="count">(<%= resource_stats.expired_embargo_now_open_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.active.authenticated.text") %> <span class="count">(<%= resource_stats.active_embargo_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.active.restricted.text") %> <span class="count">(<%= resource_stats.active_embargo_now_restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.expired.restricted.text") %> <span class="count">(<%= resource_stats.expired_lease_now_restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.expired.authenticated.text") %> <span class="count">(<%= resource_stats.expired_lease_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.active.authenticated.text") %> <span class="count">(<%= resource_stats.active_lease_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.active.open.text") %> <span class="count">(<%= resource_stats.active_lease_now_open_concerns_count %>)</span></li>
</ul>
17 changes: 2 additions & 15 deletions app/views/curation_concerns/admin/_total_objects.html.erb
@@ -1,15 +1,2 @@
<% resource_stats = @configuration[:data_sources][:resource_stats] %>
<h4>Totals by Visibility</h4>
<ul>
<li><%= t("curation_concerns.visibility.open.text") %> <span class="count">(<%= resource_stats.open_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.authenticated.text") %> <span class="count">(<%= resource_stats.authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.restricted.text") %> <span class="count">(<%= resource_stats.restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.expired.authenticated.text") %> <span class="count">(<%= resource_stats.expired_embargo_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.expired.open.text") %> <span class="count">(<%= resource_stats.expired_embargo_now_open_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.active.authenticated.text") %> <span class="count">(<%= resource_stats.active_embargo_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.embargo.active.restricted.text") %> <span class="count">(<%= resource_stats.active_embargo_now_restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.expired.restricted.text") %> <span class="count">(<%= resource_stats.expired_lease_now_restricted_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.expired.authenticated.text") %> <span class="count">(<%= resource_stats.expired_lease_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.active.authenticated.text") %> <span class="count">(<%= resource_stats.active_lease_now_authenticated_concerns_count %>)</span></li>
<li><%= t("curation_concerns.visibility.lease.active.open.text") %> <span class="count">(<%= resource_stats.active_lease_now_open_concerns_count %>)</span></li>
</ul>
<% resource_stats = @configuration[:data_sources][:resource_stats].new %>
<%= render "resource_stats", resource_stats: resource_stats %>
38 changes: 26 additions & 12 deletions spec/sources/curation_concerns/resource_statistics_source_spec.rb
@@ -1,17 +1,31 @@
require 'spec_helper'

describe CurationConcerns::ResourceStatisticsSource do
subject { described_class.new }
context "when given a scoped query" do
it "only returns stats for those values" do
create :public_generic_work, creator: ["Test"]
create :public_generic_work, creator: ["Alfred"]
search_builder = CurationConcerns::AdminController.new.search_builder.except(:add_access_controls_to_solr_params)

expect(subject.open_concerns_count).to eq 2
search_builder = search_builder.with(f: { creator_sim: ["Test"] }, fq: { test_sim: [1] })

expect(described_class.new(search_builder: search_builder).open_concerns_count).to eq 1
end
end
describe "#open_concerns_count" do
it "returns the number of open concerns" do
expect(described_class.open_concerns_count).to eq(0)
create :private_generic_work
expect(subject.open_concerns_count).to eq(0)
end

context "when I have concerns" do
before do
create :public_generic_work
end
it "returns the number of open concerns" do
expect(described_class.open_concerns_count).to eq(1)
expect(subject.open_concerns_count).to eq(1)
end
end
end
Expand All @@ -22,7 +36,7 @@
create :authenticated_generic_work
end
it "returns the number of open concerns" do
expect(described_class.authenticated_concerns_count).to eq(1)
expect(subject.authenticated_concerns_count).to eq(1)
end
end
end
Expand All @@ -33,7 +47,7 @@
create :generic_work
end
it "returns the number of open concerns" do
expect(described_class.restricted_concerns_count).to eq(1)
expect(subject.restricted_concerns_count).to eq(1)
end
end
end
Expand All @@ -51,7 +65,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
it "returns the number of embargo concerns" do
expect(described_class.active_embargo_now_authenticated_concerns_count).to eq(1)
expect(subject.active_embargo_now_authenticated_concerns_count).to eq(1)
end
end

Expand All @@ -60,7 +74,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
it "returns the number of embargo concerns" do
expect(described_class.active_embargo_now_restricted_concerns_count).to eq(1)
expect(subject.active_embargo_now_restricted_concerns_count).to eq(1)
end
end

Expand All @@ -69,7 +83,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
it "returns the number of embargo concerns" do
expect(described_class.expired_embargo_now_authenticated_concerns_count).to eq(1)
expect(subject.expired_embargo_now_authenticated_concerns_count).to eq(1)
end
end

Expand All @@ -78,7 +92,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
it "returns the number of embargo concerns" do
expect(described_class.expired_embargo_now_open_concerns_count).to eq(1)
expect(subject.expired_embargo_now_open_concerns_count).to eq(1)
end
end
end
Expand All @@ -96,7 +110,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
it "returns the number of lease concerns" do
expect(described_class.active_lease_now_authenticated_concerns_count).to eq(1)
expect(subject.active_lease_now_authenticated_concerns_count).to eq(1)
end
end

Expand All @@ -105,7 +119,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
it "returns the number of lease concerns" do
expect(described_class.active_lease_now_open_concerns_count).to eq(1)
expect(subject.active_lease_now_open_concerns_count).to eq(1)
end
end

Expand All @@ -114,7 +128,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
it "returns the number of lease concerns" do
expect(described_class.expired_lease_now_authenticated_concerns_count).to eq(1)
expect(subject.expired_lease_now_authenticated_concerns_count).to eq(1)
end
end

Expand All @@ -123,7 +137,7 @@
let(:current_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
let(:future_state) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
it "returns the number of lease concerns" do
expect(described_class.expired_lease_now_restricted_concerns_count).to eq(1)
expect(subject.expired_lease_now_restricted_concerns_count).to eq(1)
end
end
end
Expand Down

0 comments on commit f85cf0e

Please sign in to comment.