mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 08:22:04 +08:00
FIX: Allow plugins to correctly extend API key scopes. (#12113)
Adding a scope from a plugin was broken. This commit fixes it and adds a test. It also documents the instance method and renames the serialized "id" attribute to "scope_id" to avoid a conflict when the scope also has a parameter with the same name.
This commit is contained in:
@ -27,7 +27,7 @@ class Admin::ApiController < Admin::AdminController
|
||||
memo.tap do |m|
|
||||
m[resource] = actions.map do |k, v|
|
||||
{
|
||||
id: "#{resource}:#{k}",
|
||||
scope_id: "#{resource}:#{k}",
|
||||
key: k,
|
||||
name: k.to_s.gsub('_', ' '),
|
||||
params: v[:params],
|
||||
@ -99,7 +99,7 @@ class Admin::ApiController < Admin::AdminController
|
||||
|
||||
def build_scopes
|
||||
params.require(:key)[:scopes].to_a.map do |scope_params|
|
||||
resource, action = scope_params[:id].split(':')
|
||||
resource, action = scope_params[:scope_id].split(':')
|
||||
|
||||
mapping = ApiKeyScope.scope_mappings.dig(resource.to_sym, action.to_sym)
|
||||
raise Discourse::InvalidParameters if mapping.nil? # invalid mapping
|
||||
|
Reference in New Issue
Block a user