FEATURE: site setting to enable solved globally

This commit is contained in:
Sam 2015-06-19 16:08:43 +10:00
parent ec6a5cd109
commit d8705a278b
5 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,4 @@
{{#unless siteSettings.allow_solved_on_all_topics}}
<section class='field'> <section class='field'>
<div class="enable-accepted-answer"> <div class="enable-accepted-answer">
<label class="checkbox-label"> <label class="checkbox-label">
@ -6,3 +7,4 @@
</label> </label>
</div> </div>
</section> </section>
{{/unless}}

View File

@ -3,7 +3,7 @@ import PostView from 'discourse/views/post';
import { Button } from 'discourse/views/post-menu'; import { Button } from 'discourse/views/post-menu';
import Topic from 'discourse/models/topic'; import Topic from 'discourse/models/topic';
import User from 'discourse/models/user'; import User from 'discourse/models/user';
import TopicStatus from 'discourse/views/topic-status' import TopicStatus from 'discourse/views/topic-status';
export default { export default {
name: 'extend-for-solved-button', name: 'extend-for-solved-button',
@ -17,7 +17,7 @@ export default {
var fields = this.get('custom_fields'); var fields = this.get('custom_fields');
return fields && (fields.enable_accepted_answers === "true"); return fields && (fields.enable_accepted_answers === "true");
}.property('custom_fields') }.property('custom_fields')
}), });
Topic.reopen({ Topic.reopen({

View File

@ -0,0 +1,3 @@
en:
site_settings:
allow_solved_on_all_topics: "Allow users to select solutions on all topics (by default you control this by editing categories)"

4
config/settings.yml Normal file
View File

@ -0,0 +1,4 @@
plugins:
allow_solved_on_all_topics:
default: false
client: true

View File

@ -138,6 +138,8 @@ after_initialize do
end end
def allow_accepted_answers_on_category?(category_id) def allow_accepted_answers_on_category?(category_id)
return true if SiteSetting.allow_solved_on_all_topics
self.class.reset_accepted_answer_cache unless @@allowed_accepted_cache["allowed"] self.class.reset_accepted_answer_cache unless @@allowed_accepted_cache["allowed"]
@@allowed_accepted_cache["allowed"].include?(category_id) @@allowed_accepted_cache["allowed"].include?(category_id)
end end
@ -157,6 +159,7 @@ after_initialize do
def can_accept_answer def can_accept_answer
topic = (topic_view && topic_view.topic) || object.topic topic = (topic_view && topic_view.topic) || object.topic
if topic if topic
scope.can_accept_answer?(topic) && scope.can_accept_answer?(topic) &&
object.post_number > 1 && !accepted_answer object.post_number > 1 && !accepted_answer