Skip to content

Commit

Permalink
Merge pull request #436 from samvera/backports_for_10.5.1
Browse files Browse the repository at this point in the history
Backports for 10.5.1
  • Loading branch information
cjcolvar authored Apr 6, 2018
2 parents 908aea2 + 196dc0b commit 1a0d0ee
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 121 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
language: ruby
sudo: false
rvm: 2.4.1
rvm: 2.4.2

matrix:
include:
- rvm: 2.3.4
env: "BLACKLIGHT_VERSION=5.17.2"
- env: "RAILS_VERION=5.1.4"
- rvm: 2.3.5
env: "BLACKLIGHT_VERSION=5.17.2 RAILS_VERSION=5.0.6"

env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- RAILS_VERSION=5.0.2
- BLACKLIGHT_VERSION=6.9.0
- BLACKLIGHT_VERSION=6.12.0
before_install:
- gem update --system

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Contributors to this project:
* Graeme West
* Jeremy Friesen
* Jessie Keck
* Joe Atzberger
* John Scofield
* Joseph Gilbert
* Justin Coyne
Expand Down
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
# Hydra-Head

[![Build Status](https://travis-ci.org/projecthydra/hydra-head.png?branch=master)](https://travis-ci.org/projecthydra/hydra-head)
[![Build Status](https://travis-ci.org/samvera/hydra-head.png?branch=master)](https://travis-ci.org/samvera/hydra-head)
[![Version](https://badge.fury.io/rb/hydra-head.png)](http://badge.fury.io/rb/hydra-head)
[![Dependencies](https://gemnasium.com/projecthydra/hydra-head.png)](https://gemnasium.com/projecthydra/hydra-head)
[![Coverage Status](https://img.shields.io/coveralls/projecthydra/hydra-head.svg)](https://coveralls.io/r/projecthydra/hydra-head)
[![Dependencies](https://gemnasium.com/samvera/hydra-head.png)](https://gemnasium.com/samvera/hydra-head)
[![Coverage Status](https://img.shields.io/coveralls/samvera/hydra-head.svg)](https://coveralls.io/r/samvera/hydra-head)

Hydra-Head is a Ruby-on-Rails gem containing the core code for a web
application using the full stack of hydra building blocks.
application using the full stack of Samvera building blocks.

See the Github wikis for information targeted to developers:
<http://github.com/projecthydra/hydra-head/wiki>
<http://github.com/samvera/hydra-head/wiki>

See the Duraspace Hydra wikis for information at the architecture level:
<http://wiki.duraspace.org/display/hydra/>
<http://wiki.duraspace.org/display/samvera/>

Additionally, new adopters and potential adopters may find the pages
here useful: <http://projecthydra.org/>
here useful: <http://samvera.org/>

If you are new to Hydra and looking to start a new Hydra head with a set
of components that have been tested for compatibility, and for which
there will be a documented upgrade path to the next versions, we
recommend you use the Hydra gem: https://github.com/projecthydra/hydra
recommend you use the Hydra gem: https://github.com/samvera/hydra

Further questions? Ask the [hydra-tech
list](http://groups.google.com/group/hydra-tech) or join the freenode
\#projecthydra IRC channel.
Further questions? [Get in touch](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391)

## Installation/Setup

This process is covered step-by-step in the [Tutorial: Dive Into
Hydra](https://github.com/projecthydra/hydra/wiki/Dive-into-Hydra)
Hydra](https://github.com/samvera/hydra/wiki/Dive-into-Hydra)

### Installation Prerequisites

See the [Installation Prerequisites](http://github.com/projecthydra/hydra-head/wiki/Installation-Prerequisites) wiki page.
See the [Installation Prerequisites](http://github.com/samvera/hydra-head/wiki/Installation-Prerequisites) wiki page.

Ruby 1.9.3+ is required by Hydra-Head release 6+; RVM is strongly suggested.
Ruby 2.1.0+ is required by Hydra-Head release 10+; RVM is strongly suggested.

### Install Rails

gem install 'rails' --version '~>4.0.0'
gem install 'rails' --version '~>5.1.0'

### Generate a new rails application:

Expand Down Expand Up @@ -82,16 +80,16 @@ Run the database migrations
Congratulations. You've set up the code for your Hydra Head.

Read [Tools for Developing and Testing your
Application](http://github.com/projecthydra/hydra-head/wiki/Tools-for-Developing-and-Testing-your-Application),
Application](http://github.com/samvera/hydra-head/wiki/Tools-for-Developing-and-Testing-your-Application),
then read [How to Get
Started](http://github.com/projecthydra/hydra-head/wiki/How-to-Get-Started)
Started](http://github.com/samvera/hydra-head/wiki/How-to-Get-Started)
to get a sense of what you can do with your Hydra Head.

## Modifying and Testing the hydra-head Gem

For those developers who want to or need to work on the hydra-head gem
itself, see the [Instructions for
Contributors](http://github.com/projecthydra/hydra-head/wiki/For-Contributors)
Contributors](http://github.com/samvera/hydra-head/wiki/For-Contributors)

## Acknowledgments

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# Repeats access controls evaluation methods, but checks against a governing "Policy" object (or "Collection" object) that provides inherited access controls.
module Hydra::PolicyAwareAccessControlsEnforcement

# Extends Hydra::AccessControlsEnforcement.apply_gated_discovery to reflect policy-provided access
# appends the result of policy_clauses into the :fq
# @param solr_parameters the current solr parameters
# @param user_parameters the current user-subitted parameters
# Extends Hydra::AccessControlsEnforcement.apply_gated_discovery to reflect policy-provided access.
# Appends the result of policy_clauses into the :fq
# @param [Hash] solr_parameters the current solr parameters, to be modified herein!
def apply_gated_discovery(solr_parameters)
super
logger.debug("POLICY-aware Solr parameters: #{ solr_parameters.inspect }")
end

# returns solr query for finding all objects whose policies grant discover access to current_user
# @return [String,nil] solr query for finding all objects whose policies grant discover access to current_user
def policy_clauses
policy_ids = policies_with_access
return nil if policy_ids.empty?
'(' + policy_ids.map {|id| ActiveFedora::SolrQueryBuilder.construct_query_for_rel(isGovernedBy: id)}.join(' OR '.freeze) + ')'
end

# find all the policies that grant discover/read/edit permissions to this user or any of its groups
# Find all the policies that grant discover/read/edit permissions to this user or any of its groups.
# Grant access based on user id & group
def policies_with_access
#### TODO -- Memoize this and put it in the session?
user_access_filters = []
# Grant access based on user id & group
user_access_filters += apply_policy_group_permissions(discovery_permissions)
user_access_filters += apply_policy_user_permissions(discovery_permissions)
result = policy_class.search_with_conditions( user_access_filters.join(" OR "), fl: "id", rows: policy_class.count )
logger.debug "get policies: #{result}\n\n"
result.map {|h| h['id']}
end

# for groups
# @param [Array{String,#to_sym}] permission_types symbols (or equivalent) from Hydra.config.permissions.inheritable
def apply_policy_group_permissions(permission_types = discovery_permissions)
# for groups
user_access_filters = []
current_ability.user_groups.each_with_index do |group, i|
permission_types.each do |type|
Expand All @@ -40,8 +40,9 @@ def apply_policy_group_permissions(permission_types = discovery_permissions)
user_access_filters
end

# for individual user access
# @param [Array{String,#to_sym}] permission_types
def apply_policy_user_permissions(permission_types = discovery_permissions)
# for individual user access
user = current_ability.current_user
return [] unless user && user.user_key.present?
permission_types.map do |type|
Expand Down
2 changes: 1 addition & 1 deletion hydra-access-controls/spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do

# Users

Expand Down
8 changes: 4 additions & 4 deletions hydra-access-controls/spec/services/embargo_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
let(:past_date) { 2.days.ago }

let!(:work_with_expired_embargo1) do
FactoryGirl.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
FactoryBot.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
work.save(validate:false)
end
end

let!(:work_with_expired_embargo2) do
FactoryGirl.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
FactoryBot.build(:asset, embargo_release_date: past_date.to_s).tap do |work|
work.save(validate:false)
end
end

let!(:work_with_embargo_in_effect) { FactoryGirl.create(:asset, embargo_release_date: future_date.to_s)}
let!(:work_without_embargo) { FactoryGirl.create(:asset)}
let!(:work_with_embargo_in_effect) { FactoryBot.create(:asset, embargo_release_date: future_date.to_s)}
let!(:work_without_embargo) { FactoryBot.create(:asset)}

describe "#assets_with_expired_embargoes" do
it "returns an array of assets with expired embargoes" do
Expand Down
8 changes: 4 additions & 4 deletions hydra-access-controls/spec/services/lease_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
let(:past_date) { 2.days.ago }

let!(:work_with_expired_lease1) do
FactoryGirl.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
FactoryBot.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
work.save(validate: false)
end
end

let!(:work_with_expired_lease2) do
FactoryGirl.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
FactoryBot.build(:asset, lease_expiration_date: past_date.to_s).tap do |work|
work.save(validate: false)
end
end

let!(:work_with_lease_in_effect) { FactoryGirl.create(:asset, lease_expiration_date: future_date.to_s)}
let!(:work_without_lease) { FactoryGirl.create(:asset)}
let!(:work_with_lease_in_effect) { FactoryBot.create(:asset, lease_expiration_date: future_date.to_s)}
let!(:work_without_lease) { FactoryBot.create(:asset)}

describe "#assets_with_expired_leases" do
it "returns an array of assets with expired embargoes" do
Expand Down
2 changes: 1 addition & 1 deletion hydra-access-controls/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
require 'support/mods_asset'
require 'support/solr_document'
require "support/user"
require "factory_girl"
require "factory_bot"
require 'rspec/mocks'
require 'rspec/its'
require "factories"
Expand Down
Loading

0 comments on commit 1a0d0ee

Please sign in to comment.