From 87d4eb8b0d2f62fab67ae4ec3c4ac658515f2ea3 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Tue, 10 May 2016 18:17:02 +0200 Subject: [PATCH] Let everyone see all comments and polish request for comments overview --- app/controllers/comments_controller.rb | 31 ++----------------- app/policies/comment_policy.rb | 6 +++- .../request_for_comments/index.html.slim | 6 ++-- config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ 5 files changed, 15 insertions(+), 32 deletions(-) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 2335a469..fd6840ff 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -12,41 +12,16 @@ class CommentsController < ApplicationController # GET /comments # GET /comments.json 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]) #there might be no submission yet, so dont use find submission = Submission.find_by(id: file.context_id) if submission - is_admin = false - 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 = Comment.where(file_id: params[:file_id]) @comments.map{|comment| - 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] + comment.username = comment.user.displayname } else - @comments = Comment.all.limit(0) #we need an empty relation here + @comments = [] end authorize! end diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 091ed5e2..ef7a0922 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -8,7 +8,11 @@ class CommentPolicy < ApplicationPolicy everyone end - [:new?, :show?, :destroy?].each do |action| + def show? + everyone + end + + [:new?, :destroy?].each do |action| define_method(action) { admin? || author? } end diff --git a/app/views/request_for_comments/index.html.slim b/app/views/request_for_comments/index.html.slim index 8471cca4..6d4e059c 100644 --- a/app/views/request_for_comments/index.html.slim +++ b/app/views/request_for_comments/index.html.slim @@ -12,11 +12,11 @@ h1 = RequestForComment.model_name.human(count: 2) - @request_for_comments.each do |request_for_comment| tr data-id=request_for_comment.id td = link_to(request_for_comment.exercise.title, request_for_comment) - - if request_for_comment.has_attribute?(:question) - td = request_for_comment.question + - if request_for_comment.has_attribute?(:question) && request_for_comment.question + td = truncate(request_for_comment.question, length: 200) - else td = '-' 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) \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index ddc6bfa4..a93a98db 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -396,6 +396,8 @@ de: shortcut: 'Tastaturkürzel: %{shortcut}' update: '%{model} aktualisieren' upload_file: Datei hochladen + time: + before: "%{time} zuvor" submissions: causes: autosave: Autosave diff --git a/config/locales/en.yml b/config/locales/en.yml index f083f5f9..b835a721 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -396,6 +396,8 @@ en: shortcut: 'Keyboard shortcut: %{shortcut}' update: 'Update %{model}' upload_file: Upload file + time: + before: "%{time} ago" submissions: causes: autosave: Autosave