From ec7ef2140394487f50e201a93436a5eb7f830228 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 27 Feb 2014 17:38:01 -0500 Subject: [PATCH] Add a Staff category. Have a topic for assets in the Staff category. Move admin quick start guide to Staff category. Quick start guide is not invisible anymore. --- config/locales/server.en.yml | 5 +++ config/site_settings.yml | 3 ++ db/fixtures/502_staff_category.rb | 36 +++++++++++++++++++ db/fixtures/999_topics.rb | 5 +-- .../20140227201005_add_staff_category.rb | 25 +++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 db/fixtures/502_staff_category.rb create mode 100644 db/migrate/20140227201005_add_staff_category.rb diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 84e9d9cd1d..fe50842f55 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -200,6 +200,11 @@ en: meta_category_name: "Meta" meta_category_description: "Discussion about this forum, its organization, how it works, and how we can improve it." + staff_category_name: "Staff" + staff_category_description: "Private category for staff discussions. Topics are only visible to admins and moderators." + + assets_topic_body: "This is a topic to store forum assets used in the forum design. Don't delete it!" + category: topic_prefix: "About the %{category} category" replace_paragraph: "[Replace this first paragraph with a short description of your new category. This guidance will appear in the category selection area, so try to keep it below 200 characters. Until you edit this text or create topics, this category won't appear on the categories page.]" diff --git a/config/site_settings.yml b/config/site_settings.yml index e33b80574c..ef00962fb4 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -448,5 +448,8 @@ uncategorized: meta_category_id: default: -1 hidden: true + staff_category_id: + default: -1 + hidden: true min_posts_for_search_in_topic: 10 diff --git a/db/fixtures/502_staff_category.rb b/db/fixtures/502_staff_category.rb new file mode 100644 index 0000000000..a977726f95 --- /dev/null +++ b/db/fixtures/502_staff_category.rb @@ -0,0 +1,36 @@ +unless Rails.env.test? + staff = Category.where(id: SiteSetting.staff_category_id).first + if staff and !staff.group_ids.include?(Group[:staff].id) + + # Add permissions and a description to the Staff category. + + staff.group_names = ['staff'] + unless staff.save + puts staff.errors.full_messages + raise "Failed to set permissions on the Staff category!" + end + + creator = PostCreator.new(Discourse.system_user, + raw: I18n.t('staff_category_description'), + title: I18n.t('category.topic_prefix', category: staff.name), + category: staff.name, + archetype: Archetype.default + ) + post = creator.create + + unless post && post.id + puts post.errors.full_messages if post + puts creator.errors.inspect + raise "Failed to create description for Staff category!" + end + + staff.topic_id = post.topic.id + unless staff.save + puts staff.errors.full_messages + puts "Failed to set the Staff category description topic!" + end + + # Reset topic count because we don't count the description topic + Category.exec_sql "UPDATE categories SET topic_count = 0 WHERE id = #{staff.id}" + end +end diff --git a/db/fixtures/999_topics.rb b/db/fixtures/999_topics.rb index 62ea8d09ac..e93c408d53 100644 --- a/db/fixtures/999_topics.rb +++ b/db/fixtures/999_topics.rb @@ -5,9 +5,10 @@ Post.reset_column_information if Topic.where('id NOT IN (SELECT topic_id from categories where topic_id is not null)').count == 0 && !Rails.env.test? puts "Seeding welcome topics" + staff = Category.where(id: SiteSetting.staff_category_id).first welcome = File.read(Rails.root + 'docs/ADMIN-QUICK-START-GUIDE.md') - post = PostCreator.create(Discourse.system_user, raw: welcome, title: "Discourse Admin Quick Start Guide", skip_validations: true) - post.topic.update_column('visible', false) + PostCreator.create(Discourse.system_user, raw: welcome, title: "Discourse Admin Quick Start Guide", skip_validations: true, category: staff ? staff.name : nil) + PostCreator.create(Discourse.system_user, raw: I18n.t('assets_topic_body'), title: "Assets for the forum design", skip_validations: true, category: staff ? staff.name : nil) welcome = File.read(Rails.root + 'docs/WELCOME-TO-DISCOURSE.md') post = PostCreator.create(Discourse.system_user, raw: welcome, title: "Welcome to Discourse", skip_validations: true) diff --git a/db/migrate/20140227201005_add_staff_category.rb b/db/migrate/20140227201005_add_staff_category.rb new file mode 100644 index 0000000000..8494a0f2d5 --- /dev/null +++ b/db/migrate/20140227201005_add_staff_category.rb @@ -0,0 +1,25 @@ +class AddStaffCategory < ActiveRecord::Migration + def up + unless Rails.env.test? + result = Category.exec_sql "SELECT 1 FROM site_settings where name = 'staff_category_id'" + if result.count == 0 + description = I18n.t('staff_category_description') + name = I18n.t('staff_category_name') + if Category.exec_sql("SELECT 1 FROM categories where name ilike '#{name}'").count == 0 + result = execute "INSERT INTO categories + (name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted) + VALUES ('#{name}', '283890', 'FFFFFF', now(), now(), -1, '#{Slug.for(name)}', '#{description}', true) + RETURNING id" + category_id = result[0]["id"].to_i + + execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at) + VALUES ('staff_category_id', 3, #{category_id}, now(), now())" + end + end + end + end + + def down + # Do nothing + end +end