diff --git a/app/controllers/request_for_comments_controller.rb b/app/controllers/request_for_comments_controller.rb index 1c245814..435ad2d6 100644 --- a/app/controllers/request_for_comments_controller.rb +++ b/app/controllers/request_for_comments_controller.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true class RequestForCommentsController < ApplicationController + include CommonBehavior before_action :require_user! - before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note] + before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note clear_question] before_action :set_study_group_grouping, only: %i[index my_comment_requests rfcs_with_my_comments rfcs_for_exercise] @@ -101,6 +102,12 @@ class RequestForCommentsController < ApplicationController end end + # POST /request_for_comments/1/clear_question + def clear_question + authorize! + update_and_respond(object: @request_for_comment, params: {question: nil}) + end + # GET /request_for_comments/1 # GET /request_for_comments/1.json def show diff --git a/app/policies/request_for_comment_policy.rb b/app/policies/request_for_comment_policy.rb index d69e0cc6..55c01b4d 100644 --- a/app/policies/request_for_comment_policy.rb +++ b/app/policies/request_for_comment_policy.rb @@ -25,6 +25,10 @@ class RequestForCommentPolicy < ApplicationPolicy admin? || author? end + def clear_question? + admin? || teacher_in_study_group? + end + def edit? admin? end diff --git a/app/views/request_for_comments/_admin_menu.html.slim b/app/views/request_for_comments/_admin_menu.html.slim index 64580229..030e3276 100644 --- a/app/views/request_for_comments/_admin_menu.html.slim +++ b/app/views/request_for_comments/_admin_menu.html.slim @@ -1,6 +1,7 @@ hr h5.mt-4 Admin Menu ul.text + li = link_to "Clear question text (in case of explicit text)", clear_question_request_for_comment_path(id: @request_for_comment.id), method: :post if policy(@request_for_comment).clear_question? li = link_to "User's current status of this exercise", statistics_external_user_exercise_path(id: @request_for_comment.exercise_id, external_user_id: @request_for_comment.user_id) if policy(@request_for_comment.exercise).statistics? li = link_to "All exercises of this user", statistics_external_user_path(id: @request_for_comment.user_id) if policy(@request_for_comment.user).statistics? ul.text diff --git a/config/routes.rb b/config/routes.rb index 19e70cc4..3890129c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ Rails.application.routes.draw do member do get :mark_as_solved, defaults: {format: :json} post :set_thank_you_note, defaults: {format: :json} + post :clear_question end end resources :comments, defaults: {format: :json}