sufia-models 4.0.0.rc1 → 4.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/actors/sufia/generic_file/actor.rb +14 -5
  3. data/{lib/sufia/models → app}/jobs/active_fedora_pid_based_job.rb +0 -0
  4. data/{lib/sufia/models → app}/jobs/audit_job.rb +4 -10
  5. data/{lib/sufia/models → app}/jobs/batch_update_job.rb +22 -18
  6. data/{lib/sufia/models → app}/jobs/characterize_job.rb +0 -0
  7. data/{lib/sufia/models → app}/jobs/create_derivatives_job.rb +0 -0
  8. data/{lib/sufia/models → app}/jobs/import_url_job.rb +0 -0
  9. data/{lib/sufia/models → app}/jobs/resolrize_job.rb +0 -0
  10. data/app/models/collection.rb +1 -39
  11. data/{lib → app/models/concerns}/sufia/ability.rb +0 -0
  12. data/app/models/concerns/sufia/collection.rb +55 -0
  13. data/app/models/concerns/sufia/generic_file.rb +5 -11
  14. data/app/models/concerns/sufia/generic_file/audit.rb +1 -2
  15. data/app/models/concerns/sufia/generic_file/characterization.rb +4 -2
  16. data/app/models/concerns/sufia/generic_file/full_text_indexing.rb +27 -0
  17. data/app/models/concerns/sufia/generic_file/mime_types.rb +1 -0
  18. data/app/models/concerns/sufia/generic_file/permissions.rb +2 -49
  19. data/{lib/sufia/models → app/models/concerns/sufia}/model_methods.rb +0 -0
  20. data/app/models/concerns/sufia/user.rb +8 -1
  21. data/app/models/sufia/avatar_uploader.rb +2 -3
  22. data/app/services/sufia/noid.rb +9 -0
  23. data/config/locales/sufia.en.yml +1 -0
  24. data/lib/generators/sufia/models/fulltext_generator.rb +27 -0
  25. data/lib/generators/sufia/models/install_generator.rb +7 -0
  26. data/lib/generators/sufia/models/templates/config/analytics.yml +5 -5
  27. data/lib/generators/sufia/models/templates/config/solrconfig.xml +177 -0
  28. data/lib/generators/sufia/models/templates/config/sufia.rb +3 -1
  29. data/lib/generators/sufia/models/upgrade400_generator.rb +7 -0
  30. data/lib/sufia/messages.rb +67 -0
  31. data/lib/sufia/models.rb +2 -0
  32. data/lib/sufia/models/active_fedora/redis.rb +0 -6
  33. data/lib/sufia/models/engine.rb +1 -3
  34. data/lib/sufia/models/resque.rb +1 -1
  35. data/lib/sufia/models/version.rb +1 -1
  36. data/lib/sufia/permissions.rb +9 -0
  37. data/lib/sufia/permissions/readable.rb +20 -0
  38. data/lib/sufia/permissions/writable.rb +56 -0
  39. data/lib/tasks/sufia-models_tasks.rake +58 -2
  40. data/sufia-models.gemspec +11 -11
  41. metadata +45 -38
@@ -21,6 +21,7 @@ module Sufia::User
21
21
  mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
22
22
  validates_with AvatarValidator
23
23
  has_many :trophies
24
+ attr_accessor :update_directory
24
25
  end
25
26
 
26
27
  # Format the json for select2 which requires just an id and a field called text.
@@ -63,13 +64,19 @@ module Sufia::User
63
64
  @ability ||= ::Ability.new(self)
64
65
  end
65
66
 
67
+ def get_all_user_activity( since = DateTime.now.to_i - 8640)
68
+ events = self.events.reverse.collect { |event| event if event[:timestamp].to_i > since }.compact
69
+ profile_events = self.profile_events.reverse.collect { |event| event if event[:timestamp].to_i > since }.compact
70
+ events.concat(profile_events).sort { |a, b| b[:timestamp].to_i <=> a[:timestamp].to_i }
71
+ end
72
+
66
73
  module ClassMethods
67
74
 
68
75
  def permitted_attributes
