sufia-models 6.0.0.beta1 → 6.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/sufia/generic_file/actor.rb +1 -1
  3. data/app/jobs/batch_update_job.rb +5 -5
  4. data/app/models/batch.rb +7 -3
  5. data/app/models/concerns/sufia/collection.rb +7 -25
  6. data/app/models/concerns/sufia/generic_file.rb +0 -1
  7. data/app/models/concerns/sufia/generic_file/export.rb +2 -2
  8. data/app/models/concerns/sufia/generic_file/indexing.rb +4 -13
  9. data/app/models/concerns/sufia/generic_file/metadata.rb +1 -1
  10. data/app/models/concerns/sufia/user.rb +24 -17
  11. data/app/models/sufia/orcid_validator.rb +8 -0
  12. data/app/services/sufia/generic_file_indexing_service.rb +13 -0
  13. data/app/services/sufia/indexing_service.rb +15 -0
  14. data/lib/generators/sufia/models/abstract_migration_generator.rb +30 -0
  15. data/lib/generators/sufia/models/cached_stats_generator.rb +3 -47
  16. data/lib/generators/sufia/models/install_generator.rb +11 -31
  17. data/lib/generators/sufia/models/orcid_field_generator.rb +19 -0
  18. data/lib/generators/sufia/models/proxies_generator.rb +2 -31
  19. data/lib/generators/sufia/models/templates/config/redis.yml +3 -0
  20. data/lib/generators/sufia/models/templates/config/sufia.rb +3 -0
  21. data/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +5 -0
  22. data/lib/generators/sufia/models/upgrade400_generator.rb +2 -33
  23. data/lib/generators/sufia/models/user_stats_generator.rb +31 -0
  24. data/lib/sufia/models/engine.rb +1 -0
  25. data/lib/sufia/models/version.rb +1 -1
  26. data/sufia-models.gemspec +5 -5
  27. metadata +19 -14
  28. data/app/models/concerns/sufia/generic_file/accessible_attributes.rb +0 -87
  29. data/app/models/concerns/sufia/generic_file/web_form.rb +0 -62
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4314a9ee6401c790ffce36c91f621c9c3fa9ec4a
4
- data.tar.gz: d8cb9e5007c3d8130ceaf6e59a279f88a03ec622
3
+ metadata.gz: b91961eb43dcfd1c29bfafc09c472ee106c6f44c
4
+ data.tar.gz: 73a99ff722911ef488be5ecc5b6ee5c12a4d10df
5
5
  SHA512:
6
- metadata.gz: b1e0ab2d2b46c88005855ae5d609a9d1f4a474a4c5cfa912ca0f59d29f72f486fbc6d062f04c0949c1287d36a28d17e100747d31fab6eb6b0111be93c2d43a63
7
- data.tar.gz: b174426b321d1921c85264409f27c7f6a5b984a690061a5e81e32755bc309b2f0c5e37abbd4348fe1d8eed293def5fca38e7482eb0aee7207f61cef022be842e
6
+ metadata.gz: bbd507e709ff276f2fbd63571b23c9ecb7b0ba006781a8851ae5cda68e2da671ab118137372763f6373fd9bcea4d4aa476b1e672a8213a4c29b9ac23d2f2fe36
7
+ data.tar.gz: 08cf35ef184ec551b484a199a03accbfa281b8ff414f5d2202f82a2588a5dc684d5b33df2e7831bd2616e266e504845bcdb3abb99a772e7c534f156f65dc9a0f
@@ -56,7 +56,7 @@ module Sufia::GenericFile
56
56
  end
57
57
 
58
58
  def update_metadata(attributes, visibility)
59
- generic_file.attributes = generic_file.sanitize_attributes(attributes)
59
+ generic_file.attributes = attributes
60
60
  update_visibility(visibility)
61
61
  generic_file.date_modified = DateTime.now
62
62
  remove_from_feature_works if generic_file.visibility_changed? && !generic_file.public?
@@ -8,12 +8,12 @@ class BatchUpdateJob
8
8
 
9
9
  attr_accessor :login, :title, :file_attributes, :batch_id, :visibility, :saved, :denied
10
10
 
11
- def initialize(login, params)
11
+ def initialize(login, batch_id, title, file_attributes, visibility)
12
12
  self.login = login
13
- self.title = params[:title] || {}
14
- self.file_attributes = params[:generic_file]
15
- self.visibility = params[:visibility]
16
- self.batch_id = params[:id]
13
+ self.title = title || {}
14
+ self.file_attributes = file_attributes
15
+ self.visibility = visibility
16
+ self.batch_id = batch_id
17
17
  self.saved = []
