curation_concerns-models 0.1.0

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.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.md +177 -0
  5. data/README.md +42 -0
  6. data/Rakefile +1 -0
  7. data/app/actors/concerns/curation_concerns/manages_embargoes_actor.rb +99 -0
  8. data/app/actors/curation_concerns/base_actor.rb +90 -0
  9. data/app/actors/curation_concerns/generic_file_actor.rb +150 -0
  10. data/app/actors/curation_concerns/work_actor_behavior.rb +88 -0
  11. data/app/jobs/active_fedora_id_based_job.rb +22 -0
  12. data/app/jobs/active_fedora_pid_based_job.rb +6 -0
  13. data/app/jobs/audit_job.rb +58 -0
  14. data/app/jobs/characterize_job.rb +11 -0
  15. data/app/jobs/copy_permissions_job.rb +24 -0
  16. data/app/jobs/create_derivatives_job.rb +15 -0
  17. data/app/jobs/import_url_job.rb +56 -0
  18. data/app/jobs/ingest_local_file_job.rb +48 -0
  19. data/app/jobs/resolrize_job.rb +9 -0
  20. data/app/models/checksum_audit_log.rb +21 -0
  21. data/app/models/concerns/curation_concerns/ability.rb +34 -0
  22. data/app/models/concerns/curation_concerns/basic_metadata.rb +87 -0
  23. data/app/models/concerns/curation_concerns/collection_behavior.rb +47 -0
  24. data/app/models/concerns/curation_concerns/generic_file/belongs_to_works.rb +53 -0
  25. data/app/models/concerns/curation_concerns/generic_file/characterization.rb +89 -0
  26. data/app/models/concerns/curation_concerns/generic_file/content.rb +8 -0
  27. data/app/models/concerns/curation_concerns/generic_file/export.rb +343 -0
  28. data/app/models/concerns/curation_concerns/generic_file/full_text_indexing.rb +12 -0
  29. data/app/models/concerns/curation_concerns/generic_file/indexing.rb +14 -0
  30. data/app/models/concerns/curation_concerns/generic_file/versions.rb +16 -0
  31. data/app/models/concerns/curation_concerns/generic_file.rb +5 -0
  32. data/app/models/concerns/curation_concerns/generic_file_behavior.rb +44 -0
  33. data/app/models/concerns/curation_concerns/generic_work_behavior.rb +38 -0
  34. data/app/models/concerns/curation_concerns/has_representative.rb +14 -0
  35. data/app/models/concerns/curation_concerns/human_readable_type.rb +23 -0
  36. data/app/models/concerns/curation_concerns/permissions/readable.rb +19 -0
  37. data/app/models/concerns/curation_concerns/permissions/writable.rb +75 -0
  38. data/app/models/concerns/curation_concerns/permissions.rb +7 -0
  39. data/app/models/concerns/curation_concerns/serializers.rb +15 -0
  40. data/app/models/concerns/curation_concerns/solr_document_behavior.rb +135 -0
  41. data/app/models/concerns/curation_concerns/user.rb +65 -0
  42. data/app/models/concerns/curation_concerns/with_basic_metadata.rb +98 -0
  43. data/app/models/concerns/curation_concerns/with_generic_files.rb +29 -0
  44. data/app/models/curation_concerns/classify_concern.rb +47 -0
  45. data/app/models/curation_concerns/quick_classification_query.rb +31 -0
  46. data/app/models/datastreams/fits_datastream.rb +148 -0
  47. data/app/models/version_committer.rb +2 -0
  48. data/app/services/curation_concerns/characterization_service.rb +71 -0
  49. data/app/services/curation_concerns/full_text_extraction_service.rb +38 -0
  50. data/app/services/curation_concerns/generic_file_audit_service.rb +85 -0
  51. data/app/services/curation_concerns/generic_file_indexing_service.rb +14 -0
  52. data/app/services/curation_concerns/generic_work_indexing_service.rb +16 -0
  53. data/app/services/curation_concerns/noid.rb +23 -0
  54. data/app/services/curation_concerns/repository_audit_service.rb +9 -0
  55. data/app/services/curation_concerns/versioning_service.rb +27 -0
  56. data/config/locales/curation_concerns.en.yml +6 -0
  57. data/curation_concerns-models.gemspec +34 -0
  58. data/lib/curation_concerns/messages.rb +66 -0
  59. data/lib/curation_concerns/models/engine.rb +61 -0
  60. data/lib/curation_concerns/models/resque.rb +36 -0
  61. data/lib/curation_concerns/models/utils.rb +22 -0
  62. data/lib/curation_concerns/models/version.rb +5 -0
  63. data/lib/curation_concerns/models.rb +32 -0
  64. data/lib/generators/curation_concerns/models/abstract_migration_generator.rb +30 -0
  65. data/lib/generators/curation_concerns/models/clamav_generator.rb +19 -0
  66. data/lib/generators/curation_concerns/models/fulltext_generator.rb +28 -0
  67. data/lib/generators/curation_concerns/models/install_generator.rb +70 -0
  68. data/lib/generators/curation_concerns/models/templates/app/models/collection.rb +4 -0
  69. data/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb +4 -0
  70. data/lib/generators/curation_concerns/models/templates/config/clamav.rb +1 -0
  71. data/lib/generators/curation_concerns/models/templates/config/curation_concerns.rb +123 -0
  72. data/lib/generators/curation_concerns/models/templates/config/mime_types.rb +6 -0
  73. data/lib/generators/curation_concerns/models/templates/config/redis.yml +9 -0
  74. data/lib/generators/curation_concerns/models/templates/config/redis_config.rb +32 -0
  75. data/lib/generators/curation_concerns/models/templates/config/resque-pool.yml +1 -0
  76. data/lib/generators/curation_concerns/models/templates/config/resque_admin.rb +10 -0
  77. data/lib/generators/curation_concerns/models/templates/config/resque_config.rb +5 -0
  78. data/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb +19 -0
  79. data/lib/generators/curation_concerns/models/templates/migrations/create_version_committers.rb +15 -0
  80. data/lib/tasks/curation_concerns-models_tasks.rake +75 -0
  81. data/lib/tasks/migrate.rake +13 -0
  82. data/lib/tasks/resque.rake +13 -0
  83. data/lib/tasks/solr_reindex.rake +8 -0
  84. metadata +282 -0
