Avoid error if no submission is present (on first load of editor)
This commit is contained in:
@ -16,8 +16,9 @@ class CommentsController < ApplicationController
|
||||
#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
|
||||
file = CodeOcean::File.find(params[:file_id])
|
||||
submission = Submission.find(file.context_id)
|
||||
|
||||
#there might be no submission yet, so dont use find
|
||||
submission = Submission.find_by(id: file.context_id)
|
||||
if submission
|
||||
is_admin = false
|
||||
if current_user.respond_to? :external_id
|
||||
user_id = current_user.external_id
|
||||
@ -37,6 +38,9 @@ class CommentsController < ApplicationController
|
||||
|
||||
#add names to comments
|
||||
@comments.map{|comment| comment.username = Xikolo::UserClient.get(comment.user_id.to_s)[:display_name]}
|
||||
else
|
||||
@comments = Comment.where(file_id: -1) #we need an empty relation here
|
||||
end
|
||||
authorize!
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ 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(:user_id => annotation[1][:user_id], :file_id => annotation[1][:file_id], :user_type => 'InternalUser', :row => annotation[1][:row], :column => annotation[1][:column], :text => annotation[1][:text])
|
||||
comment = Comment.new(:user_id => annotation[1][:user_id], :file_id => annotation[1][:file_id], :user_type => current_user.user_type, :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))
|
||||
|
Reference in New Issue
Block a user