From e90d6ec1d83ff86743e70931b49647eaf3e3e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 15 Mar 2016 17:24:55 +0100 Subject: [PATCH] Create a SentNotification record for #relabeled_issue_email / #relabeled_merge_request_email --- .../concerns/toggle_subscription_action.rb | 17 +++++++++++++++++ app/mailers/emails/issues.rb | 8 +++----- app/mailers/emails/merge_requests.rb | 8 +++----- 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 app/controllers/concerns/toggle_subscription_action.rb diff --git a/app/controllers/concerns/toggle_subscription_action.rb b/app/controllers/concerns/toggle_subscription_action.rb new file mode 100644 index 00000000000..8a43c0b93c4 --- /dev/null +++ b/app/controllers/concerns/toggle_subscription_action.rb @@ -0,0 +1,17 @@ +module ToggleSubscriptionAction + extend ActiveSupport::Concern + + def toggle_subscription + return unless current_user + + subscribable_resource.toggle_subscription(current_user) + + render nothing: true + end + + private + + def subscribable_resource + raise NotImplementedError + end +end diff --git a/app/mailers/emails/issues.rb b/app/mailers/emails/issues.rb index 160b6df0b97..5f9adb32e00 100644 --- a/app/mailers/emails/issues.rb +++ b/app/mailers/emails/issues.rb @@ -21,7 +21,7 @@ module Emails end def relabeled_issue_email(recipient_id, issue_id, label_names, updated_by_user_id) - setup_issue_mail(issue_id, recipient_id, sent_notification: false) + setup_issue_mail(issue_id, recipient_id) @label_names = label_names @labels_url = namespace_project_labels_url(@project.namespace, @project) @@ -38,14 +38,12 @@ module Emails private - def setup_issue_mail(issue_id, recipient_id, sent_notification: true) + def setup_issue_mail(issue_id, recipient_id) @issue = Issue.find(issue_id) @project = @issue.project @target_url = namespace_project_issue_url(@project.namespace, @project, @issue) - if sent_notification - @sent_notification = SentNotification.record(@issue, recipient_id, reply_key) - end + @sent_notification = SentNotification.record(@issue, recipient_id, reply_key) end def issue_thread_options(sender_id, recipient_id) diff --git a/app/mailers/emails/merge_requests.rb b/app/mailers/emails/merge_requests.rb index 334bad4e2f8..55bb4f65270 100644 --- a/app/mailers/emails/merge_requests.rb +++ b/app/mailers/emails/merge_requests.rb @@ -14,7 +14,7 @@ module Emails end def relabeled_merge_request_email(recipient_id, merge_request_id, label_names, updated_by_user_id) - setup_merge_request_mail(merge_request_id, recipient_id, sent_notification: false) + setup_merge_request_mail(merge_request_id, recipient_id) @label_names = label_names @labels_url = namespace_project_labels_url(@project.namespace, @project) @@ -44,14 +44,12 @@ module Emails private - def setup_merge_request_mail(merge_request_id, recipient_id, sent_notification: true) + def setup_merge_request_mail(merge_request_id, recipient_id) @merge_request = MergeRequest.find(merge_request_id) @project = @merge_request.project @target_url = namespace_project_merge_request_url(@project.namespace, @project, @merge_request) - if sent_notification - @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key) - end + @sent_notification = SentNotification.record(@merge_request, recipient_id, reply_key) end def merge_request_thread_options(sender_id, recipient_id)