A platform for community discussion. Free, open, simple.
FIX: Missing allowed urls when displaying granualar API key scopes.
Alan Guo Xiang Tan4e67297a7c08
diff --git a/app/models/api_key_scope.rb b/app/models/api_key_scope.rbindex ba57361fa9f..f0dcc91415a 100644--- a/app/models/api_key_scope.rb+++ b/app/models/api_key_scope.rb@@ -88,32 +88,29 @@ class ApiKeyScope < ActiveRecord::Baseenddef find_urls(actions:, methods:)- action_urls = []- method_urls = []+ urls = []if actions.present?- Rails.application.routes.routes.reduce([]) do |memo, route|+ Rails.application.routes.routes.each do |route|defaults = route.defaultsaction = "#{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]- memo.tap do |m|- if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)- m << "#{path} (#{route.verb})"- end+ if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)+ urls << "#{path} (#{route.verb})"endendendif methods.present?methods.each do |method|- method_urls << "* (#{method})"+ urls << "* (#{method})"endend- action_urls + method_urls+ urlsendenddiff --git a/spec/models/api_key_scope_spec.rb b/spec/models/api_key_scope_spec.rbnew file mode 100644index 00000000000..48ad48d4e97--- /dev/null+++ b/spec/models/api_key_scope_spec.rb@@ -0,0 +1,12 @@+# frozen_string_literal: true++require 'rails_helper'++describe ApiKeyScope do+ describe '.find_urls' do+ it 'should return the right urls' do+ expect(ApiKeyScope.find_urls(actions: ["posts#create"], methods: []))+ .to contain_exactly("/posts (POST)")+ end+ end+end