Open geekelo opened 1 month ago
This code registers a Doorkeeper::Application
model with ActiveAdmin, which is a framework for creating administration interfaces in Ruby on Rails applications. The Doorkeeper::Application
model is part of the Doorkeeper gem, which is used to manage OAuth 2.0 authorization in Rails applications.
Here's a breakdown of what each section of the code does:
permit_params :name, :redirect_uri, :confidential, :scopes, :use
:
Specifies which parameters are permitted when creating or updating a Doorkeeper::Application
. This prevents mass assignment vulnerabilities by only allowing specific attributes to be modified.
includes :owner
:
Ensures that the associated owner
is eager-loaded, reducing the number of database queries.
before_create
:
This callback sets the owner
of the Doorkeeper::Application
to the current admin user when a new application is created.
before_create do |application|
application.owner = current_admin_user
end
menu parent: 'Configuration', label: 'OAuth Apps'
:scope('All', default: true) { |scope| scope.all }
:
Creates a default scope that shows all Doorkeeper::Application
records.
scope('BanaanCrystal Apps') { |scope| scope.where(owner_type: 'AdminUser') }
:
Creates a scope to filter and show only applications owned by AdminUser
(likely indicating applications specific to your system).
scope('Store Integration Apps') { |scope| scope.where(owner_type: 'StoreIntegration') }
:
Creates a scope to filter and show only applications related to StoreIntegration
.
preserve_default_filters!
:
Keeps the default filters provided by ActiveAdmin.
remove_filter :access_grants, :access_tokens, :authorized_tokens
:
Removes unnecessary filters for these associations to simplify the interface.
index do ... end
:
Defines how the index (list) page for Doorkeeper::Application
should be displayed in the admin interface.
id
, name
, use
, redirect_uri
, scopes
, owner_type
, updated_at
, and actions (edit, delete)."Owner/Store"
column displays either the AdminUser
who owns the application or, if it's a StoreIntegration
, the name of the store associated with it.column 'Owner/Store' do |doorkeeper_application|
if doorkeeper_application.owner_type == 'StoreIntegration'
StoreIntegration.find(doorkeeper_application.owner.id).store.name
else
doorkeeper_application.owner
end
end
form do |f| ... end
:
Defines the form for creating or editing a Doorkeeper::Application
. It includes fields for name
, use
, redirect_uri
, confidential
, and scopes
.
form do |f|
f.inputs do
f.input :name
f.input :use
f.input :redirect_uri
f.input :confidential
f.input :scopes
end
f.actions
end
This configuration provides an admin interface to manage OAuth applications within your system, allowing admins to create, view, update, and delete OAuth applications, as well as view details like their owners, scopes, and redirect URIs. The customization of scopes, filters, and forms makes the admin interface more intuitive and aligned with your specific application's needs.
FILE