summaryrefslogtreecommitdiff
path: root/app/models/sent_notification.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-18 15:46:36 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-18 15:46:36 -0700
commitf76eac56b9d7d4ae61010cddcca68682824b2239 (patch)
tree703e9cb22b0e44880775d0a4bb5bdbebc87a563f /app/models/sent_notification.rb
parent204914983a015170ea1ca4cf6040c04d9a1ec1d9 (diff)
downloadgitlab-ce-f76eac56b9d7d4ae61010cddcca68682824b2239.tar.gz
Reply by email POC
Diffstat (limited to 'app/models/sent_notification.rb')
-rw-r--r--app/models/sent_notification.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb
new file mode 100644
index 00000000000..a3d24669b52
--- /dev/null
+++ b/app/models/sent_notification.rb
@@ -0,0 +1,29 @@
+class SentNotification < ActiveRecord::Base
+ belongs_to :project
+ belongs_to :noteable, polymorphic: true
+ belongs_to :recipient, class_name: "User"
+
+ validate :project, :recipient, :reply_key, presence: true
+ validate :reply_key, uniqueness: true
+
+ validates :noteable_id, presence: true, if: ->(n) { n.noteable_type.present? && n.noteable_type != 'Commit' }
+ validates :commit_id, presence: true, if: ->(n) { n.noteable_type == 'Commit' }
+
+ def self.for(reply_key)
+ find_by(reply_key: reply_key)
+ end
+
+ def for_commit?
+ noteable_type == "Commit"
+ end
+
+ def noteable
+ if for_commit?
+ project.commit(commit_id)
+ else
+ super
+ end
+ rescue
+ nil
+ end
+end