diff --git a/app/controllers/v1/complaints_controller.rb b/app/controllers/v1/complaints_controller.rb index 5015fb5c70e218362edb397f172b696d07ce52df..c6dc3b3efbd585545c31fe62d1b8eb7b64ee56c7 100644 --- a/app/controllers/v1/complaints_controller.rb +++ b/app/controllers/v1/complaints_controller.rb @@ -33,12 +33,13 @@ class V1::ComplaintsController < ApplicationController # POST v1/complaints # POST v1/complaints.json def create - complaint = Complaint.new(complaint_params) + @complaint = Complaint.new(complaint_params) - if complaint.save - render json: complaint, status: :created + if @complaint.save + ComplaintsMailer.new_complaint_received(@complaint, @current_user).deliver_now + render json: @complaint, status: :created else - render json: complaint.errors, status: :unprocessable_entity + render json: @complaint.errors, status: :unprocessable_entity end end diff --git a/app/mailers/complaints_mailer.rb b/app/mailers/complaints_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..82613d9b7a4235229733371a5a9625e287692ac7 --- /dev/null +++ b/app/mailers/complaints_mailer.rb @@ -0,0 +1,29 @@ + +# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre +# Departamento de Informatica - Universidade Federal do Parana +# +# This file is part of portalmec. +# +# portalmec is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# portalmec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with portalmec. If not, see <http://www.gnu.org/licenses/>. + +class ComplaintsMailer < ApplicationMailer + default to: 'integrada.contato@mec.gov' + default from: Proc.new { @user.email } + + def new_complaint_received(complaint, user) + @complaint = complaint + @user = user + mail(subject: "Denuncia de objeto") + end +end diff --git a/app/views/complaints_mailer/new_complaint_received.html.erb b/app/views/complaints_mailer/new_complaint_received.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..556ed05060caf9cf43dbbd4081e7fb66a6a49ebf --- /dev/null +++ b/app/views/complaints_mailer/new_complaint_received.html.erb @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome do usuário: <%= @user.name %></h1> + <h2>Email do usuário: <%= @user.email %></h1> + <h2>Descrição: <%= @complaint.description %></h1> + <h2>Classe denunciada: <%= @complaint.complainable_type %></h1> + <h2>Id: <%= @complaint.complainable_id %></h1> + <h2>Nome: <%= @complaint.complainable.name %></h1> + <h2>Razão: <%= @complaint.complaint_reason.reason %></h1> + </body> +</html>