mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Merge 2f013abc59
into a50c8e951f
This commit is contained in:
commit
0cc97bc78e
3 changed files with 18 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class InstancePresenter < ActiveModelSerializers::Model
|
class InstancePresenter < ActiveModelSerializers::Model
|
||||||
attributes :domain, :title, :version, :source_url,
|
attributes :domain, :title, :version, :source_url,
|
||||||
:description, :languages, :rules, :contact
|
:description, :languages, :rules, :report_categories, :contact
|
||||||
|
|
||||||
class ContactPresenter < ActiveModelSerializers::Model
|
class ContactPresenter < ActiveModelSerializers::Model
|
||||||
attributes :email, :account
|
attributes :email, :account
|
||||||
|
@ -50,6 +50,13 @@ class InstancePresenter < ActiveModelSerializers::Model
|
||||||
Rule.ordered
|
Rule.ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def report_categories
|
||||||
|
# We only return the `violation` category if we have rules to violate:
|
||||||
|
Report.categories.filter_map do |category, _value|
|
||||||
|
{ name: category } unless category == 'violation' && Rule.count.zero?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def user_count
|
def user_count
|
||||||
Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
|
Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||||
|
|
||||||
has_one :contact, serializer: ContactSerializer
|
has_one :contact, serializer: ContactSerializer
|
||||||
has_many :rules, serializer: REST::RuleSerializer
|
has_many :rules, serializer: REST::RuleSerializer
|
||||||
|
has_many :report_categories, serializer: REST::ReportCategorySerializer
|
||||||
|
|
||||||
def thumbnail
|
def thumbnail
|
||||||
if object.thumbnail
|
if object.thumbnail
|
||||||
|
|
9
app/serializers/rest/report_category_serializer.rb
Normal file
9
app/serializers/rest/report_category_serializer.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class REST::ReportCategorySerializer < ActiveModel::Serializer
|
||||||
|
attributes :name
|
||||||
|
|
||||||
|
def name
|
||||||
|
object[:name]
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue