List direct questions for current users or mods

This commit is contained in:
Andreas Nedbal 2022-08-17 23:19:47 +02:00 committed by Andreas Nedbal
parent 85d2ffc5ec
commit 87c2ed3ab7
3 changed files with 33 additions and 2 deletions

View File

@ -54,9 +54,9 @@ class UserController < ApplicationController
def questions
@title = 'Questions'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@questions = @user.cursored_questions(author_is_anonymous: false, direct: false, last_id: params[:last_id])
@questions = @user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: params[:last_id])
@questions_last_id = @questions.map(&:id).min
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero?
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, direct: belongs_to_current_user? || moderation_view?, last_id: @questions_last_id, size: 1).count.zero?
respond_to do |format|
format.html

View File

@ -21,6 +21,10 @@ module UserHelper
current_user&.mod? && session[:moderation_view] == true
end
def belongs_to_current_user?
@user == current_user
end
private
def profile_link(user)

View File

@ -149,4 +149,31 @@ describe UserHelper, type: :helper do
end
end
end
describe "#belongs_to_current_user?" do
context "user is logged in" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
@user = user
end
it "returns the correct value" do
expect(helper.belongs_to_current_user?).to eq(true)
end
end
context "user is not logged in" do
let(:user) { FactoryBot.create(:user) }
before do
@user = user
end
it "returns the correct value" do
expect(helper.belongs_to_current_user?).to eq(false)
end
end
end
end