hyrax 3.4.0 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.dassie/.env +2 -1
  3. data/.dassie/db/seeds.rb +70 -15
  4. data/.github/release.yml +26 -0
  5. data/app/services/hyrax/collections/nested_collection_query_service.rb +1 -1
  6. data/app/utils/hyrax/data_destroyers/collection_branding_destroyer.rb +29 -0
  7. data/app/utils/hyrax/data_destroyers/collection_types_destroyer.rb +26 -0
  8. data/app/utils/hyrax/data_destroyers/default_admin_set_id_cache_destroyer.rb +26 -0
  9. data/app/utils/hyrax/data_destroyers/featured_works_destroyer.rb +27 -0
  10. data/app/utils/hyrax/data_destroyers/permission_templates_destroyer.rb +30 -0
  11. data/app/utils/hyrax/data_destroyers/repository_metadata_destroyer.rb +42 -0
  12. data/app/utils/hyrax/data_destroyers/stats_destroyer.rb +33 -0
  13. data/app/utils/hyrax/data_maintenance.rb +51 -0
  14. data/app/utils/hyrax/required_data_seeder.rb +21 -0
  15. data/app/utils/hyrax/required_data_seeders/collection_seeder.rb +26 -0
  16. data/app/utils/hyrax/required_data_seeders/collection_type_seeder.rb +36 -0
  17. data/app/utils/hyrax/test_data_seeder.rb +24 -0
  18. data/app/utils/hyrax/test_data_seeders/collection_seeder.rb +91 -0
  19. data/app/utils/hyrax/test_data_seeders/collection_type_seeder.rb +72 -0
  20. data/app/utils/hyrax/test_data_seeders/user_seeder.rb +52 -0
  21. data/app/views/hyrax/my/_facet_pagination.html.erb +12 -9
  22. data/documentation/developing-your-hyrax-based-app.md +1 -1
  23. data/documentation/legacyREADME.md +1 -1
  24. data/lib/hyrax/schema.rb +16 -13
  25. data/lib/hyrax/version.rb +1 -1
  26. data/lib/wings/valkyrie/persister.rb +2 -0
  27. data/template.rb +1 -1
  28. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fa4543b3224a41244d522ea1eedff364bc5a611766952b7f75472c438b4fff1
4
- data.tar.gz: 19c28428038b672908944c5ad30dd144eabc934e80ecfa5c1d080d6144e7df9d
3
+ metadata.gz: 865d623446e36dc64e73cf82ef855955e83d8d8f730a65f439b9b89664641c3f
4
+ data.tar.gz: 87aec067e009093bbd119d6d39639c5c6927b2b26173088ca7000b1241f71caa
5
5
  SHA512:
6
- metadata.gz: 697a6d11f891fe1a0c42997fb80d49ab94810779745c7472670b9c32bd09d49283ceddb5736d1d5652efc9d5ac21e9dffb416fa2e75c300954c5cb529034a82c
7
- data.tar.gz: efe3443f9e7e285713ff9c53661f5202748fc0613c9282dc07d834e8802c052a3551d617460d2b1975493b9ab065b0d9c66e9bfd0561fe1aef996821093f6526
6
+ metadata.gz: d75dbf03372ee072f394a88af8449ff947ff42b21de9b10a83428ac98af5d01783f21e7f123ee00e3c0dd7b6d3808d4e7d59f0238e1fda703da8358d2b567447
7
+ data.tar.gz: 6dae952fde3a2f2fdc329775d8efe14929e23c0f92284d1848abfa8a7a8a041e4b5a197a4fa0581d3934ddc9267d0e3ca64c455a5f65b81f5287bde8110fb19e
data/.dassie/.env CHANGED
@@ -1,3 +1,4 @@
1
1
  MEMCACHED_HOST=memcached
2
2
  REDIS_PROVIDER=SIDEKIQ_REDIS_URL
3
- SIDEKIQ_REDIS_URL=redis://redis:6379/0
3
+ SIDEKIQ_REDIS_URL=redis://redis:6379/0
4
+ SEED_DASSIE=true
data/.dassie/db/seeds.rb CHANGED
@@ -1,22 +1,77 @@
1
- # This file should contain all the record creation needed to seed the database with its default values.
2
- # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
- #
4
- # Examples:
5
- #
6
- # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
- # Character.create(name: 'Luke', movie: movies.first)
1
+ wipe_data = ActiveModel::Type::Boolean.new.cast(ENV.fetch('WIPE_DATA', false))
2
+ seed_release_testing = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SEED_RELEASE_TESTING', false))
3
+ seed_dassie = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SEED_DASSIE', false))
8
4
 
