-
Notifications
You must be signed in to change notification settings - Fork 24
FEATURE: Allow QnA mode on any topic. #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<label class="topic-composer-enable-qa"> | ||
{{input type="checkbox" checked=model.isQuestion}} | ||
{{i18n "topic.set_as_qa"}} | ||
</label> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CREATE_TOPIC } from "discourse/models/composer"; | ||
|
||
export default { | ||
shouldRender(args, component) { | ||
return ( | ||
component.siteSettings.qa_enabled_globally && | ||
args.model.action === CREATE_TOPIC | ||
); | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { withPluginApi } from "discourse/lib/plugin-api"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is not running for me locally. I think it's due to the extension, i.e. it should be |
||
|
||
export default { | ||
name: "composer-topic-qa-mode", | ||
|
||
initialize(container) { | ||
const siteSettings = container.lookup("site-settings:main"); | ||
const currentUser = container.lookup("current-user:main"); | ||
|
||
if ( | ||
siteSettings.qa_enabled && | ||
siteSettings.qa_enabled_globally && | ||
currentUser | ||
) { | ||
withPluginApi("0.12.3", (api) => { | ||
api.serializeOnCreate("is_question", "isQuestion"); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More a matter of opinion, but you could add |
||
} | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ plugins: | |
qa_blacklist_tags: | ||
type: list | ||
default: "" | ||
qa_enabled_globally: | ||
default: false | ||
client: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
end | ||
end | ||
|
||
require 'rails_helper' | ||
require 'rails_helper' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe PostsController do | ||
let(:user) { Fabricate(:user) } | ||
|
||
describe '#create' do | ||
before do | ||
sign_in(user) | ||
SiteSetting.qa_enabled = true | ||
end | ||
|
||
it 'sets the question subtype when the is_question param is set to true' do | ||
post "/posts.json", params: { | ||
raw: 'this is a test question', | ||
title: 'this is the title for the question topic', | ||
is_question: true, | ||
} | ||
end | ||
|
||
it 'only sets the question subtype on regular topics' do | ||
another_user = Fabricate(:user) | ||
post "/posts.json", params: { | ||
raw: 'this is a test question', | ||
title: 'this is the title for the question topic', | ||
is_question: true, | ||
target_recipients: another_user.username, | ||
archetype: Archetype.private_message | ||
} | ||
|
||
expect(response.status).to eq(200) | ||
|
||
created_topic = Topic.last | ||
expect(created_topic.subtype).not_to eq('question') | ||
end | ||
|
||
it 'preserves the subtype when a topic gets queued' do | ||
SiteSetting.approve_post_count = 1 | ||
|
||
post "/posts.json", params: { | ||
raw: 'this is the test content', | ||
title: 'this is the test title for the topic', | ||
is_question: true, | ||
} | ||
|
||
expect(response.status).to eq(200) | ||
parsed = response.parsed_body | ||
expect(parsed["action"]).to eq("enqueued") | ||
|
||
rp = ReviewableQueuedPost.find_by(created_by: user) | ||
expect(rp).to be_present | ||
|
||
result = rp.perform(Discourse.system_user, :approve_post) | ||
expect(result.created_post.topic.subtype).to eq('question') | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this dependent on
siteSettings.qa_enabled
too?