valkyrie 0.1.0 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ctags +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +3 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +0 -4
- data/LICENSE +15 -0
- data/README.md +13 -8
- data/Rakefile +15 -1
- data/bin/jetty_wait +14 -0
- data/bin/rspec +29 -0
- data/browserslist +3 -0
- data/circle.yml +17 -0
- data/config/fedora.yml +10 -0
- data/db/migrate/20161007101725_create_orm_resources.rb +9 -1
- data/db/migrate/20171011224121_create_path_gin_index.rb +6 -0
- data/db/migrate/20171204224121_create_internal_resource_index.rb +6 -0
- data/db/migrate/20180212092225_create_updated_at_index.rb +6 -0
- data/lib/generators/valkyrie/templates/resource_spec.rb.erb +1 -1
- data/lib/valkyrie.rb +1 -7
- data/lib/valkyrie/change_set.rb +21 -7
- data/lib/valkyrie/engine.rb +2 -0
- data/lib/valkyrie/id.rb +1 -0
- data/lib/valkyrie/indexers/access_controls_indexer.rb +50 -6
- data/lib/valkyrie/metadata_adapter.rb +29 -1
- data/lib/valkyrie/persistence.rb +27 -0
- data/lib/valkyrie/persistence/buffered_persister.rb +17 -1
- data/lib/valkyrie/persistence/composite_persister.rb +14 -2
- data/lib/valkyrie/persistence/custom_query_container.rb +63 -0
- data/lib/valkyrie/persistence/delete_tracking_buffer.rb +8 -0
- data/lib/valkyrie/persistence/fedora.rb +3 -0
- data/lib/valkyrie/persistence/fedora/list_node.rb +5 -2
- data/lib/valkyrie/persistence/fedora/metadata_adapter.rb +13 -11
- data/lib/valkyrie/persistence/fedora/ordered_list.rb +2 -2
- data/lib/valkyrie/persistence/fedora/ordered_reader.rb +3 -2
- data/lib/valkyrie/persistence/fedora/permissive_schema.rb +75 -0
- data/lib/valkyrie/persistence/fedora/persister.rb +22 -0
- data/lib/valkyrie/persistence/fedora/persister/model_converter.rb +110 -25
- data/lib/valkyrie/persistence/fedora/persister/orm_converter.rb +49 -17
- data/lib/valkyrie/persistence/fedora/persister/resource_factory.rb +2 -0
- data/lib/valkyrie/persistence/fedora/query_service.rb +46 -3
- data/lib/valkyrie/persistence/memory.rb +5 -0
- data/lib/valkyrie/persistence/memory/metadata_adapter.rb +6 -1
- data/lib/valkyrie/persistence/memory/persister.rb +19 -1
- data/lib/valkyrie/persistence/memory/query_service.rb +49 -8
- data/lib/valkyrie/persistence/postgres.rb +2 -0
- data/lib/valkyrie/persistence/postgres/metadata_adapter.rb +8 -1
- data/lib/valkyrie/persistence/postgres/orm.rb +1 -0
- data/lib/valkyrie/persistence/postgres/orm/resource.rb +12 -0
- data/lib/valkyrie/persistence/postgres/orm_converter.rb +99 -74
- data/lib/valkyrie/persistence/postgres/persister.rb +16 -0
- data/lib/valkyrie/persistence/postgres/query_service.rb +94 -6
- data/lib/valkyrie/persistence/postgres/resource_converter.rb +3 -1
- data/lib/valkyrie/persistence/postgres/resource_factory.rb +5 -5
- data/lib/valkyrie/persistence/solr.rb +2 -0
- data/lib/valkyrie/persistence/solr/composite_indexer.rb +29 -0
- data/lib/valkyrie/persistence/solr/metadata_adapter.rb +26 -1
- data/lib/valkyrie/persistence/solr/model_converter.rb +38 -8
- data/lib/valkyrie/persistence/solr/orm_converter.rb +43 -20
- data/lib/valkyrie/persistence/solr/persister.rb +16 -0
- data/lib/valkyrie/persistence/solr/queries.rb +3 -0
- data/lib/valkyrie/persistence/solr/queries/default_paginator.rb +2 -0
- data/lib/valkyrie/persistence/solr/queries/find_all_query.rb +3 -1
- data/lib/valkyrie/persistence/solr/queries/find_by_id_query.rb +4 -2
- data/lib/valkyrie/persistence/solr/queries/find_inverse_references_query.rb +2 -0
- data/lib/valkyrie/persistence/solr/queries/find_many_by_ids_query.rb +21 -0
- data/lib/valkyrie/persistence/solr/queries/find_members_query.rb +13 -5
- data/lib/valkyrie/persistence/solr/queries/find_references_query.rb +7 -3
- data/lib/valkyrie/persistence/solr/query_service.rb +30 -2
- data/lib/valkyrie/persistence/solr/repository.rb +14 -2
- data/lib/valkyrie/persistence/solr/resource_factory.rb +3 -1
- data/lib/valkyrie/resource.rb +11 -4
- data/lib/valkyrie/resource/access_controls.rb +13 -0
- data/lib/valkyrie/specs/shared_specs.rb +1 -2
- data/lib/valkyrie/specs/shared_specs/change_set.rb +75 -0
- data/lib/valkyrie/specs/shared_specs/metadata_adapter.rb +3 -0
- data/lib/valkyrie/specs/shared_specs/persister.rb +145 -15
- data/lib/valkyrie/specs/shared_specs/queries.rb +153 -27
- data/lib/valkyrie/specs/shared_specs/storage_adapter.rb +8 -3
- data/lib/valkyrie/storage.rb +29 -0
- data/lib/valkyrie/storage/disk.rb +17 -5
- data/lib/valkyrie/storage/fedora.rb +14 -1
- data/lib/valkyrie/storage/memory.rb +15 -2
- data/lib/valkyrie/storage_adapter.rb +26 -4
- data/lib/valkyrie/types.rb +65 -7
- data/lib/valkyrie/version.rb +1 -1
- data/solr/config/_rest_managed.json +3 -0
- data/solr/config/admin-extra.html +31 -0
- data/solr/config/elevate.xml +36 -0
- data/solr/config/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/config/protwords.txt +21 -0
- data/solr/config/schema.xml +366 -0
- data/solr/config/scripts.conf +24 -0
- data/solr/config/solrconfig.xml +322 -0
- data/solr/config/spellings.txt +2 -0
- data/solr/config/stopwords.txt +58 -0
- data/solr/config/stopwords_en.txt +58 -0
- data/solr/config/synonyms.txt +31 -0
- data/solr/config/xslt/example.xsl +132 -0
- data/solr/config/xslt/example_atom.xsl +67 -0
- data/solr/config/xslt/example_rss.xsl +66 -0
- data/solr/config/xslt/luke.xsl +337 -0
- data/solr/solr.xml +35 -0
- data/tasks/dev.rake +66 -0
- data/valkyrie.gemspec +6 -6
- metadata +58 -63
- data/lib/valkyrie/decorators/decorator_list.rb +0 -15
- data/lib/valkyrie/decorators/decorator_with_arguments.rb +0 -14
- data/lib/valkyrie/derivative_service.rb +0 -42
- data/lib/valkyrie/file_characterization_service.rb +0 -42
- data/lib/valkyrie/local_file_service.rb +0 -11
- data/lib/valkyrie/persist_derivatives.rb +0 -29
- data/lib/valkyrie/persistence/postgres/queries.rb +0 -8
- data/lib/valkyrie/persistence/postgres/queries/find_inverse_references_query.rb +0 -31
- data/lib/valkyrie/persistence/postgres/queries/find_members_query.rb +0 -33
- data/lib/valkyrie/persistence/postgres/queries/find_references_query.rb +0 -33
- data/lib/valkyrie/specs/shared_specs/derivative_service.rb +0 -30
- data/lib/valkyrie/specs/shared_specs/file_characterization_service.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0bdf173346aa41d564f214c4e453e047a730ec7775edd7c7a0167e38fa2cd4e4
|
4
|
+
data.tar.gz: aef0b3c204da30a6241b3b217fea821504b806eb10e50ae8d3ad2d5547d0d19d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8610d09ec9088a811f80e84ad53eaa583f76bc28304266870e349ec940306871455885153cfd01ac5dce62e1bc36dbce7119ba719576da6bc86bab664e9a14a
|
7
|
+
data.tar.gz: 588b9c6d0bb1a94103a1b6c256b94cf1b26309602a984ad8094a438f7bb33a01802e3bc5602d2259c4a08b8b82430492517b1dcc2fa3d5e71ffe142cfb99c6af
|
data/.ctags
ADDED
data/.rubocop.yml
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
1
3
|
inherit_gem:
|
2
4
|
bixby: bixby_default.yml
|
3
5
|
AllCops:
|
@@ -13,6 +15,7 @@ Metrics/BlockLength:
|
|
13
15
|
Exclude:
|
14
16
|
- 'spec/**/*'
|
15
17
|
- 'lib/valkyrie/specs/**/*'
|
18
|
+
- 'tasks/**/*'
|
16
19
|
- 'db/schema.rb'
|
17
20
|
- 'Rakefile'
|
18
21
|
- '*.gemspec'
|
@@ -26,3 +29,5 @@ Style/PredicateName:
|
|
26
29
|
Exclude:
|
27
30
|
- "lib/valkyrie/resource.rb"
|
28
31
|
- "lib/valkyrie/persistence/solr/queries/default_paginator.rb"
|
32
|
+
Lint/UnusedMethodArgument:
|
33
|
+
AllowUnusedKeywordArguments: true
|
data/.rubocop_todo.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# v1.0.0.RC1 2018-03-02
|
2
|
+
|
3
|
+
Initial Release
|
4
|
+
|
5
|
+
## Changes Since Last Sprint
|
6
|
+
|
7
|
+
* Added find_many_by_ids query.
|
8
|
+
* Enforces only persisting arrays - no scalars.
|
9
|
+
* Fixes casting edge cases for `Set` and `Array`.
|
10
|
+
* Significantly improved documentation
|
11
|
+
* Support `Booleans`
|
12
|
+
* Support `RDF::Literal`
|
13
|
+
* Fix support for `DateTime`.
|
14
|
+
* Fix rake tasks leaking out of gem.
|
15
|
+
* Extract derivatives/file characterization to
|
16
|
+
[valkyrie-derivatives](https://github.com/samvera-labs/valkyrie-derivatives)
|
17
|
+
* ChangeSet shared spec
|
18
|
+
* Allow strings as an argument for find_by.
|
19
|
+
* Improve development documentation.
|
20
|
+
* Throw error on `find_inverse_references_by` for unsaved `resource`.
|
21
|
+
|
22
|
+
## Special Thanks to All Contributors:
|
23
|
+
|
24
|
+
* [atz](https://github.com/atz)
|
25
|
+
* [awead](https://github.com/awead)
|
26
|
+
* [barmintor](https://github.com/barmintor)
|
27
|
+
* [bmquinn](https://github.com/bmquinn)
|
28
|
+
* [cam156](https://github.com/cam156)
|
29
|
+
* [carrickr](https://github.com/carrickr)
|
30
|
+
* [cbeer](https://github.com/cbeer)
|
31
|
+
* [cjcolvar](https://github.com/cjcolvar)
|
32
|
+
* [csyversen](https://github.com/csyversen)
|
33
|
+
* [dlpierce](https://github.com/dlpierce)
|
34
|
+
* [escowles](https://github.com/escowles)
|
35
|
+
* [geekscruff](https://github.com/geekscruff)
|
36
|
+
* [hackmastera](https://github.com/hackmastera)
|
37
|
+
* [jcoyne](https://github.com/jcoyne)
|
38
|
+
* [jeremyf](https://github.com/jeremyf)
|
39
|
+
* [jgondron](https://github.com/jgondron)
|
40
|
+
* [jrgriffiniii](https://github.com/jrgriffiniii)
|
41
|
+
* [mbklein](https://github.com/mbklein)
|
42
|
+
* [stkenny](https://github.com/stkenny)
|
43
|
+
* [tpendragon](https://github.com/tpendragon)
|
data/Gemfile
CHANGED
@@ -3,7 +3,3 @@ source 'https://rubygems.org'
|
|
3
3
|
|
4
4
|
# Specify your gem's dependencies in valkyrie.gemspec
|
5
5
|
gemspec
|
6
|
-
|
7
|
-
# Necessary for the --ignore-parent-exclusion feature. Remove when
|
8
|
-
# https://github.com/bbatsov/rubocop/pull/4329 is merged.
|
9
|
-
gem 'rubocop', github: 'nelsonjr/rubocop', ref: 'a5db18a49b9f318644ae7209c73452fb7bbcdc49'
|
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# Copyright 2017 Princeton University Library
|
3
|
+
# Additional copyright may be held by others, as reflected in the commit log
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Valkyrie
|
2
2
|
|
3
|
-
Valkyrie is a gem for enabling multiple backends for storage of files and metadata in Samvera
|
4
|
-
currently developed in a subdirectory of the [proof-of-concept app of the same name](..).
|
3
|
+
Valkyrie is a gem for enabling multiple backends for storage of files and metadata in Samvera.
|
5
4
|
|
6
5
|
[![CircleCI](https://circleci.com/gh/samvera-labs/valkyrie.svg?style=svg)](https://circleci.com/gh/samvera-labs/valkyrie)
|
7
6
|
[![Coverage Status](https://coveralls.io/repos/github/samvera-labs/valkyrie/badge.svg?branch=master)](https://coveralls.io/github/samvera-labs/valkyrie?branch=master)
|
@@ -125,13 +124,13 @@ To create a custom Valkyrie model in your application, you can use the Rails gen
|
|
125
124
|
generate a model named `FooBar` with an unordered `title` field and an ordered `member_ids` field:
|
126
125
|
|
127
126
|
```
|
128
|
-
rails generate valkyrie:
|
127
|
+
rails generate valkyrie:resource FooBar title member_ids:array
|
129
128
|
```
|
130
129
|
|
131
130
|
You can namespace your model class by including a slash in the model name:
|
132
131
|
|
133
132
|
```
|
134
|
-
rails generate valkyrie:
|
133
|
+
rails generate valkyrie:resource Foo/Bar title member_ids:array
|
135
134
|
```
|
136
135
|
|
137
136
|
### Read and Write Data
|
@@ -154,10 +153,16 @@ Valkyrie.config.metadata_adapter.query_service.find_all_of_model(model: MyModel)
|
|
154
153
|
|
155
154
|
## Installing a Development environment
|
156
155
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
156
|
+
### External Requirements
|
157
|
+
* PostgreSQL with the uuid-ossp extension.
|
158
|
+
* Note: Enabling uuid-ossp requires database superuser privileges.
|
159
|
+
* From `psql`: `alter user [username] with superuser;`
|
160
|
+
|
161
|
+
### To run the test suite
|
162
|
+
1. Start Solr and Fedora servers for testing with `rake server:test`
|
163
|
+
1. Run `rake db:create` (First time only)
|
164
|
+
1. Run `rake db:migrate`
|
165
|
+
1. Run the gem's RSpec test suite with `rspec spec` or `rake`
|
161
166
|
|
162
167
|
|
163
168
|
## License
|
data/Rakefile
CHANGED
@@ -4,10 +4,18 @@ require "rspec/core/rake_task"
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'config/database_connection'
|
6
6
|
require 'active_record'
|
7
|
-
|
7
|
+
require 'rubocop/rake_task'
|
8
|
+
load "tasks/dev.rake"
|
8
9
|
RSpec::Core::RakeTask.new(:spec)
|
9
10
|
|
10
11
|
task default: :spec
|
12
|
+
|
13
|
+
desc 'Run RuboCop style checker'
|
14
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
15
|
+
task.requires << 'rubocop-rspec'
|
16
|
+
task.fail_on_error = true
|
17
|
+
end
|
18
|
+
|
11
19
|
namespace :db do
|
12
20
|
task :environment do
|
13
21
|
path = File.join(File.dirname(__FILE__), './db/migrate')
|
@@ -56,6 +64,12 @@ namespace :db do
|
|
56
64
|
end
|
57
65
|
end
|
58
66
|
|
67
|
+
namespace :schema do
|
68
|
+
task :load do
|
69
|
+
Rake::Task["db:migrate"].invoke
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
59
73
|
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
60
74
|
task rollback: :configure_connection do
|
61
75
|
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
data/bin/jetty_wait
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
|
3
|
+
until $(curl --output /dev/null --silent --head --fail http://localhost:8984/solr); do
|
4
|
+
printf '.'
|
5
|
+
sleep 1
|
6
|
+
done
|
7
|
+
until $(curl --output /dev/null --silent --head --fail http://localhost:8985/solr); do
|
8
|
+
printf '.'
|
9
|
+
sleep 1
|
10
|
+
done
|
11
|
+
until $(curl --output /dev/null --silent --head --fail http://localhost:8988/rest); do
|
12
|
+
printf '.'
|
13
|
+
sleep 1
|
14
|
+
done
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/browserslist
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
machine:
|
2
|
+
ruby:
|
3
|
+
version: 2.3.1
|
4
|
+
services:
|
5
|
+
- redis
|
6
|
+
general:
|
7
|
+
artifacts:
|
8
|
+
- "tmp/capybara"
|
9
|
+
dependencies:
|
10
|
+
post:
|
11
|
+
- bundle exec rake rubocop
|
12
|
+
- bundle exec rake server:test:
|
13
|
+
background: true
|
14
|
+
- bin/jetty_wait
|
15
|
+
notify:
|
16
|
+
webhooks:
|
17
|
+
- url: https://coveralls.io/webhook?repo_token=c3AnaQOFVYYTitAR1w6ySNScXSIfLQwN4
|
data/config/fedora.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
development:
|
2
|
+
user: fedoraAdmin
|
3
|
+
password: fedoraAdmin
|
4
|
+
url: http://localhost:<%= ENV['FCREPO_DEVELOPMENT_PORT'] || 8986 %>/rest
|
5
|
+
base_path: /dev
|
6
|
+
test:
|
7
|
+
user: fedoraAdmin
|
8
|
+
password: fedoraAdmin
|
9
|
+
url: http://localhost:<%= ENV['FCREPO_TEST_PORT'] || 8988 %>/rest
|
10
|
+
base_path: /test
|
@@ -1,7 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class CreateOrmResources < ActiveRecord::Migration[5.0]
|
3
|
+
def options
|
4
|
+
if ENV["VALKYRIE_ID_TYPE"] == "string"
|
5
|
+
{ id: :text, default: -> { '(uuid_generate_v4())::text' } }
|
6
|
+
else
|
7
|
+
{ id: :uuid }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
def change
|
4
|
-
create_table :orm_resources,
|
12
|
+
create_table :orm_resources, **options do |t|
|
5
13
|
t.jsonb :metadata, null: false, default: {}
|
6
14
|
t.timestamps
|
7
15
|
end
|
data/lib/valkyrie.rb
CHANGED
@@ -15,11 +15,9 @@ require 'json/ld'
|
|
15
15
|
require 'logger'
|
16
16
|
require 'active_triples'
|
17
17
|
require 'rdf/vocab'
|
18
|
+
require 'rails'
|
18
19
|
require 'active_fedora'
|
19
|
-
require 'hydra-access-controls'
|
20
|
-
require 'ruby_tika_app'
|
21
20
|
|
22
|
-
# frozen_string_literal: true
|
23
21
|
module Valkyrie
|
24
22
|
require 'valkyrie/id'
|
25
23
|
require 'valkyrie/change_set'
|
@@ -27,13 +25,9 @@ module Valkyrie
|
|
27
25
|
require 'valkyrie/persistence'
|
28
26
|
require 'valkyrie/types'
|
29
27
|
require 'valkyrie/resource'
|
30
|
-
require 'valkyrie/derivative_service'
|
31
28
|
require 'valkyrie/storage_adapter'
|
32
29
|
require 'valkyrie/metadata_adapter'
|
33
30
|
require 'valkyrie/adapter_container'
|
34
|
-
require 'valkyrie/file_characterization_service'
|
35
|
-
require 'valkyrie/decorators/decorator_list'
|
36
|
-
require 'valkyrie/decorators/decorator_with_arguments'
|
37
31
|
require 'valkyrie/resource/access_controls'
|
38
32
|
require 'valkyrie/indexers/access_controls_indexer'
|
39
33
|
require 'valkyrie/storage'
|
data/lib/valkyrie/change_set.rb
CHANGED
@@ -14,6 +14,8 @@ module Valkyrie
|
|
14
14
|
# property :title, multiple: false, required: true
|
15
15
|
# end
|
16
16
|
class ChangeSet < Reform::Form
|
17
|
+
include Reform::Form::ORM
|
18
|
+
include Reform::Form::ModelReflections
|
17
19
|
include Reform::Form::ActiveModel::Validations
|
18
20
|
feature Coercion
|
19
21
|
class_attribute :fields
|
@@ -28,17 +30,17 @@ module Valkyrie
|
|
28
30
|
end
|
29
31
|
|
30
32
|
# Returns whether or not a given field has multiple values.
|
31
|
-
# @param
|
33
|
+
# @param field_name [Symbol]
|
32
34
|
# @return [Boolean]
|
33
|
-
def multiple?(
|
34
|
-
|
35
|
+
def multiple?(field_name)
|
36
|
+
field(field_name)[:multiple] != false
|
35
37
|
end
|
36
38
|
|
37
39
|
# Returns whether or not a given field is required.
|
38
|
-
# @param
|
40
|
+
# @param field_name [Symbol]
|
39
41
|
# @return [Boolean]
|
40
|
-
def required?(
|
41
|
-
|
42
|
+
def required?(field_name)
|
43
|
+
field(field_name)[:required] == true
|
42
44
|
end
|
43
45
|
|
44
46
|
# Quick setter for fields that should be in a changeset. Defaults to multiple,
|
@@ -70,15 +72,27 @@ module Valkyrie
|
|
70
72
|
# override of Reform::Form's method to allow for single-valued fields to
|
71
73
|
# prepopulate appropriately.
|
72
74
|
def prepopulate!(_options = {})
|
73
|
-
self.class.definitions.select { |_field, definition| definition[:multiple] == false }.
|
75
|
+
self.class.definitions.select { |_field, definition| definition[:multiple] == false }.each_key do |field|
|
74
76
|
value = Array.wrap(send(field.to_s)).first
|
75
77
|
send("#{field}=", value)
|
76
78
|
end
|
79
|
+
super
|
77
80
|
self
|
78
81
|
end
|
79
82
|
|
80
83
|
def resource
|
81
84
|
model
|
82
85
|
end
|
86
|
+
|
87
|
+
def valid?
|
88
|
+
errors.clear
|
89
|
+
super
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def field(field_name)
|
95
|
+
self.class.definitions.fetch(field_name.to_s)
|
96
|
+
end
|
83
97
|
end
|
84
98
|
end
|
data/lib/valkyrie/engine.rb
CHANGED
data/lib/valkyrie/id.rb
CHANGED
@@ -1,19 +1,63 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Valkyrie::Indexers
|
3
|
+
# Provides an optional interface consistent with Hydra::AccessControls
|
4
|
+
# This allows for storing access control information into an index
|
5
|
+
#
|
6
|
+
# @note This is used primarily with Solr
|
7
|
+
#
|
8
|
+
# @example Use in Solr Adapter with a CompositeIndexer
|
9
|
+
#
|
10
|
+
# # insert into config/initializers/valkyrie.rb
|
11
|
+
# Valkyrie::MetadataAdapter.register(
|
12
|
+
# Valkyrie::Persistence::Solr::MetadataAdapter.new(
|
13
|
+
# connection: Blacklight.default_index.connection,
|
14
|
+
# resource_indexer: Valkyrie::Persistence::Solr::CompositeIndexer.new(
|
15
|
+
# Valkyrie::Indexers::AccessControlsIndexer,
|
16
|
+
# Collection::TypeIndexer
|
17
|
+
# )
|
18
|
+
# ),
|
19
|
+
# :index_solr
|
20
|
+
# )
|
21
|
+
#
|
22
|
+
# @see https://github.com/pulibrary/figgy/blob/684a4fb71cad1c9592d8272416f36e2a4f4ae3c4/config/initializers/valkyrie.rb#L82
|
23
|
+
# @see lib/valkyrie/resource/access_controls.rb
|
3
24
|
class AccessControlsIndexer
|
4
|
-
attr_reader :resource
|
5
|
-
def initialize(resource:)
|
25
|
+
attr_reader :resource, :config
|
26
|
+
def initialize(resource:, config: default_config)
|
6
27
|
@resource = resource
|
28
|
+
@config = config
|
7
29
|
end
|
8
30
|
|
9
31
|
def to_solr
|
10
32
|
return {} unless resource.respond_to?(:read_users)
|
11
33
|
{
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
34
|
+
config.fetch(:read_groups) => resource.read_groups,
|
35
|
+
config.fetch(:read_users) => resource.read_users,
|
36
|
+
config.fetch(:edit_users) => resource.edit_users,
|
37
|
+
config.fetch(:edit_groups) => resource.edit_groups
|
16
38
|
}
|
17
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# rubocop:disable Metrics/MethodLength
|
44
|
+
def default_config
|
45
|
+
if defined?(Hydra) && Hydra.respond_to?(:config)
|
46
|
+
{
|
47
|
+
read_groups: Hydra.config[:permissions][:read].group,
|
48
|
+
read_users: Hydra.config[:permissions][:read].individual,
|
49
|
+
edit_groups: Hydra.config[:permissions][:edit].group,
|
50
|
+
edit_users: Hydra.config[:permissions][:edit].individual
|
51
|
+
}
|
52
|
+
else
|
53
|
+
{
|
54
|
+
read_groups: 'read_access_group_ssim',
|
55
|
+
read_users: 'read_access_person_ssim',
|
56
|
+
edit_groups: 'edit_access_group_ssim',
|
57
|
+
edit_users: 'edit_access_person_ssim'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
# rubocop:enable Metrics/MethodLength
|
18
62
|
end
|
19
63
|
end
|