FEATURE: Add API scope for /logs route (#24956)

Adds an API scope for accessing Logster's routes. This one is a bit
different than routes from core because it is mounted like

```
mount Logster::Web => "/logs"
```

and doesn't have all the route info a traditional rails app/engine does.
This commit is contained in:
Blake Erickson 2023-12-18 19:45:04 -07:00 committed by GitHub
parent 4c8bc34475
commit 3380d283c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -234,6 +234,11 @@ class ApiKeyScope < ActiveRecord::Base
actions: %w[users#create groups#index], actions: %w[users#create groups#index],
}, },
}, },
logs: {
messages: {
actions: [Logster::Web],
},
},
} }
parse_resources!(mappings) parse_resources!(mappings)
@ -291,6 +296,11 @@ class ApiKeyScope < ActiveRecord::Base
if actions.include?(action) && api_supported_path && !excluded_paths.include?(path) if actions.include?(action) && api_supported_path && !excluded_paths.include?(path)
urls << "#{engine_mount_path}#{path} (#{route.verb})" urls << "#{engine_mount_path}#{path} (#{route.verb})"
end end
if actions.include?(Logster::Web)
urls << "/logs/messages.json (POST)"
urls << "/logs/show/:id.json (GET)"
end
end end
end end
end end

View File

@ -5017,6 +5017,8 @@ en:
commenting: Necessary for the WP Discourse plugin commenting features. commenting: Necessary for the WP Discourse plugin commenting features.
discourse_connect: Necessary for the WP Discourse plugin DiscourseConnect features. discourse_connect: Necessary for the WP Discourse plugin DiscourseConnect features.
utilities: Necessary if you use WP Discourse plugin Utilities. utilities: Necessary if you use WP Discourse plugin Utilities.
logs:
messages: List messages from /logs or get a specific log message.
web_hooks: web_hooks:
title: "Webhooks" title: "Webhooks"

View File

@ -440,6 +440,7 @@ RSpec.describe Admin::ApiController do
"search", "search",
"invites", "invites",
"wordpress", "wordpress",
"logs",
) )
topic_routes = [ topic_routes = [
@ -479,6 +480,10 @@ RSpec.describe Admin::ApiController do
"/u/:username/feature-topic (PUT)", "/u/:username/feature-topic (PUT)",
"/u/:username/clear-featured-topic (PUT)", "/u/:username/clear-featured-topic (PUT)",
) )
expect(
scopes["logs"].any? { |h| h["urls"].include?("/logs/messages.json (POST)") },
).to be_truthy
end end
end end