Some correction of column names.

Support for internal as well as external users. Added column user_type and used it where necessary
This commit is contained in:
Ralf Teusner
2015-08-18 17:44:31 +02:00
parent 512e90ebd7
commit e520914385
11 changed files with 62 additions and 30 deletions

View File

@@ -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,

View File

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

View File

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

View File

@@ -12,21 +12,25 @@
<% end %>
<div class="field">
<%= f.label :requestorid %><br>
<%= f.number_field :requestorid %>
<%= f.label :requestor_user_id %><br>
<%= f.number_field :requestor_user_id %>
</div>
<div class="field">
<%= f.label :exerciseid %><br>
<%= f.number_field :exerciseid %>
<%= f.label :exercise_id %><br>
<%= f.number_field :exercise_id %>
</div>
<div class="field">
<%= f.label :fileid %><br>
<%= f.number_field :fileid %>
<%= f.label :file_id %><br>
<%= f.number_field :file_id %>
</div>
<div class="field">
<%= f.label :requested_at %><br>
<%= f.datetime_select :requested_at %>
</div>
<div class="field">
<%= f.label :user_type %><br>
<%= f.text_field :user_type %>
</div>
<div class="actions">
<%= f.submit %>
</div>

View File

@@ -3,9 +3,18 @@
<div class="list-group">
<% @request_for_comments.each do |request_for_comment| %>
<a href="<%= request_for_comment_path(request_for_comment) %>" class="list-group-item">
<h4 class="list-group-item-heading"><%= Exercise.find(request_for_comment.exerciseid) %></h4>
<h4 class="list-group-item-heading"><%= Exercise.find(request_for_comment.exercise_id) %></h4>
<p class="list-group-item-text">
<%= 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 %>
</p>
</a>
<% end %>

View File

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

View File

@@ -1,14 +1,22 @@
<div class="list-group">
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exerciseid) %></h4>
<h4 class="list-group-item-heading"><%= Exercise.find(@request_for_comment.exercise_id) %></h4>
<p class="list-group-item-text">
<%= 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 %>
</p>
</div>
<!--
do not put a carriage return in the line below. it will be present in the presentation of the source code, otherwise.
-->
<div id='commentitor' class='editor' data-read-only='true' data-file-id='<%=@request_for_comment.fileid%>'><%= CodeOcean::File.find(@request_for_comment.fileid).content %>
<div id='commentitor' class='editor' data-read-only='true' data-file-id='<%=@request_for_comment.file_id%>'><%= CodeOcean::File.find(@request_for_comment.file_id).content %>
</div>
<script type="text/javascript">

View File

@@ -1 +1 @@
json.extract! @request_for_comment, :id, :requestorid, :exerciseid, :fileid, :requested_at, :created_at, :updated_at
json.extract! @request_for_comment, :id, :requestor_user_id, :exercise_id, :file_id, :requested_at, :created_at, :updated_at, :user_type