2013-06-11 03:33:37 +08:00
|
|
|
require_dependency 'email/renderer'
|
2013-06-04 04:12:24 +08:00
|
|
|
|
|
|
|
class Admin::EmailController < Admin::AdminController
|
|
|
|
|
|
|
|
def index
|
2013-06-12 07:00:13 +08:00
|
|
|
render_json_dump({
|
|
|
|
delivery_method: delivery_method,
|
|
|
|
settings: delivery_settings
|
|
|
|
})
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
|
|
|
params.require(:email_address)
|
2014-01-10 04:25:25 +08:00
|
|
|
Jobs::TestEmail.new.execute(to_address: params[:email_address])
|
2013-06-04 04:12:24 +08:00
|
|
|
render nothing: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def logs
|
2013-07-23 02:44:11 +08:00
|
|
|
@email_logs = EmailLog.limit(50).includes(:user).order('created_at desc').to_a
|
2013-06-04 04:12:24 +08:00
|
|
|
render_serialized(@email_logs, EmailLogSerializer)
|
|
|
|
end
|
|
|
|
|
|
|
|
def preview_digest
|
|
|
|
params.require(:last_seen_at)
|
2013-11-29 06:20:56 +08:00
|
|
|
renderer = Email::Renderer.new(UserNotifications.digest(current_user, since: params[:last_seen_at]))
|
2013-06-04 04:12:24 +08:00
|
|
|
render json: MultiJson.dump(html_content: renderer.html, text_content: renderer.text)
|
|
|
|
end
|
|
|
|
|
2013-06-12 07:00:13 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def delivery_settings
|
|
|
|
action_mailer_settings
|
|
|
|
.reject { |k, v| k == :password }
|
|
|
|
.map { |k, v| { name: k, value: v }}
|
|
|
|
end
|
|
|
|
|
|
|
|
def delivery_method
|
|
|
|
ActionMailer::Base.delivery_method
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_mailer_settings
|
|
|
|
ActionMailer::Base.public_send "#{delivery_method}_settings"
|
|
|
|
end
|
2013-06-04 04:12:24 +08:00
|
|
|
end
|