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:
Roman Rizzi
2021-02-17 14:42:44 -03:00
committed by GitHub
parent a174c8b8d4
commit 07cf0f9460
5 changed files with 31 additions and 10 deletions

View File

@ -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