Merge branch 'master' into 15209-python-arv-deps-pinned
[arvados.git] / services / api / app / models / collection.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'arvados/keep'
6 require 'sweep_trashed_objects'
7 require 'trashable'
8
9 class Collection < ArvadosModel
10   extend CurrentApiClient
11   extend DbCurrentTime
12   include HasUuid
13   include KindAndEtag
14   include CommonApiTemplate
15   include Trashable
16
17   # Posgresql JSONB columns should NOT be declared as serialized, Rails 5
18   # already know how to properly treat them.
19   attribute :properties, :jsonbHash, default: {}
20   attribute :storage_classes_desired, :jsonbArray, default: ["default"]
21   attribute :storage_classes_confirmed, :jsonbArray, default: []
22
23   before_validation :default_empty_manifest
24   before_validation :default_storage_classes, on: :create
25   before_validation :managed_properties, on: :create
26   before_validation :check_encoding
27   before_validation :check_manifest_validity
28   before_validation :check_signatures
29   before_validation :strip_signatures_and_update_replication_confirmed
30   validate :ensure_pdh_matches_manifest_text
31   validate :ensure_storage_classes_desired_is_not_empty
32   validate :ensure_storage_classes_contain_non_empty_strings
33   validate :versioning_metadata_updates, on: :update
34   validate :past_versions_cannot_be_updated, on: :update
35   validate :protected_managed_properties_updates, on: :update
36   after_validation :set_file_count_and_total_size
37   before_save :set_file_names
38   around_update :manage_versioning, unless: :is_past_version?
39
40   api_accessible :user, extend: :common do |t|
41     t.add :name
42     t.add :description
43     t.add :properties
44     t.add :portable_data_hash
45     t.add :signed_manifest_text, as: :manifest_text
46     t.add :manifest_text, as: :unsigned_manifest_text
47     t.add :replication_desired
48     t.add :replication_confirmed
49     t.add :replication_confirmed_at
50     t.add :storage_classes_desired
51     t.add :storage_classes_confirmed
52     t.add :storage_classes_confirmed_at
53     t.add :delete_at
54     t.add :trash_at
55     t.add :is_trashed
56     t.add :version
57     t.add :current_version_uuid
58     t.add :preserve_version
59     t.add :file_count
60     t.add :file_size_total
61   end
62
63   after_initialize do
64     @signatures_checked = false
65     @computed_pdh_for_manifest_text = false
66   end
67
68   def self.attributes_required_columns
69     super.merge(
70                 # If we don't list manifest_text explicitly, the
71                 # params[:select] code gets confused by the way we
72                 # expose signed_manifest_text as manifest_text in the
73                 # API response, and never let clients select the
74                 # manifest_text column.
75                 #
76                 # We need trash_at and is_trashed to determine the
77                 # correct timestamp in signed_manifest_text.
78                 'manifest_text' => ['manifest_text', 'trash_at', 'is_trashed'],
79                 'unsigned_manifest_text' => ['manifest_text'],
80                 )
81   end
82
83   def self.ignored_select_attributes
84     super + ["updated_at", "file_names"]
85   end
86
87   def self.limit_index_columns_read
88     ["manifest_text"]
89   end
90
91   FILE_TOKEN = /^[[:digit:]]+:[[:digit:]]+:/
92   def check_signatures
93     throw(:abort) if self.manifest_text.nil?
94
95     return true if current_user.andand.is_admin
96
97     # Provided the manifest_text hasn't changed materially since an
98     # earlier validation, it's safe to pass this validation on
99     # subsequent passes without checking any signatures. This is
100     # important because the signatures have probably been stripped off
101     # by the time we get to a second validation pass!
102     if @signatures_checked && @signatures_checked == computed_pdh
103       return true
104     end
105
106     if self.manifest_text_changed?
107       # Check permissions on the collection manifest.
108       # If any signature cannot be verified, raise PermissionDeniedError
109       # which will return 403 Permission denied to the client.
110       api_token = Thread.current[:token]
111       signing_opts = {
112         api_token: api_token,
113         now: @validation_timestamp.to_i,
114       }
115       self.manifest_text.each_line do |entry|
116         entry.split.each do |tok|
117           if tok == '.' or tok.starts_with? './'
118             # Stream name token.
119           elsif tok =~ FILE_TOKEN
120             # This is a filename token, not a blob locator. Note that we
121             # keep checking tokens after this, even though manifest
122             # format dictates that all subsequent tokens will also be
123             # filenames. Safety first!
124           elsif Blob.verify_signature tok, signing_opts
125             # OK.
126           elsif Keep::Locator.parse(tok).andand.signature
127             # Signature provided, but verify_signature did not like it.
128             logger.warn "Invalid signature on locator #{tok}"
129             raise ArvadosModel::PermissionDeniedError
130           elsif !Rails.configuration.Collections.BlobSigning
131             # No signature provided, but we are running in insecure mode.
132             logger.debug "Missing signature on locator #{tok} ignored"
133           elsif Blob.new(tok).empty?
134             # No signature provided -- but no data to protect, either.
135           else
136             logger.warn "Missing signature on locator #{tok}"
137             raise ArvadosModel::PermissionDeniedError
138           end
139         end
140       end
141     end
142     @signatures_checked = computed_pdh
143   end
144
145   def strip_signatures_and_update_replication_confirmed
146     if self.manifest_text_changed?
147       in_old_manifest = {}
148       if not self.replication_confirmed.nil?
149         self.class.each_manifest_locator(manifest_text_was) do |match|
150           in_old_manifest[match[1]] = true
151         end
152       end
153
154       stripped_manifest = self.class.munge_manifest_locators(manifest_text) do |match|
155         if not self.replication_confirmed.nil? and not in_old_manifest[match[1]]
156           # If the new manifest_text contains locators whose hashes
157           # weren't in the old manifest_text, storage replication is no
158           # longer confirmed.
159           self.replication_confirmed_at = nil
160           self.replication_confirmed = nil
161         end
162
163         # Return the locator with all permission signatures removed,
164         # but otherwise intact.
165         match[0].gsub(/\+A[^+]*/, '')
166       end
167
168       if @computed_pdh_for_manifest_text == manifest_text
169         # If the cached PDH was valid before stripping, it is still
170         # valid after stripping.
171         @computed_pdh_for_manifest_text = stripped_manifest.dup
172       end
173
174       self[:manifest_text] = stripped_manifest
175     end
176     true
177   end
178
179   def ensure_pdh_matches_manifest_text
180     if not manifest_text_changed? and not portable_data_hash_changed?
181       true
182     elsif portable_data_hash.nil? or not portable_data_hash_changed?
183       self.portable_data_hash = computed_pdh
184     elsif portable_data_hash !~ Keep::Locator::LOCATOR_REGEXP
185       errors.add(:portable_data_hash, "is not a valid locator")
186       false
187     elsif portable_data_hash[0..31] != computed_pdh[0..31]
188       errors.add(:portable_data_hash,
189                  "'#{portable_data_hash}' does not match computed hash '#{computed_pdh}'")
190       false
191     else
192       # Ignore the client-provided size part: always store
193       # computed_pdh in the database.
194       self.portable_data_hash = computed_pdh
195     end
196   end
197
198   def set_file_names
199     if self.manifest_text_changed?
200       self.file_names = manifest_files
201     end
202     true
203   end
204
205   def set_file_count_and_total_size
206     # Only update the file stats if the manifest changed
207     if self.manifest_text_changed?
208       m = Keep::Manifest.new(self.manifest_text)
209       self.file_size_total = m.files_size
210       self.file_count = m.files_count
211     # If the manifest didn't change but the attributes did, ignore the changes
212     elsif self.file_count_changed? || self.file_size_total_changed?
213       self.file_count = self.file_count_was
214       self.file_size_total = self.file_size_total_was
215     end
216     true
217   end
218
219   def manifest_files
220     return '' if !self.manifest_text
221
222     done = {}
223     names = ''
224     self.manifest_text.scan(/ \d+:\d+:(\S+)/) do |name|
225       next if done[name]
226       done[name] = true
227       names << name.first.gsub('\040',' ') + "\n"
228     end
229     self.manifest_text.scan(/^\.\/(\S+)/m) do |stream_name|
230       next if done[stream_name]
231       done[stream_name] = true
232       names << stream_name.first.gsub('\040',' ') + "\n"
233     end
234     names
235   end
236
237   def default_empty_manifest
238     self.manifest_text ||= ''
239   end
240
241   def skip_uuid_existence_check
242     # Avoid checking the existence of current_version_uuid, as it's
243     # assigned on creation of a new 'current version' collection, so
244     # the collection's UUID only lives on memory when the validation check
245     # is performed.
246     ['current_version_uuid']
247   end
248
249   def manage_versioning
250     should_preserve_version = should_preserve_version? # Time sensitive, cache value
251     return(yield) unless (should_preserve_version || syncable_updates.any?)
252
253     # Put aside the changes because with_lock forces a record reload
254     changes = self.changes
255     snapshot = nil
256     with_lock do
257       # Copy the original state to save it as old version
258       if should_preserve_version
259         snapshot = self.dup
260         snapshot.uuid = nil # Reset UUID so it's created as a new record
261         snapshot.created_at = self.created_at
262       end
263
264       # Restore requested changes on the current version
265       changes.keys.each do |attr|
266         if attr == 'preserve_version' && changes[attr].last == false
267           next # Ignore false assignment, once true it'll be true until next version
268         end
269         self.attributes = {attr => changes[attr].last}
270         if attr == 'uuid'
271           # Also update the current version reference
272           self.attributes = {'current_version_uuid' => changes[attr].last}
273         end
274       end
275
276       if should_preserve_version
277         self.version += 1
278         self.preserve_version = false
279       end
280
281       yield
282
283       sync_past_versions if syncable_updates.any?
284       if snapshot
285         snapshot.attributes = self.syncable_updates
286         leave_modified_by_user_alone do
287           act_as_system_user do
288             snapshot.save
289           end
290         end
291       end
292     end
293   end
294
295   def syncable_updates
296     updates = {}
297     (syncable_attrs & self.changes.keys).each do |attr|
298       if attr == 'uuid'
299         # Point old versions to current version's new UUID
300         updates['current_version_uuid'] = self.changes[attr].last
301       else
302         updates[attr] = self.changes[attr].last
303       end
304     end
305     return updates
306   end
307
308   def sync_past_versions
309     updates = self.syncable_updates
310     Collection.where('current_version_uuid = ? AND uuid != ?', self.uuid_was, self.uuid_was).each do |c|
311       c.attributes = updates
312       # Use a different validation context to skip the 'past_versions_cannot_be_updated'
313       # validator, as on this case it is legal to update some fields.
314       leave_modified_by_user_alone do
315         leave_modified_at_alone do
316           c.save(context: :update_old_versions)
317         end
318       end
319     end
320   end
321
322   def versionable_updates?(attrs)
323     (['manifest_text', 'description', 'properties', 'name'] & attrs).any?
324   end
325
326   def syncable_attrs
327     ['uuid', 'owner_uuid', 'delete_at', 'trash_at', 'is_trashed', 'replication_desired', 'storage_classes_desired']
328   end
329
330   def is_past_version?
331     # Check for the '_was' values just in case the update operation
332     # includes a change on current_version_uuid or uuid.
333     !(new_record? || self.current_version_uuid_was == self.uuid_was)
334   end
335
336   def should_preserve_version?
337     return false unless (Rails.configuration.Collections.CollectionVersioning && versionable_updates?(self.changes.keys))
338
339     return false if self.is_trashed
340
341     idle_threshold = Rails.configuration.Collections.PreserveVersionIfIdle
342     if !self.preserve_version_was &&
343       (idle_threshold < 0 ||
344         (idle_threshold > 0 && self.modified_at_was > db_current_time-idle_threshold.seconds))
345       return false
346     end
347     return true
348   end
349
350   def check_encoding
351     if !(manifest_text.encoding.name == 'UTF-8' and manifest_text.valid_encoding?)
352       begin
353         # If Ruby thinks the encoding is something else, like 7-bit
354         # ASCII, but its stored bytes are equal to the (valid) UTF-8
355         # encoding of the same string, we declare it to be a UTF-8
356         # string.
357         utf8 = manifest_text
358         utf8.force_encoding Encoding::UTF_8
359         if utf8.valid_encoding? and utf8 == manifest_text.encode(Encoding::UTF_8)
360           self.manifest_text = utf8
361           return true
362         end
363       rescue
364       end
365       errors.add :manifest_text, "must use UTF-8 encoding"
366       throw(:abort)
367     end
368   end
369
370   def check_manifest_validity
371     begin
372       Keep::Manifest.validate! manifest_text
373       true
374     rescue ArgumentError => e
375       errors.add :manifest_text, e.message
376       throw(:abort)
377     end
378   end
379
380   def signed_manifest_text
381     if !has_attribute? :manifest_text
382       return nil
383     elsif is_trashed
384       return manifest_text
385     else
386       token = Thread.current[:token]
387       exp = [db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL.to_i,
388              trash_at].compact.map(&:to_i).min
389       self.class.sign_manifest manifest_text, token, exp
390     end
391   end
392
393   def self.sign_manifest manifest, token, exp=nil
394     if exp.nil?
395       exp = db_current_time.to_i + Rails.configuration.Collections.BlobSigningTTL.to_i
396     end
397     signing_opts = {
398       api_token: token,
399       expire: exp,
400     }
401     m = munge_manifest_locators(manifest) do |match|
402       Blob.sign_locator(match[0], signing_opts)
403     end
404     return m
405   end
406
407   def self.munge_manifest_locators manifest
408     # Given a manifest text and a block, yield the regexp MatchData
409     # for each locator. Return a new manifest in which each locator
410     # has been replaced by the block's return value.
411     return nil if !manifest
412     return '' if manifest == ''
413
414     new_lines = []
415     manifest.each_line do |line|
416       line.rstrip!
417       new_words = []
418       line.split(' ').each do |word|
419         if new_words.empty?
420           new_words << word
421         elsif match = Keep::Locator::LOCATOR_REGEXP.match(word)
422           new_words << yield(match)
423         else
424           new_words << word
425         end
426       end
427       new_lines << new_words.join(' ')
428     end
429     new_lines.join("\n") + "\n"
430   end
431
432   def self.each_manifest_locator manifest
433     # Given a manifest text and a block, yield the regexp match object
434     # for each locator.
435     manifest.each_line do |line|
436       # line will have a trailing newline, but the last token is never
437       # a locator, so it's harmless here.
438       line.split(' ').each do |word|
439         if match = Keep::Locator::LOCATOR_REGEXP.match(word)
440           yield(match)
441         end
442       end
443     end
444   end
445
446   def self.normalize_uuid uuid
447     hash_part = nil
448     size_part = nil
449     uuid.split('+').each do |token|
450       if token.match(/^[0-9a-f]{32,}$/)
451         raise "uuid #{uuid} has multiple hash parts" if hash_part
452         hash_part = token
453       elsif token.match(/^\d+$/)
454         raise "uuid #{uuid} has multiple size parts" if size_part
455         size_part = token
456       end
457     end
458     raise "uuid #{uuid} has no hash part" if !hash_part
459     [hash_part, size_part].compact.join '+'
460   end
461
462   def self.get_compatible_images(readers, pattern, collections)
463     if collections.empty?
464       return []
465     end
466
467     migrations = Hash[
468       Link.where('tail_uuid in (?) AND link_class=? AND links.owner_uuid=?',
469                  collections.map(&:portable_data_hash),
470                  'docker_image_migration',
471                  system_user_uuid).
472       order('links.created_at asc').
473       map { |l|
474         [l.tail_uuid, l.head_uuid]
475       }]
476
477     migrated_collections = Hash[
478       Collection.readable_by(*readers).
479       where('portable_data_hash in (?)', migrations.values).
480       map { |c|
481         [c.portable_data_hash, c]
482       }]
483
484     collections.map { |c|
485       # Check if the listed image is compatible first, if not, then try the
486       # migration link.
487       manifest = Keep::Manifest.new(c.manifest_text)
488       if manifest.exact_file_count?(1) and manifest.files[0][1] =~ pattern
489         c
490       elsif m = migrated_collections[migrations[c.portable_data_hash]]
491         manifest = Keep::Manifest.new(m.manifest_text)
492         if manifest.exact_file_count?(1) and manifest.files[0][1] =~ pattern
493           m
494         end
495       end
496     }.compact
497   end
498
499   # Resolve a Docker repo+tag, hash, or collection PDH to an array of
500   # Collection objects, sorted by timestamp starting with the most recent
501   # match.
502   #
503   # If filter_compatible_format is true (the default), only return image
504   # collections which are support by the installation as indicated by
505   # Rails.configuration.Containers.SupportedDockerImageFormats.  Will follow
506   # 'docker_image_migration' links if search_term resolves to an incompatible
507   # image, but an equivalent compatible image is available.
508   def self.find_all_for_docker_image(search_term, search_tag=nil, readers=nil, filter_compatible_format: true)
509     readers ||= [Thread.current[:user]]
510     base_search = Link.
511       readable_by(*readers).
512       readable_by(*readers, table_name: "collections").
513       joins("JOIN collections ON links.head_uuid = collections.uuid").
514       order("links.created_at DESC")
515
516     docker_image_formats = Rails.configuration.Containers.SupportedDockerImageFormats
517
518     if (docker_image_formats.include? 'v1' and
519         docker_image_formats.include? 'v2') or filter_compatible_format == false
520       pattern = /^(sha256:)?[0-9A-Fa-f]{64}\.tar$/
521     elsif docker_image_formats.include? 'v2'
522       pattern = /^(sha256:)[0-9A-Fa-f]{64}\.tar$/
523     elsif docker_image_formats.include? 'v1'
524       pattern = /^[0-9A-Fa-f]{64}\.tar$/
525     else
526       raise "Unrecognized configuration for docker_image_formats #{docker_image_formats}"
527     end
528
529     # If the search term is a Collection locator that contains one file
530     # that looks like a Docker image, return it.
531     if loc = Keep::Locator.parse(search_term)
532       loc.strip_hints!
533       coll_match = readable_by(*readers).where(portable_data_hash: loc.to_s).limit(1)
534       rc = Rails.configuration.RemoteClusters.select{ |k|
535         k != :"*" && k != Rails.configuration.ClusterID}
536       if coll_match.any? or rc.length == 0
537         return get_compatible_images(readers, pattern, coll_match)
538       else
539         # Allow bare pdh that doesn't exist in the local database so
540         # that federated container requests which refer to remotely
541         # stored containers will validate.
542         return [Collection.new(portable_data_hash: loc.to_s)]
543       end
544     end
545
546     if search_tag.nil? and (n = search_term.index(":"))
547       search_tag = search_term[n+1..-1]
548       search_term = search_term[0..n-1]
549     end
550
551     # Find Collections with matching Docker image repository+tag pairs.
552     matches = base_search.
553       where(link_class: "docker_image_repo+tag",
554             name: "#{search_term}:#{search_tag || 'latest'}")
555
556     # If that didn't work, find Collections with matching Docker image hashes.
557     if matches.empty?
558       matches = base_search.
559         where("link_class = ? and links.name LIKE ?",
560               "docker_image_hash", "#{search_term}%")
561     end
562
563     # Generate an order key for each result.  We want to order the results
564     # so that anything with an image timestamp is considered more recent than
565     # anything without; then we use the link's created_at as a tiebreaker.
566     uuid_timestamps = {}
567     matches.each do |link|
568       uuid_timestamps[link.head_uuid] = [(-link.properties["image_timestamp"].to_datetime.to_i rescue 0),
569        -link.created_at.to_i]
570      end
571
572     sorted = Collection.where('uuid in (?)', uuid_timestamps.keys).sort_by { |c|
573       uuid_timestamps[c.uuid]
574     }
575     compatible = get_compatible_images(readers, pattern, sorted)
576     if sorted.length > 0 and compatible.empty?
577       raise ArvadosModel::UnresolvableContainerError.new "Matching Docker image is incompatible with 'docker_image_formats' configuration."
578     end
579     compatible
580   end
581
582   def self.for_latest_docker_image(search_term, search_tag=nil, readers=nil)
583     find_all_for_docker_image(search_term, search_tag, readers).first
584   end
585
586   def self.searchable_columns operator
587     super - ["manifest_text"]
588   end
589
590   def self.full_text_searchable_columns
591     super - ["manifest_text", "storage_classes_desired", "storage_classes_confirmed", "current_version_uuid"]
592   end
593
594   def self.where *args
595     SweepTrashedObjects.sweep_if_stale
596     super
597   end
598
599   protected
600
601   # Although the defaults for these columns is already set up on the schema,
602   # collection creation from an API client seems to ignore them, making the
603   # validation on empty desired storage classes return an error.
604   def default_storage_classes
605     if self.storage_classes_desired.nil? || self.storage_classes_desired.empty?
606       self.storage_classes_desired = ["default"]
607     end
608     self.storage_classes_confirmed ||= []
609   end
610
611   # Sets managed properties at creation time
612   def managed_properties
613     managed_props = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
614     if managed_props.empty?
615       return
616     end
617     (managed_props.keys - self.properties.keys).each do |key|
618       if managed_props[key].has_key?('Value')
619         self.properties[key] = managed_props[key]['Value']
620       elsif managed_props[key]['Function'].andand == 'original_owner'
621         self.properties[key] = self.user_owner_uuid
622       else
623         logger.warn "Unidentified default property definition '#{key}': #{managed_props[key].inspect}"
624       end
625     end
626   end
627
628   def portable_manifest_text
629     self.class.munge_manifest_locators(manifest_text) do |match|
630       if match[2] # size
631         match[1] + match[2]
632       else
633         match[1]
634       end
635     end
636   end
637
638   def compute_pdh
639     portable_manifest = portable_manifest_text
640     (Digest::MD5.hexdigest(portable_manifest) +
641      '+' +
642      portable_manifest.bytesize.to_s)
643   end
644
645   def computed_pdh
646     if @computed_pdh_for_manifest_text == manifest_text
647       return @computed_pdh
648     end
649     @computed_pdh = compute_pdh
650     @computed_pdh_for_manifest_text = manifest_text.dup
651     @computed_pdh
652   end
653
654   def ensure_permission_to_save
655     if (not current_user.andand.is_admin)
656       if (replication_confirmed_at_changed? or replication_confirmed_changed?) and
657         not (replication_confirmed_at.nil? and replication_confirmed.nil?)
658         raise ArvadosModel::PermissionDeniedError.new("replication_confirmed and replication_confirmed_at attributes cannot be changed, except by setting both to nil")
659       end
660       if (storage_classes_confirmed_changed? or storage_classes_confirmed_at_changed?) and
661         not (storage_classes_confirmed == [] and storage_classes_confirmed_at.nil?)
662         raise ArvadosModel::PermissionDeniedError.new("storage_classes_confirmed and storage_classes_confirmed_at attributes cannot be changed, except by setting them to [] and nil respectively")
663       end
664     end
665     super
666   end
667
668   def ensure_storage_classes_desired_is_not_empty
669     if self.storage_classes_desired.empty?
670       raise ArvadosModel::InvalidStateTransitionError.new("storage_classes_desired shouldn't be empty")
671     end
672   end
673
674   def ensure_storage_classes_contain_non_empty_strings
675     (self.storage_classes_desired + self.storage_classes_confirmed).each do |c|
676       if !c.is_a?(String) || c == ''
677         raise ArvadosModel::InvalidStateTransitionError.new("storage classes should only be non-empty strings")
678       end
679     end
680   end
681
682   def past_versions_cannot_be_updated
683     if is_past_version?
684       errors.add(:base, "past versions cannot be updated")
685       false
686     end
687   end
688
689   def protected_managed_properties_updates
690     managed_properties = Rails.configuration.Collections.ManagedProperties.with_indifferent_access
691     if managed_properties.empty? || !properties_changed? || current_user.is_admin
692       return true
693     end
694     protected_props = managed_properties.keys.select do |p|
695       Rails.configuration.Collections.ManagedProperties[p]['Protected']
696     end
697     # Pre-existent protected properties can't be updated
698     invalid_updates = properties_was.keys.select{|p| properties_was[p] != properties[p]} & protected_props
699     if !invalid_updates.empty?
700       invalid_updates.each do |p|
701         errors.add("protected property cannot be updated:", p)
702       end
703       raise PermissionDeniedError.new
704     end
705     true
706   end
707
708   def versioning_metadata_updates
709     valid = true
710     if !is_past_version? && current_version_uuid_changed?
711       errors.add(:current_version_uuid, "cannot be updated")
712       valid = false
713     end
714     if version_changed?
715       errors.add(:version, "cannot be updated")
716       valid = false
717     end
718     valid
719   end
720
721   def assign_uuid
722     super
723     self.current_version_uuid ||= self.uuid
724     true
725   end
726 end