2013-05-10 02:47:47 -04:00
|
|
|
class CategorySerializer < BasicCategorySerializer
|
|
|
|
|
2014-02-12 17:24:25 -05:00
|
|
|
attributes :read_restricted,
|
|
|
|
:available_groups,
|
|
|
|
:auto_close_hours,
|
2014-10-10 12:21:44 -04:00
|
|
|
:auto_close_based_on_last_post,
|
2014-02-12 17:24:25 -05:00
|
|
|
:group_permissions,
|
|
|
|
:position,
|
2014-02-27 07:44:21 -05:00
|
|
|
:email_in,
|
2014-02-27 10:36:33 -05:00
|
|
|
:email_in_allow_strangers,
|
2017-11-15 11:36:52 -05:00
|
|
|
:mailinglist_mirror,
|
2018-02-21 17:56:18 -05:00
|
|
|
:suppress_from_latest,
|
2016-12-18 08:38:55 -05:00
|
|
|
:all_topics_wiki,
|
2014-07-09 22:01:46 -04:00
|
|
|
:can_delete,
|
2014-07-16 15:43:44 -04:00
|
|
|
:cannot_delete_reason,
|
2015-09-10 17:04:21 -04:00
|
|
|
:is_special,
|
2015-06-09 16:07:37 -04:00
|
|
|
:allow_badges,
|
2016-05-30 16:37:06 -04:00
|
|
|
:custom_fields,
|
2016-06-07 13:08:59 -04:00
|
|
|
:allowed_tags,
|
2016-12-15 17:46:43 -05:00
|
|
|
:allowed_tag_groups,
|
2019-04-04 16:35:31 -04:00
|
|
|
:allow_global_tags,
|
2019-03-18 03:25:45 -04:00
|
|
|
:topic_featured_link_allowed,
|
2019-04-17 17:12:32 -04:00
|
|
|
:search_priority,
|
|
|
|
:reviewable_by_group_name
|
|
|
|
|
|
|
|
def reviewable_by_group_name
|
|
|
|
object.reviewable_by_group.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_reviewable_by_group_name?
|
|
|
|
SiteSetting.enable_category_group_review? && object.reviewable_by_group_id.present?
|
|
|
|
end
|
2013-05-10 02:47:47 -04:00
|
|
|
|
2013-07-13 21:24:16 -04:00
|
|
|
def group_permissions
|
|
|
|
@group_permissions ||= begin
|
2013-07-16 01:44:07 -04:00
|
|
|
perms = object.category_groups.joins(:group).includes(:group).order("groups.name").map do |cg|
|
2013-07-13 21:24:16 -04:00
|
|
|
{
|
|
|
|
permission_type: cg.permission_type,
|
|
|
|
group_name: cg.group.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if perms.length == 0 && !object.read_restricted
|
2018-04-19 05:14:18 -04:00
|
|
|
perms << { permission_type: CategoryGroup.permission_types[:full], group_name: Group[:everyone]&.name.presence || :everyone }
|
2013-07-13 21:24:16 -04:00
|
|
|
end
|
|
|
|
perms
|
|
|
|
end
|
2013-05-10 02:47:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_groups
|
2017-07-27 21:20:09 -04:00
|
|
|
Group.order(:name).pluck(:name) - group_permissions.map { |g| g[:group_name] }
|
2013-05-10 02:47:47 -04: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 12:14:45 -04: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]
|
2017-07-27 21:20:09 -04:00
|
|
|
.include? object.id
|
2015-09-10 17:04:21 -04:00
|
|
|
end
|
|
|
|
|
2015-09-11 12:14:45 -04:00
|
|
|
def is_special
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-02-12 17:24:25 -05:00
|
|
|
def include_can_delete?
|
|
|
|
scope && scope.can_delete?(object)
|
|
|
|
end
|
|
|
|
|
2014-07-16 15:43:44 -04:00
|
|
|
def cannot_delete_reason
|
|
|
|
scope && scope.cannot_delete_category_reason(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_cannot_delete_reason
|
|
|
|
!include_can_delete? && scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2014-02-27 07:44:21 -05:00
|
|
|
def include_email_in?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2014-02-27 10:36:33 -05:00
|
|
|
def include_email_in_allow_strangers?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2018-02-21 17:56:18 -05:00
|
|
|
def include_suppress_from_latest?
|
2015-09-02 14:25:18 -04:00
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2016-02-03 07:58:59 -05:00
|
|
|
def notification_level
|
2017-07-27 21:20:09 -04:00
|
|
|
user = scope && scope.user
|
2016-02-03 07:58:59 -05:00
|
|
|
object.notification_level ||
|
|
|
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
|
|
|
|
end
|
|
|
|
|
2016-05-30 16:37:06 -04:00
|
|
|
def include_allowed_tags?
|
|
|
|
SiteSetting.tagging_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_tags
|
2016-07-15 14:08:31 -04:00
|
|
|
object.tags.pluck(:name)
|
2016-05-30 16:37:06 -04:00
|
|
|
end
|
|
|
|
|
2016-06-07 13:08:59 -04:00
|
|
|
def include_allowed_tag_groups?
|
|
|
|
SiteSetting.tagging_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_tag_groups
|
|
|
|
object.tag_groups.pluck(:name)
|
|
|
|
end
|
2019-03-16 07:48:57 -04:00
|
|
|
|
|
|
|
def custom_fields
|
|
|
|
object.custom_fields
|
|
|
|
end
|
2019-03-24 22:29:56 -04:00
|
|
|
|
|
|
|
def include_custom_fields?
|
|
|
|
true
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|