Allow reply-by-email with diff notes
This commit is contained in:
parent
710c488691
commit
521a0a20f7
3 changed files with 51 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
|
||||
# for more information on how to write migrations for GitLab.
|
||||
|
||||
class AddNoteTypeAndPositionToSentNotification < ActiveRecord::Migration
|
||||
include Gitlab::Database::MigrationHelpers
|
||||
|
||||
# When using the methods "add_concurrent_index" or "add_column_with_default"
|
||||
# you must disable the use of transactions as these methods can not run in an
|
||||
# existing transaction. When using "add_concurrent_index" make sure that this
|
||||
# method is the _only_ method called in the migration, any other changes
|
||||
# should go in a separate migration. This ensures that upon failure _only_ the
|
||||
# index creation fails and can be retried or reverted easily.
|
||||
#
|
||||
# To disable transactions uncomment the following line and remove these
|
||||
# comments:
|
||||
# disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_column :sent_notifications, :note_type, :string
|
||||
add_column :sent_notifications, :position, :text
|
||||
end
|
||||
end
|
|
@ -104,15 +104,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
def create_note(reply)
|
||||
Notes::CreateService.new(
|
||||
sent_notification.project,
|
||||
sent_notification.recipient,
|
||||
note: reply,
|
||||
noteable_type: sent_notification.noteable_type,
|
||||
noteable_id: sent_notification.noteable_id,
|
||||
commit_id: sent_notification.commit_id,
|
||||
line_code: sent_notification.line_code
|
||||
).execute
|
||||
sent_notification.create_note(reply)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue