2013-05-10 14:47:47 +08:00
|
|
|
class CategorySerializer < BasicCategorySerializer
|
|
|
|
|
2014-02-13 06:24:25 +08:00
|
|
|
attributes :read_restricted,
|
|
|
|
:available_groups,
|
|
|
|
:auto_close_hours,
|
2014-10-11 00:21:44 +08:00
|
|
|
:auto_close_based_on_last_post,
|
2014-02-13 06:24:25 +08:00
|
|
|
:group_permissions,
|
|
|
|
:position,
|
2014-02-27 20:44:21 +08:00
|
|
|
:email_in,
|
2014-02-27 23:36:33 +08:00
|
|
|
:email_in_allow_strangers,
|
2015-09-03 02:25:18 +08:00
|
|
|
:suppress_from_homepage,
|
2016-12-18 21:38:55 +08:00
|
|
|
:all_topics_wiki,
|
2014-07-10 10:01:46 +08:00
|
|
|
:can_delete,
|
2014-07-17 03:43:44 +08:00
|
|
|
:cannot_delete_reason,
|
2015-09-11 05:04:21 +08:00
|
|
|
:is_special,
|
2015-06-10 04:07:37 +08:00
|
|
|
:allow_badges,
|
2016-05-31 04:37:06 +08:00
|
|
|
:custom_fields,
|
2016-06-08 01:08:59 +08:00
|
|
|
:allowed_tags,
|
2016-12-16 06:46:43 +08:00
|
|
|
:allowed_tag_groups,
|
|
|
|
:topic_featured_link_allowed
|
2013-05-10 14:47:47 +08:00
|
|
|
|
2013-07-14 09:24:16 +08:00
|
|
|
def group_permissions
|
|
|
|
@group_permissions ||= begin
|
2013-07-16 13:44:07 +08:00
|
|
|
perms = object.category_groups.joins(:group).includes(:group).order("groups.name").map do |cg|
|
2013-07-14 09:24:16 +08:00
|
|
|
{
|
|
|
|
permission_type: cg.permission_type,
|
|
|
|
group_name: cg.group.name
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if perms.length == 0 && !object.read_restricted
|
2014-10-11 00:21:44 +08:00
|
|
|
perms << { permission_type: CategoryGroup.permission_types[:full], group_name: :everyone }
|
2013-07-14 09:24:16 +08:00
|
|
|
end
|
|
|
|
perms
|
|
|
|
end
|
2013-05-10 14:47:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_groups
|
2017-07-28 09:20:09 +08:00
|
|
|
Group.order(:name).pluck(:name) - group_permissions.map { |g| g[:group_name] }
|
2013-05-10 14:47:47 +08:00
|
|
|
end
|
2013-02-22 07:09:56 +08:00
|
|
|
|
2014-02-13 06:24:25 +08:00
|
|
|
def can_delete
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2015-09-12 00:14:45 +08:00
|
|
|
def include_is_special?
|
2017-06-07 04:55:20 +08:00
|
|
|
[SiteSetting.meta_category_id, SiteSetting.staff_category_id, SiteSetting.uncategorized_category_id]
|
2017-07-28 09:20:09 +08:00
|
|
|
.include? object.id
|
2015-09-11 05:04:21 +08:00
|
|
|
end
|
|
|
|
|
2015-09-12 00:14:45 +08:00
|
|
|
def is_special
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-02-13 06:24:25 +08:00
|
|
|
def include_can_delete?
|
|
|
|
scope && scope.can_delete?(object)
|
|
|
|
end
|
|
|
|
|
2014-07-17 03:43:44 +08: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 20:44:21 +08:00
|
|
|
def include_email_in?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2014-02-27 23:36:33 +08:00
|
|
|
def include_email_in_allow_strangers?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2015-09-03 02:25:18 +08:00
|
|
|
def include_suppress_from_homepage?
|
|
|
|
scope && scope.can_edit?(object)
|
|
|
|
end
|
|
|
|
|
2016-02-03 20:58:59 +08:00
|
|
|
def notification_level
|
2017-07-28 09:20:09 +08:00
|
|
|
user = scope && scope.user
|
2016-02-03 20:58:59 +08:00
|
|
|
object.notification_level ||
|
|
|
|
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
|
|
|
|
end
|
|
|
|
|
2016-05-31 04:37:06 +08:00
|
|
|
def include_allowed_tags?
|
|
|
|
SiteSetting.tagging_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_tags
|
2016-07-16 02:08:31 +08:00
|
|
|
object.tags.pluck(:name)
|
2016-05-31 04:37:06 +08:00
|
|
|
end
|
|
|
|
|
2016-06-08 01:08:59 +08:00
|
|
|
def include_allowed_tag_groups?
|
|
|
|
SiteSetting.tagging_enabled
|
|
|
|
end
|
|
|
|
|
|
|
|
def allowed_tag_groups
|
|
|
|
object.tag_groups.pluck(:name)
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|