diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fd6840ff..fe7f454c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 4b3c71f4..e1773d48 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -11,4 +11,13 @@ class UserMailer < ActionMailer::Base @reset_password_url = reset_password_internal_user_url(user, token: user.reset_password_token) mail(subject: t('mailers.user_mailer.reset_password.subject'), to: user.email) end + + 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 diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index e4dc7f06..3f353e32 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,5 +1,5 @@
-

<%= Exercise.find(@request_for_comment.exercise_id) %>

+

<%= Exercise.find(@request_for_comment.exercise_id) %>

<% 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#exercise_caption').data('rfc-id') } }, dataType: 'json', diff --git a/app/views/user_mailer/got_new_comment.slim b/app/views/user_mailer/got_new_comment.slim new file mode 100644 index 00000000..656e245d --- /dev/null +++ b/app/views/user_mailer/got_new_comment.slim @@ -0,0 +1 @@ +== 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) diff --git a/config/locales/de.yml b/config/locales/de.yml index ae7fb930..a4d69694 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -325,6 +325,15 @@ 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} + + Diese Mail wurde automatisch von CodeOcean verschickt. + 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 6cc9dcaf..28344446 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -325,6 +325,15 @@ 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} + + This mail was automatically sent by CodeOcean. + 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