summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-19 12:35:23 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-19 12:35:23 -0700
commit992dbbd9fe619ab3002f7c0c552657da8269df49 (patch)
tree5ae59f108ffe8d208928e7d2c2265018e033ad26 /app
parenta8a861ae2a122b310d1aca6f9f9b1d0601b8c49f (diff)
downloadgitlab-ce-992dbbd9fe619ab3002f7c0c552657da8269df49.tar.gz
Move `sent_notification!` out of Notify.
Diffstat (limited to 'app')
-rw-r--r--app/mailers/emails/issues.rb8
-rw-r--r--app/mailers/emails/merge_requests.rb10
-rw-r--r--app/mailers/emails/notes.rb6
-rw-r--r--app/mailers/notify.rb21
-rw-r--r--app/models/sent_notification.rb27
5 files changed, 37 insertions, 35 deletions
diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb
index c8b7775c328..2c035fbb70b 100644
--- a/app/mailers/emails/issues.rb
+++ b/app/mailers/emails/issues.rb
@@ -9,7 +9,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
- sent_notification!(@issue, recipient_id)
+ SentNotification.record(@issue, recipient_id, reply_key)
end
def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id, updated_by_user_id)
@@ -22,7 +22,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
- sent_notification!(@issue, recipient_id)
+ SentNotification.record(@issue, recipient_id, reply_key)
end
def closed_issue_email(recipient_id, issue_id, updated_by_user_id)
@@ -35,7 +35,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
- sent_notification!(@issue, recipient_id)
+ SentNotification.record(@issue, recipient_id, reply_key)
end
def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id)
@@ -49,7 +49,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
- sent_notification!(@issue, recipient_id)
+ SentNotification.record(@issue, recipient_id, reply_key)
end
end
end
diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb
index 76902b58f32..7923fb770d0 100644
--- a/app/mailers/emails/merge_requests.rb
+++ b/app/mailers/emails/merge_requests.rb
@@ -11,7 +11,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
@@ -26,7 +26,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
@@ -41,7 +41,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
@@ -55,7 +55,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id)
@@ -71,7 +71,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
end
end
diff --git a/app/mailers/emails/notes.rb b/app/mailers/emails/notes.rb
index 2612074a5ff..63d4aca61af 100644
--- a/app/mailers/emails/notes.rb
+++ b/app/mailers/emails/notes.rb
@@ -12,7 +12,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@commit.title} (#{@commit.short_id})"))
- sent_notification!(@commit, recipient_id)
+ SentNotification.record(@commit, recipient_id, reply_key)
end
def note_issue_email(recipient_id, note_id)
@@ -27,7 +27,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
- sent_notification!(@issue, recipient_id)
+ SentNotification.record(@issue, recipient_id, reply_key)
end
def note_merge_request_email(recipient_id, note_id)
@@ -43,7 +43,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
- sent_notification!(@merge_request, recipient_id)
+ SentNotification.record(@merge_request, recipient_id, reply_key)
end
end
end
diff --git a/app/mailers/notify.rb b/app/mailers/notify.rb
index 1a2286f9d47..5717c89e61d 100644
--- a/app/mailers/notify.rb
+++ b/app/mailers/notify.rb
@@ -33,27 +33,6 @@ class Notify < BaseMailer
allowed_domains
end
- def sent_notification!(noteable, recipient_id)
- return unless reply_key
-
- noteable_id = nil
- commit_id = nil
- if noteable.is_a?(Commit)
- commit_id = noteable.id
- else
- noteable_id = noteable.id
- end
-
- SentNotification.create(
- project: noteable.project,
- noteable_type: noteable.class.name,
- noteable_id: noteable_id,
- commit_id: commit_id,
- recipient_id: recipient_id,
- reply_key: reply_key
- )
- end
-
private
def can_send_from_user_email?(sender)
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb
index 23a1b19ea7c..460ca40be3f 100644
--- a/app/models/sent_notification.rb
+++ b/app/models/sent_notification.rb
@@ -9,8 +9,31 @@ class SentNotification < ActiveRecord::Base
validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: :for_commit?
- def self.for(reply_key)
- find_by(reply_key: reply_key)
+ class << self
+ def for(reply_key)
+ find_by(reply_key: reply_key)
+ end
+
+ def record(noteable, recipient_id, reply_key)
+ return unless reply_key
+
+ noteable_id = nil
+ commit_id = nil
+ if noteable.is_a?(Commit)
+ commit_id = noteable.id
+ else
+ noteable_id = noteable.id
+ end
+
+ create(
+ project: noteable.project,
+ noteable_type: noteable.class.name,
+ noteable_id: noteable_id,
+ commit_id: commit_id,
+ recipient_id: recipient_id,
+ reply_key: reply_key
+ )
+ end
end
def for_commit?