about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-11-06 00:12:25 +0100
committerGitHub <noreply@github.com>2021-11-06 00:12:25 +0100
commit87085a5152011b2f5595feba2a6c4d56a2b425f0 (patch)
tree2140bc1044a84d308a2f8ae8cf52832ce5a8d6d1 /app
parent39cdf61ab7be267a374c472c230b315971ead43c (diff)
Fix AccountNote not having a maximum length (#16942)
Diffstat (limited to 'app')
-rw-r--r--app/models/account_note.rb1
-rw-r--r--app/workers/move_worker.rb8
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/account_note.rb b/app/models/account_note.rb
index bf61df923..b338bc92f 100644
--- a/app/models/account_note.rb
+++ b/app/models/account_note.rb
@@ -17,4 +17,5 @@ class AccountNote < ApplicationRecord
   belongs_to :target_account, class_name: 'Account'
 
   validates :account_id, uniqueness: { scope: :target_account_id }
+  validates :comment, length: { maximum: 2_000 }
 end
diff --git a/app/workers/move_worker.rb b/app/workers/move_worker.rb
index cc2c17d32..4a900e3b8 100644
--- a/app/workers/move_worker.rb
+++ b/app/workers/move_worker.rb
@@ -53,10 +53,16 @@ class MoveWorker
 
       new_note = AccountNote.find_by(account: note.account, target_account: @target_account)
       if new_note.nil?
-        AccountNote.create!(account: note.account, target_account: @target_account, comment: [text, note.comment].join("\n"))
+        begin
+          AccountNote.create!(account: note.account, target_account: @target_account, comment: [text, note.comment].join("\n"))
+        rescue ActiveRecord::RecordInvalid
+          AccountNote.create!(account: note.account, target_account: @target_account, comment: note.comment)
+        end
       else
         new_note.update!(comment: [text, note.comment, "\n", new_note.comment].join("\n"))
       end
+    rescue ActiveRecord::RecordInvalid
+      nil
     rescue => e
       @deferred_error = e
     end