From 00588e1ef80e1dacb3a6178ab4304be22c20b22b Mon Sep 17 00:00:00 2001 From: cmrd Senya <senya@riseup.net> Date: Mon, 19 Oct 2015 21:15:33 +0300 Subject: [PATCH] Disable self-notification possibility closes #6512 --- app/models/notification.rb | 2 +- spec/models/notification_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 8ad6a0fab2..5fd5117f21 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -15,7 +15,7 @@ class Notification < ActiveRecord::Base end def self.notify(recipient, target, actor) - return nil unless target.respond_to? :notification_type + return nil unless target.respond_to?(:notification_type) && recipient.person != actor note_type = target.notification_type(recipient, actor) return nil unless note_type diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index e3644db8ce..1881aec22b 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -73,6 +73,11 @@ describe Notification, :type => :model do Notification.notify(@user, @request, @person) end + it "does nothing if told to notify oneself" do + notification = Notification.notify(@user, @request, @user.person) + expect(notification).to eq(nil) + end + describe '#emails_the_user' do it 'calls mail' do opts = { -- GitLab