2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-25 15:26:49 +08:00
|
|
|
class GroupShowSerializer < BasicGroupSerializer
|
2020-05-25 13:38:47 +08:00
|
|
|
attributes :is_group_user, :is_group_owner, :is_group_owner_display, :mentionable, :messageable, :flair_icon, :flair_type
|
2016-11-25 15:26:49 +08:00
|
|
|
|
|
|
|
def include_is_group_user?
|
2017-07-27 16:51:25 +08:00
|
|
|
authenticated?
|
2016-11-25 15:26:49 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_group_user
|
2016-11-29 16:25:02 +08:00
|
|
|
!!fetch_group_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_is_group_owner?
|
2017-07-27 16:51:25 +08:00
|
|
|
authenticated?
|
2016-11-29 16:25:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_group_owner
|
|
|
|
scope.is_admin? || fetch_group_user&.owner
|
|
|
|
end
|
|
|
|
|
2018-06-13 05:57:26 +08:00
|
|
|
def include_is_group_owner_display?
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_group_owner_display
|
|
|
|
!!fetch_group_user&.owner
|
|
|
|
end
|
|
|
|
|
2017-07-27 16:51:25 +08:00
|
|
|
def include_mentionable?
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
2017-10-02 16:50:27 +08:00
|
|
|
def include_messageable?
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
2017-07-27 16:51:25 +08:00
|
|
|
def mentionable
|
|
|
|
Group.mentionable(scope.user).exists?(id: object.id)
|
|
|
|
end
|
|
|
|
|
2017-08-29 00:32:08 +08:00
|
|
|
def messageable
|
|
|
|
Group.messageable(scope.user).exists?(id: object.id)
|
|
|
|
end
|
|
|
|
|
2020-05-25 13:38:47 +08:00
|
|
|
def include_flair_icon?
|
|
|
|
is_group_owner && flair_icon.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_flair_type?
|
|
|
|
is_group_owner && flair_type.present?
|
|
|
|
end
|
|
|
|
|
2016-11-29 16:25:02 +08:00
|
|
|
private
|
|
|
|
|
2017-07-27 16:51:25 +08:00
|
|
|
def authenticated?
|
|
|
|
scope.authenticated?
|
|
|
|
end
|
|
|
|
|
2016-11-29 16:25:02 +08:00
|
|
|
def fetch_group_user
|
|
|
|
@group_user ||= object.group_users.find_by(user: scope.user)
|
2016-11-25 15:26:49 +08:00
|
|
|
end
|
|
|
|
end
|