2013-05-10 14:47:47 +08:00
|
|
|
class CategorySerializer < BasicCategorySerializer
|
|
|
|
|
2013-12-07 05:39:35 +08:00
|
|
|
attributes :read_restricted, :available_groups, :auto_close_hours, :group_permissions, :position
|
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
|
|
|
|
perms << {permission_type: CategoryGroup.permission_types[:full], group_name: :everyone}
|
|
|
|
end
|
|
|
|
perms
|
|
|
|
end
|
2013-05-10 14:47:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_groups
|
2013-07-16 13:44:07 +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
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|