aboutsummaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/account_follow_controller.rb12
-rw-r--r--app/controllers/account_unfollow_controller.rb12
-rw-r--r--app/controllers/accounts_controller.rb24
-rw-r--r--app/controllers/api/v1/accounts/lookup_controller.rb16
-rw-r--r--app/controllers/authorize_interactions_controller.rb2
-rw-r--r--app/controllers/concerns/account_controller_concern.rb7
-rw-r--r--app/controllers/concerns/web_app_controller_concern.rb18
-rw-r--r--app/controllers/directories_controller.rb28
-rw-r--r--app/controllers/follower_accounts_controller.rb9
-rw-r--r--app/controllers/following_accounts_controller.rb9
-rw-r--r--app/controllers/home_controller.rb43
-rw-r--r--app/controllers/public_timelines_controller.rb18
-rw-r--r--app/controllers/statuses_controller.rb18
-rw-r--r--app/controllers/tags_controller.rb15
14 files changed, 62 insertions, 169 deletions
diff --git a/app/controllers/account_follow_controller.rb b/app/controllers/account_follow_controller.rb
deleted file mode 100644
index 33394074d..000000000
--- a/app/controllers/account_follow_controller.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-class AccountFollowController < ApplicationController
- include AccountControllerConcern
-
- before_action :authenticate_user!
-
- def create
- FollowService.new.call(current_user.account, @account, with_rate_limit: true)
- redirect_to account_path(@account)
- end
-end
diff --git a/app/controllers/account_unfollow_controller.rb b/app/controllers/account_unfollow_controller.rb
deleted file mode 100644
index 378ec86dc..000000000
--- a/app/controllers/account_unfollow_controller.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-class AccountUnfollowController < ApplicationController
- include AccountControllerConcern
-
- before_action :authenticate_user!
-
- def create
- UnfollowService.new.call(current_user.account, @account)
- redirect_to account_path(@account)
- end
-end
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index b902ada09..4ca37b9ef 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -5,11 +5,11 @@ class AccountsController < ApplicationController
PAGE_SIZE_MAX = 200
include AccountControllerConcern
+ include WebAppControllerConcern
include SignatureAuthentication
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :set_cache_headers
- before_action :set_body_classes
skip_around_action :set_locale, if: -> { [:json, :rss].include?(request.format&.to_sym) }
skip_before_action :require_functional!, unless: :whitelist_mode?
@@ -18,24 +18,6 @@ class AccountsController < ApplicationController
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?
-
- @pinned_statuses = []
- @endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
- @featured_hashtags = @account.featured_tags.order(statuses_count: :desc)
-
- if current_account && @account.blocking?(current_account)
- @statuses = []
- return
- end
-
- @pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
- @statuses = cached_filtered_status_page
- @rss_url = rss_url
-
- unless @statuses.empty?
- @older_url = older_url if @statuses.last.id > filtered_statuses.last.id
- @newer_url = newer_url if @statuses.first.id < filtered_statuses.first.id
- end
end
format.rss do
@@ -56,10 +38,6 @@ class AccountsController < ApplicationController
private
- def set_body_classes
- @body_classes = 'with-modals'
- end
-
def show_pinned_statuses?
[replies_requested?, media_requested?, tag_requested?, params[:max_id].present?, params[:min_id].present?].none?
end
diff --git a/app/controllers/api/v1/accounts/lookup_controller.rb b/app/controllers/api/v1/accounts/lookup_controller.rb
new file mode 100644
index 000000000..aee6be18a
--- /dev/null
+++ b/app/controllers/api/v1/accounts/lookup_controller.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+class Api::V1::Accounts::LookupController < Api::BaseController
+ before_action -> { authorize_if_got_token! :read, :'read:accounts' }
+ before_action :set_account
+
+ def show
+ render json: @account, serializer: REST::AccountSerializer
+ end
+
+ private
+
+ def set_account
+ @account = ResolveAccountService.new.call(params[:acct], skip_webfinger: true) || raise(ActiveRecord::RecordNotFound)
+ end
+end
diff --git a/app/controllers/authorize_interactions_controller.rb b/app/controllers/authorize_interactions_controller.rb
index 29c0288d0..1d519c96f 100644
--- a/app/controllers/authorize_interactions_controller.rb
+++ b/app/controllers/authorize_interactions_controller.rb
@@ -13,7 +13,7 @@ class AuthorizeInteractionsController < ApplicationController
if @resource.is_a?(Account)
render :show
elsif @resource.is_a?(Status)
- redirect_to web_url("statuses/#{@resource.id}")
+ redirect_to short_account_status_path(@resource.account.acct, @resource.id)
else
render :error
end
diff --git a/app/controllers/concerns/account_controller_concern.rb b/app/controllers/concerns/account_controller_concern.rb
index 11eac0eb6..f05fa3f91 100644
--- a/app/controllers/concerns/account_controller_concern.rb
+++ b/app/controllers/concerns/account_controller_concern.rb
@@ -8,18 +8,11 @@ module AccountControllerConcern
FOLLOW_PER_PAGE = 12
included do
- layout 'public'
-
- before_action :set_instance_presenter
before_action :set_link_headers, if: -> { request.format.nil? || request.format == :html }
end
private
- def set_instance_presenter
- @instance_presenter = InstancePresenter.new
- end
-
def set_link_headers
response.headers['Link'] = LinkHeader.new(
[
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/directories_controller.rb b/app/controllers/directories_controller.rb
index f198ad5ba..cfd0fa656 100644
--- a/app/controllers/directories_controller.rb
+++ b/app/controllers/directories_controller.rb
@@ -1,42 +1,20 @@
# frozen_string_literal: true
class DirectoriesController < ApplicationController
- layout 'public'
+ include WebAppControllerConcern
before_action :authenticate_user!, if: :whitelist_mode?
before_action :require_enabled!
- before_action :set_instance_presenter
- before_action :set_tag, only: :show
- before_action :set_accounts
skip_before_action :require_functional!, unless: :whitelist_mode?
def index
- render :index
- end
-
- def show
- render :index
+ expires_in 0, public: true if current_account.nil?
end
private
def require_enabled!
- return not_found unless Setting.profile_directory
- end
-
- def set_tag
- @tag = Tag.discoverable.find_normalized!(params[:id])
- end
-
- def set_accounts
- @accounts = Account.local.discoverable.by_recent_status.page(params[:page]).per(20).tap do |query|
- query.merge!(Account.tagged_with(@tag.id)) if @tag
- query.merge!(Account.not_excluded_by_account(current_account)) if current_account
- end
- end
-
- def set_instance_presenter
- @instance_presenter = InstancePresenter.new
+ not_found unless Setting.profile_directory
end
end
diff --git a/app/controllers/follower_accounts_controller.rb b/app/controllers/follower_accounts_controller.rb
index ff4df2adf..ebdefcf9b 100644
--- a/app/controllers/follower_accounts_controller.rb
+++ b/app/controllers/follower_accounts_controller.rb
@@ -2,6 +2,7 @@
class FollowerAccountsController < ApplicationController
include AccountControllerConcern
+ include WebAppControllerConcern
include SignatureVerification
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
@@ -14,10 +15,6 @@ class FollowerAccountsController < ApplicationController
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?
-
- next if @account.user_hides_network?
-
- follows
end
format.json do
@@ -36,6 +33,10 @@ class FollowerAccountsController < ApplicationController
private
+ def username_param
+ params[:username] || params[:account_username]
+ end
+
def follows
return @follows if defined?(@follows)
diff --git a/app/controllers/following_accounts_controller.rb b/app/controllers/following_accounts_controller.rb
index 6bb95c454..4500fb5d7 100644
--- a/app/controllers/following_accounts_controller.rb
+++ b/app/controllers/following_accounts_controller.rb
@@ -2,6 +2,7 @@
class FollowingAccountsController < ApplicationController
include AccountControllerConcern
+ include WebAppControllerConcern
include SignatureVerification
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
@@ -14,10 +15,6 @@ class FollowingAccountsController < ApplicationController
respond_to do |format|
format.html do
expires_in 0, public: true unless user_signed_in?
-
- next if @account.user_hides_network?
-
- follows
end
format.json do
@@ -36,6 +33,10 @@ class FollowingAccountsController < ApplicationController
private
+ def username_param
+ params[:username] || params[:account_username]
+ end
+
def follows
return @follows if defined?(@follows)
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 702889cd0..72573d231 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,47 +1,16 @@
# frozen_string_literal: true
class HomeController < ApplicationController
- before_action :redirect_unauthenticated_to_permalinks!
before_action :authenticate_user!
- before_action :set_referrer_policy_header
- def index
- @body_classes = 'app-body'
- end
-
- private
-
- def redirect_unauthenticated_to_permalinks!
- return if user_signed_in?
+ include WebAppControllerConcern
- matches = request.path.match(/\A\/web\/(statuses|accounts)\/([\d]+)\z/)
+ def index; end
- if matches
- case matches[1]
- when 'statuses'
- status = Status.find_by(id: matches[2])
-
- if status&.distributable?
- redirect_to(ActivityPub::TagManager.instance.url_for(status))
- return
- end
- when 'accounts'
- account = Account.find_by(id: matches[2])
-
- if account
- redirect_to(ActivityPub::TagManager.instance.url_for(account))
- return
- end
- end
- end
-
- matches = request.path.match(%r{\A/web/timelines/tag/(?<tag>.+)\z})
-
- redirect_to(matches ? tag_path(CGI.unescape(matches[:tag])) : default_redirect_path)
- end
+ private
def default_redirect_path
- if request.path.start_with?('/web') || whitelist_mode?
+ if whitelist_mode?
new_user_session_path
elsif single_user_mode?
short_account_path(Account.local.without_suspended.where('id > 0').first)
@@ -49,8 +18,4 @@ class HomeController < ApplicationController
about_path
end
end
-
- def set_referrer_policy_header
- response.headers['Referrer-Policy'] = 'origin'
- end
end
diff --git a/app/controllers/public_timelines_controller.rb b/app/controllers/public_timelines_controller.rb
index 1332ba16c..1fcb9fbca 100644
--- a/app/controllers/public_timelines_controller.rb
+++ b/app/controllers/public_timelines_controller.rb
@@ -1,26 +1,18 @@
# frozen_string_literal: true
class PublicTimelinesController < ApplicationController
- layout 'public'
+ include WebAppControllerConcern
before_action :authenticate_user!, if: :whitelist_mode?
before_action :require_enabled!
- before_action :set_body_classes
- before_action :set_instance_presenter
- def show; end
+ def show
+ expires_in 0, public: true if current_account.nil?
+ end
private
def require_enabled!
- not_found unless Setting.timeline_preview
- end
-
- def set_body_classes
- @body_classes = 'with-modals'
- end
-
- def set_instance_presenter
- @instance_presenter = InstancePresenter.new
+ not_found unless user_signed_in? || Setting.timeline_preview
end
end
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
index 87612a296..a55b40103 100644
--- a/app/controllers/statuses_controller.rb
+++ b/app/controllers/statuses_controller.rb
@@ -1,21 +1,17 @@
# frozen_string_literal: true
class StatusesController < ApplicationController
- include StatusControllerConcern
include SignatureAuthentication
include Authorization
include AccountOwnedConcern
-
- layout 'public'
+ include WebAppControllerConcern
before_action :require_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_autoplay, only: :embed
skip_around_action :set_locale, if: -> { request.format == :json }
@@ -29,8 +25,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
@@ -56,10 +50,6 @@ class StatusesController < ApplicationController
private
- def set_body_classes
- @body_classes = 'with-modals'
- end
-
def set_link_headers
response.headers['Link'] = LinkHeader.new([[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]])
end
@@ -71,16 +61,12 @@ class StatusesController < ApplicationController
not_found
end
- def set_instance_presenter
- @instance_presenter = InstancePresenter.new
- end
-
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?
+ response.headers['Referrer-Policy'] = 'origin'
end
def set_autoplay
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 6616ba107..aa3969464 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -2,26 +2,23 @@
class TagsController < ApplicationController
include SignatureVerification
+ include WebAppControllerConcern
PAGE_SIZE = 20
PAGE_SIZE_MAX = 200
- layout 'public'
-
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
before_action :authenticate_user!, if: :whitelist_mode?
before_action :set_local
before_action :set_tag
before_action :set_statuses
- before_action :set_body_classes
- before_action :set_instance_presenter
skip_before_action :require_functional!, unless: :whitelist_mode?
def show
respond_to do |format|
format.html do
- expires_in 0, public: true
+ expires_in 0, public: true if current_account.nil?
end
format.rss do
@@ -55,14 +52,6 @@ class TagsController < ApplicationController
end
end
- def set_body_classes
- @body_classes = 'with-modals'
- end
-
- def set_instance_presenter
- @instance_presenter = InstancePresenter.new
- end
-
def limit_param
params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
end