From e5209143859298769d3a4a3793d0e8a1929c6acc Mon Sep 17 00:00:00 2001 From: Ralf Teusner Date: Tue, 18 Aug 2015 17:44:31 +0200 Subject: [PATCH] Some correction of column names. Support for internal as well as external users. Added column user_type and used it where necessary --- app/assets/javascripts/editor.js | 6 +++--- app/controllers/comments_controller.rb | 16 +++++++--------- .../request_for_comments_controller.rb | 2 +- app/views/request_for_comments/_form.html.erb | 16 ++++++++++------ app/views/request_for_comments/index.html.erb | 13 +++++++++++-- .../request_for_comments/index.json.jbuilder | 2 +- app/views/request_for_comments/show.html.erb | 14 +++++++++++--- .../request_for_comments/show.json.jbuilder | 2 +- ...1554_add_user_type_to_request_for_comments.rb | 5 +++++ .../20150818142251_correct_column_names.rb | 7 +++++++ db/schema.rb | 9 +++++---- 11 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 db/migrate/20150818141554_add_user_type_to_request_for_comments.rb create mode 100644 db/migrate/20150818142251_correct_column_names.rb 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 %>
- <%= f.label :requestorid %>
- <%= f.number_field :requestorid %> + <%= f.label :requestor_user_id %>
+ <%= f.number_field :requestor_user_id %>
- <%= f.label :exerciseid %>
- <%= f.number_field :exerciseid %> + <%= f.label :exercise_id %>
+ <%= f.number_field :exercise_id %>
- <%= f.label :fileid %>
- <%= f.number_field :fileid %> + <%= f.label :file_id %>
+ <%= f.number_field :file_id %>
<%= f.label :requested_at %>
<%= f.datetime_select :requested_at %>
+
+ <%= f.label :user_type %>
+ <%= f.text_field :user_type %> +
<%= f.submit %>
diff --git a/app/views/request_for_comments/index.html.erb b/app/views/request_for_comments/index.html.erb index 311be4b5..8a234e6f 100644 --- a/app/views/request_for_comments/index.html.erb +++ b/app/views/request_for_comments/index.html.erb @@ -3,9 +3,18 @@
<% @request_for_comments.each do |request_for_comment| %> -

<%= Exercise.find(request_for_comment.exerciseid) %>

+

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

- <%= 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 @@
-

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

+

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

- <%= 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 %>

-
<%= CodeOcean::File.find(@request_for_comment.fileid).content %> +
<%= CodeOcean::File.find(@request_for_comment.file_id).content %>