Check RfC visibility before redirecting users
This commit is contained in:
@ -21,7 +21,7 @@ module RedirectBehavior
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
rfc = @submission.own_unsolved_rfc
|
rfc = @submission.own_unsolved_rfc(current_user)
|
||||||
if rfc
|
if rfc
|
||||||
# set a message that informs the user that his own RFC should be closed.
|
# set a message that informs the user that his own RFC should be closed.
|
||||||
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_own_rfc')
|
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_own_rfc')
|
||||||
@ -36,7 +36,7 @@ module RedirectBehavior
|
|||||||
end
|
end
|
||||||
|
|
||||||
# else: show open rfc for same exercise if available
|
# else: show open rfc for same exercise if available
|
||||||
rfc = @submission.unsolved_rfc
|
rfc = @submission.unsolved_rfc(current_user)
|
||||||
unless rfc.nil? || @embed_options[:disable_redirect_to_rfcs] || @embed_options[:disable_rfc]
|
unless rfc.nil? || @embed_options[:disable_redirect_to_rfcs] || @embed_options[:disable_rfc]
|
||||||
# set a message that informs the user that his score was perfect and help in RFC is greatly appreciated.
|
# set a message that informs the user that his score was perfect and help in RFC is greatly appreciated.
|
||||||
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc')
|
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_rfc')
|
||||||
|
@ -128,12 +128,12 @@ class Submission < ApplicationRecord
|
|||||||
(user_id + exercise.created_at.to_i) % 10 == 1
|
(user_id + exercise.created_at.to_i) % 10 == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def own_unsolved_rfc
|
def own_unsolved_rfc(user = self.user)
|
||||||
RequestForComment.unsolved.find_by(exercise_id: exercise, user_id:)
|
Pundit.policy_scope(user, RequestForComment).unsolved.find_by(exercise_id: exercise, user_id:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsolved_rfc
|
def unsolved_rfc(user = self.user)
|
||||||
RequestForComment.unsolved.where(exercise_id: exercise).where.not(question: nil).where(created_at: OLDEST_RFC_TO_SHOW.ago..Time.current).order('RANDOM()').find do |rfc_element|
|
Pundit.policy_scope(user, RequestForComment).unsolved.where(exercise_id: exercise).where.not(question: nil).where(created_at: OLDEST_RFC_TO_SHOW.ago..Time.current).order('RANDOM()').find do |rfc_element|
|
||||||
((rfc_element.comments_count < MAX_COMMENTS_ON_RECOMMENDED_RFC) && !rfc_element.question.empty?)
|
((rfc_element.comments_count < MAX_COMMENTS_ON_RECOMMENDED_RFC) && !rfc_element.question.empty?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user