[Glitch] Allow non-logged users to access /web

Port 43b5d5e38d to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
main
Eugen Rochko 2022-09-29 04:39:33 +02:00 committed by Claire
parent 9ee2746a36
commit d86cb4cab8
5 changed files with 29 additions and 19 deletions

View File

@ -2,10 +2,10 @@
class HomeController < ApplicationController class HomeController < ApplicationController
before_action :redirect_unauthenticated_to_permalinks! before_action :redirect_unauthenticated_to_permalinks!
before_action :authenticate_user!
before_action :set_pack before_action :set_pack
before_action :set_referrer_policy_header before_action :set_referrer_policy_header
before_action :set_instance_presenter
def index def index
@body_classes = 'app-body' @body_classes = 'app-body'
@ -16,7 +16,10 @@ class HomeController < ApplicationController
def redirect_unauthenticated_to_permalinks! def redirect_unauthenticated_to_permalinks!
return if user_signed_in? return if user_signed_in?
redirect_to(PermalinkRedirector.new(request.path).redirect_path || default_redirect_path) redirect_path = PermalinkRedirector.new(request.path).redirect_path
redirect_path ||= default_redirect_path
redirect_to(redirect_path) if redirect_path.present?
end end
def set_pack def set_pack
@ -24,8 +27,10 @@ class HomeController < ApplicationController
end end
def default_redirect_path def default_redirect_path
if request.path.start_with?('/web') || whitelist_mode? if whitelist_mode?
new_user_session_path new_user_session_path
elsif request.path.start_with?('/web')
nil
elsif single_user_mode? elsif single_user_mode?
short_account_path(Account.local.without_suspended.where('id > 0').first) short_account_path(Account.local.without_suspended.where('id > 0').first)
else else
@ -36,4 +41,8 @@ class HomeController < ApplicationController
def set_referrer_policy_header def set_referrer_policy_header
response.headers['Referrer-Policy'] = 'origin' response.headers['Referrer-Policy'] = 'origin'
end end
def set_instance_presenter
@instance_presenter = InstancePresenter.new
end
end end

View File

@ -17,10 +17,6 @@ class PermalinkRedirector
find_status_url_by_id(path_segments[2]) find_status_url_by_id(path_segments[2])
elsif path_segments[1] == 'accounts' && path_segments[2] =~ /\d/ elsif path_segments[1] == 'accounts' && path_segments[2] =~ /\d/
find_account_url_by_id(path_segments[2]) find_account_url_by_id(path_segments[2])
elsif path_segments[1] == 'timelines' && path_segments[2] == 'tag' && path_segments[3].present?
find_tag_url_by_name(path_segments[3])
elsif path_segments[1] == 'tags' && path_segments[2].present?
find_tag_url_by_name(path_segments[2])
end end
end end
end end

View File

@ -1,10 +1,14 @@
- content_for :header_tags do - content_for :header_tags do
- if user_signed_in?
= preload_pack_asset 'features/getting_started.js', crossorigin: 'anonymous' = preload_pack_asset 'features/getting_started.js', crossorigin: 'anonymous'
= preload_pack_asset 'features/compose.js', crossorigin: 'anonymous' = preload_pack_asset 'features/compose.js', crossorigin: 'anonymous'
= preload_pack_asset 'features/home_timeline.js', crossorigin: 'anonymous' = preload_pack_asset 'features/home_timeline.js', crossorigin: 'anonymous'
= preload_pack_asset 'features/notifications.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} %meta{name: 'applicationServerKey', content: Rails.configuration.x.vapid_public_key}
= render_initial_state = render_initial_state
.notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } } .notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } }

View File

@ -8,9 +8,9 @@ RSpec.describe HomeController, type: :controller do
context 'when not signed in' do context 'when not signed in' do
context 'when requested path is tag timeline' do context 'when requested path is tag timeline' do
it 'redirects to the tag\'s permalink' do it 'returns http success' do
@request.path = '/web/timelines/tag/name' @request.path = '/web/timelines/tag/name'
is_expected.to redirect_to '/tags/name' is_expected.to have_http_status(:success)
end end
end end
@ -23,11 +23,12 @@ RSpec.describe HomeController, type: :controller do
context 'when signed in' do context 'when signed in' do
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
before { sign_in(user) } before do
sign_in(user)
end
it 'assigns @body_classes' do it 'returns http success' do
subject is_expected.to have_http_status(:success)
expect(assigns(:body_classes)).to eq 'app-body'
end end
end end
end end

View File

@ -21,7 +21,7 @@ describe PermalinkRedirector do
it 'returns path for legacy tag links' do it 'returns path for legacy tag links' do
redirector = described_class.new('web/timelines/tag/hoge') redirector = described_class.new('web/timelines/tag/hoge')
expect(redirector.redirect_path).to eq '/tags/hoge' expect(redirector.redirect_path).to be_nil
end end
it 'returns path for pretty account links' do it 'returns path for pretty account links' do
@ -36,7 +36,7 @@ describe PermalinkRedirector do
it 'returns path for pretty tag links' do it 'returns path for pretty tag links' do
redirector = described_class.new('web/tags/hoge') redirector = described_class.new('web/tags/hoge')
expect(redirector.redirect_path).to eq '/tags/hoge' expect(redirector.redirect_path).to be_nil
end end
end end
end end