diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3f134043c..72329052d 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -188,6 +188,9 @@ en: no_info_me: "
the About Me field of your profile is currently blank, would you like to fill it out?
" no_info_other: "
%{name} hasn't entered anything in the About Me field of their profile yet
" + vip_category_name: "Lounge" + vip_category_description: "A category exclusive to members with trust level 3 and higher." + category: topic_prefix: "Category definition for %{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 13beb4f17..b63504949 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -423,5 +423,8 @@ uncategorized: suppress_uncategorized_badge: client: true default: true + lounge_category_id: + default: -1 + hidden: true diff --git a/db/fixtures/500_lounge_category.rb b/db/fixtures/500_lounge_category.rb new file mode 100644 index 000000000..992319faa --- /dev/null +++ b/db/fixtures/500_lounge_category.rb @@ -0,0 +1,35 @@ +lounge = Category.where(id: SiteSetting.lounge_category_id).first +if lounge and !lounge.group_ids.include?(Group[:trust_level_3].id) + + # The category for users with trust level 3 has been created. + # Add permissions and a description to it. + + lounge.group_names = ['trust_level_3'] + unless lounge.save + puts lounge.errors.full_messages + raise "Failed to set permissions on trust level 3 lounge category!" + end + + creator = PostCreator.new(Discourse.system_user, + raw: I18n.t('vip_category_description'), + title: I18n.t('category.topic_prefix', category: lounge.name), + category: lounge.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 trust level 3 lounge!" + end + + lounge.topic_id = post.topic.id + unless lounge.save + puts lounge.errors.full_messages + puts "Failed to set the lounge 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 = #{lounge.id}" +end diff --git a/db/migrate/20140120155706_add_lounge_category.rb b/db/migrate/20140120155706_add_lounge_category.rb new file mode 100644 index 000000000..039d1d79f --- /dev/null +++ b/db/migrate/20140120155706_add_lounge_category.rb @@ -0,0 +1,29 @@ +class AddLoungeCategory < ActiveRecord::Migration + def up + result = Category.exec_sql "SELECT 1 FROM site_settings where name = 'lounge_category_id'" + if result.count == 0 + description = I18n.t('vip_category_description') + + default_name = I18n.t('vip_category_name') + name = if Category.exec_sql("SELECT 1 FROM categories where name = '#{default_name}'").count == 0 + default_name + else + "CHANGE_ME" + end + + result = execute "INSERT INTO categories + (name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted) + VALUES ('#{name}', 'EEEEEE', '652D90', 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 ('lounge_category_id', 3, #{category_id}, now(), now())" + end + end + + def down + # Don't reverse this change. There is so much logic around deleting a category that it's messy + # to try to do in sql. The up method will just make sure never to create the category twice. + end +end