diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js index b9ca3017..93e3539b 100644 --- a/app/assets/javascripts/editor.js +++ b/app/assets/javascripts/editor.js @@ -1014,9 +1014,9 @@ $(function() { url: '/request_for_comments', data: { request_for_comment: { - requestorid: user_id, - exerciseid: exercise_id, - fileid: file_id, + requestor_user_id: user_id, + exercise_id: exercise_id, + file_id: file_id, "requested_at(1i)": 2015, // these are the timestamp values that the request handler demands "requested_at(2i)":3, // they could be random here, because the timestamp is updated on serverside anyway "requested_at(3i)":27, diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 91e31068..434aa67b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -20,10 +20,10 @@ class CommentsController < ApplicationController 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 + user_id = current_user.id + + # if we have an internal user, check whether he is an admin + if not current_user.respond_to? :external_id is_admin = current_user.role == 'admin' end @@ -37,18 +37,16 @@ class CommentsController < ApplicationController @comments = Comment.where(file_id: params[:file_id], user_id: [user_id, submission.user_id]) end - #@comments = Comment.where(file_id: params[:file_id]) - #add names to comments # if the user is internal, set the name - # todo: - # if the user is external, fetch the displayname from xikolo + @comments.map{|comment| if(comment.user_type == 'InternalUser') comment.username = InternalUser.find(comment.user_id).name elsif(comment.user_type == 'ExternalUser') comment.username = ExternalUser.find(comment.user_id).name - #alternativ: Xikolo::UserClient.get(comment.user_id.to_s)[:display_name] + # alternative: # if the user is external, fetch the displayname from xikolo + # Xikolo::UserClient.get(comment.user_id.to_s)[:display_name] end } else diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index fbeb21b7..2a68619b 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -66,6 +66,6 @@ class RequestForCommentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def request_for_comment_params - params.require(:request_for_comment).permit(:requestorid, :exerciseid, :fileid, :requested_at) + params.require(:request_for_comment).permit(:requestor_user_id, :exercise_id, :file_id, :requested_at) end end diff --git a/app/views/request_for_comments/_form.html.erb b/app/views/request_for_comments/_form.html.erb index a8d037e9..493e2445 100644 --- a/app/views/request_for_comments/_form.html.erb +++ b/app/views/request_for_comments/_form.html.erb @@ -12,21 +12,25 @@ <% end %>
- <%= InternalUser.find(request_for_comment.requestorid) %> | <%= request_for_comment.requested_at %> + <% + user = nil + if (request_for_comment.user_type == 'InternalUser') + user = InternalUser.find(request_for_comment.requestor_user_id) + else + user = ExternalUser.find(request_for_comment.requestor_user_id) + end + %> + + <%= user %> | <%= request_for_comment.requested_at %>
<% end %> diff --git a/app/views/request_for_comments/index.json.jbuilder b/app/views/request_for_comments/index.json.jbuilder index 26b37b67..72204e6e 100644 --- a/app/views/request_for_comments/index.json.jbuilder +++ b/app/views/request_for_comments/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@request_for_comments) do |request_for_comment| - json.extract! request_for_comment, :id, :requestorid, :exerciseid, :fileid, :requested_at + json.extract! request_for_comment, :id, :requestor_user_id, :exercise_id, :file_id, :requested_at, :user_type json.url request_for_comment_url(request_for_comment, format: :json) end diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb index 1b8e7495..179c8cd5 100644 --- a/app/views/request_for_comments/show.html.erb +++ b/app/views/request_for_comments/show.html.erb @@ -1,14 +1,22 @@- <%= InternalUser.find(@request_for_comment.requestorid) %> | <%= @request_for_comment.requested_at %> + <% + user = nil + if (@request_for_comment.user_type == 'InternalUser') + user = InternalUser.find(@request_for_comment.requestor_user_id) + else + user = ExternalUser.find(@request_for_comment.requestor_user_id) + end + %> + <%= user %> | <%= @request_for_comment.requested_at %>