9
- Hyrax::Engine.load_seed unless ActiveModel::Type::Boolean.new.cast(ENV["SKIP_HYRAX_ENGINE_SEED"])
5
+ unless wipe_data || seed_release_testing
6
+ puts 'NAME'
7
+ puts ' rails db:seed (Hyrax)'
8
+ puts
9
+ puts 'SYNOPSIS'
10
+ puts ' bundle exec rails db:seed [WIPE_DATA=true|false] [SEED_RELEASE_TESTING=true|false] [SEED_DASSIE=true|false]'
11
+ puts
12
+ puts 'DESCRIPTION'
13
+ puts ' Hyrax defined db:seed provides a means to clear repository metadata from the datastore (e.g. Fedora, Postgres) and from Solr.'
14
+ puts ' Seeds can be run to pre-populate metadata to help with release testing and local development testing.'
15
+ puts
16
+ puts ' NOTE: Options can be passed in with the command on the command line or set as ENV variables.'
17
+ puts
18
+ puts ' The options are as follows:'
19
+ puts
20
+ puts ' WIPE_DATA'
21
+ puts ' USE WITH CAUTION - Deleted data cannot be recovered.'
22
+ puts
23
+ puts ' When true, it will clear all repository metadata from the datastore (e.g. Fedora, Postgres) and from Solr. It also'
24
+ puts ' clears data from the application database that are tightly coupled to repository metadata. See Hyrax::DataMaintenance'
25
+ puts ' for more information on what data will be destroyed by this process.'
26
+ puts
27
+ puts ' The wipe_data process will also restore required repository metadata including collection types and the default admin'
28
+ puts ' set. See Hyrax::RequiredDataSeeder for more information on what data will be created by this process.'
29
+ puts
30
+ puts ' SEED_RELEASE_TESTING'
31
+ puts ' When true, it will run the set of seeds for release testing creating a repository metadata and support data, including'
32
+ puts ' test users, collection types, collections, and works with and without files. See Hyrax::TestDataSeeder for more information'
33
+ puts ' on what data will be created by this process.'
34
+ puts
35
+ puts ' SEED_DASSIE'
36
+ puts ' When true, it will run a minimal set of seeds for dassie test app, including required collection types, default admin set,'
37
+ puts ' and test users.'
38
+ puts
39
+ puts ' ALLOW_RELEASE_SEEDING_IN_PRODUCTION'
40
+ puts ' USE WITH EXTERME CAUTION WHEN USED IN PRODUCTION - Deleted data cannot be recovered. Attempts are made to not overwrite'
41
+ puts ' existing data, but use in production is not recommended.'
42
+ puts
43
+ puts ' If this is NOT true, the process will abort when Rails environment is production.'
44
+ puts
45
+ end
46
+
47
+ allow_release_seeding_in_production = ActiveModel::Type::Boolean.new.cast(ENV.fetch('ALLOW_RELEASE_SEEDING_IN_PRODUCTION', false))
48
+
49
+ if Rails.env == 'production' && !allow_release_seeding_in_production
50
+ puts "Seeding data for release testing is not for use in production!"
51
+ exit
52
+ end
53
+
54
+ if wipe_data
55
+ puts '####################################################################################'
56
+ puts
57
+ puts 'WARNING: You are about to clear all repository metadata from the datastore and solr.'
58
+ puts 'Are you sure? [YES|n]'
59
+ answer = STDIN.gets.chomp
60
+ unless answer == 'YES'
61
+ puts ' Aborting!'
62
+ puts '####################################################################################'
63
+ exit
64
+ end
10
65
 
11
- puts "\n== Loading users"
12
- User.where(email: 'admin@example.com').first_or_create do |f|
13
- f.password = 'admin_password'
66
+ Hyrax::DataMaintenance.new.destroy_repository_metadata_and_related_data
67
+ Hyrax::RequiredDataSeeder.new.generate_seed_data
14
68
  end
15
69
 
16
- User.where(email: 'basic_user@example.com').first_or_create do |f|
17
- f.password = 'password'
70
+ if seed_dassie
71
+ Hyrax::RequiredDataSeeder.new.generate_seed_data
72
+ Hyrax::TestDataSeeders::UserSeeder.generate_seeds
18
73
  end
19
74
 
20
- User.where(email: 'another_user@example.com').first_or_create do |f|
21
- f.password = 'password'
75
+ if seed_release_testing
76
+ Hyrax::TestDataSeeder.new.generate_seed_data
22
77
  end
@@ -0,0 +1,26 @@
1
+ changelog:
2
+ categories:
3
+ - title: Major Changes (Potentially breaking changes)
4
+ labels:
5
+ - notes-major
6
+ - title: New Features
7
+ labels:
8
+ - notes-minor
9
+ - title: Deprecations
10
+ labels:
11
+ - notes-deprecation
12
+ - title: Bug Fixes
13
+ labels:
14
+ - notes-bugfix
15
+ - title: Valkyrie Progress
16
+ labels:
17
+ - notes-valkyrie
18
+ - title: Documentation
19
+ labels:
20
+ - notes-docs
21
+ - title: Containerization
22
+ labels:
23
+ - notes-container
24
+ - title: Other
25
+ labels:
26
+ - "*"
@@ -171,7 +171,7 @@ module Hyrax
171
171
  # @return [Fixnum] the largest number of collections in a path nested