69
76
  [:email, :login, :display_name, :address, :admin_area,
70
77
  :department, :title, :office, :chat_id, :website, :affiliation,
71
78
  :telephone, :avatar, :group_list, :groups_last_update, :facebook_handle,
72
- :twitter_handle, :googleplus_handle, :linkedin_handle]
79
+ :twitter_handle, :googleplus_handle, :linkedin_handle, :remove_avatar]
73
80
  end
74
81
 
75
82
  def current
@@ -1,9 +1,7 @@
1
1
  class Sufia::AvatarUploader < CarrierWave::Uploader::Base
2
2
  include CarrierWave::MiniMagick
3
3
  include CarrierWave::Compatibility::Paperclip
4
-
5
- process convert: 'png'
6
-
4
+
7
5
  version :medium do
8
6
  process resize_to_limit: [300, 300]
9
7
  end
@@ -19,4 +17,5 @@ class Sufia::AvatarUploader < CarrierWave::Uploader::Base
19
17
  def extension_white_list
20
18
  %w(jpg jpeg png gif bmp tif tiff)
21
19
  end
20
+
22
21
  end
@@ -1,5 +1,14 @@
1
1
  module Sufia
2
2
  module Noid
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ ## This overrides the default behavior, which is to ask Fedora for a pid
7
+ # @see ActiveFedora::Sharding.assign_pid
8
+ def assign_pid(_)
9
+ Sufia::IdService.mint
10
+ end
11
+ end
3
12
 
4
13
  def noid
5
14
  Noid.noidify(self.pid)
@@ -1,5 +1,6 @@
1
1
  en:
2
2
  sufia:
3
3
  product_name: "Sufia"
4
+ product_twitter_handle: "@HydraSphere"
4
5
  institution_name: "Institution Name"
5
6
  institution_name_full: "The Institution Name"
@@ -0,0 +1,27 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rails/generators'
3
+
4
+ class Sufia::Models::FulltextGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc """
8
+ This generator makes the following changes to your application:
9
+ 1. Copies solrconfig.xml into solr_conf/conf/
10
+ 2. Reconfigures jetty
11
+ """
12
+
13
+ def banner
14
+ say_status("warning", "GENERATING SUFIA FULL-TEXT", :yellow)
15
+ end
16
+
17
+ # Copy Sufia's solrconfig into the dir from which the jetty:config task pulls
18
+ # Sufia's solrconfig includes full-text extraction
19
+ def copy_solr_config
20
+ copy_file 'config/solrconfig.xml', 'solr_conf/conf/solrconfig.xml', force: true
21
+ end
22
+
23
+ # Copy config, schema, and jars into jetty dir if it exists
24
+ def reconfigure_jetty
25
+ rake "sufia:jetty:config" if File.directory?('jetty')
26
+ end
27
+ end
@@ -15,6 +15,8 @@ This generator makes the following changes to your application:
15
15
  3. Creates the sufia.rb configuration file
16
16
  4. Generates mailboxer
17
17
  5. Generates usage stats config
