sufia-models 5.0.0 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/actors/sufia/generic_file/actor.rb +8 -10
- data/app/jobs/active_fedora_pid_based_job.rb +2 -3
- data/app/jobs/audit_job.rb +46 -32
- 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 +12 -10
- data/app/models/concerns/sufia/ability.rb +4 -6
- data/app/models/concerns/sufia/collection.rb +4 -5
- data/app/models/concerns/sufia/generic_file/batches.rb +29 -0
- data/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
- data/app/models/concerns/sufia/generic_file/content.rb +13 -0
- data/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
- data/app/models/concerns/sufia/generic_file/export.rb +4 -0
- data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
- data/app/models/concerns/sufia/generic_file/indexing.rb +23 -0
- data/app/models/concerns/sufia/generic_file/metadata.rb +80 -11
- data/app/models/concerns/sufia/generic_file/proxy_deposit.rb +12 -3
- data/app/models/concerns/sufia/generic_file/versions.rb +4 -4
- data/app/models/concerns/sufia/generic_file/web_form.rb +14 -6
- data/app/models/concerns/sufia/generic_file.rb +3 -86
- data/app/models/concerns/sufia/model_methods.rb +11 -9
- data/app/models/concerns/sufia/user.rb +11 -33
- data/app/models/datastreams/file_content_datastream.rb +1 -1
- data/app/models/datastreams/fits_datastream.rb +1 -1
- data/app/models/file_usage.rb +3 -3
- data/app/models/local_authority.rb +2 -2
- data/app/models/proxy_deposit_request.rb +1 -1
- data/app/services/sufia/generic_file_audit_service.rb +83 -0
- data/app/services/sufia/id_service.rb +5 -5
- data/app/services/sufia/noid.rb +10 -7
- data/app/services/sufia/repository_audit_service.rb +9 -0
- data/lib/generators/sufia/models/cached_stats_generator.rb +47 -3
- 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 -0
- 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 +9 -11
- data/lib/sufia/models/stats/user_stat_importer.rb +5 -9
- data/lib/sufia/models/version.rb +1 -1
- data/lib/sufia/permissions/writable.rb +34 -16
- data/sufia-models.gemspec +4 -2
- metadata +54 -33
- data/app/models/concerns/sufia/generic_file/audit.rb +0 -116
- 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/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/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/user_stats_generator.rb +0 -31
@@ -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
|
@@ -111,6 +111,16 @@ Sufia.config do |config|
|
|
111
111
|
# 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
112
|
# config.activity_to_show_default_seconds_since_now = 24*60*60
|
113
113
|
|
114
|
+
# Specify a date you wish to start collecting Google Analytic statistics for.
|
115
|
+
# Leaving it blank will set the start date to when ever the file was uploaded by
|
116
|
+
# NOTE: if you have always sent analytics to GA for downloads and page views leave this commented out
|
117
|
+
# config.analytic_start_date = DateTime.new(2014,9,10)
|
118
|
+
#
|
119
|
+
# Method of converting pids into URIs for storage in Fedora
|
120
|
+
# config.translate_uri_to_id = lambda { |uri| uri.to_s.split('/')[-1] }
|
121
|
+
# config.translate_id_to_uri = lambda { |id|
|
122
|
+
# "#{ActiveFedora.fedora.host}#{ActiveFedora.fedora.base_path}/#{Sufia::Noid.treeify(id)}" }
|
123
|
+
|
114
124
|
# If browse-everything has been configured, load the configs. Otherwise, set to nil.
|
115
125
|
begin
|
116
126
|
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,21 @@
|
|
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 unless versions.empty?
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
return vc.empty? ? nil : vc.first.committer_login
|
14
|
+
def save
|
15
|
+
super.tap do |passing|
|
16
|
+
create_version if passing
|
17
|
+
end
|
17
18
|
end
|
18
|
-
|
19
|
-
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
23
|
-
|
@@ -12,11 +12,11 @@ module Sufia
|
|
12
12
|
start_date = date_since_last_cache(user)
|
13
13
|
|
14
14
|
stats = {}
|
15
|
-
|
16
|
-
view_stats = FileViewStat.statistics(
|
15
|
+
files_for_user(user).each do |file|
|
16
|
+
view_stats = FileViewStat.statistics(file.id, start_date, user.id)
|
17
17
|
stats = tally_results(view_stats, :views, stats)
|
18
18
|
|
19
|
-
dl_stats = FileDownloadStat.statistics(
|
19
|
+
dl_stats = FileDownloadStat.statistics(file.id, start_date, user.id)
|
20
20
|
stats = tally_results(dl_stats, :downloads, stats)
|
21
21
|
end
|
22
22
|
|
@@ -38,12 +38,8 @@ private
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
42
|
-
|
43
|
-
::GenericFile.find_in_batches("#{Solrizer.solr_name('depositor', :symbol)}:\"#{user.user_key}\"", fl:"id") do |group|
|
44
|
-
ids.concat group.map { |doc| doc["id"] }
|
45
|
-
end
|
46
|
-
ids
|
41
|
+
def files_for_user(user)
|
42
|
+
::GenericFile.where(Solrizer.solr_name('depositor', :symbol) => user.user_key)
|
47
43
|
end
|
48
44
|
|
49
45
|
# For each date, add the view and download counts for this
|
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
|
|
data/sufia-models.gemspec
CHANGED
@@ -29,7 +29,10 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_dependency 'rails', '~> 4.0', '< 5.0.0'
|
30
30
|
spec.add_dependency 'activeresource', "~> 4.0" # No longer a dependency of rails 4.0
|
31
31
|
|
32
|
-
spec.add_dependency "hydra-head", "~>
|
32
|
+
spec.add_dependency "hydra-head", "~> 9.0.0.beta1"
|
33
|
+
spec.add_dependency "active-fedora", "~> 9.0.0.beta5"
|
34
|
+
spec.add_dependency "hydra-collections", "~> 4.0.0.beta1"
|
35
|
+
spec.add_dependency 'hydra-derivatives', '~> 1.0.0.beta1'
|
33
36
|
spec.add_dependency 'nest', '~> 1.1'
|
34
37
|
spec.add_dependency 'resque', '~> 1.23'
|
35
38
|
spec.add_dependency 'resque-pool', '~> 0.3'
|
@@ -37,7 +40,6 @@ Gem::Specification.new do |spec|
|
|
37
40
|
spec.add_dependency 'mailboxer', '~> 0.12'
|
38
41
|
spec.add_dependency 'acts_as_follower', '>= 0.1.1', '< 0.3'
|
39
42
|
spec.add_dependency 'carrierwave', '~> 0.9'
|
40
|
-
spec.add_dependency 'hydra-derivatives', '~> 0.1'
|
41
43
|
spec.add_dependency 'oauth2', '~> 0.9'
|
42
44
|
spec.add_dependency 'google-api-client', '~> 0.7'
|
43
45
|
spec.add_dependency 'legato', '~> 0.3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sufia-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,14 +78,56 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 9.0.0.beta1
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 9.0.0.beta1
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: active-fedora
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 9.0.0.beta5
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 9.0.0.beta5
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: hydra-collections
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 4.0.0.beta1
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 4.0.0.beta1
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: hydra-derivatives
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 1.0.0.beta1
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.0.0.beta1
|
89
131
|
- !ruby/object:Gem::Dependency
|
90
132
|
name: nest
|
91
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,20 +232,6 @@ dependencies:
|
|
190
232
|
- - "~>"
|
191
233
|
- !ruby/object:Gem::Version
|
192
234
|
version: '0.9'
|
193
|
-
- !ruby/object:Gem::Dependency
|
194
|
-
name: hydra-derivatives
|
195
|
-
requirement: !ruby/object:Gem::Requirement
|
196
|
-
requirements:
|
197
|
-
- - "~>"
|
198
|
-
- !ruby/object:Gem::Version
|
199
|
-
version: '0.1'
|
200
|
-
type: :runtime
|
201
|
-
prerelease: false
|
202
|
-
version_requirements: !ruby/object:Gem::Requirement
|
203
|
-
requirements:
|
204
|
-
- - "~>"
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
version: '0.1'
|
207
235
|
- !ruby/object:Gem::Dependency
|
208
236
|
name: oauth2
|
209
237
|
requirement: !ruby/object:Gem::Requirement
|
@@ -302,31 +330,27 @@ files:
|
|
302
330
|
- app/models/concerns/sufia/file_stat_utils.rb
|
303
331
|
- app/models/concerns/sufia/generic_file.rb
|
304
332
|
- app/models/concerns/sufia/generic_file/accessible_attributes.rb
|
305
|
-
- app/models/concerns/sufia/generic_file/
|
333
|
+
- app/models/concerns/sufia/generic_file/batches.rb
|
306
334
|
- app/models/concerns/sufia/generic_file/characterization.rb
|
335
|
+
- app/models/concerns/sufia/generic_file/content.rb
|
307
336
|
- app/models/concerns/sufia/generic_file/derivatives.rb
|
308
337
|
- app/models/concerns/sufia/generic_file/export.rb
|
309
338
|
- app/models/concerns/sufia/generic_file/featured.rb
|
310
339
|
- app/models/concerns/sufia/generic_file/full_text_indexing.rb
|
340
|
+
- app/models/concerns/sufia/generic_file/indexing.rb
|
311
341
|
- app/models/concerns/sufia/generic_file/metadata.rb
|
312
342
|
- app/models/concerns/sufia/generic_file/mime_types.rb
|
313
343
|
- app/models/concerns/sufia/generic_file/permissions.rb
|
314
344
|
- app/models/concerns/sufia/generic_file/proxy_deposit.rb
|
315
|
-
- app/models/concerns/sufia/generic_file/reload_on_save.rb
|
316
345
|
- app/models/concerns/sufia/generic_file/trophies.rb
|
317
346
|
- app/models/concerns/sufia/generic_file/versions.rb
|
318
347
|
- app/models/concerns/sufia/generic_file/virus_check.rb
|
319
348
|
- app/models/concerns/sufia/generic_file/web_form.rb
|
320
349
|
- app/models/concerns/sufia/model_methods.rb
|
321
|
-
- app/models/concerns/sufia/properties_datastream_behavior.rb
|
322
350
|
- app/models/concerns/sufia/user.rb
|
323
351
|
- app/models/concerns/sufia/user_usage_stats.rb
|
324
|
-
- app/models/datastreams/batch_rdf_datastream.rb
|
325
352
|
- app/models/datastreams/file_content_datastream.rb
|
326
353
|
- app/models/datastreams/fits_datastream.rb
|
327
|
-
- app/models/datastreams/generic_file_rdf_datastream.rb
|
328
|
-
- app/models/datastreams/paranoid_rights_datastream.rb
|
329
|
-
- app/models/datastreams/properties_datastream.rb
|
330
354
|
- app/models/domain_term.rb
|
331
355
|
- app/models/featured_work.rb
|
332
356
|
- app/models/file_download_stat.rb
|
@@ -345,20 +369,19 @@ files:
|
|
345
369
|
- app/models/sufia/avatar_uploader.rb
|
346
370
|
- app/models/sufia/avatar_validator.rb
|
347
371
|
- app/models/sufia/download.rb
|
348
|
-
- app/models/sufia/orcid_validator.rb
|
349
372
|
- app/models/sufia/pageview.rb
|
350
373
|
- app/models/trophy.rb
|
351
374
|
- app/models/user_stat.rb
|
352
375
|
- app/models/version_committer.rb
|
353
376
|
- app/services/sufia/analytics.rb
|
377
|
+
- app/services/sufia/generic_file_audit_service.rb
|
354
378
|
- app/services/sufia/id_service.rb
|
355
379
|
- app/services/sufia/noid.rb
|
380
|
+
- app/services/sufia/repository_audit_service.rb
|
356
381
|
- config/locales/sufia.en.yml
|
357
|
-
- lib/generators/sufia/models/abstract_migration_generator.rb
|
358
382
|
- lib/generators/sufia/models/cached_stats_generator.rb
|
359
383
|
- lib/generators/sufia/models/fulltext_generator.rb
|
360
384
|
- lib/generators/sufia/models/install_generator.rb
|
361
|
-
- lib/generators/sufia/models/orcid_field_generator.rb
|
362
385
|
- lib/generators/sufia/models/proxies_generator.rb
|
363
386
|
- lib/generators/sufia/models/templates/config/analytics.yml
|
364
387
|
- lib/generators/sufia/models/templates/config/clamav.rb
|
@@ -377,7 +400,6 @@ files:
|
|
377
400
|
- lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb
|
378
401
|
- lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb
|
379
402
|
- lib/generators/sufia/models/templates/migrations/add_linkedin_to_users.rb
|
380
|
-
- lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb
|
381
403
|
- lib/generators/sufia/models/templates/migrations/add_social_to_users.rb
|
382
404
|
- lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb
|
383
405
|
- lib/generators/sufia/models/templates/migrations/create_content_blocks.rb
|
@@ -394,7 +416,6 @@ files:
|
|
394
416
|
- lib/generators/sufia/models/templates/migrations/create_version_committers.rb
|
395
417
|
- lib/generators/sufia/models/upgrade400_generator.rb
|
396
418
|
- lib/generators/sufia/models/usagestats_generator.rb
|
397
|
-
- lib/generators/sufia/models/user_stats_generator.rb
|
398
419
|
- lib/sufia/messages.rb
|
399
420
|
- lib/sufia/models.rb
|
400
421
|
- lib/sufia/models/active_fedora/redis.rb
|
@@ -430,12 +451,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
430
451
|
version: '0'
|
431
452
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
432
453
|
requirements:
|
433
|
-
- - "
|
454
|
+
- - ">"
|
434
455
|
- !ruby/object:Gem::Version
|
435
|
-
version:
|
456
|
+
version: 1.3.1
|
436
457
|
requirements: []
|
437
458
|
rubyforge_project:
|
438
|
-
rubygems_version: 2.
|
459
|
+
rubygems_version: 2.2.2
|
439
460
|
signing_key:
|
440
461
|
specification_version: 4
|
441
462
|
summary: Models and services for sufia
|
@@ -1,116 +0,0 @@
|
|
1
|
-
module Sufia
|
2
|
-
module GenericFile
|
3
|
-
module Audit
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
NO_RUNS = 999
|
7
|
-
|
8
|
-
def audit(force = false)
|
9
|
-
logs = []
|
10
|
-
self.per_version do |ver|
|
11
|
-
logs << audit_each(ver, force)
|
12
|
-
end
|
13
|
-
logs
|
14
|
-
end
|
15
|
-
|
16
|
-
def per_version(&block)
|
17
|
-
self.datastreams.each do |dsid, ds|
|
18
|
-
next if ds == full_text
|
19
|
-
ds.versions.each do |ver|
|
20
|
-
block.call(ver)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def logs(dsid)
|
26
|
-
ChecksumAuditLog.where(dsid: dsid, pid: self.pid).order('created_at desc, id desc')
|
27
|
-
end
|
28
|
-
|
29
|
-
def audit!
|
30
|
-
audit(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
def audit_stat!
|
34
|
-
audit_stat(true)
|
35
|
-
end
|
36
|
-
|
37
|
-
def audit_stat(force = false)
|
38
|
-
logs = audit(force)
|
39
|
-
audit_results = logs.collect { |result| result["pass"] }
|
40
|
-
|
41
|
-
# check how many non runs we had
|
42
|
-
non_runs = audit_results.reduce(0) { |sum, value| value == NO_RUNS ? sum += 1 : sum }
|
43
|
-
if non_runs == 0
|
44
|
-
result = audit_results.reduce(true) { |sum, value| sum && value }
|
45
|
-
return result
|
46
|
-
elsif non_runs < audit_results.length
|
47
|
-
result = audit_results.reduce(true) { |sum, value| value == NO_RUNS ? sum : sum && value }
|
48
|
-
return 'Some audits have not been run, but the ones run were '+ ((result)? 'passing' : 'failing') + '.'
|
49
|
-
else
|
50
|
-
return 'Audits have not yet been run on this file.'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def audit_each(version, force = false)
|
55
|
-
latest_audit = logs(version.dsid).first
|
56
|
-
return latest_audit unless force || ::GenericFile.needs_audit?(version, latest_audit)
|
57
|
-
|
58
|
-
# Resque.enqueue(AuditJob, version.pid, version.dsid, version.versionID)
|
59
|
-
Sufia.queue.push(AuditJob.new(version.pid, version.dsid, version.versionID))
|
60
|
-
|
61
|
-
# run the find just incase the job has finished already
|
62
|
-
latest_audit = logs(version.dsid).first
|
63
|
-
latest_audit = ChecksumAuditLog.new(pass: NO_RUNS, pid: version.pid, dsid: version.dsid, version: version.versionID) unless latest_audit
|
64
|
-
latest_audit
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
module ClassMethods
|
69
|
-
def audit!(version)
|
70
|
-
::GenericFile.audit(version, true)
|
71
|
-
end
|
72
|
-
|
73
|
-
def audit(version, force = false)
|
74
|
-
latest_audit = self.find(version.pid).audit_each( version, force)
|
75
|
-
end
|
76
|
-
|
77
|
-
def needs_audit?(version, latest_audit)
|
78
|
-
if latest_audit and latest_audit.updated_at
|
79
|
-
days_since_last_audit = (DateTime.now - latest_audit.updated_at.to_date).to_i
|
80
|
-
if days_since_last_audit < Sufia.config.max_days_between_audits
|
81
|
-
return false
|
82
|
-
end
|
83
|
-
else
|
84
|
-
logger.warn "***AUDIT*** problem with audit log! Latest Audit is not nil, but updated_at is not set #{latest_audit}" unless latest_audit.nil?
|
85
|
-
end
|
86
|
-
true
|
87
|
-
end
|
88
|
-
|
89
|
-
def audit_everything(force = false)
|
90
|
-
::GenericFile.find_each do |gf|
|
91
|
-
gf.per_version do |ver|
|
92
|
-
::GenericFile.audit(ver, force)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def audit_everything!
|
98
|
-
::GenericFile.audit_everything(true)
|
99
|
-
end
|
100
|
-
|
101
|
-
def run_audit(version)
|
102
|
-
if version.dsChecksumValid
|
103
|
-
passing = 1
|
104
|
-
ChecksumAuditLog.prune_history(version)
|
105
|
-
else
|
106
|
-
logger.warn "***AUDIT*** Audit failed for #{version.pid} #{version.versionID}"
|
107
|
-
passing = 0
|
108
|
-
end
|
109
|
-
check = ChecksumAuditLog.create!(pass: passing, pid: version.pid,
|
110
|
-
dsid: version.dsid, version: version.versionID)
|
111
|
-
check
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# add this in here until we can use a version of Active Fedora that contains this ability
|
2
|
-
module Sufia
|
3
|
-
module GenericFile
|
4
|
-
module ReloadOnSave
|
5
|
-
|
6
|
-
attr_writer :reload_on_save
|
7
|
-
|
8
|
-
def reload_on_save?
|
9
|
-
!!@reload_on_save
|
10
|
-
end
|
11
|
-
|
12
|
-
def refresh
|
13
|
-
self.reload if reload_on_save?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|