X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/41887dd213cfa165925e94d4f3bb120edeb1a30d..7eec2f46099c6bf913149a7d19c4903feb2bf835:/services/api/app/models/arvados_model.rb diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 13ccd70335..308da7fa11 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -432,6 +432,7 @@ class ArvadosModel < ActiveRecord::Base def self.uuid_prefixes unless @@prefixes_hash @@prefixes_hash = {} + Rails.application.eager_load! ActiveRecord::Base.descendants.reject(&:abstract_class?).each do |k| if k.respond_to?(:uuid_prefix) @@prefixes_hash[k.uuid_prefix] = k @@ -445,6 +446,10 @@ class ArvadosModel < ActiveRecord::Base "_____-#{uuid_prefix}-_______________" end + def self.uuid_regex + %r/[a-z0-9]{5}-#{uuid_prefix}-[a-z0-9]{15}/ + end + def ensure_valid_uuids specials = [system_user_uuid] @@ -494,7 +499,6 @@ class ArvadosModel < ActiveRecord::Base end resource_class = nil - Rails.application.eager_load! uuid.match HasUuid::UUID_REGEX do |re| return uuid_prefixes[re[1]] if uuid_prefixes[re[1]] end @@ -519,8 +523,8 @@ class ArvadosModel < ActiveRecord::Base end def log_start_state - @old_etag = etag - @old_attributes = logged_attributes + @old_attributes = Marshal.load(Marshal.dump(attributes)) + @old_logged_attributes = Marshal.load(Marshal.dump(logged_attributes)) end def log_change(event_type) @@ -539,14 +543,14 @@ class ArvadosModel < ActiveRecord::Base def log_update log_change('update') do |log| - log.fill_properties('old', @old_etag, @old_attributes) + log.fill_properties('old', etag(@old_attributes), @old_logged_attributes) log.update_to self end end def log_destroy log_change('destroy') do |log| - log.fill_properties('old', @old_etag, @old_attributes) + log.fill_properties('old', etag(@old_attributes), @old_logged_attributes) log.update_to nil end end