Change /api/v2/instance to be enabled without authentication when limited federation mode is enabled

Additionally, add `configuration.closed_federation` to indicate whether the
server has switched to limited federation.

Also sets `usage.users.active_month` to `0` in limited federation mode.
This commit is contained in:
Claire 2025-04-29 15:59:28 +02:00
parent e7dd0b37c7
commit 290f6d428d
2 changed files with 8 additions and 2 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Api::V2::InstancesController < Api::BaseController class Api::V2::InstancesController < Api::BaseController
skip_before_action :require_authenticated_user!, unless: :limited_federation_mode? skip_before_action :require_authenticated_user!
skip_around_action :set_locale skip_around_action :set_locale
vary_by '' vary_by ''

View File

@ -49,7 +49,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
def usage def usage
{ {
users: { users: {
active_month: object.active_user_count(4), active_month: limited_federation? ? 0 : object.active_user_count(4),
}, },
} }
end end
@ -99,6 +99,8 @@ class REST::InstanceSerializer < ActiveModel::Serializer
translation: { translation: {
enabled: TranslationService.configured?, enabled: TranslationService.configured?,
}, },
closed_federation: limited_federation?,
} }
end end
@ -127,6 +129,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer
markdown.render(Setting.closed_registrations_message) if Setting.closed_registrations_message.present? markdown.render(Setting.closed_registrations_message) if Setting.closed_registrations_message.present?
end end
def limited_federation?
Rails.configuration.x.limited_federation_mode
end
def markdown def markdown
@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_images: true) @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_images: true)
end end