mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 21:54:41 +08:00
Rename plugin API key scope resources to use shorter, cleaner names: - automations_trigger → automation (action: post → trigger_automation) - discourse_ai → ai - discourse_data_explorer → data_explorer Includes reversible migrations to update existing api_key_scopes records in the database and updated locale keys to match the new resource names. Also adds safety improvements: - ApiKeyScope#permits? returns false when mapping is nil, gracefully handling renamed or removed scopes - ApiKeyScopeSerializer uses safe navigation to avoid errors for missing scope mappings - Scope resources are now sorted alphabetically in both the API response and the admin UI
21 lines
499 B
Ruby
21 lines
499 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ApiKeyScopeSerializer < ApplicationSerializer
|
|
attributes :resource, :action, :parameters, :urls, :allowed_parameters, :key
|
|
|
|
def parameters
|
|
ApiKeyScope.scope_mappings.dig(object.resource.to_sym, object.action.to_sym)&.dig(:params).to_a
|
|
end
|
|
|
|
def urls
|
|
ApiKeyScope.scope_mappings.dig(object.resource.to_sym, object.action.to_sym)&.dig(:urls).to_a
|
|
end
|
|
|
|
def action
|
|
object.action.to_s.gsub("_", " ")
|
|
end
|
|
|
|
def key
|
|
object.action
|
|
end
|
|
end
|