FEATURE: Category setting to make all topics wikis

FEATURE: Category setting to make all topics wikis
This commit is contained in:
Joe Buhlig 2016-12-18 07:38:55 -06:00
parent ddd299f4aa
commit 87251fded7
10 changed files with 29 additions and 1 deletions

View File

@ -97,6 +97,7 @@ const Category = RestModel.extend({
custom_fields: this.get('custom_fields'),
topic_template: this.get('topic_template'),
suppress_from_homepage: this.get('suppress_from_homepage'),
all_topics_wiki: this.get('all_topics_wiki'),
allowed_tags: this.get('allowed_tags'),
allowed_tag_groups: this.get('allowed_tag_groups'),
sort_order: this.get('sort_order'),

View File

@ -19,6 +19,13 @@
</label>
</section>
<section class="field">
<label>
{{input type="checkbox" checked=category.all_topics_wiki}}
{{i18n "category.all_topics_wiki"}}
</label>
</section>
{{#if siteSettings.topic_featured_link_enabled}}
<section class='field'>
<div class="allowed-topic-featured-link-category">

View File

@ -230,6 +230,7 @@ class CategoriesController < ApplicationController
:email_in,
:email_in_allow_strangers,
:suppress_from_homepage,
:all_topics_wiki,
:parent_category_id,
:auto_close_hours,
:auto_close_based_on_last_post,

View File

@ -538,6 +538,7 @@ end
# auto_close_based_on_last_post :boolean default(FALSE)
# topic_template :text
# suppress_from_homepage :boolean default(FALSE)
# all_topics_wiki :boolean default(FALSE)
# contains_messages :boolean
# sort_order :string
# sort_ascending :boolean

View File

@ -9,6 +9,7 @@ class CategorySerializer < BasicCategorySerializer
:email_in,
:email_in_allow_strangers,
:suppress_from_homepage,
:all_topics_wiki,
:can_delete,
:cannot_delete_reason,
:is_special,

View File

@ -1944,6 +1944,7 @@ en:
email_in_disabled: "Posting new topics via email is disabled in the Site Settings. To enable posting new topics via email, "
email_in_disabled_click: 'enable the "email in" setting.'
suppress_from_homepage: "Suppress this category from the homepage."
all_topics_wiki: "Make new topics wikis by default."
sort_order: "Default Sort:"
allow_badges_label: "Allow badges to be awarded in this category"
edit_permissions: "Edit Permissions"

View File

@ -0,0 +1,5 @@
class AddAllTopicsWikiToCategories < ActiveRecord::Migration
def change
add_column :categories, :all_topics_wiki, :boolean, default: false, null: false
end
end

View File

@ -25,7 +25,7 @@ module ImportExport
CATEGORY_ATTRS = [:id, :name, :color, :created_at, :user_id, :slug, :description, :text_color,
:auto_close_hours, :auto_close_based_on_last_post,
:topic_template, :suppress_from_homepage, :permissions_params]
:topic_template, :suppress_from_homepage, :all_topics_wiki, :permissions_params]
def export_categories
@export_data[:category] = CATEGORY_ATTRS.inject({}) { |h,a| h[a] = @category.send(a); h }

View File

@ -361,6 +361,9 @@ class PostCreator
end
@post.topic_id = @topic.id
@post.topic = @topic
if @topic && @topic.category && @topic.category.all_topics_wiki
@post.wiki = true
end
end
def update_topic_stats

View File

@ -34,6 +34,14 @@ describe PostCreator do
expect(TopicUser.where(user_id: p.user_id, topic_id: p.topic_id).count).to eq(0)
end
it "can be created with first post as wiki" do
cat = Fabricate(:category)
cat.all_topics_wiki = true
cat.save
post = PostCreator.create(user, basic_topic_params.merge(category: cat.id ))
expect(post.wiki).to eq(true)
end
it "ensures the user can create the topic" do
Guardian.any_instance.expects(:can_create?).with(Topic,nil).returns(false)
expect { creator.create }.to raise_error(Discourse::InvalidAccess)