2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class REST::GroupSerializer < ActiveModel::Serializer
|
|
|
|
include RoutingHelper
|
|
|
|
|
2020-09-02 00:14:11 +01:00
|
|
|
attributes :id, :title, :description, :description_html, :cover_image_url, :is_archived,
|
2020-09-11 23:27:00 +01:00
|
|
|
:member_count, :created_at, :is_private, :is_visible, :slug, :tags, :group_category, :password,
|
|
|
|
:has_password
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
def id
|
|
|
|
object.id.to_s
|
|
|
|
end
|
|
|
|
|
2020-09-11 23:27:00 +01:00
|
|
|
def has_password
|
|
|
|
return !!password
|
|
|
|
end
|
|
|
|
|
|
|
|
def password
|
2020-09-14 23:18:16 +01:00
|
|
|
if !defined?(current_user) || current_user.nil?
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if object.group_accounts.where(account_id: current_user.account.id, role: :admin).exists?
|
2020-09-11 23:27:00 +01:00
|
|
|
object.password
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-10 23:14:00 +01:00
|
|
|
def group_category
|
|
|
|
if object.group_categories
|
|
|
|
object.group_categories
|
|
|
|
end
|
2020-08-06 06:09:53 +01:00
|
|
|
end
|
|
|
|
|
2020-09-02 00:14:11 +01:00
|
|
|
def description
|
|
|
|
object.description
|
|
|
|
end
|
|
|
|
|
|
|
|
def description_html
|
|
|
|
Formatter.instance.formatGroupDescription(object.description).strip
|
|
|
|
end
|
|
|
|
|
2019-07-15 14:47:05 +01:00
|
|
|
def clean_migrated_url
|
|
|
|
object
|
|
|
|
.cover_image_file_name
|
|
|
|
.sub("gab://groups/", "https://gab.com/media/user/")
|
|
|
|
end
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
def cover_image_url
|
2019-07-15 14:47:05 +01:00
|
|
|
if object.cover_image_file_name and object.cover_image_file_name.start_with? "gab://groups/"
|
|
|
|
return clean_migrated_url
|
|
|
|
end
|
|
|
|
|
2019-07-02 08:10:25 +01:00
|
|
|
full_asset_url(object.cover_image.url)
|
|
|
|
end
|
|
|
|
end
|