diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 7076ca81..4da2bf5c 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -14,7 +14,7 @@ class CommentsController < ApplicationController def index #@comments = Comment.all #if admin, show all comments. - #check whether user is the author of the passed file_id, if so, show all comments. otherwise, only show comments of auther and own comments + #check whether user is the author of the passed file_id, if so, show all comments. otherwise, only show comments of the file-author and own comments file = CodeOcean::File.find(params[:file_id]) #there might be no submission yet, so dont use find submission = Submission.find_by(id: file.context_id) @@ -31,7 +31,10 @@ class CommentsController < ApplicationController # fetch all comments for this file @comments = Comment.where(file_id: params[:file_id]) else - @comments = Comment.where(file_id: params[:file_id], user_id: user_id) + # fetch comments of the current user + #@comments = Comment.where(file_id: params[:file_id], user_id: user_id) + # fetch comments of file-author and the current user + @comments = Comment.where(file_id: params[:file_id], user_id: [user_id, submission.user_id]) end #@comments = Comment.where(file_id: params[:file_id]) diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 59a05ab6..87cf825f 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -20,7 +20,7 @@ class SubmissionsController < ApplicationController def create @submission = Submission.new(submission_params) authorize! - #copy_comments + copy_comments create_and_respond(object: @submission) end @@ -28,13 +28,14 @@ class SubmissionsController < ApplicationController # copy each annotation and set the target_file.id unless(params[:annotations_arr].nil?) params[:annotations_arr].each do | annotation | + #comment = Comment.new(annotation[1].permit(:user_id, :file_id, :user_type, :row, :column, :text, :created_at, :updated_at)) comment = Comment.new(:user_id => annotation[1][:user_id], :file_id => annotation[1][:file_id], :user_type => current_user.class.name, :row => annotation[1][:row], :column => annotation[1][:column], :text => annotation[1][:text]) source_file = CodeOcean::File.find(annotation[1][:file_id]) - #comment = Comment.new(annotation[1].permit(:user_id, :file_id, :user_type, :row, :column, :text, :created_at, :updated_at)) + # retrieve target file target_file = @submission.files.detect do |file| # file_id has to be that of a the former iteration OR of the initial file (if this is the first run) - file.file_id == source_file.file_id || file.file_id == source_file.id #seems to be needed here: (check this): || file.file_id == source_file.id + file.file_id == source_file.file_id || file.file_id == source_file.id #seems to be needed here: (check this): || file.file_id == source_file.id ; yes this is needed, for comments on templates as well as comments on files added by users. end #save to assign an id