Commit 152e5eda authored by Felipe Artur's avatar Felipe Artur

Fix rubocop failures, create email even if from address it not found, fix specs

parent 7f6df32f
...@@ -44,6 +44,7 @@ module EE ...@@ -44,6 +44,7 @@ module EE
end end
private private
def auto_refresh_service_desk_key def auto_refresh_service_desk_key
if service_desk_mail_key.blank? || service_desk_enabled_changed? if service_desk_mail_key.blank? || service_desk_enabled_changed?
refresh_service_desk_key! refresh_service_desk_key!
......
module EE module EE
module ProjectPolicy module ProjectPolicy
def rules
super
guest_access! if user.support_bot?
end
def disabled_features! def disabled_features!
raise NotImplementedError unless defined?(super) raise NotImplementedError unless defined?(super)
......
...@@ -13,7 +13,6 @@ module EE ...@@ -13,7 +13,6 @@ module EE
return unless note.noteable_type == 'Issue' return unless note.noteable_type == 'Issue'
issue = note.noteable issue = note.noteable
reply_to = issue.service_desk_reply_to
support_bot = ::User.support_bot support_bot = ::User.support_bot
return unless issue.service_desk_reply_to.present? return unless issue.service_desk_reply_to.present?
...@@ -21,7 +20,7 @@ module EE ...@@ -21,7 +20,7 @@ module EE
return if note.author == support_bot return if note.author == support_bot
return unless issue.subscribed?(support_bot, issue.project) return unless issue.subscribed?(support_bot, issue.project)
Notify.service_desk_new_note_email(issue.id, note.id) Notify.service_desk_new_note_email(issue.id, note.id).deliver_later
end end
end end
end end
...@@ -23,7 +23,7 @@ class AddServiceDeskSettings < ActiveRecord::Migration ...@@ -23,7 +23,7 @@ class AddServiceDeskSettings < ActiveRecord::Migration
# comments: # comments:
disable_ddl_transaction! disable_ddl_transaction!
def change def up
add_column :users, :support_bot, :boolean add_column :users, :support_bot, :boolean
add_column :projects, :service_desk_enabled, :boolean add_column :projects, :service_desk_enabled, :boolean
...@@ -34,4 +34,13 @@ class AddServiceDeskSettings < ActiveRecord::Migration ...@@ -34,4 +34,13 @@ class AddServiceDeskSettings < ActiveRecord::Migration
add_concurrent_index :users, :support_bot add_concurrent_index :users, :support_bot
add_concurrent_index :projects, :service_desk_mail_key, unique: true add_concurrent_index :projects, :service_desk_mail_key, unique: true
end end
def down
remove_column :users, :support_bot
remove_column :projects, :service_desk_enabled
remove_column :projects, :service_desk_mail_key
remove_column :issues, :service_desk_reply_to
end
end end
...@@ -10,11 +10,10 @@ module Gitlab ...@@ -10,11 +10,10 @@ module Gitlab
end end
def execute def execute
raise EmailUnparsableError if from_address.blank?
raise ProjectNotFound if project.nil? raise ProjectNotFound if project.nil?
create_issue! create_issue!
send_thank_you_email! send_thank_you_email! if from_address
end end
private private
...@@ -61,7 +60,9 @@ module Gitlab ...@@ -61,7 +60,9 @@ module Gitlab
end end
def issue_title def issue_title
"Service Desk (from `#{from_address}`): #{mail.subject}" from = "(from #{from_address})" if from_address
"Service Desk #{from}: #{mail.subject}"
end end
end end
end end
......
...@@ -5,7 +5,7 @@ Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <incom ...@@ -5,7 +5,7 @@ Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <incom
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700 Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
Date: Thu, 13 Jun 2013 17:03:48 -0400 Date: Thu, 13 Jun 2013 17:03:48 -0400
From: Jake the Dog <jake@adventuretime.ooo> From: Jake the Dog <jake@adventuretime.ooo>
To: incoming+service-desk+somemailkey@appmail.adventuretime.ooo To: incoming+service_desk+somemailkey@appmail.adventuretime.ooo
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com> Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
Subject: The message subject! @all Subject: The message subject! @all
Mime-Version: 1.0 Mime-Version: 1.0
......
...@@ -13,16 +13,17 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do ...@@ -13,16 +13,17 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
context 'when service desk is enabled' do context 'when service desk is enabled' do
before do before do
project.update_attributes( project.update(service_desk_enabled: true)
service_desk_enabled: true, project.update(service_desk_mail_key: 'somemailkey')
service_desk_mail_key: 'somemailkey',
) allow(Notify).to receive(:service_desk_thank_you_email)
.with(instance_of(Integer)).and_return(double(deliver_later!: true))
end end
it 'receives the email' do it 'receives the email and creates issue' do
setup_attachment setup_attachment
expect(Notify).to receive(:service_desk_thank_you_email).with(instance_of(Fixnum)) expect(Notify).to receive(:service_desk_thank_you_email).with(instance_of(Integer))
expect { receiver.execute }.to change { Issue.count }.by(1) expect { receiver.execute }.to change { Issue.count }.by(1)
...@@ -31,6 +32,21 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do ...@@ -31,6 +32,21 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
expect(new_issue.author).to eql(User.support_bot) expect(new_issue.author).to eql(User.support_bot)
expect(new_issue.confidential?).to be true expect(new_issue.confidential?).to be true
expect(new_issue.all_references.all).to be_empty expect(new_issue.all_references.all).to be_empty
expect(new_issue.title).to eq("Service Desk (from jake@adventuretime.ooo): The message subject! @all")
expect(new_issue.description).to eq("Service desk stuff!\n\n```\na = b\n```\n\n![image](uploads/image.png)")
end
context 'when there is no from address' do
before do
allow_any_instance_of(described_class).to receive(:from_address)
.and_return(nil)
end
it "creates issue and does not send thank you email" do
expect(Notify).not_to receive(:service_desk_thank_you_email)
expect { receiver.execute }.to change { Issue.count }.by(1)
end
end end
end end
......
...@@ -4,7 +4,7 @@ describe EE::NotificationService do ...@@ -4,7 +4,7 @@ describe EE::NotificationService do
let(:subject) { NotificationService.new } let(:subject) { NotificationService.new }
def should_email! def should_email!
expect(Notify).to receive(:service_desk_new_note_email).with(issue.id, instance_of(Fixnum)) expect(Notify).to receive(:service_desk_new_note_email).with(issue.id, instance_of(Integer))
end end
def should_not_email! def should_not_email!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment