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,
|
2014-07-09 22:01:46 -04:00
|
|
|
:can_delete,
|
2014-07-16 15:43:44 -04:00
|
|
|
:cannot_delete_reason,
|
2014-07-09 22:01:46 -04:00
|
|
|
:allow_badges
|
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
|
2014-10-10 12:21:44 -04:00
|
|
|
perms << { permission_type: CategoryGroup.permission_types[:full], group_name: :everyone }
|
2013-07-13 21:24:16 -04:00
|
|
|
end
|
|
|
|
perms
|
|
|
|
end
|
2013-05-10 02:47:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_groups
|
2013-07-16 01:44:07 -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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|