Let everyone see all comments and polish request for comments overview

This commit is contained in:
Maximilian Grundke
2016-05-10 18:17:02 +02:00
parent 7e4c886b65
commit 87d4eb8b0d
5 changed files with 15 additions and 32 deletions

View File

@ -12,41 +12,16 @@ class CommentsController < ApplicationController
# GET /comments # GET /comments
# GET /comments.json # GET /comments.json
def index def index
#@comments = Comment.all
#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 the file-author and own comments
file = CodeOcean::File.find(params[:file_id]) file = CodeOcean::File.find(params[:file_id])
#there might be no submission yet, so dont use find #there might be no submission yet, so dont use find
submission = Submission.find_by(id: file.context_id) submission = Submission.find_by(id: file.context_id)
if submission if submission
is_admin = false @comments = Comment.where(file_id: params[:file_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
if(is_admin || user_id == submission.user_id)
# fetch all comments for this file
@comments = Comment.where(file_id: params[:file_id])
else
# fetch comments of the current user
#@comments = Comment.where(file_id: params[:file_id], user_id: user_id)
# fetch comments of file-author and the current user
@comments = Comment.where(file_id: params[:file_id], user_id: [user_id, submission.user_id])
end
#add names to comments
# if the user is internal, set the name
@comments.map{|comment| @comments.map{|comment|
comment.username = comment.user.displayname comment.username = comment.user.displayname
# alternative: # if the user is external, fetch the displayname from xikolo
# Xikolo::UserClient.get(comment.user_id.to_s)[:display_name]
} }
else else
@comments = Comment.all.limit(0) #we need an empty relation here @comments = []
end end
authorize! authorize!
end end

View File

@ -8,7 +8,11 @@ class CommentPolicy < ApplicationPolicy
everyone everyone
end end
[:new?, :show?, :destroy?].each do |action| def show?
everyone
end
[:new?, :destroy?].each do |action|
define_method(action) { admin? || author? } define_method(action) { admin? || author? }
end end

View File

@ -12,11 +12,11 @@ h1 = RequestForComment.model_name.human(count: 2)
- @request_for_comments.each do |request_for_comment| - @request_for_comments.each do |request_for_comment|
tr data-id=request_for_comment.id tr data-id=request_for_comment.id
td = link_to(request_for_comment.exercise.title, request_for_comment) td = link_to(request_for_comment.exercise.title, request_for_comment)
- if request_for_comment.has_attribute?(:question) - if request_for_comment.has_attribute?(:question) && request_for_comment.question
td = request_for_comment.question td = truncate(request_for_comment.question, length: 200)
- else - else
td = '-' td = '-'
td = request_for_comment.user.displayname td = request_for_comment.user.displayname
td = request_for_comment.requested_at td = t('shared.time.before', time: distance_of_time_in_words_to_now(request_for_comment.requested_at))
= render('shared/pagination', collection: @request_for_comments) = render('shared/pagination', collection: @request_for_comments)

View File

@ -396,6 +396,8 @@ de:
shortcut: 'Tastaturkürzel: %{shortcut}' shortcut: 'Tastaturkürzel: %{shortcut}'
update: '%{model} aktualisieren' update: '%{model} aktualisieren'
upload_file: Datei hochladen upload_file: Datei hochladen
time:
before: "%{time} zuvor"
submissions: submissions:
causes: causes:
autosave: Autosave autosave: Autosave

View File

@ -396,6 +396,8 @@ en:
shortcut: 'Keyboard shortcut: %{shortcut}' shortcut: 'Keyboard shortcut: %{shortcut}'
update: 'Update %{model}' update: 'Update %{model}'
upload_file: Upload file upload_file: Upload file
time:
before: "%{time} ago"
submissions: submissions:
causes: causes:
autosave: Autosave autosave: Autosave