DEV: Keep track of controller actions that hijack

This commit is contained in:
Daniel Waterworth 2023-12-27 16:23:40 -06:00
parent a7fe2e1a48
commit c9f3edbb7e
17 changed files with 60 additions and 0 deletions

View File

@ -44,6 +44,7 @@ class Admin::EmojisController < Admin::AdminController
render json: data.as_json, status: good ? 200 : 422
end
end
hijacks :create
def destroy
name = params.require(:id)

View File

@ -59,6 +59,7 @@ class Admin::ReportsController < Admin::StaffController
render_json_dump(reports: reports)
end
end
hijacks :bulk
def show
report_type = params[:type]
@ -82,6 +83,7 @@ class Admin::ReportsController < Admin::StaffController
render_json_dump(report: report)
end
end
hijacks :show
private

View File

@ -168,6 +168,7 @@ class Admin::SiteTextsController < Admin::AdminController
render json: success_json
end
end
hijacks :reseed
protected

View File

@ -32,6 +32,7 @@ class Admin::ThemesController < Admin::AdminController
end
end
end
hijacks :upload_asset
def generate_key_pair
require "sshkey"
@ -163,6 +164,7 @@ class Admin::ThemesController < Admin::AdminController
rescue Theme::SettingsMigrationError => err
render_json_error err.message
end
hijacks :import
def index
@themes = Theme.include_relations.order(:name)

View File

@ -484,6 +484,7 @@ class Admin::UsersController < Admin::StaffController
end
end
end
hijacks :destroy
def badges
end

View File

@ -697,6 +697,7 @@ class GroupsController < ApplicationController
end
end
end
hijacks :test_email_settings
protected

View File

@ -15,4 +15,5 @@ class InlineOneboxController < ApplicationController
render json: { "inline-oneboxes" => oneboxes }
end
end
hijacks :show
end

View File

@ -419,6 +419,7 @@ class InvitesController < ApplicationController
end
end
end
hijacks :upload_csv
private

View File

@ -45,4 +45,5 @@ class OneboxController < ApplicationController
end
end
end
hijacks :show
end

View File

@ -186,6 +186,7 @@ class StaticController < ApplicationController
end
end
end
hijacks :favicon
def cdn_asset
is_asset_path

View File

@ -241,6 +241,7 @@ class TagsController < ::ApplicationController
end
end
end
hijacks :upload
def list_unused
guardian.ensure_can_admin_tags!

View File

@ -964,6 +964,7 @@ class TopicsController < ApplicationController
render body: nil
end
end
hijacks :timings
def feed
raise Discourse::NotFound if !Post.exists?(topic_id: params[:topic_id])
@ -1206,6 +1207,7 @@ class TopicsController < ApplicationController
end
end
end
hijacks :summary
private

View File

@ -69,6 +69,7 @@ class UploadsController < ApplicationController
end
end
end
hijacks :create
def lookup_urls
params.permit(short_urls: [])

View File

@ -35,6 +35,7 @@ class UserAvatarsController < ApplicationController
raise Discourse::NotFound
end
end
hijacks :refresh_gravatar
def show_proxy_letter
is_asset_path
@ -59,6 +60,7 @@ class UserAvatarsController < ApplicationController
end
end
end
hijacks :show_proxy_letter
def show_letter
is_asset_path
@ -80,6 +82,7 @@ class UserAvatarsController < ApplicationController
send_file image, disposition: nil
end
end
hijacks :show_letter
def show
is_asset_path
@ -89,6 +92,7 @@ class UserAvatarsController < ApplicationController
hijack { show_in_site(params[:hostname]) }
end
end
hijacks :show
protected

View File

@ -1780,6 +1780,7 @@ class UsersController < ApplicationController
end
end
end
hijacks :revoke_account
def revoke_auth_token
user = fetch_user_from_params

View File

@ -6,6 +6,22 @@ require "method_profiler"
# For cases where we are making remote calls like onebox or proxying files and so on this helps
# free up a unicorn worker while the remote IO is happening
module Hijack
module ClassMethods
def hijacks(method)
Hijack.hijacks << [self, method]
end
end
class << self
def included(base)
base.extend ClassMethods
end
def hijacks
@hijacks ||= []
end
end
def hijack(info: nil, &blk)
controller_class = self.class

23
lib/tasks/hijacks.rake Normal file
View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
task "hijacks" => "environment" do
Rails.application.eager_load!
hijacks = Hijack.hijacks
Rails.application.routes.routes.each do |route|
path = route.path.spec.to_s
controller = route.requirements[:controller]
action = route.requirements[:action]
if path && controller && action
action = action.to_sym
begin
controller = "#{controller}_controller".classify.constantize
rescue StandardError
end
puts path if hijacks.include?([controller, action])
end
end
end