17152: Avoids creating audit logs when only 'preserve_version' is updated.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 10 Dec 2020 20:58:58 +0000 (17:58 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 10 Dec 2020 22:21:18 +0000 (19:21 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

services/api/app/models/api_client_authorization.rb
services/api/app/models/collection.rb
services/api/test/fixtures/collections.yml
services/api/test/unit/log_test.rb

index 6b308a231cb7ede8cf50b949da75a861a46219d3..9290e01a1a7a5b4284580615585d963a5201c386 100644 (file)
@@ -394,7 +394,6 @@ class ApiClientAuthorization < ArvadosModel
   end
 
   def log_update
-
     super unless (saved_changes.keys - UNLOGGED_CHANGES).empty?
   end
 end
index 919d2fcb40814770952470b0ab543c57a6425417..e3802734a07580c70bf1921c64071c71dc43980b 100644 (file)
@@ -64,6 +64,8 @@ class Collection < ArvadosModel
     t.add :file_size_total
   end
 
+  UNLOGGED_CHANGES = ['preserve_version', 'updated_at']
+
   after_initialize do
     @signatures_checked = false
     @computed_pdh_for_manifest_text = false
@@ -751,4 +753,8 @@ class Collection < ArvadosModel
     self.current_version_uuid ||= self.uuid
     true
   end
+
+  def log_update
+    super unless (saved_changes.keys - UNLOGGED_CHANGES).empty?
+  end
 end
index 61bb3f79f8c882565b1ee9bd4ec5806963c1cf53..1f2eab73afedd748070086e8083f8bccc2256af8 100644 (file)
@@ -21,7 +21,7 @@ collection_owned_by_active:
   portable_data_hash: fa7aeb5140e2848d39b416daeef4ffc5+45
   owner_uuid: zzzzz-tpzed-xurymjxw79nv3jz
   created_at: 2014-02-03T17:22:54Z
-  modified_by_client_uuid: zzzzz-ozdt8-brczlopd8u8d0jr
+  modified_by_client_uuid: zzzzz-ozdt8-teyxzyd8qllg11h
   modified_by_user_uuid: zzzzz-tpzed-d9tiejq69daie8f
   modified_at: 2014-02-03T18:22:54Z
   updated_at: 2014-02-03T18:22:54Z
index 76d78f9eaa6cf14ebd83b8b7b138e3f94c69dff5..66c8c8d923d06f9f745f0c393f29ff99ce605f84 100644 (file)
@@ -228,6 +228,20 @@ class LogTest < ActiveSupport::TestCase
     assert_logged(auth, :update)
   end
 
+  test "don't log changes only to Collection.preserve_version" do
+    set_user_from_auth :admin_trustedclient
+    col = collections(:collection_owned_by_active)
+    start_log_count = get_logs_about(col).size
+    assert_equal false, col.preserve_version
+    col.preserve_version = true
+    col.save!
+    assert_equal(start_log_count, get_logs_about(col).size,
+                 "log count changed after updating Collection.preserve_version")
+    col.name = 'updated by admin'
+    col.save!
+    assert_logged(col, :update)
+  end
+
   test "token isn't included in ApiClientAuthorization logs" do
     set_user_from_auth :admin_trustedclient
     auth = ApiClientAuthorization.new