18
18
  self.denied = []
19
19
  end
data/app/models/batch.rb CHANGED
@@ -10,6 +10,9 @@ class Batch < ActiveFedora::Base
10
10
  property :status, predicate: ::RDF::DC.type
11
11
 
12
12
  def self.find_or_create(id)
13
+ # FIXME potential race condition in this method. Consider that `find' may raise
14
+ # ObjectNotFound in multiple processes. However, Fedora should raise an error
15
+ # if we try to create two objects with the same id.
13
16
  begin
14
17
  Batch.find(id)
15
18
  rescue ActiveFedora::ObjectNotFoundError
@@ -17,9 +20,10 @@ class Batch < ActiveFedora::Base
17
20
  end
18
21
  end
19
22
 
20
- def to_solr(solr_doc={})
21
- super.tap do |solr_doc|
22
- solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile::Indexing.noid_indexer)] = noid
23
+ class << self
24
+ # override the default indexing service
25
+ def indexer
26
+ Sufia::IndexingService
23
27
  end
24
28
  end
25
29
  end
@@ -5,41 +5,16 @@ module Sufia
5
5
  include Sufia::ModelMethods
6
6
  include Sufia::Noid
7
7
  include Sufia::GenericFile::Permissions
8
- include Sufia::GenericFile::WebForm # provides initialize_fields method
9
8
 
10
9
  included do
11
10
  before_save :update_permissions
12
11
  validates :title, presence: true
13
-
14
- end
15
-
16
- def terms_for_display
17
- terms_for_editing - [:title, :description]
18
- end
19
-
20
- def terms_for_editing
21
- [:resource_type, :title, :creator, :contributor, :description, :tag,
22
- :rights, :publisher, :date_created, :subject, :language, :identifier,
23
- :based_near, :related_url]
24
- end
25
-
26
- # Test to see if the given field is required
27
- # @param [Symbol] key a field
28
- # @return [Boolean] is it required or not
29
- def required?(key)
30
- self.class.validators_on(key).any?{|v| v.kind_of? ActiveModel::Validations::PresenceValidator}
31
12
  end
32
13
 
33
14
  def to_param
34
15
  noid
35
16
  end
36
17
 
37
- def to_solr(solr_doc={})
38
- super.tap do |solr_doc|
39
- solr_doc[Solrizer.solr_name("noid", Sufia::GenericFile::Indexing.noid_indexer)] = noid
40
- end
41
- end
42
-
43
18
  def update_permissions
44
19
  self.visibility = "open"
45
20
  end
@@ -50,5 +25,12 @@ module Sufia
50
25
  members.reduce(0) { |sum, gf| sum + gf.file_size.first.to_i }
51
26
  end
52
27
 
28
+ module ClassMethods
29
+ # override the default indexing service
30
+ def indexer
31
+ Sufia::IndexingService
32
+ end
33
+ end
34
+
53
35
  end
54
36
  end
@@ -9,7 +9,6 @@ module Sufia
9
9
  include Sufia::GenericFile::Export
10
10
  include Sufia::GenericFile::Characterization
11
11
  include Sufia::GenericFile::Permissions
12
- include Sufia::GenericFile::WebForm
13
12
  include Sufia::GenericFile::Derivatives
14
13
  include Sufia::GenericFile::Trophies
15
14
  include Sufia::GenericFile::Featured
@@ -21,8 +21,8 @@ module Sufia
21
21
  '%G' => [:language],
22
22
  '%[' => [:date_modified],
23
23
  '%9' => [:resource_type],
24
- '%~' => Application.config.application_name,
25
- '%W' => t('sufia.institution_name')
24
+ '%~' => I18n.t('sufia.product_name'),
25
+ '%W' => I18n.t('sufia.institution_name')
26
26
  }
27
27
  text = []
28
28
  text << "%0 GenericFile"
@@ -3,19 +3,10 @@ module Sufia
3
3
  module Indexing
4
4
  extend ActiveSupport::Concern
5
5
 
6
- # Unstemmed, searchable, stored
7
- def self.noid_indexer
8
- @noid_indexer ||= Solrizer::Descriptor.new(:text, :indexed, :stored)
9
- end
10
-
11
- def to_solr(solr_doc={})
12
- super.tap do |solr_doc|
13
- solr_doc[Solrizer.solr_name('label')] = label
14
- solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile::Indexing.noid_indexer)] = noid
15
- solr_doc[Solrizer.solr_name('file_format')] = file_format
16
- solr_doc[Solrizer.solr_name('file_format', :facetable)] = file_format
17
- solr_doc['all_text_timv'] = full_text.content
18
- solr_doc = index_collection_ids(solr_doc)
6
+ module ClassMethods
7
+ # override the default indexing service
8
+ def indexer
9
+ Sufia::GenericFileIndexingService
19
10
  end
