Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tracking supportclient email details in comments #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions db/migrate/009_create_custom_owner_name_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateCustomOwnerNameField < ActiveRecord::Migration
def self.up
c = CustomField.new(
:name => 'owner-name',
:editable => true,
:field_format => 'string')
c.type = 'IssueCustomField' # cannot be set by mass assignement!
c.save
Tracker.all.each do |t|
execute "INSERT INTO custom_fields_trackers (custom_field_id,tracker_id) VALUES (#{c.id},#{t.id})"
end
end

def self.down
c = CustomField.find_by_name('owner-name')
execute "DELETE FROM custom_fields_trackers WHERE custom_field_id=#{c.id}"
c.delete
end
end
39 changes: 32 additions & 7 deletions lib/mail_handler_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def self.included(base) # :nodoc:

base.class_eval do
alias_method_chain :dispatch_to_default, :helpdesk
alias_method_chain :receive_issue_reply, :helpdesk
end
end

Expand All @@ -20,13 +21,6 @@ def dispatch_to_default_with_helpdesk
# permission treat_user_as_supportclient enabled
if roles.any? {|role| role.allowed_to?(:treat_user_as_supportclient) }
sender_email = @email.from.first
email_details = "From: " + @email[:from].formatted.first + "\n"
email_details << "To: " + @email[:to].formatted.join(', ') + "\n"
if [email protected]?
email_details << "Cc: " + @email[:cc].formatted.join(', ') + "\n"
end
email_details << "Date: " + @email[:date].to_s + "\n"
email_details = "<pre>\n" + Mail::Encodings.unquote_and_convert_to(email_details, 'utf-8') + "</pre>"
issue.description = email_details + issue.description
issue.save
custom_field = CustomField.find_by_name('owner-email')
Expand All @@ -35,6 +29,17 @@ def dispatch_to_default_with_helpdesk
first
custom_value.value = sender_email
custom_value.save(:validate => false) # skip validation!
custom_field = CustomField.find_by_name('owner-name')
unless custom_field.nil?
custom_value = CustomValue.where(
"customized_id = ? AND custom_field_id = ?", issue.id, custom_field.id).
first
unless custom_value.nil?
address = Mail::Address.new(@email[:from].formatted.first)
custom_value.value = address.display_name
custom_value.save(:validate => false) # skip validation!
end
end
# regular email sending to known users is done
# on the first issue.save. So we need to send
# the notification email to the supportclient
Expand Down Expand Up @@ -63,6 +68,26 @@ def add_attachments(obj)
end
end

def email_details
details = "From: " + @email[:from].formatted.first + "\n"
details << "To: " + @email[:to].formatted.join(', ') + "\n"
if [email protected]?
details << "Cc: " + @email[:cc].formatted.join(', ') + "\n"
end
details << "Date: " + @email[:date].to_s + "\n"
"<pre>\n" + Mail::Encodings.unquote_and_convert_to(details, 'utf-8') + "</pre>"
end

# Overrides the receive_issue_reply method to add
# email details to the journal note
def receive_issue_reply_with_helpdesk(issue_id, from_journal=nil)
receive_issue_reply_without_helpdesk(issue_id, from_journal=nil)
issue = Issue.find_by_id(issue_id)
last_journal = Journal.find(issue.last_journal_id)
last_journal.notes = email_details + last_journal.notes
last_journal.save
end

end # module InstanceMethods
end # module MailHandlerPatch
end # module RedmineHelpdesk
Expand Down