2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-19 11:40:56 +03:00
|
|
|
class CategorySerializer < SiteCategorySerializer
|
2023-03-10 13:45:01 +08:00
|
|
|
class CategorySettingSerializer < ApplicationSerializer
|
|
|
|
attributes :auto_bump_cooldown_days,
|
|
|
|
:num_auto_bump_daily,
|
|
|
|
:require_reply_approval,
|
|
|
|
:require_topic_approval
|
|
|
|
end
|
|
|
|
|
2014-02-12 17:24:25 -05:00
|
|
|
attributes :read_restricted,
|
|
|
|
:available_groups,
|
|
|
|
:auto_close_hours,
|
2014-10-10 18:21:44 +02:00
|
|
|
:auto_close_based_on_last_post,
|
2014-02-12 17:24:25 -05:00
|
|
|
:group_permissions,
|
|
|
|
:position,
|
2014-02-27 13:44:21 +01:00
|
|
|
:email_in,
|
2014-02-27 16:36:33 +01:00
|
|
|
:email_in_allow_strangers,
|
2017-11-15 17:36:52 +01:00
|
|
|
:mailinglist_mirror,
|
2016-12-18 07:38:55 -06:00
|
|
|
:all_topics_wiki,
|
2021-04-14 15:54:09 +10:00
|
|
|
:allow_unlimited_owner_edits_on_first_post,
|
2014-07-10 12:01:46 +10:00
|
|
|
:can_delete,
|
2014-07-16 15:43:44 -04:00
|
|
|
:cannot_delete_reason,
|
2015-09-10 14:04:21 -07:00
|
|
|
:is_special,
|
2015-06-10 06:07:37 +10:00
|
|
|
:allow_badges,
|
2016-05-30 16:37:06 -04:00
|
|
|
:custom_fields,
|
2019-03-18 15:25:45 +08:00
|
|
|
:topic_featured_link_allowed,
|
2019-04-17 17:12:32 -04:00
|
|
|
:search_priority,
|
2024-09-04 04:38:46 +03:00
|
|
|
:moderating_group_ids,
|
2021-06-27 21:46:11 +02:00
|
|
|
:default_slow_mode_seconds
|
2019-04-17 17:12:32 -04:00
|
|
|
|
2023-03-10 13:45:01 +08:00
|
|
|
has_one :category_setting, serializer: CategorySettingSerializer, embed: :objects
|
|
|
|
|
2024-09-04 04:38:46 +03:00
|
|
|
def include_moderating_group_ids?
|
|
|
|
SiteSetting.enable_category_group_moderation?
|
2019-04-17 17:12:32 -04:00
|
|
|
end
|
2013-05-10 16:47:47 +10:00
|
|
|
|
2023-03-10 13:45:01 +08:00
|
|
|
def include_category_setting?
|
|
|
|
object.association(:category_setting).loaded?
|
|
|
|
end
|
|
|
|
|
2013-07-14 11:24:16 +10:00
|
|
|
def group_permissions
|
|
|
|
@group_permissions ||=
|
|
|
|
begin
|
2022-03-31 14:39:01 +08:00
|
|
|
perms =
|
|
|
|
object
|
|
|
|
.category_groups
|
|
|
|
.joins(:group)
|
|
|
|
.includes(:group)
|
2022-04-07 12:21:29 +03:00
|
|
|
.merge(Group.visible_groups(scope&.user, "groups.name ASC", include_everyone: true))
|
2022-04-01 08:58:06 +08:00
|
|
|
.map { |cg| { permission_type: cg.permission_type, group_name: cg.group.name } }
|
2023-01-09 12:20:10 +00:00
|
|
|
|
2013-07-14 11:24:16 +10:00
|
|
|
if perms.length == 0 && !object.read_restricted
|
2022-03-31 14:39:01 +08:00
|
|
|
perms << {
|
|
|
|
permission_type: CategoryGroup.permission_types[:full],
|
|
|
|
group_name: Group[:everyone]&.name.presence || :everyone,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-04-19 11:14:18 +02:00
|
|
|
perms
|
2013-07-14 11:24:16 +10:00
|
|
|
end
|
2013-05-10 16:47:47 +10:00
|
|
|
end
|
|
|
|
|
2022-04-08 11:14:06 +08:00
|
|
|
def include_group_permissions?
|
|
|
|
scope&.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2021-06-02 13:18:45 -04:00
|
|
|
def include_available_groups?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2013-05-10 16:47:47 +10:00
|
|
|
def available_groups
|
2013-07-16 15:44:07 +10:00
|
|
|
Group.order(:name).pluck(:name) - group_permissions.map { |g| g[:group_name] }
|
2013-05-10 16:47:47 +10:00
|
|
|
end
|
2013-02-21 18:09:56 -05:00
|
|
|
|
2014-02-12 17:24:25 -05:00
|
|
|
def can_delete
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2015-09-11 09:14:45 -07:00
|
|
|
def include_is_special?
|
2017-06-06 16:55:20 -04:00
|
|
|
[
|
|
|
|
SiteSetting.meta_category_id,
|
|
|
|
SiteSetting.staff_category_id,
|
|
|
|
SiteSetting.uncategorized_category_id,
|
2015-09-10 14:04:21 -07:00
|
|
|
].include? object.id
|
|
|
|
end
|
|
|
|
|
2015-09-11 09:14:45 -07:00
|
|
|
def is_special
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-02-12 17:24:25 -05:00
|
|
|
def include_can_delete?
|
|
|
|
scope && scope.can_delete?(object)
|
|
|
|
end
|
|
|
|
|
2021-09-22 16:01:25 +03:00
|
|
|
def include_cannot_delete_reason?
|
2014-07-16 15:43:44 -04:00
|
|
|
!include_can_delete? && scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2014-02-27 13:44:21 +01:00
|
|
|
def include_email_in?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2014-02-27 16:36:33 +01:00
|
|
|
def include_email_in_allow_strangers?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2020-06-24 17:07:52 +10:00
|
|
|
def include_notification_level?
|
|
|
|
scope && scope.user
|
|
|
|
end
|
|
|
|
|
2016-02-03 23:58:59 +11:00
|
|
|
def notification_level
|
2016-02-04 00:19:08 +11:00
|
|
|
user = scope && scope.user
|
2020-04-28 12:05:53 -04:00
|
|
|
object.notification_level ||
|
|
|
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level)) ||
|
|
|
|
CategoryUser.default_notification_level
|
2016-02-03 23:58:59 +11:00
|
|
|
end
|
|
|
|
|
2019-03-16 17:18:57 +05:30
|
|
|
def custom_fields
|
|
|
|
object.custom_fields
|
|
|
|
end
|
2019-03-25 07:59:56 +05:30
|
|
|
|
|
|
|
def include_custom_fields?
|
|
|
|
true
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|