Apply automatic rubocop fixes
This commit is contained in:
@ -5,7 +5,8 @@ class RequestForCommentsController < ApplicationController
|
||||
|
||||
before_action :require_user!
|
||||
before_action :set_request_for_comment, only: %i[show mark_as_solved set_thank_you_note]
|
||||
before_action :set_study_group_grouping, only: %i[index get_my_comment_requests get_rfcs_with_my_comments get_rfcs_for_exercise]
|
||||
before_action :set_study_group_grouping,
|
||||
only: %i[index get_my_comment_requests get_rfcs_with_my_comments get_rfcs_for_exercise]
|
||||
|
||||
def authorize!
|
||||
authorize(@request_for_comments || @request_for_comment)
|
||||
@ -16,15 +17,15 @@ class RequestForCommentsController < ApplicationController
|
||||
# GET /request_for_comments.json
|
||||
def index
|
||||
@search = RequestForComment
|
||||
.last_per_user(2)
|
||||
.with_last_activity
|
||||
.ransack(params[:q])
|
||||
.last_per_user(2)
|
||||
.with_last_activity
|
||||
.ransack(params[:q])
|
||||
@request_for_comments = @search.result
|
||||
.joins(:exercise)
|
||||
.where(exercises: {unpublished: false})
|
||||
.includes(submission: [:study_group])
|
||||
.order('created_at DESC')
|
||||
.paginate(page: params[:page], total_entries: @search.result.length)
|
||||
.joins(:exercise)
|
||||
.where(exercises: {unpublished: false})
|
||||
.includes(submission: [:study_group])
|
||||
.order('created_at DESC')
|
||||
.paginate(page: params[:page], total_entries: @search.result.length)
|
||||
|
||||
authorize!
|
||||
end
|
||||
@ -32,12 +33,12 @@ class RequestForCommentsController < ApplicationController
|
||||
# GET /my_request_for_comments
|
||||
def get_my_comment_requests
|
||||
@search = RequestForComment
|
||||
.with_last_activity
|
||||
.where(user: current_user)
|
||||
.ransack(params[:q])
|
||||
.with_last_activity
|
||||
.where(user: current_user)
|
||||
.ransack(params[:q])
|
||||
@request_for_comments = @search.result
|
||||
.order('created_at DESC')
|
||||
.paginate(page: params[:page])
|
||||
.order('created_at DESC')
|
||||
.paginate(page: params[:page])
|
||||
authorize!
|
||||
render 'index'
|
||||
end
|
||||
@ -45,13 +46,13 @@ class RequestForCommentsController < ApplicationController
|
||||
# GET /my_rfc_activity
|
||||
def get_rfcs_with_my_comments
|
||||
@search = RequestForComment
|
||||
.with_last_activity
|
||||
.joins(:comments) # we don't need to outer join here, because we know the user has commented on these
|
||||
.where(comments: {user_id: current_user.id})
|
||||
.ransack(params[:q])
|
||||
.with_last_activity
|
||||
.joins(:comments) # we don't need to outer join here, because we know the user has commented on these
|
||||
.where(comments: {user_id: current_user.id})
|
||||
.ransack(params[:q])
|
||||
@request_for_comments = @search.result
|
||||
.order('last_comment DESC')
|
||||
.paginate(page: params[:page])
|
||||
.order('last_comment DESC')
|
||||
.paginate(page: params[:page])
|
||||
authorize!
|
||||
render 'index'
|
||||
end
|
||||
@ -60,13 +61,13 @@ class RequestForCommentsController < ApplicationController
|
||||
def get_rfcs_for_exercise
|
||||
exercise = Exercise.find(params[:exercise_id])
|
||||
@search = RequestForComment
|
||||
.with_last_activity
|
||||
.where(exercise_id: exercise.id)
|
||||
.ransack(params[:q])
|
||||
.with_last_activity
|
||||
.where(exercise_id: exercise.id)
|
||||
.ransack(params[:q])
|
||||
@request_for_comments = @search.result
|
||||
.joins(:exercise)
|
||||
.order('last_comment DESC')
|
||||
.paginate(page: params[:page])
|
||||
.joins(:exercise)
|
||||
.order('last_comment DESC')
|
||||
.paginate(page: params[:page])
|
||||
# let the exercise decide, whether its rfcs should be visible
|
||||
authorize(exercise)
|
||||
render 'index'
|
||||
@ -91,7 +92,7 @@ class RequestForCommentsController < ApplicationController
|
||||
@request_for_comment.thank_you_note = params[:note]
|
||||
|
||||
commenters = @request_for_comment.commenters
|
||||
commenters.each { |commenter| UserMailer.send_thank_you_note(@request_for_comment, commenter).deliver_now }
|
||||
commenters.each {|commenter| UserMailer.send_thank_you_note(@request_for_comment, commenter).deliver_now }
|
||||
|
||||
respond_to do |format|
|
||||
if @request_for_comment.save
|
||||
@ -143,14 +144,16 @@ class RequestForCommentsController < ApplicationController
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def request_for_comment_params
|
||||
# The study_group_id might not be present in the session (e.g. for internal users), resulting in session[:study_group_id] = nil which is intended.
|
||||
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(
|
||||
user_id: current_user.id, user_type: current_user.class.name
|
||||
)
|
||||
end
|
||||
|
||||
# The index page requires the grouping of the study groups
|
||||
# The study groups are grouped by the current study group and other study groups of the user
|
||||
def set_study_group_grouping
|
||||
current_study_group = StudyGroup.find_by(id: session[:study_group_id])
|
||||
my_study_groups = current_user.study_groups.reject { |group| group == current_study_group }
|
||||
my_study_groups = current_user.study_groups.reject {|group| group == current_study_group }
|
||||
@study_groups_grouping = [[t('request_for_comments.index.study_groups.current'), Array(current_study_group)],
|
||||
[t('request_for_comments.index.study_groups.my'), my_study_groups]]
|
||||
end
|
||||
|
Reference in New Issue
Block a user