From 35ce7aae019462b5b39b89a4f900a0c100ff71bd Mon Sep 17 00:00:00 2001
From: Douwe Maan <douwe@selenight.nl>
Date: Mon, 25 Jul 2016 22:51:26 -0600
Subject: [PATCH] Use sha1 of discussion ID.

---
 app/helpers/notes_helper.rb    | 4 ++--
 app/models/diff_note.rb        | 4 ++--
 app/models/legacy_diff_note.rb | 2 +-
 app/models/note.rb             | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/app/helpers/notes_helper.rb b/app/helpers/notes_helper.rb
index 226f0423132..57d32165e70 100644
--- a/app/helpers/notes_helper.rb
+++ b/app/helpers/notes_helper.rb
@@ -57,7 +57,7 @@ module NotesHelper
 
       data.merge!(
         note_type: LegacyDiffNote.name,
-        discussion_id: discussion_id
+        discussion_id: Digest::SHA1.hexdigest(discussion_id)
       )
     else
       discussion_id = DiffNote.build_discussion_id(
@@ -69,7 +69,7 @@ module NotesHelper
       data.merge!(
         position: position.to_json,
         note_type: DiffNote.name,
-        discussion_id: discussion_id
+        discussion_id: Digest::SHA1.hexdigest(discussion_id)
       )
     end
 
diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb
index 3edbdf9f966..8c99be7df8a 100644
--- a/app/models/diff_note.rb
+++ b/app/models/diff_note.rb
@@ -34,11 +34,11 @@ class DiffNote < Note
   end
 
   def discussion_id
-    @discussion_id ||= self.class.build_discussion_id(noteable_type, noteable_id || commit_id, position)
+    @discussion_id ||= Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id, position))
   end
 
   def original_discussion_id
-    @original_discussion_id ||= self.class.build_discussion_id(noteable_type, noteable_id || commit_id, original_position)
+    @original_discussion_id ||= Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id, original_position))
   end
 
   def position=(new_position)
diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb
index 04a651d50ab..7bff9f4f052 100644
--- a/app/models/legacy_diff_note.rb
+++ b/app/models/legacy_diff_note.rb
@@ -22,7 +22,7 @@ class LegacyDiffNote < Note
   end
 
   def discussion_id
-    @discussion_id ||= self.class.build_discussion_id(noteable_type, noteable_id || commit_id, line_code)
+    @discussion_id ||= Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id, line_code))
   end
 
   def diff_file_hash
diff --git a/app/models/note.rb b/app/models/note.rb
index 7668f3378e9..2c23e04e545 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -145,9 +145,9 @@ class Note < ActiveRecord::Base
   def discussion_id
     @discussion_id ||=
       if for_merge_request?
-        [:discussion, :note, id].join("-")
+        Digest::SHA1.hexdigest([:discussion, :note, id].join("-"))
       else
-        self.class.build_discussion_id(noteable_type, noteable_id || commit_id)
+        Digest::SHA1.hexdigest(self.class.build_discussion_id(noteable_type, noteable_id || commit_id))
       end
   end
 
-- 
2.30.9