172
172
  # under this collection (including this collection)
173
173
  def self.child_nesting_depth(child:, scope:)
174
- return 1 if child.nil?
174
+ return 1 unless child
175
175
  # The nesting depth of a child collection is found by finding the largest nesting depth
176
176
  # among all collections and works which have the child collection in the paths, and
177
177
  # subtracting the nesting depth of the child collection itself.
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # Collection branding info is tightly coupled to collections. When they are
5
+ # removed using wipe!, the associated database entries for collection branding
6
+ # also have to be deleted.
7
+ #
8
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
9
+ # Data can not be recovered.
10
+ #
11
+ # @todo This destroys branding info in the database. Should it also delete
12
+ # related banner and logo files?
13
+ class CollectionBrandingDestroyer
14
+ class << self
15
+ attr_accessor :logger
16
+
17
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
18
+ raise("CollectionBrandingDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
19
+ @logger = logger
20
+
21
+ logger.info("Destroying collection branding...")
22
+
23
+ Hyrax::CollectionBrandingInfo.destroy_all
24
+ logger.info(" collection branding -- DESTROYED")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # Collection types are recreated by the release seed data. Clear out here to
5
+ # start with a fresh set.
6
+ #
7
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
8
+ # Data can not be recovered.
9
+ #
10
+ class CollectionTypesDestroyer
11
+ class << self
12
+ attr_accessor :logger
13
+
14
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
15
+ raise("CollectionTypesDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
16
+ @logger = logger
17
+
18
+ logger.info("Destroying collection types...")
19
+
20
+ Hyrax::CollectionType.destroy_all
21
+ logger.info(" collection types -- DESTROYED")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # When the default admin set is removed using wipe!, the cache of the default
5
+ # admin set id also needs to be deleted.
6
+ #
7
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
8
+ # Data can not be recovered.
9
+ #
10
+ class DefaultAdminSetIdCacheDestroyer
11
+ class << self
12
+ attr_accessor :logger
13
+
14
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
15
+ raise("DefaultAdminSetIdCacheDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
16
+ @logger = logger
17
+
18
+ logger.info("Destroying default admin set id cache...")
19
+
20
+ Hyrax::DefaultAdministrativeSet.destroy_all
21
+ logger.info(" default admin set id cache -- DESTROYED")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # Featured works are tightly coupled to works in the repository. When they
5
+ # are removed using wipe!, the associated database entries for featured
6
+ # works also need to be deleted.
7
+ #
8
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
9
+ # Data can not be recovered.
10
+ #
11
+ class FeaturedWorksDestroyer
12
+ class << self
13
+ attr_accessor :logger
14
+
15
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
16
+ raise("FeaturedWorksDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
17
+ @logger = logger
18
+
19
+ logger.info("Destroying featured works...")
20
+
21
+ FeaturedWork.destroy_all
22
+ logger.info(" featured works -- DESTROYED")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # PermissionTemplates are tightly coupled to admin sets and collections.
5
+ # When they are removed using wipe!, the associated database entries for
6
+ # permission templates also have to be deleted.
7
+ #
8
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
9
+ # Data can not be recovered.
10
+ #
11
+ class PermissionTemplatesDestroyer
12
+ class << self
13
+ attr_accessor :logger
14
+
15
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
16
+ raise("PermissionTemplatesDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
17
+ @logger = logger
18
+
19
+ logger.info("Destroying permission templates...")
20
+
21
+ Hyrax::PermissionTemplateAccess.destroy_all
22
+ logger.info(" permission templates access -- DESTROYED")
23
+
24
+ Hyrax::PermissionTemplate.destroy_all
25
+ logger.info(" permission templates -- DESTROYED")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # Clear all repository metadata from the datastore (e.g. Fedora, Postgres)
5
+ # and from Solr.
6
+ #
7
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
8
+ # Data can not be recovered.
9
+ #
10
+ # @note When using Wings adapter, which wraps ActiveFedora, the persister wipe!
11
+ # method clears both Fedora and Solr. Optionally, an index_adapter may also
12
+ # be set to use Valkyrie to write to a second Solr core. If the Hyrax index
13
+ # adapter is the NullIndexingAdapter, that means that Valkyrie is not being
14
+ # used to index the repository metadata and does not need to be cleared using
15
+ # the Hyrax index adapter.
16
+ #
17
+ # When using other Valkyrie persistence adapters, wipe! only clears the repository
18
+ # metadata from the datastore (e.g. ORM table in Postgres). The index adapter
19
+ # is used to clear metadata from Solr.
20
+ #
21
+ class RepositoryMetadataDestroyer
22
+ class << self
23
+ attr_accessor :logger
24
+
25
+ def destroy_metadata(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
26
+ raise("RepositoryMetadataDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
27
+ @logger = logger
28
+
29
+ logger.info("Destroying all repository metadata...")
30
+
31
+ unless Hyrax.index_adapter.is_a? Valkyrie::Indexing::NullIndexingAdapter
32
+ conn = Hyrax.index_adapter.connection
33
+ conn.delete_by_query('*:*', params: { 'softCommit' => true })
34
+ end
35
+ Hyrax.persister.wipe!
36
+
37
+ logger.info(" repository metadata -- DESTROYED")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module DataDestroyers
4
+ # Stats are tightly coupled to works and files in the repository. When they
5
+ # are removed using wipe!, the associated database entries for stats also
6
+ # need to be deleted.
7
+ #
8
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
9
+ # Data can not be recovered.
10
+ #
11
+ class StatsDestroyer
12
+ class << self
13
+ attr_accessor :logger
14
+
15
+ def destroy_data(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
16
+ raise("StatsDataDestroyer is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
17
+ @logger = logger
18
+
19
+ logger.info("Destroying stats...")
20
+
21
+ FileDownloadStat.destroy_all
22
+ logger.info(" file download stats -- DESTROYED")
23
+
24
+ FileViewStat.destroy_all
25
+ logger.info(" file view stats -- DESTROYED")
26
+
27
+ WorkViewStat.destroy_all
28
+ logger.info(" work view stats -- DESTROYED")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ ##
5
+ # These methods created for use in rake tasks and db/seeds.rb They can be used to:
6
+ # * clear repository metadata and related data and files
7
+ # * clear temporary files
8
+ # * clear logs
9
+ #
10
+ # @note WARNING: DO NOT USE IN PRODUCTION! The methods in this class are destructive.
11
+ # Data can not be recovered.
12
+ #
13
+ class DataMaintenance
14
+ attr_accessor :logger, :allow_destruction_in_production
15
+
16
+ def initialize(logger: Logger.new(STDOUT), allow_destruction_in_production: false)
17
+ raise("Destruction of data is not for use in production!") if Rails.env.production? && !allow_destruction_in_production
18
+ @logger = logger
19
+ @allow_destruction_in_production = allow_destruction_in_production
20
+ end
21
+
22
+ # Clear repository metadata and related data
23
+ # * clear repository metadata from the datastore (e.g. Fedora, Postgres) and from Solr
24
+ # * clear targeted application data that is tightly coupled to repository metadata
25
+ # * delete files that are tightly coupled to repository metadata
26
+ def destroy_repository_metadata_and_related_data
27
+ Hyrax::DataDestroyers::RepositoryMetadataDestroyer.destroy_metadata(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
28
+ Hyrax::DataDestroyers::StatsDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
29
+ Hyrax::DataDestroyers::FeaturedWorksDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
30
+ Hyrax::DataDestroyers::PermissionTemplatesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
31
+ Hyrax::DataDestroyers::CollectionBrandingDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
32
+ Hyrax::DataDestroyers::DefaultAdminSetIdCacheDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
33
+ Hyrax::DataDestroyers::CollectionTypesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
34
+
35
+ # TODO: Stubbed until RepositoryFilesDestroyer is written
36
+ # Hyrax::DataDestroyers::RepositoryFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
37
+ end
38
+
39
+ # @todo write code to clear out log files
40
+ def destroy_log_files
41
+ # Stubbed until LogFilesDestroyer is written
42
+ # Hyrax::DataDestroyers::LogFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
43
+ end
44
+
45
+ # @todo write code to delete tmp files
46
+ def destroy_tmp_files
47
+ # Stubbed until TmpFilesDestroyer is written
48
+ # Hyrax::DataDestroyers::TmpFilesDestroyer.destroy_data(logger: logger, allow_destruction_in_production: allow_destruction_in_production)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
4
+ # required repository metadata including Admin Set and User collection types and
5
+ # the default admin set.
6
+ #
7
+ # Seeders of required data are non-destructive. If the data already exists,
8
+ # it will not be replaced.
9
+ class RequiredDataSeeder
10
+ attr_accessor :logger
11
+
12
+ def initialize(logger: Logger.new(STDOUT))
13
+ @logger = logger
14
+ end
15
+
16
+ def generate_seed_data
17
+ Hyrax::RequiredDataSeeders::CollectionTypeSeeder.generate_seeds(logger: logger)
18
+ Hyrax::RequiredDataSeeders::CollectionSeeder.generate_seeds(logger: logger)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+
2
+
3
+ # frozen_string_literal: true
4
+ module Hyrax
5
+ module RequiredDataSeeders
6
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
7
+ # collections that are required for all Hyrax applications.
8
+ #
9
+ # Seeders of required data are non-destructive. If the data already exists,
10
+ # it will not be replaced.
11
+ class CollectionSeeder
12
+ class << self
13
+ attr_accessor :logger
14
+
15
+ def generate_seeds(logger: Logger.new(STDOUT))
16
+ @logger = logger
17
+
18
+ logger.info("Adding required collections...")
19
+
20
+ default_admin_set = Hyrax::AdminSetCreateService.find_or_create_default_admin_set
21
+ logger.info " #{default_admin_set.title.first} -- FOUND OR CREATED"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module RequiredDataSeeders
4
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
5
+ # collection types that are required for all Hyrax applications.
6
+ #
7
+ # Seeders of required data are non-destructive. If the data already exists,
8
+ # it will not be replaced.
9
+ class CollectionTypeSeeder
10
+ class << self
11
+ attr_accessor :logger
12
+
13
+ def generate_seeds(logger: Logger.new(STDOUT))
14
+ @logger = logger
15
+
16
+ logger.info("Adding required collection types...")
17
+
18
+ as_ct = Hyrax::CollectionType.find_or_create_admin_set_type
19
+ set_badge_color(as_ct, '#990000')
20
+ logger.info(" #{as_ct.title} -- FOUND OR CREATED")
21
+
22
+ user_ct = Hyrax::CollectionType.find_or_create_default_collection_type
23
+ set_badge_color(user_ct, '#0099cc')
24
+ logger.info(" #{user_ct.title} -- FOUND OR CREATED")
25
+ end
26
+
27
+ private
28
+
29
+ def set_badge_color(collection_type, badge_color = nil)
30
+ collection_type.badge_color = badge_color
31
+ collection_type.save
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
5
+ # repository metadata needed for release testing. This data can also be helpful
6
+ # for local development testing.
7
+ class TestDataSeeder
8
+ attr_accessor :logger, :allow_seeding_in_production
9
+
10
+ def initialize(logger: Logger.new(STDOUT), allow_seeding_in_production: false)
11
+ raise("TestDataSeeder is not for use in production!") if Rails.env.production? && !allow_seeding_in_production
12
+ @logger = logger
13
+ @allow_seeding_in_production = allow_seeding_in_production
14
+ end
15
+
16
+ def generate_seed_data
17
+ Hyrax::TestDataSeeders::UserSeeder.generate_seeds(logger: logger, allow_seeding_in_production: allow_seeding_in_production)
18
+ Hyrax::TestDataSeeders::CollectionTypeSeeder.generate_seeds(logger: logger, allow_seeding_in_production: allow_seeding_in_production)
19
+ Hyrax::TestDataSeeders::CollectionSeeder.generate_seeds(logger: logger, allow_seeding_in_production: allow_seeding_in_production)
20
+ # TODO: add work seeder
21
+ # Hyrax::TestDataSeeders::WorkSeeder.generate_seeds(logger: logger, allow_seeding_in_production: allow_seeding_in_production)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module TestDataSeeders
4
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
5
+ # collection that can be used in release testing. This data can also be helpful
6
+ # for local development testing.
7
+ #
8
+ # Adding collections is non-destructive. But it may create an additional
9
+ # collection of the same.
10
+ #
11
+ # @todo Do we want to assume that if a collection of the same name exists, then
12
+ # it is the collection we want for release testing?
13
+ class CollectionSeeder
14
+ class << self
15
+ attr_accessor :logger
16
+
17
+ def generate_seeds(logger: Logger.new(STDOUT), allow_seeding_in_production: false) # rubocop:disable Metrics/AbcSize
18
+ raise("TestDataSeeders are not for use in production!") if Rails.env.production? && !allow_seeding_in_production
19
+ @logger = logger
20
+
21
+ logger.info("Adding collections...")
22
+
23
+ create_collection("Grand Parent Collection", collection_types['Nestable only'])
24
+ create_collection("Parent Collection", collection_types['Nestable only'])
25
+ create_collection("Child Collection", collection_types['Nestable only'])
26
+ create_collection("Branded Collection", collection_types['Brandable only'])
27
+ create_collection("Discoverable Collection", collection_types['Discoverable only'])
28
+ create_collection("Shared", collection_types['Sharable only'])
29
+ create_collection("Share Applies to Works", collection_types['Sharable only (and works)'])
30
+ create_collection("(SM1) Single Membership Collection", collection_types['Single Membership 1'])
31
+ create_collection("(SM1) Another Single Membership Collection", collection_types['Single Membership 1'])
32
+ create_collection("(SM2) Single Membership Collection", collection_types['Single Membership 2'])
33
+ create_collection("(SM2) Another Single Membership Collection", collection_types['Single Membership 2'])
34
+ end
35
+
36
+ ##
37
+ # @api private
38
+ class NullUser
39
+ ##
40
+ # @return [nil]
41
+ def user_key
42
+ nil
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def create_collection(title, collection_type_gid)
49
+ return unless valid_collection_type?(title, collection_type_gid)
50
+ return if exists?(title, collection_type_gid)
51
+
52
+ collection = Hyrax::PcdmCollection.new(title: title, collection_type_gid: collection_type_gid)
53
+ Hyrax.persister.save(resource: collection)
54
+ Hyrax.publisher.publish('collection.metadata.updated', collection: collection, user: seed_user)
55
+ logger.info(" #{collection.title.first} -- CREATED")
56
+ end
57
+
58
+ def seed_user
59
+ @seed_user ||= NullUser.new
60
+ end
61
+
62
+ def collection_types
63
+ @collection_types ||=
64
+ Hyrax::CollectionType.all
65
+ .each_with_object({}) { |ct, hsh| hsh[ct.title] = ct.to_global_id.to_s }
66
+ end
67
+
68
+ def valid_collection_type?(title, collection_type_gid)
69
+ return true if collection_type_gid.present? && collection_types.value?(collection_type_gid.to_s)
70
+
71
+ msg = " #{title} -- NOT CREATED -- Collection type gid (#{collection_type_gid}) " \
72
+ "is invalid or doesn't exist."
73
+ logger.info(msg)
74
+ false
75
+ end
76
+
77
+ def existing_collections
78
+ @existing_collections ||=
79
+ Hyrax.query_service.find_all_of_model(model: Hyrax::PcdmCollection)
80
+ .each_with_object({}) { |col, hsh| hsh[col.title&.first] = col.collection_type_gid.to_s }
81
+ end
82
+
83
+ def exists?(title, collection_type_gid)
84
+ return false unless existing_collections[title] == collection_type_gid.to_s
85
+ logger.info(" #{title} -- ALREADY EXISTS")
86
+ true
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module TestDataSeeders
4
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
5
+ # collection types that can be used in release testing. This data can also be
6
+ # helpful for local development testing.
7
+ #
8
+ # Adding collection types is non-destructive. If a collection type with the
9
+ # title already exists, it will not be replaced.
10
+ class CollectionTypeSeeder
11
+ class << self
12
+ attr_accessor :logger
13
+
14
+ def generate_seeds(logger: Logger.new(STDOUT), allow_seeding_in_production: false) # rubocop:disable Metrics/MethodLength
15
+ raise("TestDataSeeders are not for use in production!") if Rails.env.production? && !allow_seeding_in_production
16
+ @logger = logger
17
+
18
+ logger.info("Adding collection types...")
19
+
20
+ create_collection_type(title: "Nestable only", badge_color: "#282D3C", nestable: true,
21
+ description: "Collections of this type can be nested.")
22
+ create_collection_type(title: "Brandable only", badge_color: "#ff6600", brandable: true,
23
+ description: "Collections of this type can have branding images.")
24
+ create_collection_type(title: "Discoverable only", badge_color: "#00A170", discoverable: true,
25
+ description: "Collections of this type can have visibility settings modified.")
26
+ create_collection_type(title: "Sharable only", badge_color: "#ff0066", sharable: true, share_applies_to_new_works: false,
27
+ description: "Collections of this type are sharable. Works " \
28
+ "do NOT inherit sharable settings when they are created.")
29
+ create_collection_type(title: "Sharable only (and works)", badge_color: "#0072B5", sharable: true, share_applies_to_new_works: true,
30
+ description: "Collections of this type are sharable. Works " \
31
+ "inherit sharable settings when they are created.")
32
+ create_collection_type(title: "Single Membership 1", badge_color: "#b34700", allow_multiple_membership: false,
33
+ description: "This Single Membership 1 collection type restricts collection membership. " \
34
+ "Collections of this type do not allow works to live in multiple collections of this type.")
35
+ create_collection_type(title: "Single Membership 2", badge_color: "#926AA6", allow_multiple_membership: false,
36
+ description: "This Single Membership 2 collection type restricts collection membership. " \
37
+ "Collections of this type do not allow works to live in multiple collections of this type.")
38
+ end
39
+
40
+ private
41
+
42
+ def collection_type_titles
43
+ @collection_type_titles ||= Hyrax::CollectionType.all.map(&:title)
44
+ end
45
+
46
+ def create_collection_type(options = {})
47
+ title = options[:title]
48
+ return logger.info(" #{title} -- ALREADY EXISTS") if collection_type_titles.include? title
49
+
50
+ defaults_for_options(options)
51
+ Hyrax::CollectionType.new(options).save
52
+ logger.info(" #{title} -- CREATED")
53
+ end
54
+
55
+ def defaults_for_options(options = {})
56
+ options[:nestable] ||= false
57
+ options[:brandable] ||= false
58
+ options[:discoverable] ||= false
59
+ options[:sharable] ||= false
60
+ options[:share_applies_to_new_works] ||= false
61
+ options[:allow_multiple_membership] ||= true
62
+
63
+ # These should always false unless the collection type is Admin Set.
64
+ # Admin Set collection type is created by required_data_seeders
65
+ options[:require_membership] = false
66
+ options[:assigns_workflow] = false
67
+ options[:assigns_visibility] = false
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module TestDataSeeders
4
+ # This class was created for use in rake tasks and db/seeds.rb. It generates
5
+ # users that can be used in release testing. This data can also be helpful
6
+ # for local development testing.
7
+ #
8
+ # Adding users is non-destructive. If a user with the email already exists,
9
+ # they will not be replaced.
10
+ class UserSeeder
11
+ class << self
12
+ attr_accessor :logger
13
+
14
+ def generate_seeds(logger: Logger.new(STDOUT), allow_seeding_in_production: false)
15
+ raise("TestDataSeeders are not for use in production!") if Rails.env.production? && !allow_seeding_in_production
16
+ @logger = logger
17
+
18
+ logger.info("Adding users...")
19
+
20
+ add_user('admin@example.com', 'admin_password', admin_role)
21
+ add_user('basic_user@example.com', 'password')
22
+ add_user('another_user@example.com', 'password')
23
+ end
24
+
25
+ private
26
+
27
+ def admin_role
28
+ unless defined? Role
29
+ logger.warn("Cannot create `Role` because the `hyrda-role-management` gem, or " \
30
+ "other gem providing a definition for a Role class, is not installed. " \
31
+ "For development, you can edit `config/role_map.yml` and add the user's " \
32
+ "email under the role you want to assign.")
33
+ return
34
+ end
35
+ @admin_role ||= Role.find_by(name: Hyrax.config.admin_user_group_name)
36
+ end
37
+
38
+ def add_user(email, password, role = nil)
39
+ created = false
40
+ user = ::User.find_or_create_by(email: email) do |f|
41
+ created = true
42
+ f.password = password
43
+ end
44
+ logger.info(" #{email} -- #{created ? 'CREATED' : 'ALREADY EXISTS'}")
45
+ return unless role && !user.roles.include?(role)
46
+ user.roles << role
47
+ user.save
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,13 +1,16 @@
1
- <div class="prev_next_links btn-group pull-left">
2
- <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), route_set: hyrax, params: search_state.to_h, param_name: Blacklight::Solr::FacetPaginator.request_keys[:page], class: 'btn btn-link', data: {ajax_modal: "preserve"} do %>
3
- <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.previous')) %></span>
4
- <% end %>
5
- <%= link_to_next_page @pagination, raw(t('views.pagination.next')), route_set: hyrax, params: search_state.to_h, param_name: Blacklight::Solr::FacetPaginator.request_keys[:page], class: 'btn btn-link', data: {ajax_modal: "preserve"} do %>
1
+ <div class="prev_next_links btn-group pull-left">
2
+ <% if @pagination.first_page? %>
3
+ <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.previous')) %></span>
4
+ <% else %>
5
+ <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), route_set: hyrax, params: search_state.to_h, param_name: Blacklight::Solr::FacetPaginator.request_keys[:page], class: 'btn btn-link', data: {ajax_modal: "preserve"} %>
6
+ <% end %>
6
7
 
7
- <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.next')) %></span>
8
- <% end %>
9
-
10
- </div>
8
+ <% if @pagination.last_page? %>
9
+ <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.next')) %></span>
10
+ <% else %>
11
+ <%= link_to_next_page @pagination, raw(t('views.pagination.next')), route_set: hyrax, params: search_state.to_h, param_name: Blacklight::Solr::FacetPaginator.request_keys[:page], class: 'btn btn-link', data: {ajax_modal: "preserve"} %>
12
+ <% end %>
13
+ </div>
11
14
 
12
15
  <div class="sort_options btn-group pull-right">
13
16
  <% if @pagination.sort == 'index' -%>
@@ -125,7 +125,7 @@ NOTE: The steps need to be done in order to create a new Hyrax based app.
125
125
  Generate a new Rails application using the template.
126
126
 
127
127
  ```
128
- rails _5.2.6_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v3.4.0/template.rb
128
+ rails _5.2.6_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v3.4.1/template.rb
129
129
  ```
130
130
 
131
131
  Generating a new Rails application using Hyrax's template above takes cares of a number of steps for you, including:
@@ -50,7 +50,7 @@ The Samvera community is here to help. Please see our [support guide](./.github/
50
50
  # Getting started
51
51
 
52
52
  This document contains instructions specific to setting up an app with __Hyrax
53
- v3.4.0__. If you are looking for instructions on installing a different
53
+ v3.4.1__. If you are looking for instructions on installing a different
54
54
  version, be sure to select the appropriate branch or tag from the drop-down
55
55
  menu above.
56
56
 
data/lib/hyrax/schema.rb CHANGED
@@ -4,24 +4,27 @@ module Hyrax
4
4
  ##
5
5
  # @api public
6
6
  #
7
- # Builds a schema module for a Valkyrie resource. The schema itself is
8
- # resolved by schema loader, which must respond to
9
- # `#attributes_for(schema: :name)` with a hash from attribute names to
10
- # `Dry::Type` types.
7
+ # Builds a schema module for a +Valkyrie::Resource+. The schema itself is
8
+ # resolved by a schema loader instance, which must implement
9
+ # {SimpleSchemaLoader#attributes_for}, with a hash from attribute names to
10
+ # +Dry::Type+ types.
11
11
  #
12
12
  # For the default schema loader, configuration is loaded from
13
- # `config/metadata/[name]}.yaml`. Custom schema loaders can be provided
14
- # for other types.
13
+ # +config/metadata/{name}.yaml+. A custom schema loader can be provided as
14
+ # +:schema_loader+ to
15
+ # resolve the schema in other ways.
15
16
  #
16
- # @note `Valkyrie::Resources`/`Hyrax::Resources` are not required to use this
17
- # interface, and may define custom attributes using the base
18
- # `Valkyrie::Resource.attribute` interface. This mechanism is provided to
19
- # allow schemas to be defined in a unified way that don't require programmer
20
- # intervention ("configurable schemas"). While the default usage defines
21
- # schemas in application configuration, they could also be held in repository
22
- # storage, an external schema service, etc... by using a custom schema loader.
17
+ # @note +Valkyrie::Resource+ and {Hyrax::Resource} classes are not required to
18
+ # use this interface, and may define custom attributes using the base
19
+ # +Valkyrie::Resource.attribute+ interface. This mechanism is provided to
20
+ # allow schemas to be defined in a unified way that don't require programmer
21
+ # intervention ("configurable schemas"). While the default schema loader derives
22
+ # schemas from configuration files, alternate implementations could provide
23
+ # schema definitions pulled from repository storage, an external schema service,
24
+ # etc...
23
25
  #
24
26
  # @param [Symbol] schema_name
27
+ # @param [#attributes_for] schema_loader
25
28
  #
26
29
  # @return [Module] a module that, when included, applies a schema to a
27
30
  # `Valkyire::Resource`
data/lib/hyrax/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
- VERSION = '3.4.0'
3
+ VERSION = '3.4.1'
4
4
  end
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
+ require 'active_fedora/cleaner'
3
+
2
4
  module Wings
3
5
  module Valkyrie
4
6
  ##
data/template.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  # Hack for https://github.com/rails/rails/issues/35153
3
3
  gsub_file 'Gemfile', /^gem ["']sqlite3["']$/, 'gem "sqlite3", "~> 1.3.0"'
4
- gem 'hyrax', '3.4.0'
4
+ gem 'hyrax', '3.4.1'
5
5
  run 'bundle install'
6
6
  generate 'hyrax:install', '-f'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2022-03-23 00:00:00.000000000 Z
17
+ date: 2022-03-30 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: rails
@@ -1461,6 +1461,7 @@ files:
1461
1461
  - ".github/ISSUE_TEMPLATE.md"
1462
1462
  - ".github/PULL_REQUEST_TEMPLATE.md"
1463
1463
  - ".github/SUPPORT.md"
1464
+ - ".github/release.yml"
1464
1465
  - ".github/stale.yml"
1465
1466
  - ".github/workflows/main.yml"
1466
1467
  - ".github/workflows/release.yml"
@@ -2271,6 +2272,21 @@ files:
2271
2272
  - app/strategies/hyrax/strategies/yaml_strategy.rb
2272
2273
  - app/uploaders/hyrax/avatar_uploader.rb
2273
2274
  - app/uploaders/hyrax/uploaded_file_uploader.rb
2275
+ - app/utils/hyrax/data_destroyers/collection_branding_destroyer.rb
2276
+ - app/utils/hyrax/data_destroyers/collection_types_destroyer.rb
2277
+ - app/utils/hyrax/data_destroyers/default_admin_set_id_cache_destroyer.rb
2278
+ - app/utils/hyrax/data_destroyers/featured_works_destroyer.rb
2279
+ - app/utils/hyrax/data_destroyers/permission_templates_destroyer.rb
2280
+ - app/utils/hyrax/data_destroyers/repository_metadata_destroyer.rb
2281
+ - app/utils/hyrax/data_destroyers/stats_destroyer.rb
2282
+ - app/utils/hyrax/data_maintenance.rb
2283
+ - app/utils/hyrax/required_data_seeder.rb
2284
+ - app/utils/hyrax/required_data_seeders/collection_seeder.rb
2285
+ - app/utils/hyrax/required_data_seeders/collection_type_seeder.rb
2286
+ - app/utils/hyrax/test_data_seeder.rb
2287
+ - app/utils/hyrax/test_data_seeders/collection_seeder.rb
2288
+ - app/utils/hyrax/test_data_seeders/collection_type_seeder.rb
2289
+ - app/utils/hyrax/test_data_seeders/user_seeder.rb
2274
2290
  - app/validators/hyrax/collection_membership_validator.rb
2275
2291
  - app/validators/hyrax/has_one_title_validator.rb
2276
2292
  - app/values/hyrax/chart_data.rb