Allow admins and teachers to remove explicit RfC text

This commit is contained in:
Sebastian Serth
2022-04-28 15:31:58 +02:00
parent e9efb5bc2b
commit 9a0f26a84f
4 changed files with 14 additions and 1 deletions

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class RequestForCommentsController < ApplicationController class RequestForCommentsController < ApplicationController
include CommonBehavior
before_action :require_user! 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, before_action :set_study_group_grouping,
only: %i[index my_comment_requests rfcs_with_my_comments rfcs_for_exercise] only: %i[index my_comment_requests rfcs_with_my_comments rfcs_for_exercise]
@ -101,6 +102,12 @@ class RequestForCommentsController < ApplicationController
end end
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
# GET /request_for_comments/1.json # GET /request_for_comments/1.json
def show def show

View File

@ -25,6 +25,10 @@ class RequestForCommentPolicy < ApplicationPolicy
admin? || author? admin? || author?
end end
def clear_question?
admin? || teacher_in_study_group?
end
def edit? def edit?
admin? admin?
end end

View File

@ -1,6 +1,7 @@
hr hr
h5.mt-4 Admin Menu h5.mt-4 Admin Menu
ul.text 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 "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? 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 ul.text

View File

@ -21,6 +21,7 @@ Rails.application.routes.draw do
member do member do
get :mark_as_solved, defaults: {format: :json} get :mark_as_solved, defaults: {format: :json}
post :set_thank_you_note, defaults: {format: :json} post :set_thank_you_note, defaults: {format: :json}
post :clear_question
end end
end end
resources :comments, defaults: {format: :json} resources :comments, defaults: {format: :json}