20
11
  end
21
12
  end
@@ -5,7 +5,7 @@ module Sufia
5
5
 
6
6
  included do
7
7
 
8
- property :label, predicate: ::RDF::DC.title, multiple: false
8
+ property :label, predicate: ActiveFedora::RDF::Fcrepo::Model.downloadFilename, multiple: false
9
9
 
10
10
  property :depositor, predicate: ::RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt"), multiple: false do |index|
11
11
  index.as :symbol, :stored_searchable
@@ -18,33 +18,50 @@ module Sufia::User
18
18
  # Users should be followable
19
19
  acts_as_followable
20
20
 
21
- # Setup accessible (or protected) attributes for your model
21
+ # Set up proxy-related relationships
22
22
  has_many :proxy_deposit_requests, foreign_key: 'receiving_user_id'
23
-
24
23
  has_many :deposit_rights_given, foreign_key: 'grantor_id', class_name: 'ProxyDepositRights', dependent: :destroy
25
24
  has_many :can_receive_deposits_from, through: :deposit_rights_given, source: :grantee
26
-
27
25
  has_many :deposit_rights_received, foreign_key: 'grantee_id', class_name: 'ProxyDepositRights', dependent: :destroy
28
26
  has_many :can_make_deposits_for, through: :deposit_rights_received, source: :grantor
29
27
 
28
+ # Validate and normalize ORCIDs
29
+ validates_with OrcidValidator
30
+ after_validation :normalize_orcid
31
+
32
+ # Set up user profile avatars
30
33
  mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
31
34
  validates_with AvatarValidator
35
+
32
36
  has_many :trophies
33
37
  attr_accessor :update_directory
34
38
  end
35
39
 
40
+ # Coerce the ORCID into URL format
41
+ def normalize_orcid
42
+ # Skip normalization if:
43
+ # 1. validation has already flagged the ORCID as invalid
44
+ # 2. the orcid field is blank
45
+ # 3. the orcid is already in its normalized form
46
+ return if self.errors[:orcid].first.present? || self.orcid.blank? || self.orcid.starts_with?('http://orcid.org/')
47
+ bare_orcid = /\d{4}-\d{4}-\d{4}-\d{4}/.match(self.orcid).string
48
+ self.orcid = "http://orcid.org/#{bare_orcid}"
49
+ end
50
+
36
51
  # Format the json for select2 which requires just an id and a field called text.
37
52
  # If we need an alternate format we should probably look at a json template gem
38
53
  def as_json(opts = nil)
39
- {id: user_key, text: display_name ? "#{display_name} (#{user_key})" : user_key}
54
+ { id: user_key, text: display_name ? "#{display_name} (#{user_key})" : user_key }
40
55
  end
41
56
 
42
57
  def email_address
43
- return self.email
58
+ self.email
44
59
  end
45
60
 
46
61
  def name
47
- return self.display_name.titleize || self.user_key rescue self.user_key
62
+ self.display_name.titleize || raise
63
+ rescue
64
+ self.user_key
48
65
  end
49
66
 
50
67
  # Redefine this for more intuitive keys in Redis
@@ -61,7 +78,7 @@ module Sufia::User
61
78
 
62
79
  # method needed for messaging
63
80
  def mailboxer_email(obj=nil)
64
- return nil
81
+ nil
65
82
  end
66
83
 
67
84
  # The basic groups method, override or will fallback to Sufia::Ldap::User
@@ -80,14 +97,6 @@ module Sufia::User
80
97
  end
81
98
 
82
99
  module ClassMethods
83
-
84
- def permitted_attributes
85
- [:email, :login, :display_name, :address, :admin_area,
86
- :department, :title, :office, :chat_id, :website, :affiliation,
87
- :telephone, :avatar, :group_list, :groups_last_update, :facebook_handle,
88
- :twitter_handle, :googleplus_handle, :linkedin_handle, :remove_avatar]
89
- end
90
-
91
100
  def current
92
101
  Thread.current[:user]
93
102
  end
@@ -119,7 +128,5 @@ module Sufia::User
119
128
  def from_url_component(component)
120
129
  User.find_by_user_key(component.gsub(/-dot-/, '.'))
121
130
  end
122
-
123
131
  end
124
-
125
132
  end
