This commit is contained in:
Emelia Smith 2025-05-06 15:03:45 +00:00 committed by GitHub
commit 6f72407394
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -2,7 +2,7 @@
class InstancePresenter < ActiveModelSerializers::Model
attributes :domain, :title, :version, :source_url,
:description, :languages, :rules, :contact
:description, :languages, :rules, :report_categories, :contact
class ContactPresenter < ActiveModelSerializers::Model
attributes :email, :account
@ -50,6 +50,13 @@ class InstancePresenter < ActiveModelSerializers::Model
Rule.ordered
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
Rails.cache.fetch('user_count') { User.confirmed.joins(:account).merge(Account.without_suspended).count }
end

View File

@ -16,6 +16,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
has_one :contact, serializer: ContactSerializer
has_many :rules, serializer: REST::RuleSerializer
has_many :report_categories, serializer: REST::ReportCategorySerializer
def thumbnail
if object.thumbnail

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class REST::ReportCategorySerializer < ActiveModel::Serializer
attributes :name
def name
object[:name]
end
end