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