Avoid error if no submission is present (on first load of editor)
This commit is contained in:
@ -16,27 +16,31 @@ class CommentsController < ApplicationController
|
|||||||
#if admin, show all comments.
|
#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 auther and own comments
|
||||||
file = CodeOcean::File.find(params[:file_id])
|
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
|
||||||
|
else
|
||||||
|
user_id = current_user.id
|
||||||
|
is_admin = current_user.role == 'admin'
|
||||||
|
end
|
||||||
|
|
||||||
is_admin = false
|
if(is_admin || user_id == submission.user_id)
|
||||||
if current_user.respond_to? :external_id
|
# fetch all comments for this file
|
||||||
user_id = current_user.external_id
|
@comments = Comment.where(file_id: params[:file_id])
|
||||||
|
else
|
||||||
|
@comments = Comment.where(file_id: params[:file_id], user_id: user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
#@comments = Comment.where(file_id: params[:file_id])
|
||||||
|
|
||||||
|
#add names to comments
|
||||||
|
@comments.map{|comment| comment.username = Xikolo::UserClient.get(comment.user_id.to_s)[:display_name]}
|
||||||
else
|
else
|
||||||
user_id = current_user.id
|
@comments = Comment.where(file_id: -1) #we need an empty relation here
|
||||||
is_admin = current_user.role == 'admin'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if(is_admin || user_id == submission.user_id)
|
|
||||||
# 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)
|
|
||||||
end
|
|
||||||
|
|
||||||
#@comments = Comment.where(file_id: params[:file_id])
|
|
||||||
|
|
||||||
#add names to comments
|
|
||||||
@comments.map{|comment| comment.username = Xikolo::UserClient.get(comment.user_id.to_s)[:display_name]}
|
|
||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class SubmissionsController < ApplicationController
|
|||||||
# copy each annotation and set the target_file.id
|
# copy each annotation and set the target_file.id
|
||||||
unless(params[:annotations_arr].nil?)
|
unless(params[:annotations_arr].nil?)
|
||||||
params[:annotations_arr].each do | annotation |
|
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])
|
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))
|
#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