summaryrefslogtreecommitdiff
path: root/app/models/sent_notification.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-06-20 19:23:10 +0200
committerDouwe Maan <douwe@selenight.nl>2016-07-06 18:51:00 -0400
commit521a0a20f7b52a2fb6ea209b39824a752f2613bd (patch)
treef4a11de3f31f43a2e8e1ba2bd73a72fed0ceff4c /app/models/sent_notification.rb
parent710c4886911682742d439b15c5a7add7ca0bd898 (diff)
downloadgitlab-ce-521a0a20f7b52a2fb6ea209b39824a752f2613bd.tar.gz
Allow reply-by-email with diff notes
Diffstat (limited to 'app/models/sent_notification.rb')
-rw-r--r--app/models/sent_notification.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb
index 928873fb5c3..016172c6d7e 100644
--- a/app/models/sent_notification.rb
+++ b/app/models/sent_notification.rb
@@ -1,4 +1,6 @@
class SentNotification < ActiveRecord::Base
+ serialize :position, Gitlab::Diff::Position
+
belongs_to :project
belongs_to :noteable, polymorphic: true
belongs_to :recipient, class_name: "User"
@@ -7,7 +9,7 @@ class SentNotification < ActiveRecord::Base
validates :reply_key, uniqueness: true
validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: :for_commit?
- validates :line_code, line_code: true, allow_blank: true
+ validate :note_valid
after_save :keep_around_commit
@@ -74,8 +76,33 @@ class SentNotification < ActiveRecord::Base
self.reply_key
end
+ def note_attributes
+ {
+ project: self.project,
+ author: self.recipient,
+ type: self.note_type,
+ noteable_type: self.noteable_type,
+ noteable_id: self.noteable_id,
+ commit_id: self.commit_id,
+ line_code: self.line_code,
+ position: self.position.to_json
+ }
+ end
+
+ def create_note(note)
+ Notes::CreateService.new(
+ self.project,
+ self.recipient,
+ self.note_attributes.merge(note: note)
+ ).execute
+ end
+
private
+ def note_valid
+ Note.new(note_attributes.merge(note: "Test")).valid?
+ end
+
def keep_around_commit
project.repository.keep_around(self.commit_id)
end