From ab96fb92c2e6c43d0237880136d4caafe19c8226 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 29 Nov 2019 15:28:06 +0100 Subject: [PATCH] Add Request for Comments view per exercise, adopt policies for teachers --- app/controllers/exercises_controller.rb | 14 +++++++++++++- app/policies/exercise_policy.rb | 4 ++-- app/views/exercises/index.html.slim | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/routes.rb | 1 + 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 855ad5e6..96762e2b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -7,7 +7,7 @@ class ExercisesController < ApplicationController before_action :handle_file_uploads, only: [:create, :update] before_action :set_execution_environments, only: [:create, :edit, :new, :update] - before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :study_group_dashboard] + before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :requests_for_comments, :study_group_dashboard] before_action :set_external_user_and_authorize, only: [:statistics] before_action :set_file_types, only: [:create, :edit, :new, :update] before_action :set_course_token, only: [:implement] @@ -110,6 +110,18 @@ class ExercisesController < ApplicationController end end + def requests_for_comments + authorize! + @search = RequestForComment + .with_last_activity + .where(exercise: @exercise) + .ransack(params[:q]) + @request_for_comments = @search.result + .order('last_comment DESC') + .paginate(page: params[:page]) + render 'request_for_comments/index' + end + def import_proforma_xml begin user = user_for_oauth2_request() diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index 662349fe..500930c6 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -3,11 +3,11 @@ class ExercisePolicy < AdminOrAuthorPolicy admin? end - [:show?, :study_group_dashboard?].each do |action| + [:show?, :study_group_dashboard?, :feedback?, :requests_for_comments?].each do |action| define_method(action) { admin? || teacher? } end - [:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?].each do |action| + [:clone?, :destroy?, :edit?, :statistics?, :update?].each do |action| define_method(action) { admin? || author? } end diff --git a/app/views/exercises/index.html.slim b/app/views/exercises/index.html.slim index 9c26ab6f..2594fb28 100644 --- a/app/views/exercises/index.html.slim +++ b/app/views/exercises/index.html.slim @@ -44,6 +44,7 @@ h1 = Exercise.model_name.human(count: 2) ul.dropdown-menu.float-right role="menu" li = link_to(t('shared.show'), exercise, 'data-turbolinks' => "false", class: 'dropdown-item') if policy(exercise).show? li = link_to(t('activerecord.models.user_exercise_feedback.other'), feedback_exercise_path(exercise), class: 'dropdown-item') if policy(exercise).feedback? + li = link_to(t('activerecord.models.request_for_comment.other'), requests_for_comments_exercise_path(exercise), class: 'dropdown-item') if policy(exercise).requests_for_comments? li = link_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy? li = link_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone? diff --git a/config/locales/de.yml b/config/locales/de.yml index f36e5cbb..dee7ba41 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -353,6 +353,7 @@ de: implement: Implementieren test_files: Test-Dateien feedback: Feedback + requests_for_comments: Kommentaranfragen study_group_dashboard: Live Dashboard statistics: average_score: Durchschnittliche Punktzahl diff --git a/config/locales/en.yml b/config/locales/en.yml index e9d30ec0..eb5c399f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -353,6 +353,7 @@ en: implement: Implement test_files: Test Files feedback: Feedback + requests_for_comments: Requests for Comments study_group_dashboard: Live Dashboard statistics: average_score: Average Score diff --git a/config/routes.rb b/config/routes.rb index 42cee5a3..43f54694 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,6 +81,7 @@ Rails.application.routes.draw do post :search get :statistics get :feedback + get :requests_for_comments get :reload post :submit get 'study_group_dashboard/:study_group_id', to: 'exercises#study_group_dashboard'