about summary refs log tree commit diff
path: root/app/presenters/instance_presenter.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-10-05 03:47:56 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-10-09 19:51:39 +0200
commitbf3cb42da78a3f31a9e07167a764aa942ec73731 (patch)
tree5035a63d70172b51a8f70a7debb0f42107e63da4 /app/presenters/instance_presenter.rb
parentc9fadb3caede626a371cc481cbe1f2dba0bec0c4 (diff)
Add server banner to web app, add `GET /api/v2/instance` to REST API (#19294)
Cherry-picked d2528b26b6da34f34b5d7a392e263428d3c09d69

Conflicts:
- `app/serializers/initial_state_serializer.rb`:
  Upstream changed stuff, we had extra attributes.
  Applied upstream changes while keeping our extra attributes.
- `app/serializers/rest/instance_serializer.rb`:
  Upstream actually moved that to `app/serializers/rest/v1/instance_serializer.rb`,
  so updated that file by keeping our extra attributes, and took upstream's
  version of `app/serializers/rest/instance_serializer.rb`.
- `spec/views/about/show.html.haml_spec.rb`:
  Took upstream's version.
Diffstat (limited to 'app/presenters/instance_presenter.rb')
-rw-r--r--app/presenters/instance_presenter.rb64
1 files changed, 48 insertions, 16 deletions
diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb
index 3e85faa92..c461ac55f 100644
--- a/app/presenters/instance_presenter.rb
+++ b/app/presenters/instance_presenter.rb
@@ -1,19 +1,51 @@
 # frozen_string_literal: true
 
-class InstancePresenter
-  delegate(
-    :site_contact_email,
-    :site_title,
-    :site_short_description,
-    :site_description,
-    :site_extended_description,
-    :site_terms,
-    :closed_registrations_message,
-    to: Setting
-  )
-
-  def contact_account
-    Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
+class InstancePresenter < ActiveModelSerializers::Model
+  attributes :domain, :title, :version, :source_url,
+             :description, :languages, :rules, :contact
+
+  class ContactPresenter < ActiveModelSerializers::Model
+    attributes :email, :account
+
+    def email
+      Setting.site_contact_email
+    end
+
+    def account
+      Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, ''))
+    end
+  end
+
+  def contact
+    ContactPresenter.new
+  end
+
+  def closed_registrations_message
+    Setting.closed_registrations_message
+  end
+
+  def description
+    Setting.site_short_description
+  end
+
+  def extended_description
+    Setting.site_extended_description
+  end
+
+  def privacy_policy
+    Setting.site_terms
+  end
+
+  def domain
+    Rails.configuration.x.local_domain
+  end
+
+  def title
+    Setting.site_title
+  end
+
+  def languages
+    [I18n.default_locale]
   end
 
   def rules
@@ -40,8 +72,8 @@ class InstancePresenter
     Rails.cache.fetch('sample_accounts', expires_in: 12.hours) { Account.local.discoverable.popular.limit(3) }
   end
 
-  def version_number
-    Mastodon::Version
+  def version
+    Mastodon::Version.to_s
   end
 
   def source_url