From d2528b26b6da34f34b5d7a392e263428d3c09d69 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 5 Oct 2022 03:47:56 +0200 Subject: Add server banner to web app, add `GET /api/v2/instance` to REST API (#19294) --- spec/views/about/show.html.haml_spec.rb | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'spec/views') diff --git a/spec/views/about/show.html.haml_spec.rb b/spec/views/about/show.html.haml_spec.rb index 4eab97da9..bf6e19d2b 100644 --- a/spec/views/about/show.html.haml_spec.rb +++ b/spec/views/about/show.html.haml_spec.rb @@ -12,25 +12,7 @@ describe 'about/show.html.haml', without_verify_partial_doubles: true do end it 'has valid open graph tags' do - instance_presenter = double( - :instance_presenter, - site_title: 'something', - site_short_description: 'something', - site_description: 'something', - version_number: '1.0', - source_url: 'https://github.com/mastodon/mastodon', - open_registrations: false, - thumbnail: nil, - hero: nil, - mascot: nil, - user_count: 420, - status_count: 69, - active_user_count: 420, - contact_account: nil, - sample_accounts: [] - ) - - assign(:instance_presenter, instance_presenter) + assign(:instance_presenter, InstancePresenter.new) render header_tags = view.content_for(:header_tags) -- cgit From 58d5b28cb00ffadfeb7a3e1e03f7ae0d3b0d8486 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 6 Oct 2022 02:19:45 +0200 Subject: Remove previous landing page (#19300) --- app/controllers/about_controller.rb | 5 +-- app/views/about/_logged_in.html.haml | 10 ----- app/views/about/_login.html.haml | 22 ---------- app/views/about/_registration.html.haml | 37 ----------------- app/views/about/show.html.haml | 69 ------------------------------- config/locales/en.yml | 14 ------- config/routes.rb | 2 +- spec/controllers/about_controller_spec.rb | 22 ---------- spec/requests/localization_spec.rb | 12 +++--- spec/views/about/show.html.haml_spec.rb | 25 ----------- 10 files changed, 8 insertions(+), 210 deletions(-) delete mode 100644 app/views/about/_logged_in.html.haml delete mode 100644 app/views/about/_login.html.haml delete mode 100644 app/views/about/_registration.html.haml delete mode 100644 app/views/about/show.html.haml delete mode 100644 spec/views/about/show.html.haml_spec.rb (limited to 'spec/views') diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index 8da4a19ab..eae7de8c8 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -5,16 +5,13 @@ class AboutController < ApplicationController layout 'public' - before_action :require_open_federation!, only: [:show, :more] + before_action :require_open_federation!, only: [:more] before_action :set_body_classes, only: :show before_action :set_instance_presenter before_action :set_expires_in, only: [:more] - before_action :set_registration_form_time, only: :show skip_before_action :require_functional!, only: [:more] - def show; end - def more flash.now[:notice] = I18n.t('about.instance_actor_flash') if params[:instance_actor] diff --git a/app/views/about/_logged_in.html.haml b/app/views/about/_logged_in.html.haml deleted file mode 100644 index e1bcfffb3..000000000 --- a/app/views/about/_logged_in.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -.simple_form - %p.lead= t('about.logged_in_as_html', username: content_tag(:strong, current_account.username)) - - .actions - = link_to t('about.continue_to_web'), root_url, class: 'button button-primary' - -.form-footer - %ul.no-list - %li= link_to t('about.get_apps'), 'https://joinmastodon.org/apps', target: '_blank', rel: 'noopener noreferrer' - %li= link_to t('auth.logout'), destroy_user_session_path, data: { method: :delete } diff --git a/app/views/about/_login.html.haml b/app/views/about/_login.html.haml deleted file mode 100644 index 0f19e8164..000000000 --- a/app/views/about/_login.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -- unless omniauth_only? - = simple_form_for(new_user, url: user_session_path, namespace: 'login') do |f| - .fields-group - - if use_seamless_external_login? - = f.input :email, placeholder: t('simple_form.labels.defaults.username_or_email'), input_html: { 'aria-label' => t('simple_form.labels.defaults.username_or_email') }, hint: false - - else - = f.input :email, placeholder: t('simple_form.labels.defaults.email'), input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }, hint: false - - = f.input :password, placeholder: t('simple_form.labels.defaults.password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.password') }, hint: false - - .actions - = f.button :button, t('auth.login'), type: :submit, class: 'button button-primary' - - %p.hint.subtle-hint= link_to t('auth.trouble_logging_in'), new_user_password_path - -- if Devise.mappings[:user].omniauthable? and User.omniauth_providers.any? - .simple_form.alternative-login - %h4= omniauth_only? ? t('auth.log_in_with') : t('auth.or_log_in_with') - - .actions - - User.omniauth_providers.each do |provider| - = provider_sign_in_link(provider) diff --git a/app/views/about/_registration.html.haml b/app/views/about/_registration.html.haml deleted file mode 100644 index 5db620b2d..000000000 --- a/app/views/about/_registration.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -- disabled = closed_registrations? || omniauth_only? || current_account.present? -- show_message = disabled && (current_user.present? || @instance_presenter.closed_registrations_message.present?) - -.simple_form__overlay-area{ class: show_message ? 'simple_form__overlay-area__blurred' : '' } - = simple_form_for(new_user, url: user_registration_path, namespace: 'registration', html: { novalidate: false }) do |f| - %p.lead= t('about.federation_hint_html', instance: content_tag(:strong, site_hostname)) - - .fields-group - = f.simple_fields_for :account do |account_fields| - = account_fields.input :username, wrapper: :with_label, label: false, required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username'), :autocomplete => 'off', placeholder: t('simple_form.labels.defaults.username'), pattern: '[a-zA-Z0-9_]+', maxlength: 30 }, append: "@#{site_hostname}", hint: false, disabled: disabled - - = f.input :email, placeholder: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email'), :autocomplete => 'off' }, hint: false, disabled: disabled - = f.input :password, placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password'), :autocomplete => 'new-password', :minlength => User.password_length.first, :maxlength => User.password_length.last }, hint: false, disabled: disabled - = f.input :password_confirmation, placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password'), :autocomplete => 'new-password' }, hint: false, disabled: disabled - - = f.input :confirm_password, as: :string, placeholder: t('simple_form.labels.defaults.honeypot', label: t('simple_form.labels.defaults.password')), required: false, input_html: { 'aria-label' => t('simple_form.labels.defaults.honeypot', label: t('simple_form.labels.defaults.password')), :autocomplete => 'off' }, hint: false, disabled: disabled - = f.input :website, as: :url, placeholder: t('simple_form.labels.defaults.honeypot', label: 'Website'), required: false, input_html: { 'aria-label' => t('simple_form.labels.defaults.honeypot', label: 'Website'), :autocomplete => 'off' }, hint: false, disabled: disabled - - - if approved_registrations? - .fields-group - = f.simple_fields_for :invite_request do |invite_request_fields| - = invite_request_fields.input :text, as: :text, wrapper: :with_block_label, required: Setting.require_invite_text - - .fields-group - = f.input :agreement, as: :boolean, wrapper: :with_label, label: t('auth.checkbox_agreement_html', rules_path: about_more_path, terms_path: terms_path), required: true, disabled: disabled - - .actions - = f.button :button, sign_up_message, type: :submit, class: 'button button-primary', disabled: disabled - - - if show_message - .simple_form__overlay-area__overlay - .simple_form__overlay-area__overlay__content.rich-formatting - .block-icon= fa_icon 'warning' - - if current_account.present? - = t('about.logout_before_registering') - - else - = @instance_presenter.closed_registrations_message.html_safe diff --git a/app/views/about/show.html.haml b/app/views/about/show.html.haml deleted file mode 100644 index 75124d5e2..000000000 --- a/app/views/about/show.html.haml +++ /dev/null @@ -1,69 +0,0 @@ -- content_for :page_title do - = site_hostname - -- content_for :header_tags do - %link{ rel: 'canonical', href: about_url }/ - = render partial: 'shared/og' - -.landing - .landing__brand - = link_to root_url, class: 'brand' do - = logo_as_symbol(:wordmark) - %span.brand__tagline=t 'about.tagline' - - .landing__grid - .landing__grid__column.landing__grid__column-registration - .box-widget - = render 'registration' - - .directory - .directory__tag - = link_to web_path do - %h4 - = fa_icon 'globe fw' - = t('about.see_whats_happening') - %small= t('about.browse_public_posts') - - .directory__tag - = link_to 'https://joinmastodon.org/apps', target: '_blank', rel: 'noopener noreferrer' do - %h4 - = fa_icon 'tablet fw' - = t('about.get_apps') - %small= t('about.apps_platforms') - - .landing__grid__column.landing__grid__column-login - .box-widget - - if current_user.present? - = render 'logged_in' - - else - = render 'login' - - .hero-widget - .hero-widget__img - = image_tag @instance_presenter.hero&.file&.url || @instance_presenter.thumbnail&.file&.url || asset_pack_path('media/images/preview.png'), alt: @instance_presenter.title - - .hero-widget__text - %p - = @instance_presenter.description.html_safe.presence || t('about.about_mastodon_html') - = link_to about_more_path do - = t('about.learn_more') - = fa_icon 'angle-double-right' - - .hero-widget__footer - .hero-widget__footer__column - %h4= t 'about.administered_by' - - = account_link_to @instance_presenter.contact.account - - .hero-widget__footer__column - %h4= t 'about.server_stats' - - .hero-widget__counters__wrapper - .hero-widget__counter - %strong= friendly_number_to_human @instance_presenter.user_count - %span= t 'about.user_count_after', count: @instance_presenter.user_count - .hero-widget__counter - %strong= friendly_number_to_human @instance_presenter.active_user_count - %span - = t 'about.active_count_after' - %abbr{ title: t('about.active_footnote') } * diff --git a/config/locales/en.yml b/config/locales/en.yml index 0f2e08ee7..b41e4f47b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,38 +3,25 @@ en: about: about_mastodon_html: 'The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!' about_this: About - active_count_after: active - active_footnote: Monthly Active Users (MAU) administered_by: 'Administered by:' api: API apps: Mobile apps - apps_platforms: Use Mastodon from iOS, Android and other platforms - browse_public_posts: Browse a live stream of public posts on Mastodon contact: Contact contact_missing: Not set contact_unavailable: N/A - continue_to_web: Continue to web app documentation: Documentation - federation_hint_html: With an account on %{instance} you'll be able to follow people on any Mastodon server and beyond. - get_apps: Try a mobile app hosted_on: Mastodon hosted on %{domain} instance_actor_flash: | This account is a virtual actor used to represent the server itself and not any individual user. It is used for federation purposes and should not be blocked unless you want to block the whole instance, in which case you should use a domain block. - learn_more: Learn more - logged_in_as_html: You are currently logged in as %{username}. - logout_before_registering: You are already logged in. privacy_policy: Privacy Policy rules: Server rules rules_html: 'Below is a summary of rules you need to follow if you want to have an account on this server of Mastodon:' - see_whats_happening: See what's happening - server_stats: 'Server stats:' source_code: Source code status_count_after: one: post other: posts status_count_before: Who published - tagline: Decentralized social network unavailable_content: Moderated servers unavailable_content_description: domain: Server @@ -1049,7 +1036,6 @@ en: redirecting_to: Your account is inactive because it is currently redirecting to %{acct}. view_strikes: View past strikes against your account too_fast: Form submitted too fast, try again. - trouble_logging_in: Trouble logging in? use_security_key: Use security key authorize_follow: already_following: You are already following this account diff --git a/config/routes.rb b/config/routes.rb index 188898fd0..472e6aa6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -641,7 +641,7 @@ Rails.application.routes.draw do get '/web/(*any)', to: 'home#index', as: :web - get '/about', to: 'about#show' + get '/about', to: redirect('/') get '/about/more', to: 'about#more' get '/privacy-policy', to: 'privacy#show', as: :privacy_policy diff --git a/spec/controllers/about_controller_spec.rb b/spec/controllers/about_controller_spec.rb index 40e395a64..20069e413 100644 --- a/spec/controllers/about_controller_spec.rb +++ b/spec/controllers/about_controller_spec.rb @@ -3,20 +3,6 @@ require 'rails_helper' RSpec.describe AboutController, type: :controller do render_views - describe 'GET #show' do - before do - get :show - end - - it 'assigns @instance_presenter' do - expect(assigns(:instance_presenter)).to be_kind_of InstancePresenter - end - - it 'returns http success' do - expect(response).to have_http_status(200) - end - end - describe 'GET #more' do before do get :more @@ -30,12 +16,4 @@ RSpec.describe AboutController, type: :controller do expect(response).to have_http_status(200) end end - - describe 'helper_method :new_user' do - it 'returns a new User' do - user = @controller.view_context.new_user - expect(user).to be_kind_of User - expect(user.account).to be_kind_of Account - end - end end diff --git a/spec/requests/localization_spec.rb b/spec/requests/localization_spec.rb index 175f02ae9..0bc2786ac 100644 --- a/spec/requests/localization_spec.rb +++ b/spec/requests/localization_spec.rb @@ -10,30 +10,30 @@ describe 'Localization' do it 'uses a specific region when provided' do headers = { 'Accept-Language' => 'zh-HK' } - get "/about", headers: headers + get "/auth/sign_in", headers: headers expect(response.body).to include( - I18n.t('about.tagline', locale: 'zh-HK') + I18n.t('auth.login', locale: 'zh-HK') ) end it 'falls back to a locale when region missing' do headers = { 'Accept-Language' => 'es-FAKE' } - get "/about", headers: headers + get "/auth/sign_in", headers: headers expect(response.body).to include( - I18n.t('about.tagline', locale: 'es') + I18n.t('auth.login', locale: 'es') ) end it 'falls back to english when locale is missing' do headers = { 'Accept-Language' => '12-FAKE' } - get "/about", headers: headers + get "/auth/sign_in", headers: headers expect(response.body).to include( - I18n.t('about.tagline', locale: 'en') + I18n.t('auth.login', locale: 'en') ) end end diff --git a/spec/views/about/show.html.haml_spec.rb b/spec/views/about/show.html.haml_spec.rb deleted file mode 100644 index bf6e19d2b..000000000 --- a/spec/views/about/show.html.haml_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe 'about/show.html.haml', without_verify_partial_doubles: true do - before do - allow(view).to receive(:site_hostname).and_return('example.com') - allow(view).to receive(:site_title).and_return('example site') - allow(view).to receive(:new_user).and_return(User.new) - allow(view).to receive(:use_seamless_external_login?).and_return(false) - allow(view).to receive(:current_account).and_return(nil) - end - - it 'has valid open graph tags' do - assign(:instance_presenter, InstancePresenter.new) - render - - header_tags = view.content_for(:header_tags) - - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) - expect(header_tags).to match(%r{}) - end -end -- cgit From 62782babd08bc2385a604e275bf88af925d137c1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 6 Oct 2022 02:26:34 +0200 Subject: Change public statuses pages to mount the web UI (#19301) --- .../concerns/web_app_controller_concern.rb | 18 ++++++++ app/controllers/home_controller.rb | 11 ++--- app/controllers/statuses_controller.rb | 12 +----- app/views/home/index.html.haml | 18 +------- app/views/shared/_web_app.html.haml | 17 ++++++++ app/views/statuses/show.html.haml | 7 +--- spec/views/statuses/show.html.haml_spec.rb | 48 ---------------------- 7 files changed, 42 insertions(+), 89 deletions(-) create mode 100644 app/controllers/concerns/web_app_controller_concern.rb create mode 100644 app/views/shared/_web_app.html.haml (limited to 'spec/views') diff --git a/app/controllers/concerns/web_app_controller_concern.rb b/app/controllers/concerns/web_app_controller_concern.rb new file mode 100644 index 000000000..8a6c73af3 --- /dev/null +++ b/app/controllers/concerns/web_app_controller_concern.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module WebAppControllerConcern + extend ActiveSupport::Concern + + included do + before_action :set_body_classes + before_action :set_referrer_policy_header + end + + def set_body_classes + @body_classes = 'app-body' + end + + def set_referrer_policy_header + response.headers['Referrer-Policy'] = 'origin' + end +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 29478209d..b4d6578b9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true class HomeController < ApplicationController + include WebAppControllerConcern + before_action :redirect_unauthenticated_to_permalinks! - before_action :set_referrer_policy_header before_action :set_instance_presenter - def index - @body_classes = 'app-body' - end + def index; end private @@ -19,10 +18,6 @@ class HomeController < ApplicationController redirect_to(redirect_path) if redirect_path.present? end - def set_referrer_policy_header - response.headers['Referrer-Policy'] = 'origin' - end - def set_instance_presenter @instance_presenter = InstancePresenter.new end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index 7d9db4d5b..181c76c9a 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -5,17 +5,15 @@ class StatusesController < ApplicationController include SignatureAuthentication include Authorization include AccountOwnedConcern - - layout 'public' + include WebAppControllerConcern before_action :require_account_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? } before_action :set_status before_action :set_instance_presenter before_action :set_link_headers before_action :redirect_to_original, only: :show - before_action :set_referrer_policy_header, only: :show before_action :set_cache_headers - before_action :set_body_classes + before_action :set_body_classes, only: :embed skip_around_action :set_locale, if: -> { request.format == :json } skip_before_action :require_functional!, only: [:show, :embed], unless: :whitelist_mode? @@ -28,8 +26,6 @@ class StatusesController < ApplicationController respond_to do |format| format.html do expires_in 10.seconds, public: true if current_account.nil? - set_ancestors - set_descendants end format.json do @@ -77,8 +73,4 @@ class StatusesController < ApplicationController def redirect_to_original redirect_to ActivityPub::TagManager.instance.url_for(@status.reblog) if @status.reblog? end - - def set_referrer_policy_header - response.headers['Referrer-Policy'] = 'origin' unless @status.distributable? - end end diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 19c5191d8..76a02e0f0 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,20 +1,4 @@ - content_for :header_tags do - - if user_signed_in? - = preload_pack_asset 'features/getting_started.js', crossorigin: 'anonymous' - = preload_pack_asset 'features/compose.js', crossorigin: 'anonymous' - = preload_pack_asset 'features/home_timeline.js', crossorigin: 'anonymous' - = preload_pack_asset 'features/notifications.js', crossorigin: 'anonymous' - = render partial: 'shared/og' - %meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key} - - = render_initial_state - = javascript_pack_tag 'application', crossorigin: 'anonymous' - -.notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } - %noscript - = image_pack_tag 'logo.svg', alt: 'Mastodon' - - %div - = t('errors.noscript_html', apps_path: 'https://joinmastodon.org/apps') += render 'shared/web_app' diff --git a/app/views/shared/_web_app.html.haml b/app/views/shared/_web_app.html.haml new file mode 100644 index 000000000..998cee9fa --- /dev/null +++ b/app/views/shared/_web_app.html.haml @@ -0,0 +1,17 @@ +- content_for :header_tags do + - if user_signed_in? + = preload_pack_asset 'features/compose.js', crossorigin: 'anonymous' + = preload_pack_asset 'features/home_timeline.js', crossorigin: 'anonymous' + = preload_pack_asset 'features/notifications.js', crossorigin: 'anonymous' + + %meta{ name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key } + + = render_initial_state + = javascript_pack_tag 'application', crossorigin: 'anonymous' + +.notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } + %noscript + = image_pack_tag 'logo.svg', alt: 'Mastodon' + + %div + = t('errors.noscript_html', apps_path: 'https://joinmastodon.org/apps') diff --git a/app/views/statuses/show.html.haml b/app/views/statuses/show.html.haml index 7ef7b09a2..5a3c94b84 100644 --- a/app/views/statuses/show.html.haml +++ b/app/views/statuses/show.html.haml @@ -17,9 +17,4 @@ = render 'og_description', activity: @status = render 'og_image', activity: @status, account: @account -.grid - .column-0 - .activity-stream.h-entry - = render partial: 'status', locals: { status: @status, include_threads: true } - .column-1 - = render 'application/sidebar' += render 'shared/web_app' diff --git a/spec/views/statuses/show.html.haml_spec.rb b/spec/views/statuses/show.html.haml_spec.rb index 879a26959..a69843216 100644 --- a/spec/views/statuses/show.html.haml_spec.rb +++ b/spec/views/statuses/show.html.haml_spec.rb @@ -15,54 +15,6 @@ describe 'statuses/show.html.haml', without_verify_partial_doubles: true do assign(:instance_presenter, InstancePresenter.new) end - it 'has valid author h-card and basic data for a detailed_status' do - alice = Fabricate(:account, username: 'alice', display_name: 'Alice') - bob = Fabricate(:account, username: 'bob', display_name: 'Bob') - status = Fabricate(:status, account: alice, text: 'Hello World') - media = Fabricate(:media_attachment, account: alice, status: status, type: :video) - reply = Fabricate(:status, account: bob, thread: status, text: 'Hello Alice') - - assign(:status, status) - assign(:account, alice) - assign(:descendant_threads, []) - - render - - mf2 = Microformats.parse(rendered) - - expect(mf2.entry.url.to_s).not_to be_empty - expect(mf2.entry.author.name.to_s).to eq alice.display_name - expect(mf2.entry.author.url.to_s).not_to be_empty - end - - it 'has valid h-cites for p-in-reply-to and p-comment' do - alice = Fabricate(:account, username: 'alice', display_name: 'Alice') - bob = Fabricate(:account, username: 'bob', display_name: 'Bob') - carl = Fabricate(:account, username: 'carl', display_name: 'Carl') - status = Fabricate(:status, account: alice, text: 'Hello World') - media = Fabricate(:media_attachment, account: alice, status: status, type: :video) - reply = Fabricate(:status, account: bob, thread: status, text: 'Hello Alice') - comment = Fabricate(:status, account: carl, thread: reply, text: 'Hello Bob') - - assign(:status, reply) - assign(:account, alice) - assign(:ancestors, reply.ancestors(1, bob)) - assign(:descendant_threads, [{ statuses: reply.descendants(1) }]) - - render - - mf2 = Microformats.parse(rendered) - - expect(mf2.entry.url.to_s).not_to be_empty - expect(mf2.entry.comment.url.to_s).not_to be_empty - expect(mf2.entry.comment.author.name.to_s).to eq carl.display_name - expect(mf2.entry.comment.author.url.to_s).not_to be_empty - - expect(mf2.entry.in_reply_to.url.to_s).not_to be_empty - expect(mf2.entry.in_reply_to.author.name.to_s).to eq alice.display_name - expect(mf2.entry.in_reply_to.author.url.to_s).not_to be_empty - end - it 'has valid opengraph tags' do alice = Fabricate(:account, username: 'alice', display_name: 'Alice') status = Fabricate(:status, account: alice, text: 'Hello World') -- cgit From 7afc6a630c76fb071bd189af3ac1366efc82f819 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Thu, 13 Oct 2022 04:07:30 +0900 Subject: Redirect non-logged-in user to owner statuses on single user mode (#19333) --- app/helpers/application_helper.rb | 4 ++ app/javascript/mastodon/features/ui/index.js | 4 +- app/javascript/mastodon/initial_state.js | 80 +++++++++++++++++++++------- app/presenters/initial_state_presenter.rb | 2 +- app/serializers/initial_state_serializer.rb | 6 +++ spec/views/statuses/show.html.haml_spec.rb | 1 + 6 files changed, 77 insertions(+), 20 deletions(-) (limited to 'spec/views') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 23884fbd4..9cc34cab6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -211,6 +211,10 @@ module ApplicationHelper state_params[:admin] = Account.find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')) end + if single_user_mode? + state_params[:owner] = Account.local.without_suspended.where('id > 0').first + end + json = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(state_params), serializer: InitialStateSerializer).to_json # rubocop:disable Rails/OutputSafety content_tag(:script, json_escape(json).html_safe, id: 'initial-state', type: 'application/json') diff --git a/app/javascript/mastodon/features/ui/index.js b/app/javascript/mastodon/features/ui/index.js index 2edd3b9fe..8333ea282 100644 --- a/app/javascript/mastodon/features/ui/index.js +++ b/app/javascript/mastodon/features/ui/index.js @@ -54,7 +54,7 @@ import { About, PrivacyPolicy, } from './util/async-components'; -import { me } from '../../initial_state'; +import initialState, { me, owner, singleUserMode } from '../../initial_state'; import { closeOnboarding, INTRODUCTION_VERSION } from 'mastodon/actions/onboarding'; import Header from './components/header'; @@ -161,6 +161,8 @@ class SwitchingColumnsArea extends React.PureComponent { } else { redirect = ; } + } else if (singleUserMode && owner && initialState?.accounts[owner]) { + redirect = ; } else { redirect = ; } diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 031c748cf..f9843f7f8 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -1,5 +1,44 @@ // @ts-check +/** + * @typedef Emoji + * @property {string} shortcode + * @property {string} static_url + * @property {string} url + */ + +/** + * @typedef AccountField + * @property {string} name + * @property {string} value + * @property {string} verified_at + */ + +/** + * @typedef Account + * @property {string} acct + * @property {string} avatar + * @property {string} avatar_static + * @property {boolean} bot + * @property {string} created_at + * @property {boolean=} discoverable + * @property {string} display_name + * @property {Emoji[]} emojis + * @property {AccountField[]} fields + * @property {number} followers_count + * @property {number} following_count + * @property {boolean} group + * @property {string} header + * @property {string} header_static + * @property {string} id + * @property {string=} last_status_at + * @property {boolean} locked + * @property {string} note + * @property {number} statuses_count + * @property {string} url + * @property {string} username + */ + /** * @typedef {[code: string, name: string, localName: string]} InitialStateLanguage */ @@ -22,11 +61,13 @@ * @property {string} locale * @property {string | null} mascot * @property {string=} me + * @property {string=} owner * @property {boolean} profile_directory * @property {boolean} registrations_open * @property {boolean} reduce_motion * @property {string} repository * @property {boolean} search_enabled + * @property {boolean} single_user_mode * @property {string} source_url * @property {string} streaming_api_base_url * @property {boolean} timeline_preview @@ -40,13 +81,14 @@ /** * @typedef InitialState + * @property {Record} accounts * @property {InitialStateLanguage[]} languages * @property {InitialStateMeta} meta */ const element = document.getElementById('initial-state'); /** @type {InitialState | undefined} */ -const initialState = element && JSON.parse(element.textContent); +const initialState = element?.textContent && JSON.parse(element.textContent); /** * @template {keyof InitialStateMeta} K @@ -55,32 +97,34 @@ const initialState = element && JSON.parse(element.textContent); */ const getMeta = (prop) => initialState?.meta && initialState.meta[prop]; -export const domain = getMeta('domain'); -export const reduceMotion = getMeta('reduce_motion'); +export const activityApiEnabled = getMeta('activity_api_enabled'); export const autoPlayGif = getMeta('auto_play_gif'); -export const displayMedia = getMeta('display_media'); -export const expandSpoilers = getMeta('expand_spoilers'); -export const unfollowModal = getMeta('unfollow_modal'); export const boostModal = getMeta('boost_modal'); +export const cropImages = getMeta('crop_images'); export const deleteModal = getMeta('delete_modal'); -export const me = getMeta('me'); -export const searchEnabled = getMeta('search_enabled'); +export const disableSwiping = getMeta('disable_swiping'); +export const displayMedia = getMeta('display_media'); +export const domain = getMeta('domain'); +export const expandSpoilers = getMeta('expand_spoilers'); +export const forceSingleColumn = !getMeta('advanced_layout'); export const limitedFederationMode = getMeta('limited_federation_mode'); +export const mascot = getMeta('mascot'); +export const me = getMeta('me'); +export const owner = getMeta('owner'); +export const profile_directory = getMeta('profile_directory'); +export const reduceMotion = getMeta('reduce_motion'); export const registrationsOpen = getMeta('registrations_open'); export const repository = getMeta('repository'); +export const searchEnabled = getMeta('search_enabled'); +export const showTrends = getMeta('trends'); +export const singleUserMode = getMeta('single_user_mode'); export const source_url = getMeta('source_url'); -export const version = getMeta('version'); -export const mascot = getMeta('mascot'); -export const profile_directory = getMeta('profile_directory'); -export const forceSingleColumn = !getMeta('advanced_layout'); +export const timelinePreview = getMeta('timeline_preview'); +export const title = getMeta('title'); +export const unfollowModal = getMeta('unfollow_modal'); export const useBlurhash = getMeta('use_blurhash'); export const usePendingItems = getMeta('use_pending_items'); -export const showTrends = getMeta('trends'); -export const title = getMeta('title'); -export const cropImages = getMeta('crop_images'); -export const disableSwiping = getMeta('disable_swiping'); -export const timelinePreview = getMeta('timeline_preview'); -export const activityApiEnabled = getMeta('activity_api_enabled'); +export const version = getMeta('version'); export const languages = initialState?.languages; export default initialState; diff --git a/app/presenters/initial_state_presenter.rb b/app/presenters/initial_state_presenter.rb index 129ea2a46..ed0479211 100644 --- a/app/presenters/initial_state_presenter.rb +++ b/app/presenters/initial_state_presenter.rb @@ -2,7 +2,7 @@ class InitialStatePresenter < ActiveModelSerializers::Model attributes :settings, :push_subscription, :token, - :current_account, :admin, :text, :visibility + :current_account, :admin, :owner, :text, :visibility def role current_account&.user_role diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index bec725e1b..ba446854c 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -30,6 +30,7 @@ class InitialStateSerializer < ActiveModel::Serializer registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode, timeline_preview: Setting.timeline_preview, activity_api_enabled: Setting.activity_api_enabled, + single_user_mode: Rails.configuration.x.single_user_mode, } if object.current_account @@ -55,6 +56,10 @@ class InitialStateSerializer < ActiveModel::Serializer store[:crop_images] = Setting.crop_images end + if Rails.configuration.x.single_user_mode + store[:owner] = object.owner&.id&.to_s + end + store end # rubocop:enable Metrics/AbcSize @@ -78,6 +83,7 @@ class InitialStateSerializer < ActiveModel::Serializer store = {} store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin + store[object.owner.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.owner, serializer: REST::AccountSerializer) if object.owner store end diff --git a/spec/views/statuses/show.html.haml_spec.rb b/spec/views/statuses/show.html.haml_spec.rb index a69843216..eeea2f698 100644 --- a/spec/views/statuses/show.html.haml_spec.rb +++ b/spec/views/statuses/show.html.haml_spec.rb @@ -12,6 +12,7 @@ describe 'statuses/show.html.haml', without_verify_partial_doubles: true do allow(view).to receive(:local_time) allow(view).to receive(:local_time_ago) allow(view).to receive(:current_account).and_return(nil) + allow(view).to receive(:single_user_mode?).and_return(false) assign(:instance_presenter, InstancePresenter.new) end -- cgit