2014-01-20 15:49:43 -05:00
|
|
|
unless Rails.env.test?
|
2014-05-06 09:41:59 -04:00
|
|
|
lounge = Category.find_by(id: SiteSetting.lounge_category_id)
|
2017-06-06 16:55:20 -04:00
|
|
|
if lounge && lounge.created_at == lounge.updated_at &&
|
|
|
|
!lounge.group_ids.include?(Group[:trust_level_3].id)
|
2014-01-20 15:49:43 -05:00
|
|
|
|
|
|
|
# The category for users with trust level 3 has been created.
|
2017-06-06 16:55:20 -04:00
|
|
|
# Add initial permissions and description. They can be changed later.
|
2014-01-20 15:49:43 -05:00
|
|
|
|
2014-03-19 11:59:53 -04:00
|
|
|
Category.transaction do
|
|
|
|
lounge.group_names = ['trust_level_3']
|
2014-03-14 10:26:17 -04:00
|
|
|
unless lounge.save
|
|
|
|
puts lounge.errors.full_messages
|
2014-03-19 11:59:53 -04:00
|
|
|
raise "Failed to set permissions on trust level 3 lounge category!"
|
2014-03-14 10:26:17 -04:00
|
|
|
end
|
2014-01-20 15:49:43 -05:00
|
|
|
|
2014-03-19 11:59:53 -04:00
|
|
|
if lounge.topic_id.nil?
|
|
|
|
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,
|
|
|
|
skip_validations: true
|
|
|
|
)
|
|
|
|
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
|
2018-06-19 02:13:14 -04:00
|
|
|
DB.exec "UPDATE categories SET topic_count = 0 WHERE id = #{lounge.id}"
|
2014-03-19 11:59:53 -04:00
|
|
|
end
|
2014-03-14 10:26:17 -04:00
|
|
|
end
|
2014-01-20 15:49:43 -05:00
|
|
|
end
|
|
|
|
end
|