Respect user_type for RfC index routes

This commit is contained in:
Sebastian Serth
2020-12-04 16:58:05 +01:00
parent 389a5c424a
commit fac29f73d4
2 changed files with 8 additions and 8 deletions

View File

@ -27,7 +27,7 @@ class RequestForCommentsController < ApplicationController
def get_my_comment_requests
@search = RequestForComment
.with_last_activity
.where(user_id: current_user&.id)
.where(user: current_user)
.ransack(params[:q])
@request_for_comments = @search.result
.order('created_at DESC')

View File

@ -17,12 +17,12 @@ class RequestForComment < ApplicationRecord
def self.last_per_user(n = 5)
from("(#{row_number_user_sql}) as request_for_comments")
.where("row_number <= ?", n)
.group('request_for_comments.id, request_for_comments.user_id, request_for_comments.exercise_id,
request_for_comments.file_id, request_for_comments.question, request_for_comments.created_at,
request_for_comments.updated_at, request_for_comments.user_type, request_for_comments.solved,
request_for_comments.full_score_reached, request_for_comments.submission_id, request_for_comments.row_number')
# ugly, but necessary
end
.group('request_for_comments.id, request_for_comments.user_id, request_for_comments.user_type,
request_for_comments.exercise_id, request_for_comments.file_id, request_for_comments.question,
request_for_comments.created_at, request_for_comments.updated_at, request_for_comments.solved,
request_for_comments.full_score_reached, request_for_comments.submission_id, request_for_comments.row_number')
# ugly, but necessary
end
# not used right now, finds the last submission for the respective user and exercise.
# might be helpful to check whether the exercise has been solved in the meantime.
@ -67,6 +67,6 @@ class RequestForComment < ApplicationRecord
private
def self.row_number_user_sql
select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, full_score_reached, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
select("id, user_id, user_type, exercise_id, file_id, question, created_at, updated_at, solved, full_score_reached, submission_id, row_number() OVER (PARTITION BY user_id, user_type ORDER BY created_at DESC) as row_number").to_sql
end
end