mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-12 03:22:02 +08:00
This feature allow admins to personalize their communities by associating emojis or icons with their site categories. There are now 3 style types for categories: - Square (the default) - Emoji - Icon ### How it looks 🎨 Adding an icon: <img width="502" alt="Category with an icon" src="https://github.com/user-attachments/assets/8f711340-166e-4781-a7b7-7267469dbabd" /> Adding an emoji: <img width="651" alt="Category with an emoji" src="https://github.com/user-attachments/assets/588c38ce-c719-4ed5-83f9-f1e1cb52c929" /> Sidebar: <img width="248" alt="Sidebar with emojis" src="https://github.com/user-attachments/assets/cd03d591-6170-4515-998c-0cec20118568" /> Category menus: <img width="621" alt="Screenshot 2025-03-13 at 10 32 30 AM" src="https://github.com/user-attachments/assets/7d89797a-f69f-45e5-bf64-a92d4cff8753" /> Within posts/topics: <img width="382" alt="Screenshot 2025-03-13 at 10 33 41 AM" src="https://github.com/user-attachments/assets/b7b1a951-44c6-4a4f-82ad-8ee31ddd6061" /> Chat messages: <img width="392" alt="Screenshot 2025-03-13 at 10 30 20 AM" src="https://github.com/user-attachments/assets/126f8076-0ea3-4f19-8452-1041fd2af29f" /> Autocomplete: <img width="390" alt="Screenshot 2025-03-13 at 10 29 53 AM" src="https://github.com/user-attachments/assets/cad75669-225f-4b8e-a7b5-ae5aa8f1bcad" /> --------- Co-authored-by: Martin Brennan <martin@discourse.org> Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
129 lines
3.1 KiB
Ruby
129 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class CategorySerializer < SiteCategorySerializer
|
|
class CategorySettingSerializer < ApplicationSerializer
|
|
attributes :auto_bump_cooldown_days,
|
|
:num_auto_bump_daily,
|
|
:require_reply_approval,
|
|
:require_topic_approval
|
|
end
|
|
|
|
attributes :read_restricted,
|
|
:available_groups,
|
|
:auto_close_hours,
|
|
:auto_close_based_on_last_post,
|
|
:group_permissions,
|
|
:position,
|
|
:email_in,
|
|
:email_in_allow_strangers,
|
|
:mailinglist_mirror,
|
|
:all_topics_wiki,
|
|
:allow_unlimited_owner_edits_on_first_post,
|
|
:can_delete,
|
|
:cannot_delete_reason,
|
|
:is_special,
|
|
:allow_badges,
|
|
:custom_fields,
|
|
:topic_featured_link_allowed,
|
|
:search_priority,
|
|
:moderating_group_ids,
|
|
:default_slow_mode_seconds,
|
|
:style_type,
|
|
:emoji,
|
|
:icon
|
|
|
|
has_one :category_setting, serializer: CategorySettingSerializer, embed: :objects
|
|
|
|
def include_moderating_group_ids?
|
|
SiteSetting.enable_category_group_moderation?
|
|
end
|
|
|
|
def include_category_setting?
|
|
object.association(:category_setting).loaded?
|
|
end
|
|
|
|
def group_permissions
|
|
@group_permissions ||=
|
|
begin
|
|
perms =
|
|
object
|
|
.category_groups
|
|
.joins(:group)
|
|
.includes(:group)
|
|
.merge(Group.visible_groups(scope&.user, "groups.name ASC", include_everyone: true))
|
|
.map { |cg| { permission_type: cg.permission_type, group_name: cg.group.name } }
|
|
|
|
if perms.length == 0 && !object.read_restricted
|
|
perms << {
|
|
permission_type: CategoryGroup.permission_types[:full],
|
|
group_name: Group[:everyone]&.name.presence || :everyone,
|
|
}
|
|
end
|
|
|
|
perms
|
|
end
|
|
end
|
|
|
|
def include_group_permissions?
|
|
scope&.can_edit?(object)
|
|
end
|
|
|
|
def include_available_groups?
|
|
scope && scope.can_edit?(object)
|
|
end
|
|
|
|
def available_groups
|
|
Group.order(:name).pluck(:name) - group_permissions.map { |g| g[:group_name] }
|
|
end
|
|
|
|
def can_delete
|
|
true
|
|
end
|
|
|
|
def include_is_special?
|
|
[
|
|
SiteSetting.meta_category_id,
|
|
SiteSetting.staff_category_id,
|
|
SiteSetting.uncategorized_category_id,
|
|
].include? object.id
|
|
end
|
|
|
|
def is_special
|
|
true
|
|
end
|
|
|
|
def include_can_delete?
|
|
scope && scope.can_delete?(object)
|
|
end
|
|
|
|
def include_cannot_delete_reason?
|
|
!include_can_delete? && scope && scope.can_edit?(object)
|
|
end
|
|
|
|
def include_email_in?
|
|
scope && scope.can_edit?(object)
|
|
end
|
|
|
|
def include_email_in_allow_strangers?
|
|
scope && scope.can_edit?(object)
|
|
end
|
|
|
|
def include_notification_level?
|
|
scope && scope.user
|
|
end
|
|
|
|
def notification_level
|
|
user = scope && scope.user
|
|
object.notification_level ||
|
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level)) ||
|
|
CategoryUser.default_notification_level
|
|
end
|
|
|
|
def custom_fields
|
|
object.custom_fields
|
|
end
|
|
|
|
def include_custom_fields?
|
|
true
|
|
end
|
|
end
|