diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 78dcee3..91a18c0 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -4,6 +4,8 @@ class TasksController < MyProfileController protect :perform_task, :profile, :except => [:index] def index + @email_templates = profile.email_templates.find_all_by_template_type(:task_rejection) + @filter_type = params[:filter_type].presence @filter_text = params[:filter_text].presence @filter_responsible = params[:filter_responsible] diff --git a/app/mailers/task_mailer.rb b/app/mailers/task_mailer.rb index cc46f6d..9720c64 100644 --- a/app/mailers/task_mailer.rb +++ b/app/mailers/task_mailer.rb @@ -33,11 +33,14 @@ class TaskMailer < ActionMailer::Base @requestor = task.requestor.name @environment = task.requestor.environment.name @url = url_for(:host => task.requestor.environment.default_hostname, :controller => 'home') + @email_template = task.email_template + template_params = {:environment => task.requestor.environment, :task => task} mail( to: task.requestor.notification_emails, from: self.class.generate_from(task), - subject: '[%s] %s' % [task.requestor.environment.name, task.target_notification_description] + subject: @email_template.present? ? @email_template.parsed_subject(template_params) : '[%s] %s' % [task.requestor.environment.name, task.target_notification_description], + body: @email_template.present? ? @email_template.parsed_body(template_params) : nil ) end diff --git a/app/models/task.rb b/app/models/task.rb index 927031d..adbc30c 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -41,6 +41,8 @@ class Task < ActiveRecord::Base attr_protected :status + settings_items :email_template_id, :type => :integer + def initialize(*args) super self.status = (args.first ? args.first[:status] : nil) || Task::Status::ACTIVE @@ -236,6 +238,17 @@ class Task < ActiveRecord::Base end end + def email_template + @email_template ||= email_template_id.present? ? EmailTemplate.find_by_id(email_template_id) : nil + end + + def to_liquid + HashWithIndifferentAccess.new({ + :requestor => requestor, + :reject_explanation => reject_explanation + }) + end + scope :pending, :conditions => { :status => Task::Status::ACTIVE } scope :hidden, :conditions => { :status => Task::Status::HIDDEN } scope :finished, :conditions => { :status => Task::Status::FINISHED } diff --git a/app/views/tasks/_task_reject_details.html.erb b/app/views/tasks/_task_reject_details.html.erb index 13bc80c..975457f 100644 --- a/app/views/tasks/_task_reject_details.html.erb +++ b/app/views/tasks/_task_reject_details.html.erb @@ -1 +1,7 @@ +<% if @email_templates.present? %> +