@@ -0,0 +1,343 @@
1
+ module CurationConcerns
2
+ module GenericFile
3
+ module Export
4
+ # MIME: 'application/x-endnote-refer'
5
+ def export_as_endnote
6
+ end_note_format = {
7
+ '%T' => [:title, lambda { |x| x.first }],
8
+ '%Q' => [:title, lambda { |x| x.drop(1) }],
9
+ '%A' => [:creator],
10
+ '%C' => [:publication_place],
11
+ '%D' => [:date_created],
12
+ '%8' => [:date_uploaded],
13
+ '%E' => [:contributor],
14
+ '%I' => [:publisher],
15
+ '%J' => [:series_title],
16
+ '%@' => [:isbn],
17
+ '%U' => [:related_url],
18
+ '%7' => [:edition_statement],
19
+ '%R' => [:persistent_url],
20
+ '%X' => [:description],
21
+ '%G' => [:language],
22
+ '%[' => [:date_modified],
23
+ '%9' => [:resource_type],
24
+ '%~' => I18n.t('curation_concerns.product_name'),
25
+ '%W' => I18n.t('curation_concerns.institution_name')
26
+ }
27
+ text = []
28
+ text << "%0 GenericFile"
29
+ end_note_format.each do |endnote_key, mapping|
30
+ if mapping.is_a? String
31
+ values = [mapping]
32
+ else
33
+ values = self.send(mapping[0]) if self.respond_to? mapping[0]
34
+ values = mapping[1].call(values) if mapping.length == 2
35
+ values = Array(values)
36
+ end
37
+ next if values.empty? or values.first.nil?
38
+ spaced_values = values.join("; ")
39
+ text << "#{endnote_key} #{spaced_values}"
40
+ end
41
+ return text.join("\n")
42
+ end
43
+
44
+ def persistent_url
45
+ "#{CurationConcerns.config.persistent_hostpath}#{id}"
46
+ end
47
+
48
+ # MIME type: 'application/x-openurl-ctx-kev'
49
+ def export_as_openurl_ctx_kev
50
+ export_text = []
51
+ export_text << "url_ver=Z39.88-2004&ctx_ver=Z39.88-2004&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&rfr_id=info%3Asid%2Fblacklight.rubyforge.org%3Agenerator"
52
+ field_map = {
53
+ title: 'title',
54
+ creator: 'creator',
55
+ subject: 'subject',
56
+ description: 'description',
57
+ publisher: 'publisher',
58
+ contributor: 'contributor',
59
+ date_created: 'date',
60
+ resource_type: 'format',
61
+ identifier: 'identifier',
62
+ language: 'language',
63
+ tag: 'relation',
64
+ based_near: 'coverage',
65
+ rights: 'rights'
66
+ }
67
+ field_map.each do |element, kev|
68
+ values = self.send(element)
69
+ next if values.empty? or values.first.nil?
70
+ values.each do |value|
71
+ export_text << "rft.#{kev}=#{CGI::escape(value.to_s)}"
72
+ end
73
+ end
74
+ export_text.join('&') unless export_text.blank?
75
+ end
76
+
77
+ def export_as_apa_citation
78
+ text = ''
79
+ authors_list = []
80
+ authors_list_final = []
81
+
82
+ #setup formatted author list
83
+ authors = get_author_list
84
+ authors.each do |author|
85
+ next if author.blank?
86
+ authors_list.push(abbreviate_name(author))
87
+ end
88
+ authors_list.each do |author|
89
+ if author == authors_list.first #first
90
+ authors_list_final.push(author.strip)
91
+ elsif author == authors_list.last #last
92
+ authors_list_final.push(", &amp; " + author.strip)
93
+ else #all others
94
+ authors_list_final.push(", " + author.strip)
95
+ end
96
+ end
97
+ text << authors_list_final.join
98
+ unless text.blank?
99
+ if text[-1,1] != "."
100
+ text << ". "
101
+ else
102
+ text << " "
103
+ end
104
+ end
105
+ # Get Pub Date
106
+ text << "(" + setup_pub_date + "). " unless setup_pub_date.nil?
107
+
108
+ # setup title info
109
+ title_info = setup_title_info
110
+ text << "<i>" + title_info + "</i> " unless title_info.nil?
111
+
112
+ # Publisher info
113
+ text << setup_pub_info unless setup_pub_info.nil?
114
+ unless text.blank?
115
+ if text[-1,1] != "."
116
+ text += "."
117
+ end
118
+ end
119
+ text.html_safe
120
+ end
121
+
122
+ def export_as_mla_citation
123
+ text = ''
124
+ authors_final = []
125
+
126
+ #setup formatted author list
127
+ authors = get_author_list
128
+
129
+ if authors.length < 4
130
+ authors.each do |author|
131
+ if author == authors.first #first
132
+ authors_final.push(author)
133
+ elsif author == authors.last #last
134
+ authors_final.push(", and " + name_reverse(author) + ".")
135
+ else #all others
136
+ authors_final.push(", " + name_reverse(author))
137
+ end
138
+ end
139
+ text << authors_final.join
140
+ unless text.blank?
141
+ if text[-1,1] != "."
142
+ text << ". "
143
+ else
144
+ text << " "
145
+ end
146
+ end
147
+ else
148
+ text << authors.first + ", et al. "
149
+ end
150
+ # setup title
151
+ title_info = setup_title_info
152
+ text << "<i>" + mla_citation_title(title_info) + "</i> " unless title.blank?
153
+
154
+ # Publication
155
+ text << setup_pub_info + ", " unless setup_pub_info.nil?
156
+
157
+ # Get Pub Date
158
+ text << setup_pub_date unless setup_pub_date.nil?
159
+ if text[-1,1] != "."
160
+ text << "." unless text.blank?
161
+ end
162
+ text.html_safe
163
+ end
164
+
165
+ def export_as_chicago_citation
166
+ author_text = ""
167
+ authors = get_all_authors
168
+ unless authors.blank?
169
+ if authors.length > 10
170
+ authors.each_with_index do |author, index|
171
+ if index < 7
172
+ if index == 0
173
+ author_text << "#{author}"
174
+ if author.ends_with?(",")
175
+ author_text << " "
176
+ else
177
+ author_text << ", "
178
+ end
179
+ else
180
+ author_text << "#{name_reverse(author)}, "
181
+ end
182
+ end
183
+ end
184
+ author_text << " et al."
185
+ elsif authors.length > 1
186
+ authors.each_with_index do |author,index|
187
+ if index == 0
188
+ author_text << "#{author}"
189
+ if author.ends_with?(",")
190
+ author_text << " "
191
+ else
192
+ author_text << ", "
193
+ end
194
+ elsif index + 1 == authors.length
195
+ author_text << "and #{name_reverse(author)}."
196
+ else
197
+ author_text << "#{name_reverse(author)}, "
198
+ end
199
+ end
200
+ else
201
+ author_text << authors.first
202
+ end
203
+ end
204
+ title_info = ""
205
+ title_info << citation_title(clean_end_punctuation(CGI::escapeHTML(title.first)).strip) unless title.blank?
206
+
207
+ pub_info = ""
208
+ place = self.based_near.first
209
+ publisher = self.publisher.first
210
+ unless place.blank?
211
+ place = CGI::escapeHTML(place)
212
+ pub_info << place
213
+ pub_info << ": " unless publisher.blank?
214
+ end
215
+ unless publisher.blank?
216
+ publisher = CGI::escapeHTML(publisher)
217
+ pub_info << publisher
218
+ pub_info << ", " unless setup_pub_date.nil?
219
+ end
220
+ unless setup_pub_date.nil?
221
+ pub_info << setup_pub_date
222
+ end
223
+
224
+ citation = ""
225
+ citation << "#{author_text} " unless author_text.blank?
226
+ citation << "<i>#{title_info}.</i> " unless title_info.blank?
227
+ citation << "#{pub_info}." unless pub_info.blank?
228
+ citation.html_safe
229
+ end
230
+
231
+ private
232
+
233
+ def setup_pub_date
234
+ first_date = self.date_created.first
235
+ unless first_date.blank?
236
+ first_date = CGI::escapeHTML(first_date)
237
+ date_value = first_date.gsub(/[^0-9|n\.d\.]/, "")[0,4]
238
+ return nil if date_value.nil?
239
+ end
240
+ clean_end_punctuation(date_value) if date_value
241
+ end
242
+
243
+ def setup_pub_info
244
+ text = ''
245
+ place = self.based_near.first
246
+ publisher = self.publisher.first
247
+ unless place.blank?
248
+ place = CGI::escapeHTML(place)
249
+ text << place
250
+ text << ": " unless publisher.blank?
251
+ end
252
+ unless publisher.blank?
253
+ publisher = CGI::escapeHTML(publisher)
254
+ text << publisher
255
+ end
256
+ return nil if text.strip.blank?
257
+ clean_end_punctuation(text.strip)
258
+ end
259
+
260
+ def mla_citation_title(text)
261
+ no_upcase = ["a","an","and","but","by","for","it","of","the","to","with"]
262
+ new_text = []
263
+ word_parts = text.split(" ")
264
+ word_parts.each do |w|
265
+ if !no_upcase.include? w
266
+ new_text.push(w.capitalize)
267
+ else
268
+ new_text.push(w)
269
+ end
270
+ end
271
+ new_text.join(" ")
272
+ end
273
+
274
+ def citation_title(title_text)
275
+ prepositions = ["a","about","across","an","and","before","but","by","for","it","of","the","to","with","without"]
276
+ new_text = []
277
+ title_text.split(" ").each_with_index do |word,index|
278
+ if (index == 0 and word != word.upcase) or (word.length > 1 and word != word.upcase and !prepositions.include?(word))
279
+ # the split("-") will handle the capitalization of hyphenated words
280
+ new_text << word.split("-").map!{|w| w.capitalize }.join("-")
281
+ else
282
+ new_text << word
283
+ end
284
+ end
285
+ new_text.join(" ")
286
+ end
287
+
288
+ def setup_title_info
289
+ text = ''
290
+ title = self.title.first
291
+ unless title.blank?
292
+ title = CGI::escapeHTML(title)
293
+ title_info = clean_end_punctuation(title.strip)
294
+ text << title_info
295
+ end
296
+
297
+ return nil if text.strip.blank?
298
+ clean_end_punctuation(text.strip) + "."
299
+ end
300
+
301
+ def clean_end_punctuation(text)
302
+ if [".",",",":",";","/"].include? text[-1,1]
303
+ return text[0,text.length-1]
304
+ end
305
+ text
306
+ end
307
+
308
+ def get_author_list
309
+ self.creator.map { |author| clean_end_punctuation(CGI::escapeHTML(author)) }.uniq
310
+ end
311
+
312
+ def get_all_authors
313
+ authors = self.creator
314
+ return authors.empty? ? nil : authors.map { |author| CGI::escapeHTML(author) }
315
+ end
316
+
317
+ def abbreviate_name(name)
318
+ abbreviated_name = ''
319
+ name = name.join('') if name.is_a? Array
320
+ # make sure we handle "Cher" correctly
321
+ return name if !name.include?(' ') and !name.include?(',')
322
+ surnames_first = name.include?(',')
323
+ delimiter = surnames_first ? ', ' : ' '
324
+ name_segments = name.split(delimiter)
325
+ given_names = surnames_first ? name_segments.last.split(' ') : name_segments.first.split(' ')
326
+ surnames = surnames_first ? name_segments.first.split(' ') : name_segments.last.split(' ')
327
+ abbreviated_name << surnames.join(' ')
328
+ abbreviated_name << ', '
329
+ abbreviated_name << given_names.map { |n| "#{n[0]}." }.join if given_names.is_a? Array
330
+ abbreviated_name << "#{given_names[0]}." if given_names.is_a? String
331
+ abbreviated_name
332
+ end
333
+
334
+ def name_reverse(name)
335
+ name = clean_end_punctuation(name)
336
+ return name unless name =~ /,/
337
+ temp_name = name.split(", ")
338
+ return temp_name.last + " " + temp_name.first
339
+ end
340
+
341
+ end
342
+ end
343
+ end
@@ -0,0 +1,12 @@
1
+ module CurationConcerns
2
+ module GenericFile
3
+ module FullTextIndexing
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ contains 'full_text'
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module CurationConcerns
2
+ module GenericFile
3
+ module Indexing
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ # override the default indexing service
8
+ def indexer
9
+ CurationConcerns::GenericFileIndexingService
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module CurationConcerns
2
+ module GenericFile
3
+ module Versions
4
+ @@count = 0
5
+ def record_version_committer(user)
6
+ version = self.latest_version
7
+ # content datastream not (yet?) present
8
+ return if version.nil?
9
+ @@count += 1
10
+ # raise "Recording #{@@count} #{version.uri} for #{user.user_key}" if @@count == 3
11
+ VersionCommitter.create(version_id: version.uri, committer_login: user.user_key)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module CurationConcerns
2
+ # Base namespace for GenericFile Behavior modules
3
+ module GenericFile
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ module CurationConcerns
2
+ module GenericFileBehavior
3
+ extend ActiveSupport::Concern
4
+ include Hydra::Works::GenericFileBehavior
5
+ include Hydra::Works::GenericFile::VirusCheck
6
+ include Hydra::WithDepositor
7
+ include CurationConcerns::Serializers
8
+ include CurationConcerns::Noid
9
+ include CurationConcerns::Permissions
10
+ include CurationConcerns::GenericFile::Export
11
+ include CurationConcerns::GenericFile::Characterization
12
+ include CurationConcerns::BasicMetadata
13
+ include CurationConcerns::GenericFile::Content
14
+ include CurationConcerns::GenericFile::FullTextIndexing
15
+ include CurationConcerns::GenericFile::Indexing
16
+ include CurationConcerns::GenericFile::BelongsToWorks
17
+ include Hydra::AccessControls::Embargoable
18
+
19
+ included do
20
+ attr_accessor :file
21
+
22
+ # make filename single-value (CurationConcerns::GenericFile::Characterization makes it multivalue)
23
+ def filename
24
+ self[:filename].first
25
+ end
26
+ end
27
+
28
+ def human_readable_type
29
+ self.class.to_s.demodulize.titleize
30
+ end
31
+
32
+ def representative
33
+ to_param
34
+ end
35
+
36
+ def to_solr(solr_doc = {})
37
+ super(solr_doc).tap do |solr_doc|
38
+ # Enables Riiif to not have to recalculate this each time.
39
+ solr_doc['height_isi'] = Integer(height.first) if height.present?
40
+ solr_doc['width_isi'] = Integer(width.first) if width.present?
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ module CurationConcerns::GenericWorkBehavior
2
+ extend ActiveSupport::Concern
3
+
4
+ include Hydra::Works::GenericWorkBehavior
5
+ include ::CurationConcerns::HumanReadableType
6
+ include CurationConcerns::Noid
7
+ include CurationConcerns::Permissions
8
+ include CurationConcerns::Serializers
9
+ include Hydra::WithDepositor
10
+ include Solrizer::Common
11
+ include ::CurationConcerns::HasRepresentative
12
+ include ::CurationConcerns::WithGenericFiles
13
+ include Hydra::AccessControls::Embargoable
14
+
15
+ included do
16
+ property :owner, predicate: RDF::URI.new('http://opaquenamespace.org/ns/hydra/owner'), multiple: false
17
+ class_attribute :human_readable_short_description
18
+ end
19
+
20
+ module ClassMethods
21
+ def indexer
22
+ CurationConcerns::GenericWorkIndexingService
23
+ end
24
+ end
25
+
26
+ def to_s
27
+ title.join(', ')
28
+ end
29
+
30
+ # Returns a string identifying the path associated with the object. ActionPack uses this to find a suitable partial to represent the object.
31
+ def to_partial_path
32
+ "curation_concerns/#{super}"
33
+ end
34
+
35
+ def can_be_member_of_collection?(collection)
36
+ true
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module CurationConcerns::HasRepresentative
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ property :representative, predicate: RDF::URI.new('http://opaquenamespace.org/ns/hydra/representative'), multiple: false
6
+ end
7
+
8
+ def to_solr(solr_doc={})
9
+ super.tap do |solr_doc|
10
+ solr_doc[Solrizer.solr_name('representative', :stored_searchable)] = representative
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,23 @@
1
+ module CurationConcerns
2
+ module HumanReadableType
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_attribute :human_readable_short_description, :human_readable_type
7
+ self.human_readable_type = name.demodulize.titleize
8
+ end
9
+
10
+ def human_readable_type
11
+ self.class.human_readable_type
12
+ end
13
+
14
+ def to_solr(solr_doc={})
15
+ super(solr_doc).tap do |solr_doc|
16
+ solr_doc[Solrizer.solr_name('human_readable_type',:facetable)] = human_readable_type
17
+ solr_doc[Solrizer.solr_name('human_readable_type', :stored_searchable)] = human_readable_type
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,19 @@
1
+ module CurationConcerns
2
+ module Permissions
3
+ module Readable
4
+ extend ActiveSupport::Concern
5
+ def public?
6
+ read_groups.include?('public')
7
+ end
8
+
9
+ def registered?
10
+ read_groups.include?('registered')
11
+ end
12
+
13
+ def private?
14
+ !(public? || registered?)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,75 @@
1
+ module CurationConcerns
2
+ module Permissions
3
+ module Writable
4
+ extend ActiveSupport::Concern
5
+
6
+ #we're overriding the permissions= method which is in Hydra::AccessControls::Permissions
7
+ include Hydra::AccessControls::Permissions
8
+ include Hydra::AccessControls::Visibility
9
+
10
+ included do
11
+ validate :paranoid_permissions
12
+ end
13
+
14
+ def paranoid_permissions
15
+ valid = true
16
+ paranoid_edit_permissions.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
24
+ end
25
+
26
+ def paranoid_edit_permissions
27
+ [
28
+ {key: :edit_users, message: 'Depositor must have edit access', condition: lambda { |obj| !obj.edit_users.include?(obj.depositor) }},
29
+ {key: :edit_groups, message: 'Public cannot have edit access', condition: lambda { |obj| obj.edit_groups.include?('public') }},
30
+ {key: :edit_groups, message: 'Registered cannot have edit access', condition: lambda { |obj| obj.edit_groups.include?('registered') }}
31
+ ]
32
+ end
33
+
34
+ def clear_permissions!
35
+ self.permissions = []
36
+ end
37
+
38
+ ## Updates those permissions that are provided to it. Does not replace any permissions unless they are provided
39
+ # def permissions=(params)
40
+ # raise "Fixme #{params}"
41
+ # perm_hash = permission_hash
42
+ # params[:new_user_name].each { |name, access| perm_hash['person'][name] = access } if params[:new_user_name].present?
43
+ # params[:new_group_name].each { |name, access| perm_hash['group'][name] = access } if params[:new_group_name].present?
44
+
45
+ # params[:user].each { |name, access| perm_hash['person'][name] = access} if params[:user]
46
+ # params[:group].each { |name, access| perm_hash['group'][name] = access if ['read', 'edit'].include?(access)} if params[:group]
47
+
48
+ # # rightsMetadata.update_permissions(perm_hash)
49
+ # end
50
+
51
+ # def permissions
52
+ # raise "Fixme "
53
+ # perms = super
54
+ # perms.map {|p| { name: p.name, access: p.access, type:p.type } }
55
+ # end
56
+
57
+ private
58
+
59
+ def permission_hash
60
+ old_perms = self.permissions
61
+ user_perms = {}
62
+ old_perms.select{|r| r[:type] == 'user'}.each do |r|
63
+ user_perms[r[:name]] = r[:access]
64
+ end
65
+ user_perms
66
+ group_perms = {}
67
+ old_perms.select{|r| r[:type] == 'group'}.each do |r|
68
+ group_perms[r[:name]] = r[:access]
69
+ end
70
+ {'person'=>user_perms, 'group'=>group_perms}
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,7 @@
1
+ module CurationConcerns
2
+ module Permissions
3
+ extend ActiveSupport::Concern
4
+ include CurationConcerns::Permissions::Writable
5
+ include CurationConcerns::Permissions::Readable
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module CurationConcerns
2
+ module Serializers
3
+
4
+ def to_s
5
+ if title.present?
6
+ Array(title).join(" | ")
7
+ elsif label.present?
8
+ Array(label).join(" | ")
9
+ else
10
+ "No Title"
11
+ end
12
+ end
13
+
14
+ end
15
+ end