18
+ 6. Installs Blacklight gallery
19
+ 7. Runs full-text generator
18
20
  """
19
21
 
20
22
  # Implement the required interface for Rails::Generators::Migration.
@@ -94,6 +96,11 @@ This generator makes the following changes to your application:
94
96
  generate "blacklight_gallery:install"
95
97
  end
96
98
 
99
+ # Sets up full-text indexing (Solr config + jars)
100
+ def full_text_indexing
101
+ generate "sufia:models:fulltext"
102
+ end
103
+
97
104
  private
98
105
 
99
106
  def better_migration_template(file)
@@ -2,8 +2,8 @@
2
2
  # To integrate your app with Google Analytics, uncomment the lines below and add your API key information.
3
3
  #
4
4
  # analytics:
5
- # :app_name: GOOGLE_OAUTH_APP_NAME
6
- # :app_version: GOOGLE_OAUTH_APP_VERSION
7
- # :privkey_path: GOOGLE_OAUTH_PRIVATE_KEY_PATH
8
- # :privkey_secret: GOOGLE_OAUTH_PRIVATE_KEY_SECRET
9
- # :client_email: GOOGLE_OAUTH_CLIENT_EMAIL
5
+ # app_name: GOOGLE_OAUTH_APP_NAME
6
+ # app_version: GOOGLE_OAUTH_APP_VERSION
7
+ # privkey_path: GOOGLE_OAUTH_PRIVATE_KEY_PATH
8
+ # privkey_secret: GOOGLE_OAUTH_PRIVATE_KEY_SECRET
9
+ # client_email: GOOGLE_OAUTH_CLIENT_EMAIL
@@ -0,0 +1,177 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <config>
3
+ <!-- NOTE: various comments and unused configuration possibilities have been purged
4
+ from this file. Please refer to http://wiki.apache.org/solr/SolrConfigXml,
5
+ as well as the default solrconfig file included with Solr -->
6
+
7
+ <abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>
8
+
9
+ <luceneMatchVersion>LUCENE_40</luceneMatchVersion>
10
+
11
+ <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>
12
+
13
+ <!-- solr lib dirs -->
14
+ <lib dir="../lib/contrib/analysis-extras/lib" />
15
+ <lib dir="../lib/contrib/analysis-extras/lucene-libs" />
16
+ <!-- for full-text indexing -->
17
+ <lib dir="../lib/contrib/extraction/lib" regex=".*\.jar" />
18
+
19
+ <dataDir>${solr.data.dir:}</dataDir>
20
+
21
+ <requestHandler name="search" class="solr.SearchHandler" default="true">
22
+ <!-- default values for query parameters can be specified, these
23
+ will be overridden by parameters in the request
24
+ -->
25
+ <lst name="defaults">
26
+ <str name="defType">edismax</str>
27
+ <str name="echoParams">explicit</str>
28
+ <str name="q.alt">*:*</str>
29
+ <str name="mm">2&lt;-1 5&lt;-2 6&lt;90%</str>
30
+ <int name="qs">1</int>
31
+ <int name="ps">2</int>
32
+ <float name="tie">0.01</float>
33
+ <!-- this qf and pf are used by default, if not otherwise specified by
34
+ client. The default blacklight_config will use these for the
35
+ "keywords" search. See the author_qf/author_pf, title_qf, etc
36
+ below, which the default blacklight_config will specify for
37
+ those searches. You may also be interested in:
38
+ http://wiki.apache.org/solr/LocalParams
39
+ -->
40
+ <str name="qf">
41
+ id
42
+ all_text_timv
43
+ active_fedora_model_ssi
44
+ object_type_si
45
+ </str>
46
+ <str name="pf">
47
+ all_text_timv^10
48
+ </str>
49
+
50
+ <str name="author_qf">
51
+ </str>
52
+ <str name="author_pf">
53
+ </str>
54
+ <str name="title_qf">
55
+ </str>
56
+ <str name="title_pf">
57
+ </str>
58
+ <str name="subject_qf">
59
+ </str>
60
+ <str name="subject_pf">
61
+ </str>
62
+
63
+ <str name="fl">
64
+ *,
65
+ score
66
+ </str>
67
+
68
+ <str name="facet">true</str>
69
+ <str name="facet.mincount">1</str>
70
+ <str name="facet.limit">10</str>
71
+ <str name="facet.field">active_fedora_model_ssi</str>
72
+ <str name="facet.field">object_type_si</str>
73
+
74
+ <str name="spellcheck">true</str>
75
+ <str name="spellcheck.dictionary">default</str>
76
+ <str name="spellcheck.onlyMorePopular">true</str>
77
+ <str name="spellcheck.extendedResults">true</str>
78
+ <str name="spellcheck.collate">false</str>
79
+ <str name="spellcheck.count">5</str>
80
+
81
+ </lst>
82
+ <arr name="last-components">
83
+ <str>spellcheck</str>
84
+ </arr>
85
+ </requestHandler>
86
+
87
+ <requestHandler name="permissions" class="solr.SearchHandler" >
88
+ <lst name="defaults">
89
+ <str name="facet">off</str>
90
+ <str name="echoParams">all</str>
91
+ <str name="rows">1</str>
92
+ <str name="q">{!raw f=id v=$id}</str> <!-- use id=666 instead of q=id:666 -->
93
+ <str name="fl">
94
+ id,
95
+ access_ssim,
96
+ discover_access_group_ssim,discover_access_person_ssim,
97
+ read_access_group_ssim,read_access_person_ssim,
98
+ edit_access_group_ssim,edit_access_person_ssim,
99
+ depositor_ti,
100
+ embargo_release_date_dtsi
101
+ inheritable_access_ssim,
102
+ inheritable_discover_access_group_ssim,inheritable_discover_access_person_ssim,
103
+ inheritable_read_access_group_ssim,inheritable_read_access_person_ssim,
104
+ inheritable_edit_access_group_ssim,inheritable_edit_access_person_ssim,
105
+ inheritable_embargo_release_date_dtsi
106
+ </str>
107
+ </lst>
108
+ </requestHandler>
109
+
110
+ <requestHandler name="/update/extract" startup="lazy" class="org.apache.solr.handler.extraction.ExtractingRequestHandler" >
111
+ <lst name="defaults">
112
+ <!-- All the main content goes into "text"... if you need to return the extracted text or do highlighting, use a stored field. -->
113
+ <str name="fmap.content">text</str>
114
+ <str name="lowernames">true</str>
115
+ <str name="uprefix">ignored_</str>
116
+ <!-- capture link hrefs but ignore div attributes -->
117
+ <str name="captureAttr">true</str>
118
+ <str name="fmap.a">links</str>
119
+ <str name="fmap.div">ignored_</str>
120
+ </lst>
121
+ </requestHandler>
122
+
123
+ <requestHandler name="standard" class="solr.SearchHandler">
124
+ <lst name="defaults">
125
+ <str name="echoParams">explicit</str>
126
+ <str name="defType">lucene</str>
127
+ </lst>
128
+ </requestHandler>
129
+
130
+ <!-- for requests to get a single document; use id=666 instead of q=id:666 -->
131
+ <requestHandler name="document" class="solr.SearchHandler" >
132
+ <lst name="defaults">
133
+ <str name="echoParams">all</str>
134
+ <str name="fl">*</str>
135
+ <str name="rows">1</str>
136
+ <str name="q">{!raw f=id v=$id}</str> <!-- use id=666 instead of q=id:666 -->
137
+ </lst>
138
+ </requestHandler>
139
+
140
+ <searchComponent name="spellcheck" class="solr.SpellCheckComponent">
141
+ <str name="queryAnalyzerFieldType">textSpell</str>
142
+ <!-- Multiple "Spell Checkers" can be declared and used by this component
143
+ (e.g. for title_spell field)
144
+ -->
145
+ <lst name="spellchecker">
146
+ <str name="name">default</str>
147
+ <str name="field">spell</str>
148
+ <str name="spellcheckIndexDir">./spell</str>
149
+ <str name="buildOnOptimize">true</str>
150
+ </lst>
151
+ </searchComponent>
152
+
153
+ <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" />
154
+
155
+ <requestDispatcher handleSelect="true" >
156
+ <requestParsers enableRemoteStreaming="true" multipartUploadLimitInKB="2048" />
157
+ </requestDispatcher>
158
+
159
+ <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
160
+ <requestHandler name="/update" class="solr.UpdateRequestHandler" />
161
+ <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
162
+
163
+ <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
164
+ <lst name="invariants">
165
+ <str name="q">solrpingquery</str>
166
+ </lst>
167
+ <lst name="defaults">
168
+ <str name="echoParams">all</str>
169
+ </lst>
170
+ </requestHandler>
171
+
172
+ <!-- config for the admin interface -->
173
+ <admin>
174
+ <defaultQuery>search</defaultQuery>
175
+ </admin>
176
+
177
+ </config>
@@ -11,6 +11,8 @@ Sufia.config do |config|
11
11
 
12
12
  config.max_days_between_audits = 7
13
13
 
14
+ config.max_notifications_for_dashboard = 5
15
+
14
16
  config.cc_licenses = {
15
17
  'Attribution 3.0 United States' => 'http://creativecommons.org/licenses/by/3.0/us/',
16
18
  'Attribution-ShareAlike 3.0 United States' => 'http://creativecommons.org/licenses/by-sa/3.0/us/',
@@ -108,7 +110,7 @@ Sufia.config do |config|
108
110
  if defined? BrowseEverything
109
111
  config.browse_everything = BrowseEverything.config
110
112
  else
111
- logger.warn "BrowseEverything is not installed"
113
+ Rails.logger.warn "BrowseEverything is not installed"
112
114
  end
113
115
  rescue Errno::ENOENT
114
116
  config.browse_everything = nil
@@ -13,6 +13,7 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
13
13
  1. Creates several database migrations if they do not exist in /db/migrate
14
14
  2. Runs the mailboxer upgrade generator
15
15
  3. Adds analytics to the sufia.rb configuration file
16
+ 4. Runs full-text generator
16
17
  """
17
18
 
18
19
  # Implement the required interface for Rails::Generators::Migration.
@@ -49,6 +50,7 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
49
50
  # Upgrade mailboxer
50
51
  def install_mailboxer
51
52
  generate "mailboxer:namespacing_compatibility"
53
+ generate "mailboxer:install -s"
52
54
  end
53
55
 
54
56
  # Add config file for Google Analytics
@@ -66,6 +68,11 @@ This generator for upgrading sufia-models from 3.7.2 to 4.0 makes the following
66
68
  end
67
69
  end
68
70
 
71
+ # Sets up full-text indexing (Solr config + jars)
72
+ def full_text_indexing
73
+ generate "sufia:models:fulltext"
74
+ end
75
+
69
76
  private
70
77
 
71
78
  def better_migration_template(file)
@@ -0,0 +1,67 @@
1
+ module Sufia
2
+ module Messages
3
+ extend ActiveSupport::Concern
4
+
5
+ # Borrowed from AbstractController so we can render html content tags
6
+ attr_accessor :output_buffer
7
+ include ActionView::Helpers::TagHelper
8
+ include ActionView::Helpers::UrlHelper
9
+
10
+ def success_subject
11
+ I18n.t("sufia.messages.success.subject")
12
+ end
13
+
14
+ def failure_subject
15
+ I18n.t("sufia.messages.failure.subject")
16
+ end
17
+
18
+ def single_success id, file
19
+ content_tag :span, id: "ss-"+id do
20
+ [link_to_file(file), I18n.t("sufia.messages.success.single")].join(" ").html_safe
21
+ end
22
+ end
23
+
24
+ def multiple_success id, files
25
+ content_tag :span, id: "ss-"+id do
26
+ [success_link(files), I18n.t("sufia.messages.success.multiple.tag")].join(" ").html_safe
27
+ end
28
+ end
29
+
30
+ def single_failure id, file
31
+ content_tag :span, id: "ss-"+id do
32
+ [link_to_file(file), I18n.t("sufia.messages.failure.single")].join(" ").html_safe
33
+ end
34
+ end
35
+
36
+ def multiple_failure id, files
37
+ content_tag :span, id: "ss-"+id do
38
+ [failure_link(files), I18n.t("sufia.messages.failure.multiple.tag")].join(" ").html_safe
39
+ end
40
+ end
41
+
42
+ # Double-quotes are replaced with single ones so this list can be included in a data block. Ex:
43
+ # <a href="#" data-content="<a href='#'>embedded link</a>" rel="popover">Click me</a>
44
+ def file_list files
45
+ files.map { |gf| link_to_file(gf) }.join(', ').gsub(/"/, "'")
46
+ end
47
+
48
+ def link_to_file file
49
+ link_to(file.to_s, Sufia::Engine.routes.url_helpers.generic_file_path(file.noid))
50
+ end
51
+
52
+ private
53
+
54
+ def success_link files
55
+ link_to I18n.t("sufia.messages.success.multiple.link"), "#",
56
+ rel: "popover",
57
+ data: { content: file_list(files).html_safe, title: I18n.t("sufia.messages.success.title") }
58
+ end
59
+
60
+ def failure_link files
61
+ link_to I18n.t("sufia.messages.failure.multiple.link"), "#",
62
+ rel: "popover",
63
+ data: { content: file_list(files).html_safe, title: I18n.t("sufia.messages.failure.title") }
64
+ end
65
+
66
+ end
67
+ end
data/lib/sufia/models.rb CHANGED
@@ -15,6 +15,8 @@ module Sufia
15
15
  end
16
16
 
17
17
  autoload :Utils, 'sufia/models/utils'
18
+ autoload :Permissions
19
+ autoload :Messages
18
20
 
19
21
  attr_writer :queue
20
22
 
@@ -1,10 +1,4 @@
1
1
  module ActiveFedora
2
- class UnsavedDigitalObject
3
- def assign_pid
4
- @pid ||= Sufia::IdService.mint
5
- end
6
- end
7
-
8
2
  class Base
9
3
  def stream
10
4
  Nest.new(self.class.name, $redis)[to_param]