2016-11-25 01:26:49 -06:00
|
|
|
class GroupShowSerializer < BasicGroupSerializer
|
2017-10-02 03:50:27 -05:00
|
|
|
attributes :is_group_user, :is_group_owner, :mentionable, :messageable
|
2016-11-25 01:26:49 -06:00
|
|
|
|
|
|
|
def include_is_group_user?
|
2017-07-27 03:51:25 -05:00
|
|
|
authenticated?
|
2016-11-25 01:26:49 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_group_user
|
2016-11-29 02:25:02 -06:00
|
|
|
!!fetch_group_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_is_group_owner?
|
2017-07-27 03:51:25 -05:00
|
|
|
authenticated?
|
2016-11-29 02:25:02 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_group_owner
|
|
|
|
scope.is_admin? || fetch_group_user&.owner
|
|
|
|
end
|
|
|
|
|
2017-07-27 03:51:25 -05:00
|
|
|
def include_mentionable?
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
2017-10-02 03:50:27 -05:00
|
|
|
def include_messageable?
|
|
|
|
authenticated?
|
|
|
|
end
|
|
|
|
|
2017-07-27 03:51:25 -05:00
|
|
|
def mentionable
|
|
|
|
Group.mentionable(scope.user).exists?(id: object.id)
|
|
|
|
end
|
|
|
|
|
2017-08-28 11:32:08 -05:00
|
|
|
def messageable
|
|
|
|
Group.messageable(scope.user).exists?(id: object.id)
|
|
|
|
end
|
|
|
|
|
2016-11-29 02:25:02 -06:00
|
|
|
private
|
|
|
|
|
2017-07-27 03:51:25 -05:00
|
|
|
def authenticated?
|
|
|
|
scope.authenticated?
|
|
|
|
end
|
|
|
|
|
2016-11-29 02:25:02 -06:00
|
|
|
def fetch_group_user
|
|
|
|
@group_user ||= object.group_users.find_by(user: scope.user)
|
2016-11-25 01:26:49 -06:00
|
|
|
end
|
|
|
|
end
|