Allow anonymous questions to be returned when the user has disabled anonymous questions
Fixes #267
This commit is contained in:
parent
a37b6135ec
commit
cca8795b01
|
@ -66,8 +66,8 @@ class Ajax::AnswerController < AjaxController
|
||||||
end
|
end
|
||||||
|
|
||||||
if answer.user == current_user
|
if answer.user == current_user
|
||||||
Inbox.create!(user: answer.user, question: answer.question, new: true)
|
Inbox.create!(user: answer.user, question: answer.question, new: true, returning: true)
|
||||||
end # TODO: decide what happens with the question
|
end
|
||||||
answer.destroy
|
answer.destroy
|
||||||
|
|
||||||
@response[:status] = :okay
|
@response[:status] = :okay
|
||||||
|
|
|
@ -2,8 +2,13 @@ class Inbox < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :question
|
belongs_to :question
|
||||||
|
|
||||||
|
attr_accessor :returning
|
||||||
|
|
||||||
before_create do
|
before_create do
|
||||||
raise "User does not want to receive anonymous questions" if self.question.author_is_anonymous and self.question.author_name != 'justask' and !self.user.privacy_allow_anonymous_questions?
|
raise "User does not want to receive anonymous questions" if !returning &&
|
||||||
|
question.author_is_anonymous &&
|
||||||
|
(question.author_name != "justask") &&
|
||||||
|
!user.privacy_allow_anonymous_questions?
|
||||||
end
|
end
|
||||||
|
|
||||||
def answer(answer_content, user)
|
def answer(answer_content, user)
|
||||||
|
|
|
@ -268,6 +268,12 @@ describe Ajax::AnswerController, :ajax_controller, type: :controller do
|
||||||
it "returns the question back to the user's inbox" do
|
it "returns the question back to the user's inbox" do
|
||||||
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
|
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns the question back to the user's inbox when the user has anonymous questions disabled" do
|
||||||
|
user.privacy_allow_anonymous_questions = false
|
||||||
|
user.save
|
||||||
|
expect { subject }.to(change { Inbox.where(question_id: answer.question.id, user_id: user.id).count }.by(1))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the answer exists and was not made by the current user" do
|
context "when the answer exists and was not made by the current user" do
|
||||||
|
|
Loading…
Reference in New Issue