First working version of mails on comments.

This commit is contained in:
Ralf Teusner
2016-06-17 14:48:57 +02:00
parent 80503a636a
commit ec26a095f6
6 changed files with 39 additions and 9 deletions

View File

@ -46,7 +46,11 @@ class CommentsController < ApplicationController
# POST /comments
# POST /comments.json
def create
@comment = Comment.new(comment_params)
@comment = Comment.new(comment_params_without_request_id)
if comment_params[:request_id]
UserMailer.got_new_comment(@comment, RequestForComment.find(comment_params[:request_id]), current_user)
end
respond_to do |format|
if @comment.save
@ -64,7 +68,7 @@ class CommentsController < ApplicationController
# PATCH/PUT /comments/1.json
def update
respond_to do |format|
if @comment.update(comment_params)
if @comment.update(comment_params_without_request_id)
format.html { head :no_content, notice: 'Comment was successfully updated.' }
format.json { render :show, status: :ok, location: @comment }
else
@ -101,10 +105,14 @@ class CommentsController < ApplicationController
@comment = Comment.find(params[:id])
end
def comment_params_without_request_id
comment_params.except :request_id
end
# Never trust parameters from the scary internet, only allow the white list through.
def comment_params
#params.require(:comment).permit(:user_id, :file_id, :row, :column, :text)
# fuer production mode, damit böse menschen keine falsche user_id uebergeben:
params.require(:comment).permit(:file_id, :row, :column, :text).merge(user_id: current_user.id, user_type: current_user.class.name)
params.require(:comment).permit(:file_id, :row, :column, :text, :request_id).merge(user_id: current_user.id, user_type: current_user.class.name)
end
end

View File

@ -12,8 +12,12 @@ class UserMailer < ActionMailer::Base
mail(subject: t('mailers.user_mailer.reset_password.subject'), to: user.email)
end
def got_new_comment(comment, user, commenting_user)
@commenting_user = commenting_user
mail(subject: t('mailers.user_mailer.got_new_comment.subject'), to: user.email)
def got_new_comment(comment, request_for_comment, commenting_user)
# todo: check whether we can take the last known locale of the receiver?
@receiver_displayname = request_for_comment.user.displayname
@commenting_user_displayname = commenting_user.displayname
@comment_text = comment.text
@rfc_link = request_for_comment_url(request_for_comment)
mail(subject: t('mailers.user_mailer.got_new_comment.subject', commenting_user_displayname: @commenting_user_displayname), to: request_for_comment.user.email).deliver
end
end

View File

@ -1,5 +1,5 @@
<div class="list-group">
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
<h4 class="list-group-item-heading" data-rfc-id = "<%= @request_for_comment.id %>" ><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
<p class="list-group-item-text">
<%
user = @request_for_comment.user
@ -101,7 +101,8 @@ do not put a carriage return in the line below. it will be present in the presen
file_id: file_id,
row: row,
column: 0,
text: commenttext
text: commenttext,
request_id: $('h4').data('rfc-id')
}
},
dataType: 'json',

View File

@ -1 +1 @@
== t('mailers.user_mailer.activation_needed.body', link: link_to(@activation_url, @activation_url))
== t('mailers.user_mailer.got_new_comment.body', receiver_displayname: @receiver_displayname, link: link_to(@rfc_link, @rfc_link), commenting_user_displayname: @commenting_user_displayname, comment_text: @comment_text)

View File

@ -325,6 +325,13 @@ de:
activation_needed:
body: 'Bitte besuchen Sie %{link} und wählen Sie ein Passwort, um Ihre Registrierung abzuschließen.'
subject: Bitte schließen Sie Ihre Registrierung ab.
got_new_comment:
body: |
Hallo %{receiver_displayname},
es gibt einen neuen Kommentar von %{commenting_user_displayname} zu Ihrer Kommentaranfrage auf CodeOcean.
Sie finden ihn hier: %{link}
subject: Sie haben einen neuen Kommentar von %{commenting_user_displayname} auf CodeOcean erhalten.
reset_password:
body: 'Bitte besuchen Sie %{link}, sofern Sie Ihr Passwort zurücksetzen wollen.'
subject: Anweisungen zum Zurücksetzen Ihres Passworts

View File

@ -325,6 +325,16 @@ en:
activation_needed:
body: 'Please visit %{link} and set up a password in order to complete your registration.'
subject: Please complete your registration.
got_new_comment:
body: |
Dear %{receiver_displayname},
you received a new comment from %{commenting_user_displayname} to your request for comments on CodeOcean.
You can find it here: %{link}
Best regards,
your Teaching Team
subject: 'You received a new comment on CodeOcean from %{commenting_user_displayname}.'
reset_password:
body: 'Please visit %{link} if you want to reset your password.'
subject: Password reset instructions