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:
@ -1014,9 +1014,9 @@ $(function() {
|
|||||||
url: '/request_for_comments',
|
url: '/request_for_comments',
|
||||||
data: {
|
data: {
|
||||||
request_for_comment: {
|
request_for_comment: {
|
||||||
requestorid: user_id,
|
requestor_user_id: user_id,
|
||||||
exerciseid: exercise_id,
|
exercise_id: exercise_id,
|
||||||
fileid: file_id,
|
file_id: file_id,
|
||||||
"requested_at(1i)": 2015, // these are the timestamp values that the request handler demands
|
"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(2i)":3, // they could be random here, because the timestamp is updated on serverside anyway
|
||||||
"requested_at(3i)":27,
|
"requested_at(3i)":27,
|
||||||
|
@ -20,10 +20,10 @@ class CommentsController < ApplicationController
|
|||||||
submission = Submission.find_by(id: file.context_id)
|
submission = Submission.find_by(id: file.context_id)
|
||||||
if submission
|
if submission
|
||||||
is_admin = false
|
is_admin = false
|
||||||
if current_user.respond_to? :external_id
|
user_id = current_user.id
|
||||||
user_id = current_user.external_id
|
|
||||||
else
|
# if we have an internal user, check whether he is an admin
|
||||||
user_id = current_user.id
|
if not current_user.respond_to? :external_id
|
||||||
is_admin = current_user.role == 'admin'
|
is_admin = current_user.role == 'admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,18 +37,16 @@ class CommentsController < ApplicationController
|
|||||||
@comments = Comment.where(file_id: params[:file_id], user_id: [user_id, submission.user_id])
|
@comments = Comment.where(file_id: params[:file_id], user_id: [user_id, submission.user_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
#@comments = Comment.where(file_id: params[:file_id])
|
|
||||||
|
|
||||||
#add names to comments
|
#add names to comments
|
||||||
# if the user is internal, set the name
|
# if the user is internal, set the name
|
||||||
# todo:
|
|
||||||
# if the user is external, fetch the displayname from xikolo
|
|
||||||
@comments.map{|comment|
|
@comments.map{|comment|
|
||||||
if(comment.user_type == 'InternalUser')
|
if(comment.user_type == 'InternalUser')
|
||||||
comment.username = InternalUser.find(comment.user_id).name
|
comment.username = InternalUser.find(comment.user_id).name
|
||||||
elsif(comment.user_type == 'ExternalUser')
|
elsif(comment.user_type == 'ExternalUser')
|
||||||
comment.username = ExternalUser.find(comment.user_id).name
|
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
|
end
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -66,6 +66,6 @@ class RequestForCommentsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def request_for_comment_params
|
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
|
||||||
end
|
end
|
||||||
|
@ -12,21 +12,25 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :requestorid %><br>
|
<%= f.label :requestor_user_id %><br>
|
||||||
<%= f.number_field :requestorid %>
|
<%= f.number_field :requestor_user_id %>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :exerciseid %><br>
|
<%= f.label :exercise_id %><br>
|
||||||
<%= f.number_field :exerciseid %>
|
<%= f.number_field :exercise_id %>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :fileid %><br>
|
<%= f.label :file_id %><br>
|
||||||
<%= f.number_field :fileid %>
|
<%= f.number_field :file_id %>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :requested_at %><br>
|
<%= f.label :requested_at %><br>
|
||||||
<%= f.datetime_select :requested_at %>
|
<%= f.datetime_select :requested_at %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :user_type %><br>
|
||||||
|
<%= f.text_field :user_type %>
|
||||||
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit %>
|
<%= f.submit %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,9 +3,18 @@
|
|||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<% @request_for_comments.each do |request_for_comment| %>
|
<% @request_for_comments.each do |request_for_comment| %>
|
||||||
<a href="<%= request_for_comment_path(request_for_comment) %>" class="list-group-item">
|
<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">
|
<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>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
json.array!(@request_for_comments) do |request_for_comment|
|
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)
|
json.url request_for_comment_url(request_for_comment, format: :json)
|
||||||
end
|
end
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
<div class="list-group">
|
<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">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
do not put a carriage return in the line below. it will be present in the presentation of the source code, otherwise.
|
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>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -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
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddUserTypeToRequestForComments < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :request_for_comments, :user_type, :string
|
||||||
|
end
|
||||||
|
end
|
7
db/migrate/20150818142251_correct_column_names.rb
Normal file
7
db/migrate/20150818142251_correct_column_names.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class CorrectColumnNames < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_column :request_for_comments, :requestorid, :requestor_user_id
|
||||||
|
rename_column :request_for_comments, :exerciseid, :exercise_id
|
||||||
|
rename_column :request_for_comments, :fileid, :file_id
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150421074734) do
|
ActiveRecord::Schema.define(version: 20150818142251) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -171,12 +171,13 @@ ActiveRecord::Schema.define(version: 20150421074734) do
|
|||||||
add_index "internal_users_teams", ["team_id"], name: "index_internal_users_teams_on_team_id", using: :btree
|
add_index "internal_users_teams", ["team_id"], name: "index_internal_users_teams_on_team_id", using: :btree
|
||||||
|
|
||||||
create_table "request_for_comments", force: true do |t|
|
create_table "request_for_comments", force: true do |t|
|
||||||
t.integer "requestorid", null: false
|
t.integer "requestor_user_id", null: false
|
||||||
t.integer "exerciseid", null: false
|
t.integer "exercise_id", null: false
|
||||||
t.integer "fileid", null: false
|
t.integer "file_id", null: false
|
||||||
t.datetime "requested_at"
|
t.datetime "requested_at"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.string "user_type"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "submissions", force: true do |t|
|
create_table "submissions", force: true do |t|
|
||||||
|
Reference in New Issue
Block a user