List direct questions for current users or mods
This commit is contained in:
parent
85d2ffc5ec
commit
87c2ed3ab7
|
@ -54,9 +54,9 @@ class UserController < ApplicationController
|
||||||
def questions
|
def questions
|
||||||
@title = 'Questions'
|
@title = 'Questions'
|
||||||
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
|
@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
|
@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|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
|
|
@ -21,6 +21,10 @@ module UserHelper
|
||||||
current_user&.mod? && session[:moderation_view] == true
|
current_user&.mod? && session[:moderation_view] == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def belongs_to_current_user?
|
||||||
|
@user == current_user
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def profile_link(user)
|
def profile_link(user)
|
||||||
|
|
|
@ -149,4 +149,31 @@ describe UserHelper, type: :helper do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue