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
end
private
def auto_refresh_service_desk_key
if service_desk_mail_key.blank? || service_desk_enabled_changed?
refresh_service_desk_key!
......
module EE
module ProjectPolicy
def rules
super
guest_access! if user.support_bot?
end
def disabled_features!
raise NotImplementedError unless defined?(super)
......
......@@ -13,7 +13,6 @@ module EE
return unless note.noteable_type == 'Issue'
issue = note.noteable
reply_to = issue.service_desk_reply_to
support_bot = ::User.support_bot
return unless issue.service_desk_reply_to.present?
......@@ -21,7 +20,7 @@ module EE
return if note.author == support_bot
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
......@@ -23,7 +23,7 @@ class AddServiceDeskSettings < ActiveRecord::Migration
# comments:
disable_ddl_transaction!
def change
def up
add_column :users, :support_bot, :boolean
add_column :projects, :service_desk_enabled, :boolean
......@@ -34,4 +34,13 @@ class AddServiceDeskSettings < ActiveRecord::Migration
add_concurrent_index :users, :support_bot
add_concurrent_index :projects, :service_desk_mail_key, unique: true
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
......@@ -10,11 +10,10 @@ module Gitlab
end
def execute
raise EmailUnparsableError if from_address.blank?
raise ProjectNotFound if project.nil?
create_issue!
send_thank_you_email!
send_thank_you_email! if from_address
end
private
......@@ -61,7 +60,9 @@ module Gitlab
end
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
......
......@@ -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
Date: Thu, 13 Jun 2013 17:03:48 -0400
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>
Subject: The message subject! @all
Mime-Version: 1.0
......
......@@ -13,16 +13,17 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
context 'when service desk is enabled' do
before do
project.update_attributes(
service_desk_enabled: true,
service_desk_mail_key: 'somemailkey',
)
project.update(service_desk_enabled: true)
project.update(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
it 'receives the email' do
it 'receives the email and creates issue' do
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)
......@@ -31,6 +32,21 @@ describe Gitlab::Email::Handler::EE::ServiceDeskHandler do
expect(new_issue.author).to eql(User.support_bot)
expect(new_issue.confidential?).to be true
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
......
......@@ -4,7 +4,7 @@ describe EE::NotificationService do
let(:subject) { NotificationService.new }
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
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