discourse/app/serializers/category_serializer.rb
Robin Ward f73a3f252a FIX: Don't allow parent categories to be deleted. Also, remove
duplicated logic and rely on the server response for `can_delete`
status.
2014-02-12 17:24:25 -05:00

39 lines
909 B
Ruby

class CategorySerializer < BasicCategorySerializer
attributes :read_restricted,
:available_groups,
:auto_close_hours,
:group_permissions,
:position,
:can_delete
def group_permissions
@group_permissions ||= begin
perms = object.category_groups.joins(:group).includes(:group).order("groups.name").map do |cg|
{
permission_type: cg.permission_type,
group_name: cg.group.name
}
end
if perms.length == 0 && !object.read_restricted
perms << {permission_type: CategoryGroup.permission_types[:full], group_name: :everyone}
end
perms
end
end
def available_groups
Group.order(:name).pluck(:name) - group_permissions.map{|g| g[:group_name]}
end
def can_delete
true
end
def include_can_delete?
scope && scope.can_delete?(object)
end
end