@@ -0,0 +1,8 @@
1
+ module Sufia
2
+ class OrcidValidator < ActiveModel::Validator
3
+ def validate(record)
4
+ return if record.orcid.blank?
5
+ record.errors.add(:orcid, 'must be a string of 19 characters, e.g., "0000-0000-0000-0000"') unless /\d{4}-\d{4}-\d{4}-\d{4}/.match(record.orcid)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Sufia
2
+ class GenericFileIndexingService < IndexingService
3
+ def generate_solr_document
4
+ super.tap do |solr_doc|
5
+ solr_doc[Solrizer.solr_name('label')] = object.label
6
+ solr_doc[Solrizer.solr_name('file_format')] = object.file_format
7
+ solr_doc[Solrizer.solr_name('file_format', :facetable)] = object.file_format
8
+ solr_doc['all_text_timv'] = object.full_text.content
9
+ solr_doc = object.index_collection_ids(solr_doc)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Sufia
2
+ class IndexingService < ActiveFedora::IndexingService
3
+
4
+ # Unstemmed, searchable, stored
5
+ def self.noid_indexer
6
+ @noid_indexer ||= Solrizer::Descriptor.new(:text, :indexed, :stored)
7
+ end
8
+
9
+ def generate_solr_document
10
+ super.tap do |solr_doc|
11
+ solr_doc[Solrizer.solr_name("noid", Sufia::IndexingService.noid_indexer)] = object.noid
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ class Sufia::Models::AbstractMigrationGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+
8
+ # Implement the required interface for Rails::Generators::Migration.
9
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
10
+ def self.next_migration_number(path)
11
+ if @prev_migration_nr
12
+ @prev_migration_nr += 1
13
+ else
14
+ if last_migration = Dir[File.join(path, '*.rb')].sort.last
15
+ @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
16
+ else
17
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
18
+ end
19
+ end
20
+ @prev_migration_nr.to_s
21
+ end
22
+
23
+ protected
24
+
25
+ def better_migration_template(file)
26
+ migration_template "migrations/#{file}", "db/migrate/#{file}"
27
+ rescue Rails::Generators::Error => e
28
+ say_status("warning", e.message, :yellow)
29
+ end
30
+ end
@@ -1,32 +1,12 @@
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
1
+ require_relative 'abstract_migration_generator'
7
2
 
3
+ class Sufia::Models::CachedStatsGenerator < Sufia::Models::AbstractMigrationGenerator
8
4
  source_root File.expand_path('../templates', __FILE__)
9
- argument :model_name, type: :string , default: "user"
10
5
 
11
6
  desc """
12
7
  This generator adds the ability to cache usage stats to your application:
13
8
  1. Creates several database migrations if they do not exist in /db/migrate
14
- 2. Adds stats methods to the user model
15
9
  """
16
- # Implement the required interface for Rails::Generators::Migration.
17
- # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
18
- def self.next_migration_number(path)
19
- if @prev_migration_nr
20
- @prev_migration_nr += 1
21
- else
22
- if last_migration = Dir[File.join(path, '*.rb')].sort.last
23
- @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
24
- else
25
- @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
26
- end
27
- end
28
- @prev_migration_nr.to_s
29
- end
30
10
 
31
11
  def banner
32
12
  say_status("warning", "ADDING STATS CACHING-RELATED SUFIA MODELS", :yellow)
@@ -34,35 +14,11 @@ This generator adds the ability to cache usage stats to your application:
34
14
 
35
15
  # Setup the database migrations
36
16
  def copy_migrations
37
- # Can't get this any more DRY, because we need this order.
38
17
  [
39
18
  'create_file_view_stats.rb',
40
- 'create_file_download_stats.rb',
41
- 'create_user_stats.rb'
19
+ 'create_file_download_stats.rb'
42
20
  ].each do |file|
43
21
  better_migration_template file
44
22
  end
45
23
  end
46
-
47
- def add_stats_mixin_to_user_model
48
- file_path = "app/models/#{model_name.underscore}.rb"
49
-
50
- if File.exists?(file_path)
51
- inject_into_file file_path, after: /include Sufia\:\:User.*$/ do
52
- "\n include Sufia::UserUsageStats"
53
- end
54
- else
55
- puts " \e[31mFailure\e[0m Sufia requires a user object. This generators assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails -g sufia client"
56
- end
57
- end
58
-
59
- private
60
-
61
- def better_migration_template(file)
62
- begin
63
- migration_template "migrations/#{file}", "db/migrate/#{file}"
64
- rescue Rails::Generators::Error => e
65
- say_status("warning", e.message, :yellow)
66
- end
67
- end
68
24
  end
@@ -1,12 +1,7 @@
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
1
+ require_relative 'abstract_migration_generator'
7
2
 
