]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Allow non-logged users to access /web
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 29 Sep 2022 02:39:33 +0000 (04:39 +0200)
committeraescling <aescling+gitlab@cat.family>
Thu, 17 Nov 2022 05:28:25 +0000 (00:28 -0500)
Port 43b5d5e38d2b8ad8f1d1ad0911c3c1718159c912 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
app/controllers/home_controller.rb
app/lib/permalink_redirector.rb
app/views/home/index.html.haml
spec/controllers/home_controller_spec.rb
spec/lib/permalink_redirector_spec.rb

index 450f92bd4049deea2b18fbf54e5cfbaa6e379e80..61b1690fab1bcf0bdba35948ad8f684873c80d3f 100644 (file)
@@ -2,10 +2,10 @@
 
 class HomeController < ApplicationController
   before_action :redirect_unauthenticated_to_permalinks!
-  before_action :authenticate_user!
 
   before_action :set_pack
   before_action :set_referrer_policy_header
+  before_action :set_instance_presenter
 
   def index
     @body_classes = 'app-body'
@@ -16,7 +16,10 @@ class HomeController < ApplicationController
   def redirect_unauthenticated_to_permalinks!
     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
 
   def set_pack
@@ -24,8 +27,10 @@ class HomeController < ApplicationController
   end
 
   def default_redirect_path
-    if request.path.start_with?('/web') || whitelist_mode?
+    if whitelist_mode?
       new_user_session_path
+    elsif request.path.start_with?('/web')
+      nil
     elsif single_user_mode?
       short_account_path(Account.local.without_suspended.where('id > 0').first)
     else
@@ -36,4 +41,8 @@ class HomeController < ApplicationController
   def set_referrer_policy_header
     response.headers['Referrer-Policy'] = 'origin'
   end
+
+  def set_instance_presenter
+    @instance_presenter = InstancePresenter.new
+  end
 end
index e48bce06099429024727e7ed28f81debb681a423..6d15f39638b5ee603dd743e33f82abe9d22a7241 100644 (file)
@@ -17,10 +17,6 @@ class PermalinkRedirector
         find_status_url_by_id(path_segments[2])
       elsif path_segments[1] == 'accounts' && path_segments[2] =~ /\d/
         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
index 568b23effc52bd03344f0b8b75090b54b4f2fdd7..437c3371546e39e0af99961d577b62f90f3d94c4 100644 (file)
@@ -1,10 +1,14 @@
 - content_for :header_tags do
-  = 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'
+  - 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
 
 .notranslate.app-holder#mastodon{ data: { props: Oj.dump(default_props) } }
index d845ae01d7dc539516aeb9645cc70ff078db48bc..914ca6307ad04868b5f8521ff016692636be4c89 100644 (file)
@@ -7,9 +7,16 @@ RSpec.describe HomeController, type: :controller do
     subject { get :index }
 
     context 'when not signed in' do
-      it 'returns http success' do
+      context 'when requested path is tag timeline' do
+        it 'returns http success' do
+          @request.path = '/web/timelines/tag/name'
+          is_expected.to have_http_status(:success)
+        end
+      end
+
+      it 'redirects to about page' do
         @request.path = '/'
-        is_expected.to have_http_status(:success)
+        is_expected.to redirect_to(about_path)
       end
     end
 
index b916b33b22c60bee695c02ae43f33a3e8f120bef..abda57da49727ac6e515b87edfa1e1ef3572dae6 100644 (file)
@@ -21,7 +21,7 @@ describe PermalinkRedirector do
 
     it 'returns path for legacy tag links' do
       redirector = described_class.new('web/timelines/tag/hoge')
-      expect(redirector.redirect_path).to eq '/tags/hoge'
+      expect(redirector.redirect_path).to be_nil
     end
 
     it 'returns path for pretty account links' do
@@ -36,7 +36,7 @@ describe PermalinkRedirector do
 
     it 'returns path for pretty tag links' do
       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