mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 19:08:10 -05:00
36 lines
1.1 KiB
Ruby
36 lines
1.1 KiB
Ruby
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
|