3
+ class Sufia::Models::InstallGenerator < Sufia::Models::AbstractMigrationGenerator
8
4
  source_root File.expand_path('../templates', __FILE__)
9
-
10
5
  argument :model_name, type: :string , default: "user"
11
6
  desc """
12
7
  This generator makes the following changes to your application:
@@ -19,30 +14,15 @@ This generator makes the following changes to your application:
19
14
  7. Runs full-text generator
20
15
  8. Runs proxies generator
21
16
  9. Runs cached stats generator
17
+ 10. Runs ORCID field generator
18
+ 11. Runs user stats generator
22
19
  """
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
-
39
20
  def banner
40
21
  say_status("warning", "GENERATING SUFIA MODELS", :yellow)
41
22
  end
42
23
 
43
24
  # Setup the database migrations
44
25
  def copy_migrations
45
- # Can't get this any more DRY, because we need this order.
46
26
  [
47
27
  "acts_as_follower_migration.rb",
48
28
  "add_social_to_users.rb",
@@ -114,13 +94,13 @@ This generator makes the following changes to your application:
114
94
  generate 'sufia:models:cached_stats'
115
95
  end
116
96
 
117
- private
97
+ # Adds orcid field to user model
98
+ def orcid_field
99
+ generate 'sufia:models:orcid_field'
100
+ end
118
101
 
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
102
+ # Adds user stats-related migration & methods
103
+ def user_stats
104
+ generate 'sufia:models:user_stats'
125
105
  end
126
106
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'abstract_migration_generator'
2
+
3
+ class Sufia::Models::OrcidFieldGenerator < Sufia::Models::AbstractMigrationGenerator
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc """
7
+ This generator adds a field to hold users' ORCIDs to your application:
8
+ 1. Creates a database migration if they do not exist in /db/migrate
9
+ """
10
+
11
+ def banner
12
+ say_status("warning", "ADDING ORCID FIELD TO USER MODEL", :yellow)
13
+ end
14
+
15
+ # Setup the database migration
16
+ def copy_migrations
17
+ better_migration_template 'add_orcid_to_users.rb'
18
+ end
19
+ end
@@ -1,30 +1,12 @@
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
1
+ require_relative 'abstract_migration_generator'
7
2
 
3
+ class Sufia::Models::ProxiesGenerator < Sufia::Models::AbstractMigrationGenerator
8
4
  source_root File.expand_path('../templates', __FILE__)
9
5
 
10
6
  desc """
11
7
  This generator adds proxies and transfers to your application:
12
8
  1. Creates several database migrations if they do not exist in /db/migrate
13
9
  """
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
28
10
 
29
11
  def banner
30
12
  say_status("warning", "ADDING PROXY/TRANSFER-RELATED SUFIA MODELS", :yellow)
@@ -32,7 +14,6 @@ This generator adds proxies and transfers to your application:
32
14
 
33
15
  # Setup the database migrations
34
16
  def copy_migrations
35
- # Can't get this any more DRY, because we need this order.
36
17
  [
37
18
  'create_proxy_deposit_rights.rb',
38
19
  'create_proxy_deposit_requests.rb'
@@ -40,14 +21,4 @@ This generator adds proxies and transfers to your application:
40
21
  better_migration_template file
41
22
  end
42
23
  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
53
24
  end
@@ -4,3 +4,6 @@ development:
4
4
  test:
5
5
  host: localhost
6
6
  port: 6379
7
+ production:
8
+ host: localhost
9
+ port: 6379
@@ -99,6 +99,9 @@ Sufia.config do |config|
99
99
  # Where to store tempfiles, leave blank for the system temp directory (e.g. /tmp)
100
100
  # config.temp_file_base = '/home/developer1'
101
101
 
102
+ # Specify the form of hostpath to be used in Endnote exports
103
+ # config.persistent_hostpath = 'http://localhost/files/'
104
+
102
105
  # If you have ffmpeg installed and want to transcode audio and video uncomment this line
103
106
  # config.enable_ffmpeg = true
104
107
 
@@ -0,0 +1,5 @@
1
+ class AddOrcidToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :orcid, :string
4
+ end
5
+ end
@@ -1,13 +1,8 @@
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
1
+ require_relative 'abstract_migration_generator'
7
2
 
3
+ class Sufia::Models::Upgrade400Generator < Sufia::Models::AbstractMigrationGenerator
8
4
  source_root File.expand_path('../templates', __FILE__)
9
5
 
10
- argument :model_name, type: :string , default: "user"
11
6
  desc """
12
7
  This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following changes to your application:
13
8
  1. Creates several database migrations if they do not exist in /db/migrate
@@ -16,28 +11,12 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
16
11
  4. Runs full-text generator
17
12
  """
18
13
 
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
-
34
14
  def banner
35
15
  say_status("warning", "UPGRADING SUFIA MODELS", :yellow)
36
16
  end
37
17
 
38
18
  # Setup the database migrations
39
19
  def copy_migrations
40
- # Can't get this any more DRY, because we need this order.
41
20
  [
42
21
  'create_tinymce_assets.rb',
43
22
  'create_content_blocks.rb',
@@ -72,14 +51,4 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
72
51
  def full_text_indexing
73
52
  generate "sufia:models:fulltext"
74
53
  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
85
54
  end
@@ -0,0 +1,31 @@
1
+ require_relative 'abstract_migration_generator'
2
+
3
+ class Sufia::Models::UserStatsGenerator < Sufia::Models::AbstractMigrationGenerator
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ argument :model_name, type: :string , default: "user"
6
+
7
+ desc """
8
+ This generator adds usage stats methods to the user model in your application:
9
+ """
10
+
11
+ def banner
12
+ say_status("warning", "ADDING USER STATS-RELATED ABILITIES TO SUFIA MODELS", :yellow)
13
+ end
14
+
15
+ # Setup the database migrations
16
+ def copy_migrations
17
+ better_migration_template 'create_user_stats.rb'
18
+ end
19
+
20
+ def add_stats_mixin_to_user_model
21
+ file_path = "app/models/#{model_name.underscore}.rb"
22
+
23
+ if File.exists?(file_path)
24
+ inject_into_file file_path, after: /include Sufia\:\:User.*$/ do
25
+ "\n include Sufia::UserUsageStats"
26
+ end
27
+ else
28
+ puts " \e[31mFailure\e[0m Sufia requires a user object. This generator assumes that the model is defined in the file #{file_path}, which does not exist. If you used a different name, please re-run the generator and provide that name as an argument. Such as \b rails g sufia:models:user_stats client"
29
+ end
30
+ end
31
+ end
@@ -12,6 +12,7 @@ module Sufia
12
12
  require 'sufia/models/resque'
13
13
 
14
14
  # Set some configuration defaults
15
+ config.persistent_hostpath = "http://localhost/files/"
15
16
  config.enable_ffmpeg = false
16
17
  config.noid_template = '.reeddeeddk'
17
18
  config.ffmpeg_path = 'ffmpeg'
@@ -1,5 +1,5 @@
1
1
  module Sufia
2
2
  module Models
3
- VERSION = "6.0.0.beta1"
3
+ VERSION = "6.0.0.rc1"
4
4
  end
5
5
  end
data/sufia-models.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  # This is a temporary homepage until we've had a chance to review the
17
17
  # process
18
18
  spec.homepage = "https://github.com/projecthydra/sufia"
19
- spec.license = "Apache"
19
+ spec.license = "Apache2"
20
20
 
21
21
  spec.files = `git ls-files`.split($/)
22
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -29,10 +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", "~> 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'
32
+ spec.add_dependency "hydra-head", "~> 9.0.0.rc2"
33
+ spec.add_dependency "active-fedora", "~> 9.0.0.rc2"
34
+ spec.add_dependency "hydra-collections", "~> 4.0.0.rc2"
35
+ spec.add_dependency 'hydra-derivatives', '~> 1.0.0.rc1'
36
36
  spec.add_dependency 'nest', '~> 1.1'
37
37
  spec.add_dependency 'resque', '~> 1.23'
38
38
  spec.add_dependency 'resque-pool', '~> 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: 6.0.0.beta1
4
+ version: 6.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,56 +78,56 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 9.0.0.beta1
81
+ version: 9.0.0.rc2
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: 9.0.0.beta1
88
+ version: 9.0.0.rc2
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: active-fedora
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 9.0.0.beta5
95
+ version: 9.0.0.rc2
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 9.0.0.beta5
102
+ version: 9.0.0.rc2
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: hydra-collections
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 4.0.0.beta1
109
+ version: 4.0.0.rc2
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: 4.0.0.beta1
116
+ version: 4.0.0.rc2
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: hydra-derivatives
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 1.0.0.beta1
123
+ version: 1.0.0.rc1
124
124
  type: :runtime
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 1.0.0.beta1
130
+ version: 1.0.0.rc1
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: nest
133
133
  requirement: !ruby/object:Gem::Requirement
@@ -329,7 +329,6 @@ files:
329
329
  - app/models/concerns/sufia/collection.rb
330
330
  - app/models/concerns/sufia/file_stat_utils.rb
331
331
  - app/models/concerns/sufia/generic_file.rb
332
- - app/models/concerns/sufia/generic_file/accessible_attributes.rb
333
332
  - app/models/concerns/sufia/generic_file/batches.rb
334
333
  - app/models/concerns/sufia/generic_file/characterization.rb
335
334
  - app/models/concerns/sufia/generic_file/content.rb
@@ -345,7 +344,6 @@ files:
345
344
  - app/models/concerns/sufia/generic_file/trophies.rb
346
345
  - app/models/concerns/sufia/generic_file/versions.rb
347
346
  - app/models/concerns/sufia/generic_file/virus_check.rb
348
- - app/models/concerns/sufia/generic_file/web_form.rb
349
347
  - app/models/concerns/sufia/model_methods.rb
350
348
  - app/models/concerns/sufia/user.rb
351
349
  - app/models/concerns/sufia/user_usage_stats.rb
@@ -369,19 +367,24 @@ files:
369
367
  - app/models/sufia/avatar_uploader.rb
370
368
  - app/models/sufia/avatar_validator.rb
371
369
  - app/models/sufia/download.rb
370
+ - app/models/sufia/orcid_validator.rb
372
371
  - app/models/sufia/pageview.rb
373
372
  - app/models/trophy.rb
374
373
  - app/models/user_stat.rb
375
374
  - app/models/version_committer.rb
376
375
  - app/services/sufia/analytics.rb
377
376
  - app/services/sufia/generic_file_audit_service.rb
377
+ - app/services/sufia/generic_file_indexing_service.rb
378
378
  - app/services/sufia/id_service.rb
379
+ - app/services/sufia/indexing_service.rb
379
380
  - app/services/sufia/noid.rb
380
381
  - app/services/sufia/repository_audit_service.rb
381
382
  - config/locales/sufia.en.yml
383
+ - lib/generators/sufia/models/abstract_migration_generator.rb
382
384
  - lib/generators/sufia/models/cached_stats_generator.rb
383
385
  - lib/generators/sufia/models/fulltext_generator.rb
384
386
  - lib/generators/sufia/models/install_generator.rb
387
+ - lib/generators/sufia/models/orcid_field_generator.rb
385
388
  - lib/generators/sufia/models/proxies_generator.rb
386
389
  - lib/generators/sufia/models/templates/config/analytics.yml
387
390
  - lib/generators/sufia/models/templates/config/clamav.rb
@@ -400,6 +403,7 @@ files:
400
403
  - lib/generators/sufia/models/templates/migrations/add_groups_to_users.rb
401
404
  - lib/generators/sufia/models/templates/migrations/add_ldap_attrs_to_user.rb
402
405
  - lib/generators/sufia/models/templates/migrations/add_linkedin_to_users.rb
406
+ - lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb
403
407
  - lib/generators/sufia/models/templates/migrations/add_social_to_users.rb
404
408
  - lib/generators/sufia/models/templates/migrations/create_checksum_audit_logs.rb
405
409
  - lib/generators/sufia/models/templates/migrations/create_content_blocks.rb
@@ -416,6 +420,7 @@ files:
416
420
  - lib/generators/sufia/models/templates/migrations/create_version_committers.rb
417
421
  - lib/generators/sufia/models/upgrade400_generator.rb
418
422
  - lib/generators/sufia/models/usagestats_generator.rb
423
+ - lib/generators/sufia/models/user_stats_generator.rb
419
424
  - lib/sufia/messages.rb
420
425
  - lib/sufia/models.rb
421
426
  - lib/sufia/models/active_fedora/redis.rb
@@ -438,7 +443,7 @@ files:
438
443
  - sufia-models.gemspec
439
444
  homepage: https://github.com/projecthydra/sufia
440
445
  licenses:
441
- - Apache
446
+ - Apache2
442
447
  metadata: {}
443
448
  post_install_message:
444
449
  rdoc_options: []
@@ -456,7 +461,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
456
461
  version: 1.3.1
457
462
  requirements: []
458
463
  rubyforge_project:
459
- rubygems_version: 2.2.2
464
+ rubygems_version: 2.4.3
460
465
  signing_key:
461
466
  specification_version: 4
462
467
  summary: Models and services for sufia
@@ -1,87 +0,0 @@
1
- module Sufia
2
- module GenericFile
3
- module AccessibleAttributes
4
- extend ActiveSupport::Concern
5
- included do
6
- class_attribute :_accessible_attributes
7
- self._accessible_attributes = {}
8
- end
9
-
10
- def accessible_attributes(role = :default)
11
- self.class._accessible_attributes[role] || []
12
- end
13
-
14
- # Sanitize the provided attributes using only those that are specified
15
- # as accessible by attr_accessor
16
- # @param [Hash] attributes the raw parameters
17
- # @param [Hash] args a hash of options
18
- # @option args [Symbol] :as (:default) the role to use
19
- # @return A sanitized hash of parameters
20
- def sanitize_attributes(attributes = {}, args = {})
21
- role = args[:as] || :default
22
- attributes.select { |k,v| accessible_attributes.include?(k.to_sym)}
23
- end
24
-
25
- module ClassMethods
26
- # Specifies a white list of model attributes that can be set via
27
- # mass-assignment.
28
- #
29
- # Like +attr_protected+, a role for the attributes is optional,
30
- # if no role is provided then :default is used. A role can be defined by
31
- # using the :as option.
32
- #
33
- # Mass-assignment will only set attributes in this list, to assign to
34
- # the rest of # attributes you can use direct writer methods. This is
35
- # meant to protect sensitive attributes from being overwritten by
36
- # malicious users # tampering with URLs or forms.
37
- #
38
- # class Customer
39
- # include ActiveModel::MassAssignmentSecurity
40
- #
41
- # attr_accessor :name, :credit_rating
42
- #
43
- # attr_accessible :name
44
- # attr_accessible :name, :credit_rating, as: :admin
45
- #
46
- # def assign_attributes(values, options = {})
47
- # sanitize_for_mass_assignment(values, options[:as]).each do |k, v|
48
- # send("#{k}=", v)
49
- # end
50
- # end
51
- # end
52
- #
53
- # When using the :default role:
54
- #
55
- # customer = Customer.new
56
- # customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", last_login: 1.day.ago }, as: :default)
57
- # customer.name # => "David"
58
- # customer.credit_rating # => nil
59
- #
60
- # customer.credit_rating = "Average"
61
- # customer.credit_rating # => "Average"
62
- #
63
- # And using the :admin role:
64
- #
65
- # customer = Customer.new
66
- # customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", last_login: 1.day.ago }, as: :admin)
67
- # customer.name # => "David"
68
- # customer.credit_rating # => "Excellent"
69
- #
70
- # Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of
71
- # +attr_accessible+ to sanitize attributes provides basically the same
72
- # functionality, but it makes a bit tricky to deal with nested attributes.
73
- def attr_accessible(*args)
74
- options = args.extract_options!
75
- role = options[:as] || :default
76
-
77
- self._accessible_attributes ||= {}
78
-
79
- Array.wrap(role).each do |name|
80
- self._accessible_attributes[name] = args.map &:to_sym
81
- end
82
- end
83
-
84
- end
85
- end
86
- end
87
- end
@@ -1,62 +0,0 @@
1
- module Sufia
2
- module GenericFile
3
- module WebForm
4
- extend ActiveSupport::Concern
5
- include Sufia::GenericFile::AccessibleAttributes
6
- included do
7
- before_save :remove_blank_assertions
8
- attr_accessible *(terms_for_display + [:part_of, :permissions_attributes])
9
- end
10
-
11
- def remove_blank_assertions
12
- terms_for_editing.each do |key|
13
- if self[key] == ['']
14
- self[key] = []
15
- changed_attributes.delete(key) if attribute_was(key) == []
16
- end
17
- end
18
- end
19
-
20
- # override this method if you need to initialize more complex RDF assertions (b-nodes)
21
- def initialize_fields
22
- terms_for_editing.select { |key| self[key].blank? }.each do |key|
23
- # if value is empty, we create an one element array to loop over for output
24
- if self.class.multiple?(key)
25
- self[key] = ['']
26
- else
27
- self[key] = ''
28
- end
29
- end
30
- end
31
-
32
- def terms_for_editing
33
- terms_for_display - [:date_modified, :date_uploaded, :format]
34
- end
35
-
36
- def terms_for_display
37
- # 'type' is the RDF.type assertion, which is not present by default, but may be
38
- # provided in some RDF schemas
39
- self.class.terms_for_display
40
- end
41
-
42
- module ClassMethods
43
- def terms_for_display
44
- [:resource_type, :title, :creator, :contributor, :description, :tag, :rights, :publisher, :date_created,
45
- :subject, :language, :identifier, :based_near, :related_url]
46
- end
47
- end
48
-
49
- def to_jq_upload
50
- return {
51
- "name" => title,
52
- "size" => file_size,
53
- "url" => "/files/#{noid}",
54
- "thumbnail_url" => id,
55
- "delete_url" => "deleteme", # generic_file_path(id: id),
56
- "delete_type" => "DELETE"
57
- }
58
- end
59
-
60
- end
61
- end
62
- end