gitlab-org--gitlab-foss/app/models/sent_notification.rb

28 lines
613 B
Ruby
Raw Normal View History

2015-08-18 22:46:36 +00:00
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
2015-08-19 00:02:26 +00:00
validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: :for_commit?
2015-08-18 22:46:36 +00:00
def self.for(reply_key)
find_by(reply_key: reply_key)
end
def for_commit?
noteable_type == "Commit"
end
def noteable
if for_commit?
2015-08-19 00:02:26 +00:00
project.commit(commit_id) rescue nil
2015-08-18 22:46:36 +00:00
else
super
end
end
end