A platform for community discussion. Free, open, simple.
FIX: Include engine mount path for API scopes added by plugins (#16154)
Osama Sayegh8d96761a4f67
diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rbindex 9d26803ec40..a0b86bf590b 100644--- a/app/models/api_key_scope.rb+++ b/app/models/api_key_scope.rb@@ -106,22 +106,26 @@ class ApiKeyScope < ActiveRecord::Baseurls = []if actions.present?- routes = Rails.application.routes.routes.to_a+ route_sets = [Rails.application.routes]Rails::Engine.descendants.each do |engine|next if engine == Rails::Application # abstract engine, can't call routes on itnext if engine == Discourse::Application # equiv. to Rails.application- routes.concat(engine.routes.routes.to_a)+ route_sets << engine.routesend- routes.each do |route|- defaults = route.defaults- action = "#{defaults[:controller].to_s}##{defaults[:action]}"- path = route.path.spec.to_s.gsub(/\(\.:format\)/, '')- api_supported_path = path.end_with?('.rss') || route.path.requirements[:format]&.match?('json')- excluded_paths = %w[/new-topic /new-message /exception]-- if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)- urls << "#{path} (#{route.verb})"+ route_sets.each do |set|+ engine_mount_path = set.find_script_name({}).presence+ engine_mount_path = nil if engine_mount_path == "/"+ set.routes.each do |route|+ defaults = route.defaults+ action = "#{defaults[:controller].to_s}##{defaults[:action]}"+ path = route.path.spec.to_s.gsub(/\(\.:format\)/, '')+ api_supported_path = path.end_with?('.rss') || route.path.requirements[:format]&.match?('json')+ excluded_paths = %w[/new-topic /new-message /exception]++ if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)+ urls << "#{engine_mount_path}#{path} (#{route.verb})"+ endendendend