sufia-models 4.3.1 → 5.0.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/actors/sufia/generic_file/actor.rb +7 -10
- data/app/jobs/active_fedora_pid_based_job.rb +2 -3
- data/app/jobs/audit_job.rb +28 -31
- data/app/jobs/batch_update_job.rb +9 -8
- data/app/jobs/import_url_job.rb +2 -2
- data/app/models/batch.rb +11 -12
- data/app/models/checksum_audit_log.rb +7 -8
- data/app/models/concerns/sufia/ability.rb +4 -6
- data/app/models/concerns/sufia/collection.rb +4 -5
- data/app/models/concerns/sufia/file_stat_utils.rb +3 -3
- data/app/models/concerns/sufia/generic_file.rb +16 -14
- data/app/models/concerns/sufia/generic_file/audit.rb +50 -31
- data/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
- data/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
- data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
- data/app/models/concerns/sufia/generic_file/metadata.rb +82 -11
- data/app/models/concerns/sufia/generic_file/proxy_deposit.rb +12 -3
- data/app/models/concerns/sufia/generic_file/versions.rb +1 -4
- data/app/models/concerns/sufia/generic_file/web_form.rb +13 -6
- data/app/models/concerns/sufia/model_methods.rb +11 -9
- data/app/models/concerns/sufia/user.rb +11 -28
- data/app/models/datastreams/file_content_datastream.rb +1 -1
- data/app/models/datastreams/fits_datastream.rb +1 -1
- data/app/models/file_download_stat.rb +2 -2
- data/app/models/file_usage.rb +5 -9
- data/app/models/file_view_stat.rb +2 -2
- data/app/models/local_authority.rb +2 -2
- data/app/models/proxy_deposit_request.rb +1 -1
- data/app/services/sufia/id_service.rb +5 -5
- data/app/services/sufia/noid.rb +10 -7
- data/lib/generators/sufia/models/cached_stats_generator.rb +31 -2
- data/lib/generators/sufia/models/install_generator.rb +31 -11
- data/lib/generators/sufia/models/proxies_generator.rb +31 -2
- data/lib/generators/sufia/models/templates/config/sufia.rb +10 -3
- data/lib/generators/sufia/models/upgrade400_generator.rb +33 -2
- data/lib/sufia/models/engine.rb +13 -4
- data/lib/sufia/models/file_content/versions.rb +12 -8
- data/lib/sufia/models/version.rb +1 -1
- data/lib/sufia/permissions/writable.rb +34 -16
- data/sufia-models.gemspec +4 -2
- metadata +91 -79
- data/app/models/concerns/sufia/generic_file/reload_on_save.rb +0 -18
- data/app/models/concerns/sufia/properties_datastream_behavior.rb +0 -32
- data/app/models/concerns/sufia/user_usage_stats.rb +0 -15
- data/app/models/datastreams/batch_rdf_datastream.rb +0 -6
- data/app/models/datastreams/generic_file_rdf_datastream.rb +0 -69
- data/app/models/datastreams/paranoid_rights_datastream.rb +0 -22
- data/app/models/datastreams/properties_datastream.rb +0 -4
- data/app/models/sufia/orcid_validator.rb +0 -8
- data/app/models/user_stat.rb +0 -2
- data/lib/generators/sufia/models/abstract_migration_generator.rb +0 -30
- data/lib/generators/sufia/models/orcid_field_generator.rb +0 -19
- data/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +0 -5
- data/lib/generators/sufia/models/templates/migrations/create_user_stats.rb +0 -19
- data/lib/generators/sufia/models/user_stats_generator.rb +0 -31
- data/lib/sufia/models/stats/user_stat_importer.rb +0 -85
- data/lib/tasks/stats_tasks.rake +0 -12
@@ -9,10 +9,10 @@ class LocalAuthority < ActiveRecord::Base
|
|
9
9
|
return unless self.where(name: name).empty?
|
10
10
|
authority = self.create(name: name)
|
11
11
|
format = opts.fetch(:format, :ntriples)
|
12
|
-
predicate = opts.fetch(:predicate, RDF::SKOS.prefLabel)
|
12
|
+
predicate = opts.fetch(:predicate, ::RDF::SKOS.prefLabel)
|
13
13
|
entries = []
|
14
14
|
sources.each do |uri|
|
15
|
-
RDF::Reader.open(uri, format: format) do |reader|
|
15
|
+
::RDF::Reader.open(uri, format: format) do |reader|
|
16
16
|
reader.each_statement do |statement|
|
17
17
|
if statement.predicate == predicate
|
18
18
|
entries << LocalAuthorityEntry.new(local_authority: authority,
|
@@ -78,7 +78,7 @@ class ProxyDepositRequest < ActiveRecord::Base
|
|
78
78
|
|
79
79
|
def title
|
80
80
|
return 'file not found' if deleted_file?
|
81
|
-
query = ActiveFedora::
|
81
|
+
query = ActiveFedora::SolrQueryBuilder.construct_query_for_ids([pid])
|
82
82
|
solr_response = ActiveFedora::SolrService.query(query, raw: true)
|
83
83
|
SolrDocument.new(solr_response['response']['docs'].first, solr_response).title
|
84
84
|
end
|
@@ -9,11 +9,11 @@ module Sufia
|
|
9
9
|
|
10
10
|
@minter = ::Noid::Minter.new(template: noid_template)
|
11
11
|
@pid = $$
|
12
|
-
|
12
|
+
#@namespace = Sufia.config.id_namespace
|
13
13
|
@semaphore = Mutex.new
|
14
14
|
def self.valid?(identifier)
|
15
15
|
# remove the fedora namespace since it's not part of the noid
|
16
|
-
noid = identifier
|
16
|
+
noid = identifier#.split(":").last
|
17
17
|
return @minter.valid? noid
|
18
18
|
end
|
19
19
|
def self.mint
|
@@ -28,20 +28,20 @@ module Sufia
|
|
28
28
|
protected
|
29
29
|
|
30
30
|
def self.next_id
|
31
|
-
|
31
|
+
id = ''
|
32
32
|
File.open(Sufia.config.minter_statefile, File::RDWR|File::CREAT, 0644) do |f|
|
33
33
|
f.flock(File::LOCK_EX)
|
34
34
|
yaml = YAML::load(f.read)
|
35
35
|
yaml = {template: noid_template} unless yaml
|
36
36
|
minter = ::Noid::Minter.new(yaml)
|
37
|
-
|
37
|
+
id = minter.mint
|
38
38
|
f.rewind
|
39
39
|
yaml = YAML::dump(minter.dump)
|
40
40
|
f.write yaml
|
41
41
|
f.flush
|
42
42
|
f.truncate(f.pos)
|
43
43
|
end
|
44
|
-
|
44
|
+
id
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/app/services/sufia/noid.rb
CHANGED
@@ -2,16 +2,14 @@ module Sufia
|
|
2
2
|
module Noid
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Sufia::IdService.mint
|
10
|
-
end
|
5
|
+
## This overrides the default behavior, which is to ask Fedora for a pid
|
6
|
+
# @see ActiveFedora::Sharding.assign_pid
|
7
|
+
def assign_pid
|
8
|
+
Sufia::IdService.mint
|
11
9
|
end
|
12
10
|
|
13
11
|
def noid
|
14
|
-
Noid.noidify(
|
12
|
+
Noid.noidify(id)
|
15
13
|
end
|
16
14
|
|
17
15
|
# Redefine this for more intuitive keys in Redis
|
@@ -24,6 +22,11 @@ module Sufia
|
|
24
22
|
String(identifier).split(":").last
|
25
23
|
end
|
26
24
|
|
25
|
+
# Create a pairtree like path for the given identifier
|
26
|
+
def treeify(identifier)
|
27
|
+
(identifier.scan(/..?/).first(4) + [identifier]).join('/')
|
28
|
+
end
|
29
|
+
|
27
30
|
def namespaceize(identifier)
|
28
31
|
return identifier if identifier.include?(':')
|
29
32
|
"#{namespace}:#{identifier}"
|
@@ -1,12 +1,30 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
class Sufia::Models::CachedStatsGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
2
7
|
|
3
|
-
class Sufia::Models::CachedStatsGenerator < Sufia::Models::AbstractMigrationGenerator
|
4
8
|
source_root File.expand_path('../templates', __FILE__)
|
5
9
|
|
6
10
|
desc """
|
7
11
|
This generator adds the ability to cache usage stats to your application:
|
8
12
|
1. Creates several database migrations if they do not exist in /db/migrate
|
9
13
|
"""
|
14
|
+
# Implement the required interface for Rails::Generators::Migration.
|
15
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
16
|
+
def self.next_migration_number(path)
|
17
|
+
if @prev_migration_nr
|
18
|
+
@prev_migration_nr += 1
|
19
|
+
else
|
20
|
+
if last_migration = Dir[File.join(path, '*.rb')].sort.last
|
21
|
+
@prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
|
22
|
+
else
|
23
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@prev_migration_nr.to_s
|
27
|
+
end
|
10
28
|
|
11
29
|
def banner
|
12
30
|
say_status("warning", "ADDING STATS CACHING-RELATED SUFIA MODELS", :yellow)
|
@@ -14,6 +32,7 @@ This generator adds the ability to cache usage stats to your application:
|
|
14
32
|
|
15
33
|
# Setup the database migrations
|
16
34
|
def copy_migrations
|
35
|
+
# Can't get this any more DRY, because we need this order.
|
17
36
|
[
|
18
37
|
'create_file_view_stats.rb',
|
19
38
|
'create_file_download_stats.rb'
|
@@ -21,4 +40,14 @@ This generator adds the ability to cache usage stats to your application:
|
|
21
40
|
better_migration_template file
|
22
41
|
end
|
23
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def better_migration_template(file)
|
47
|
+
begin
|
48
|
+
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
49
|
+
rescue Rails::Generators::Error => e
|
50
|
+
say_status("warning", e.message, :yellow)
|
51
|
+
end
|
52
|
+
end
|
24
53
|
end
|
@@ -1,7 +1,12 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
class Sufia::Models::InstallGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
2
7
|
|
3
|
-
class Sufia::Models::InstallGenerator < Sufia::Models::AbstractMigrationGenerator
|
4
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
5
10
|
argument :model_name, type: :string , default: "user"
|
6
11
|
desc """
|
7
12
|
This generator makes the following changes to your application:
|
@@ -14,15 +19,30 @@ This generator makes the following changes to your application:
|
|
14
19
|
7. Runs full-text generator
|
15
20
|
8. Runs proxies generator
|
16
21
|
9. Runs cached stats generator
|
17
|
-
10. Runs ORCID field generator
|
18
|
-
11. Runs user stats generator
|
19
22
|
"""
|
23
|
+
|
24
|
+
# Implement the required interface for Rails::Generators::Migration.
|
25
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
26
|
+
def self.next_migration_number(path)
|
27
|
+
if @prev_migration_nr
|
28
|
+
@prev_migration_nr += 1
|
29
|
+
else
|
30
|
+
if last_migration = Dir[File.join(path, '*.rb')].sort.last
|
31
|
+
@prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
|
32
|
+
else
|
33
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@prev_migration_nr.to_s
|
37
|
+
end
|
38
|
+
|
20
39
|
def banner
|
21
40
|
say_status("warning", "GENERATING SUFIA MODELS", :yellow)
|
22
41
|
end
|
23
42
|
|
24
43
|
# Setup the database migrations
|
25
44
|
def copy_migrations
|
45
|
+
# Can't get this any more DRY, because we need this order.
|
26
46
|
[
|
27
47
|
"acts_as_follower_migration.rb",
|
28
48
|
"add_social_to_users.rb",
|
@@ -94,13 +114,13 @@ This generator makes the following changes to your application:
|
|
94
114
|
generate 'sufia:models:cached_stats'
|
95
115
|
end
|
96
116
|
|
97
|
-
|
98
|
-
def orcid_field
|
99
|
-
generate 'sufia:models:orcid_field'
|
100
|
-
end
|
117
|
+
private
|
101
118
|
|
102
|
-
|
103
|
-
|
104
|
-
|
119
|
+
def better_migration_template(file)
|
120
|
+
begin
|
121
|
+
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
122
|
+
rescue Rails::Generators::Error => e
|
123
|
+
say_status("warning", e.message, :yellow)
|
124
|
+
end
|
105
125
|
end
|
106
126
|
end
|
@@ -1,12 +1,30 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
class Sufia::Models::ProxiesGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
2
7
|
|
3
|
-
class Sufia::Models::ProxiesGenerator < Sufia::Models::AbstractMigrationGenerator
|
4
8
|
source_root File.expand_path('../templates', __FILE__)
|
5
9
|
|
6
10
|
desc """
|
7
11
|
This generator adds proxies and transfers to your application:
|
8
12
|
1. Creates several database migrations if they do not exist in /db/migrate
|
9
13
|
"""
|
14
|
+
# Implement the required interface for Rails::Generators::Migration.
|
15
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
16
|
+
def self.next_migration_number(path)
|
17
|
+
if @prev_migration_nr
|
18
|
+
@prev_migration_nr += 1
|
19
|
+
else
|
20
|
+
if last_migration = Dir[File.join(path, '*.rb')].sort.last
|
21
|
+
@prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
|
22
|
+
else
|
23
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@prev_migration_nr.to_s
|
27
|
+
end
|
10
28
|
|
11
29
|
def banner
|
12
30
|
say_status("warning", "ADDING PROXY/TRANSFER-RELATED SUFIA MODELS", :yellow)
|
@@ -14,6 +32,7 @@ This generator adds proxies and transfers to your application:
|
|
14
32
|
|
15
33
|
# Setup the database migrations
|
16
34
|
def copy_migrations
|
35
|
+
# Can't get this any more DRY, because we need this order.
|
17
36
|
[
|
18
37
|
'create_proxy_deposit_rights.rb',
|
19
38
|
'create_proxy_deposit_requests.rb'
|
@@ -21,4 +40,14 @@ This generator adds proxies and transfers to your application:
|
|
21
40
|
better_migration_template file
|
22
41
|
end
|
23
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def better_migration_template(file)
|
47
|
+
begin
|
48
|
+
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
49
|
+
rescue Rails::Generators::Error => e
|
50
|
+
say_status("warning", e.message, :yellow)
|
51
|
+
end
|
52
|
+
end
|
24
53
|
end
|
@@ -93,9 +93,6 @@ Sufia.config do |config|
|
|
93
93
|
# Specify a Google Analytics tracking ID to gather usage statistics
|
94
94
|
# config.google_analytics_id = 'UA-99999999-1'
|
95
95
|
|
96
|
-
# Specify a date you wish to start collecting Google Analytic statistics for.
|
97
|
-
# config.analytic_start_date = DateTime.new(2014,9,10)
|
98
|
-
|
99
96
|
# Where to store tempfiles, leave blank for the system temp directory (e.g. /tmp)
|
100
97
|
# config.temp_file_base = '/home/developer1'
|
101
98
|
|
@@ -111,6 +108,16 @@ Sufia.config do |config|
|
|
111
108
|
# Specify how many seconds back from the current time that we should show by default of the user's activity on the user's dashboard
|
112
109
|
# config.activity_to_show_default_seconds_since_now = 24*60*60
|
113
110
|
|
111
|
+
# Specify a date you wish to start collecting Google Analytic statistics for.
|
112
|
+
# Leaving it blank will set the start date to when ever the file was uploaded by
|
113
|
+
# NOTE: if you have always sent analytics to GA for downloads and page views leave this commented out
|
114
|
+
# config.analytic_start_date = DateTime.new(2014,9,10)
|
115
|
+
#
|
116
|
+
# Method of converting pids into URIs for storage in Fedora
|
117
|
+
# config.translate_uri_to_id = lambda { |uri| uri.to_s.split('/')[-1] }
|
118
|
+
# config.translate_id_to_uri = lambda { |id|
|
119
|
+
# "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{Sufia::Noid.treeify(id)}" }
|
120
|
+
|
114
121
|
# If browse-everything has been configured, load the configs. Otherwise, set to nil.
|
115
122
|
begin
|
116
123
|
if defined? BrowseEverything
|
@@ -1,8 +1,13 @@
|
|
1
|
-
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/migration'
|
4
|
+
|
5
|
+
class Sufia::Models::Upgrade400Generator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
2
7
|
|
3
|
-
class Sufia::Models::Upgrade400Generator < Sufia::Models::AbstractMigrationGenerator
|
4
8
|
source_root File.expand_path('../templates', __FILE__)
|
5
9
|
|
10
|
+
argument :model_name, type: :string , default: "user"
|
6
11
|
desc """
|
7
12
|
This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following changes to your application:
|
8
13
|
1. Creates several database migrations if they do not exist in /db/migrate
|
@@ -11,12 +16,28 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
|
|
11
16
|
4. Runs full-text generator
|
12
17
|
"""
|
13
18
|
|
19
|
+
# Implement the required interface for Rails::Generators::Migration.
|
20
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
21
|
+
def self.next_migration_number(path)
|
22
|
+
if @prev_migration_nr
|
23
|
+
@prev_migration_nr += 1
|
24
|
+
else
|
25
|
+
if last_migration = Dir[File.join(path, '*.rb')].sort.last
|
26
|
+
@prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
|
27
|
+
else
|
28
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@prev_migration_nr.to_s
|
32
|
+
end
|
33
|
+
|
14
34
|
def banner
|
15
35
|
say_status("warning", "UPGRADING SUFIA MODELS", :yellow)
|
16
36
|
end
|
17
37
|
|
18
38
|
# Setup the database migrations
|
19
39
|
def copy_migrations
|
40
|
+
# Can't get this any more DRY, because we need this order.
|
20
41
|
[
|
21
42
|
'create_tinymce_assets.rb',
|
22
43
|
'create_content_blocks.rb',
|
@@ -51,4 +72,14 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
|
|
51
72
|
def full_text_indexing
|
52
73
|
generate "sufia:models:fulltext"
|
53
74
|
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def better_migration_template(file)
|
79
|
+
begin
|
80
|
+
migration_template "migrations/#{file}", "db/migrate/#{file}"
|
81
|
+
rescue Rails::Generators::Error => e
|
82
|
+
say_status("warning", e.message, :yellow)
|
83
|
+
end
|
84
|
+
end
|
54
85
|
end
|
data/lib/sufia/models/engine.rb
CHANGED
@@ -31,6 +31,10 @@ module Sufia
|
|
31
31
|
# Defaulting analytic start date to when ever the file was uploaded by leaving it blank
|
32
32
|
config.analytic_start_date = nil
|
33
33
|
|
34
|
+
config.translate_uri_to_id = lambda { |uri| uri.to_s.split('/')[-1] }
|
35
|
+
config.translate_id_to_uri = lambda { |id|
|
36
|
+
"#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{Sufia::Noid.treeify(id)}" }
|
37
|
+
|
34
38
|
config.autoload_paths += %W(
|
35
39
|
#{config.root}/app/models/datastreams
|
36
40
|
)
|
@@ -58,10 +62,15 @@ module Sufia
|
|
58
62
|
end
|
59
63
|
|
60
64
|
initializer 'configure' do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
Sufia.config.tap do |c|
|
66
|
+
Hydra::Derivatives.ffmpeg_path = c.ffmpeg_path
|
67
|
+
Hydra::Derivatives.temp_file_base = c.temp_file_base
|
68
|
+
Hydra::Derivatives.fits_path = c.fits_path
|
69
|
+
Hydra::Derivatives.enable_ffmpeg = c.enable_ffmpeg
|
70
|
+
|
71
|
+
ActiveFedora::Base.translate_uri_to_id = c.translate_uri_to_id
|
72
|
+
ActiveFedora::Base.translate_id_to_uri = c.translate_id_to_uri
|
73
|
+
end
|
65
74
|
end
|
66
75
|
end
|
67
76
|
end
|
@@ -1,23 +1,27 @@
|
|
1
1
|
module Sufia
|
2
2
|
module FileContent
|
3
3
|
module Versions
|
4
|
-
|
5
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_many_versions
|
6
8
|
end
|
7
9
|
|
8
10
|
def latest_version
|
9
|
-
|
11
|
+
versions.last.label unless versions.empty?
|
10
12
|
end
|
11
13
|
|
12
14
|
def version_committer(version)
|
13
|
-
vc = VersionCommitter.where(
|
14
|
-
datastream_id: version.dsid,
|
15
|
-
version_id: version.versionID)
|
15
|
+
vc = VersionCommitter.where(version_id: version)
|
16
16
|
return vc.empty? ? nil : vc.first.committer_login
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
def save
|
20
|
+
super.tap do |passing|
|
21
|
+
create_version if passing
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
23
|
-
|
data/lib/sufia/models/version.rb
CHANGED
@@ -8,32 +8,50 @@ module Sufia
|
|
8
8
|
include Hydra::AccessControls::Visibility
|
9
9
|
|
10
10
|
included do
|
11
|
-
has_metadata "rightsMetadata", type: ParanoidRightsDatastream
|
12
11
|
validate :paranoid_permissions
|
13
12
|
end
|
14
13
|
|
15
14
|
def paranoid_permissions
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
valid = true
|
16
|
+
VALIDATIONS.each do |validation|
|
17
|
+
if validation[:condition].call(self)
|
18
|
+
errors[validation[:key]] ||= []
|
19
|
+
errors[validation[:key]] << validation[:message]
|
20
|
+
valid = false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return valid
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
VALIDATIONS = [
|
27
|
+
{key: :edit_users, message: 'Depositor must have edit access', condition: lambda { |obj| !obj.edit_users.include?(obj.depositor) }},
|
28
|
+
{key: :edit_groups, message: 'Public cannot have edit access', condition: lambda { |obj| obj.edit_groups.include?('public') }},
|
29
|
+
{key: :edit_groups, message: 'Registered cannot have edit access', condition: lambda { |obj| obj.edit_groups.include?('registered') }}
|
30
|
+
]
|
26
31
|
|
27
|
-
params[:user].each { |name, access| perm_hash['person'][name] = access} if params[:user]
|
28
|
-
params[:group].each { |name, access| perm_hash['group'][name] = access if ['read', 'edit'].include?(access)} if params[:group]
|
29
32
|
|
30
|
-
|
33
|
+
def clear_permissions!
|
34
|
+
self.permissions = []
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
## Updates those permissions that are provided to it. Does not replace any permissions unless they are provided
|
38
|
+
# def permissions=(params)
|
39
|
+
# raise "Fixme #{params}"
|
40
|
+
# perm_hash = permission_hash
|
41
|
+
# params[:new_user_name].each { |name, access| perm_hash['person'][name] = access } if params[:new_user_name].present?
|
42
|
+
# params[:new_group_name].each { |name, access| perm_hash['group'][name] = access } if params[:new_group_name].present?
|
43
|
+
|
44
|
+
# params[:user].each { |name, access| perm_hash['person'][name] = access} if params[:user]
|
45
|
+
# params[:group].each { |name, access| perm_hash['group'][name] = access if ['read', 'edit'].include?(access)} if params[:group]
|
46
|
+
|
47
|
+
# # rightsMetadata.update_permissions(perm_hash)
|
48
|
+
# end
|
49
|
+
|
50
|
+
# def permissions
|
51
|
+
# raise "Fixme "
|
52
|
+
# perms = super
|
53
|
+
# perms.map {|p| { name: p.name, access: p.access, type:p.type } }
|
54
|
+
# end
|
37
55
|
|
38
56
|
private
|
39
57
|
|