reactiveadmin 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +88 -0
- data/LICENSE +21 -0
- data/README.md +81 -0
- data/app/assets/reactive_admin/bridge.js +89 -0
- data/app/controllers/reactive_admin/api_controller.rb +30 -0
- data/app/controllers/reactive_admin/client_errors_controller.rb +38 -0
- data/app/controllers/reactive_admin/manifest_controller.rb +10 -0
- data/app/controllers/reactive_admin/mcp_controller.rb +48 -0
- data/app/controllers/reactive_admin/openapi_controller.rb +13 -0
- data/app/controllers/reactive_admin/session_controller.rb +11 -0
- data/app/views/layouts/reactive_admin/embed.html.erb +30 -0
- data/lib/generators/reactiveadmin/install/install_generator.rb +341 -0
- data/lib/generators/reactiveadmin/install/templates/menu.rb.tt +25 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin.rb.tt +53 -0
- data/lib/generators/reactiveadmin/install/templates/reactive_admin_annotated.rb.tt +110 -0
- data/lib/reactive_admin/aa/v3/controller.rb +76 -0
- data/lib/reactive_admin/aa/v3/forms.rb +29 -0
- data/lib/reactive_admin/aa/v3/inputs/filters/typeahead_input.rb +51 -0
- data/lib/reactive_admin/aa/v3/inputs/typeahead_input.rb +8 -0
- data/lib/reactive_admin/aa/v3/install.rb +36 -0
- data/lib/reactive_admin/aa/v3/menu.rb +67 -0
- data/lib/reactive_admin/aa/v3/presenters.rb +102 -0
- data/lib/reactive_admin/aa/v3/registry.rb +78 -0
- data/lib/reactive_admin/aa/v3/views.rb +63 -0
- data/lib/reactive_admin/aa/v3.rb +23 -0
- data/lib/reactive_admin/aa/v4.rb +59 -0
- data/lib/reactive_admin/aa.rb +46 -0
- data/lib/reactive_admin/action_items.rb +39 -0
- data/lib/reactive_admin/action_links.rb +197 -0
- data/lib/reactive_admin/action_safety.rb +19 -0
- data/lib/reactive_admin/actions.rb +95 -0
- data/lib/reactive_admin/api_errors.rb +116 -0
- data/lib/reactive_admin/api_fallback.rb +15 -0
- data/lib/reactive_admin/api_guards.rb +445 -0
- data/lib/reactive_admin/audit.rb +72 -0
- data/lib/reactive_admin/auth/guard.rb +68 -0
- data/lib/reactive_admin/auth/token_requests.rb +15 -0
- data/lib/reactive_admin/auth.rb +135 -0
- data/lib/reactive_admin/authorizer.rb +47 -0
- data/lib/reactive_admin/background_requests.rb +33 -0
- data/lib/reactive_admin/batch_actions.rb +57 -0
- data/lib/reactive_admin/choices.rb +289 -0
- data/lib/reactive_admin/client_error.rb +70 -0
- data/lib/reactive_admin/composite_keys.rb +12 -0
- data/lib/reactive_admin/configuration.rb +221 -0
- data/lib/reactive_admin/controller_extension.rb +229 -0
- data/lib/reactive_admin/csv_injection.rb +26 -0
- data/lib/reactive_admin/date_bound.rb +31 -0
- data/lib/reactive_admin/degradation.rb +72 -0
- data/lib/reactive_admin/diagnostics.rb +16 -0
- data/lib/reactive_admin/doctor.rb +466 -0
- data/lib/reactive_admin/dry_run.rb +147 -0
- data/lib/reactive_admin/dry_run_flag.rb +18 -0
- data/lib/reactive_admin/embed.rb +73 -0
- data/lib/reactive_admin/engine.rb +47 -0
- data/lib/reactive_admin/error_keys.rb +23 -0
- data/lib/reactive_admin/exposure.rb +86 -0
- data/lib/reactive_admin/filters.rb +165 -0
- data/lib/reactive_admin/fixtures/scrubber.rb +1075 -0
- data/lib/reactive_admin/fixtures.rb +161 -0
- data/lib/reactive_admin/form_content.rb +78 -0
- data/lib/reactive_admin/form_field.rb +279 -0
- data/lib/reactive_admin/form_has_many.rb +116 -0
- data/lib/reactive_admin/form_lock.rb +71 -0
- data/lib/reactive_admin/form_payload.rb +57 -0
- data/lib/reactive_admin/form_recorder.rb +192 -0
- data/lib/reactive_admin/form_schema.rb +160 -0
- data/lib/reactive_admin/frame.rb +97 -0
- data/lib/reactive_admin/html_nodes.rb +390 -0
- data/lib/reactive_admin/html_policy.rb +338 -0
- data/lib/reactive_admin/html_rich.rb +186 -0
- data/lib/reactive_admin/implicit_defaults.rb +102 -0
- data/lib/reactive_admin/index_options.rb +41 -0
- data/lib/reactive_admin/index_payload.rb +259 -0
- data/lib/reactive_admin/index_recorder.rb +115 -0
- data/lib/reactive_admin/index_views.rb +85 -0
- data/lib/reactive_admin/inline_style.rb +125 -0
- data/lib/reactive_admin/labels_payload.rb +34 -0
- data/lib/reactive_admin/ladder.rb +268 -0
- data/lib/reactive_admin/layout_classes.rb +167 -0
- data/lib/reactive_admin/legacy_inventory.rb +547 -0
- data/lib/reactive_admin/location.rb +22 -0
- data/lib/reactive_admin/lookup_audit.rb +30 -0
- data/lib/reactive_admin/lookup_payload.rb +41 -0
- data/lib/reactive_admin/manifest.rb +36 -0
- data/lib/reactive_admin/masked_json.rb +62 -0
- data/lib/reactive_admin/masking.rb +100 -0
- data/lib/reactive_admin/mcp/access.rb +111 -0
- data/lib/reactive_admin/mcp/api.rb +123 -0
- data/lib/reactive_admin/mcp/count_tool.rb +22 -0
- data/lib/reactive_admin/mcp/layout.rb +175 -0
- data/lib/reactive_admin/mcp/output.rb +46 -0
- data/lib/reactive_admin/mcp/prompts.rb +111 -0
- data/lib/reactive_admin/mcp/server.rb +134 -0
- data/lib/reactive_admin/mcp/shapes.rb +164 -0
- data/lib/reactive_admin/mcp/tools.rb +386 -0
- data/lib/reactive_admin/mcp.rb +53 -0
- data/lib/reactive_admin/media_nodes.rb +34 -0
- data/lib/reactive_admin/menu.rb +90 -0
- data/lib/reactive_admin/menu_overlay.rb +291 -0
- data/lib/reactive_admin/node_registry.rb +47 -0
- data/lib/reactive_admin/open_api/builder.rb +156 -0
- data/lib/reactive_admin/open_api/context.rb +46 -0
- data/lib/reactive_admin/open_api/core.rb +51 -0
- data/lib/reactive_admin/open_api/operation_ids.rb +18 -0
- data/lib/reactive_admin/open_api/page_doc.rb +75 -0
- data/lib/reactive_admin/open_api/parts.rb +86 -0
- data/lib/reactive_admin/open_api/resource_doc.rb +423 -0
- data/lib/reactive_admin/open_api/security.rb +55 -0
- data/lib/reactive_admin/open_api/write_schema.rb +104 -0
- data/lib/reactive_admin/open_api.rb +41 -0
- data/lib/reactive_admin/option_source.rb +36 -0
- data/lib/reactive_admin/option_sources.rb +14 -0
- data/lib/reactive_admin/options_payload.rb +61 -0
- data/lib/reactive_admin/page_controller_extension.rb +112 -0
- data/lib/reactive_admin/page_forms.rb +181 -0
- data/lib/reactive_admin/page_payload.rb +120 -0
- data/lib/reactive_admin/param_normalizer.rb +89 -0
- data/lib/reactive_admin/paths.rb +63 -0
- data/lib/reactive_admin/permissions.rb +31 -0
- data/lib/reactive_admin/provenance.rb +57 -0
- data/lib/reactive_admin/query_guard.rb +108 -0
- data/lib/reactive_admin/ransack_guard.rb +107 -0
- data/lib/reactive_admin/rate_limit.rb +59 -0
- data/lib/reactive_admin/reactive_dsl.rb +99 -0
- data/lib/reactive_admin/readiness.rb +189 -0
- data/lib/reactive_admin/registry.rb +69 -0
- data/lib/reactive_admin/resource_meta.rb +120 -0
- data/lib/reactive_admin/resource_summary.rb +41 -0
- data/lib/reactive_admin/routes.rb +60 -0
- data/lib/reactive_admin/row_errors.rb +29 -0
- data/lib/reactive_admin/rspec.rb +116 -0
- data/lib/reactive_admin/scrubbed_error.rb +22 -0
- data/lib/reactive_admin/search.rb +79 -0
- data/lib/reactive_admin/server_timing.rb +31 -0
- data/lib/reactive_admin/show_payload.rb +88 -0
- data/lib/reactive_admin/sidebars.rb +34 -0
- data/lib/reactive_admin/site.rb +55 -0
- data/lib/reactive_admin/style_report.rb +129 -0
- data/lib/reactive_admin/style_sources.rb +83 -0
- data/lib/reactive_admin/template_actions.rb +126 -0
- data/lib/reactive_admin/template_content.rb +49 -0
- data/lib/reactive_admin/template_form.rb +442 -0
- data/lib/reactive_admin/test_support.rb +31 -0
- data/lib/reactive_admin/typeahead.rb +33 -0
- data/lib/reactive_admin/ui/assets.rb +91 -0
- data/lib/reactive_admin/ui/client_build.rb +47 -0
- data/lib/reactive_admin/ui/helper.rb +24 -0
- data/lib/reactive_admin/ui/packaged_client.rb +67 -0
- data/lib/reactive_admin/ui/shell.rb +81 -0
- data/lib/reactive_admin/ui/switch.rb +38 -0
- data/lib/reactive_admin/ui.rb +43 -0
- data/lib/reactive_admin/value_payload.rb +147 -0
- data/lib/reactive_admin/value_token.rb +36 -0
- data/lib/reactive_admin/values.rb +43 -0
- data/lib/reactive_admin/version.rb +3 -0
- data/lib/reactive_admin/write_audit.rb +60 -0
- data/lib/reactive_admin/write_guards.rb +142 -0
- data/lib/reactive_admin.rb +153 -0
- data/lib/reactiveadmin.rb +1 -0
- data/lib/tasks/reactiveadmin.rake +36 -0
- data/lib/tasks/reactiveadmin_client.rake +11 -0
- data/lib/tasks/reactiveadmin_legacy.rake +7 -0
- data/lib/tasks/reactiveadmin_styles.rake +6 -0
- data/openapi/core.yaml +1643 -0
- data/vendor/client/assets/ActionPage-XUYorI8E.js +1 -0
- data/vendor/client/assets/ActionView-BsZFcsgp.js +1 -0
- data/vendor/client/assets/CommandPalette-C59HT1ip.js +1 -0
- data/vendor/client/assets/DatePicker-DuaK0iMg.js +1 -0
- data/vendor/client/assets/DateRangeCalendar-B2BDsG-X.js +1 -0
- data/vendor/client/assets/DegradedNotice-DiH5n2DO.js +1 -0
- data/vendor/client/assets/FormDialog-pmYl8Eov.js +1 -0
- data/vendor/client/assets/FormSkeleton-DuSBZO3C.js +1 -0
- data/vendor/client/assets/FrameView-2X8cFvUt.css +1 -0
- data/vendor/client/assets/FrameView-zmUeDO8d.js +1 -0
- data/vendor/client/assets/GroupOverview-DI5T3k5K.js +1 -0
- data/vendor/client/assets/InlineForm-CMEIMgeh.js +1 -0
- data/vendor/client/assets/JsonDiff-o7JWr7CH.js +3 -0
- data/vendor/client/assets/JsonEditor-D4VXdlEx.js +1 -0
- data/vendor/client/assets/JsonView-BrJLDmSN.js +1 -0
- data/vendor/client/assets/MobileMenu-GAeFOeEb.js +1 -0
- data/vendor/client/assets/Node-SQl61V4K.js +2 -0
- data/vendor/client/assets/PageView-C-laNEPZ.js +1 -0
- data/vendor/client/assets/ResourceForm-BPjsoCY6.js +1 -0
- data/vendor/client/assets/ResourceIndex-COezAw5t.js +3 -0
- data/vendor/client/assets/ResourceOrPage-CRZGCY84.js +1 -0
- data/vendor/client/assets/ResourceShow-DweRXn18.js +1 -0
- data/vendor/client/assets/Segmented-BE9TCbph.js +1 -0
- data/vendor/client/assets/Sidebars-CsB9rFqX.js +1 -0
- data/vendor/client/assets/breadcrumb-DSA3Tlyd.js +1 -0
- data/vendor/client/assets/button-CvZ4_DFC.js +1 -0
- data/vendor/client/assets/calendar-BoyMpJIf.js +1 -0
- data/vendor/client/assets/check-C5A3J16N.js +1 -0
- data/vendor/client/assets/command-CMuk0oAt.js +1 -0
- data/vendor/client/assets/dist-CqEI82S_.js +1 -0
- data/vendor/client/assets/dist-IW4yX942.js +1 -0
- data/vendor/client/assets/editor-yqRLzgsJ.js +2 -0
- data/vendor/client/assets/external-link-C2aR4slL.js +1 -0
- data/vendor/client/assets/frames-C9gPCc3N.js +1 -0
- data/vendor/client/assets/humanize-DtU_Kpr4.js +1 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- data/vendor/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- data/vendor/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- data/vendor/client/assets/index-B51aUaAY.js +43 -0
- data/vendor/client/assets/index-Cs9rCoWM.css +2 -0
- data/vendor/client/assets/input-DByFmQPa.js +1 -0
- data/vendor/client/assets/json-De3PN-R6.css +1 -0
- data/vendor/client/assets/json-oTp7Q-d-.js +5 -0
- data/vendor/client/assets/media-D4a_En8R.js +1 -0
- data/vendor/client/assets/plus-CfJ9vo8X.js +1 -0
- data/vendor/client/assets/popover-CDtI9R8Q.js +1 -0
- data/vendor/client/assets/purify-G7QKJyJq.js +1 -0
- data/vendor/client/assets/query-CCsZN2fa.js +1 -0
- data/vendor/client/assets/recent-BrzLwL0D.js +1 -0
- data/vendor/client/assets/rich-BQc_q5T7.js +1 -0
- data/vendor/client/assets/rolldown-runtime-XKyaHtl9.js +1 -0
- data/vendor/client/assets/select-C43qDA3k.js +1 -0
- data/vendor/client/assets/sheet-BPl2n-4n.js +1 -0
- data/vendor/client/assets/textarea-BnOphXry.js +1 -0
- data/vendor/client/assets/uiMode-z0ZbRV49.js +1 -0
- data/vendor/client/assets/uiToggle-DwnRQTH1.js +1 -0
- data/vendor/client/assets/useRecordForm-X_DExEP2.js +1 -0
- data/vendor/client/assets/useRecordVisit-BRtfMi-q.js +1 -0
- data/vendor/client/assets/utils-DwBGbDkG.js +1 -0
- data/vendor/client/assets/vendor-calendar-nTZiq9oY.js +1 -0
- data/vendor/client/assets/vendor-datefns-BoC6MCnl.js +1 -0
- data/vendor/client/assets/vendor-forms-D0h8hG_S.js +55 -0
- data/vendor/client/assets/vendor-purify-BXoPR7WT.js +3 -0
- data/vendor/client/assets/vendor-query-DZ6APRNI.js +1 -0
- data/vendor/client/assets/vendor-react-C1iE8mnY.js +9 -0
- data/vendor/client/assets/vendor-router-CI6Vh4k_.js +1 -0
- data/vendor/client/assets/vendor-table-DuQ835by.js +4 -0
- data/vendor/client/index.html +24 -0
- data/vendor/client/manifest.json +867 -0
- data/vendor/client/reactiveadmin-client.json +4 -0
- metadata +350 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
require "open3"
|
|
2
|
+
require "rails/generators"
|
|
3
|
+
|
|
4
|
+
module ReactiveAdmin
|
|
5
|
+
module Generators
|
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
|
7
|
+
DOCS = "https://github.com/formhealth/reactiveadmin/blob/main/docs/guide"
|
|
8
|
+
INITIALIZERS = %w[config/initializers/reactive_admin.rb config/initializers/reactiveadmin.rb]
|
|
9
|
+
MENU = "app/admin/menu.rb"
|
|
10
|
+
DASHBOARD = "app/admin/dashboard.rb"
|
|
11
|
+
ADAPTERS = {"pundit" => "ActiveAdmin::PunditAdapter", "cancancan" => "ActiveAdmin::CanCanAdapter"}
|
|
12
|
+
AA_ROUTES = /^[ \t]*ActiveAdmin\.routes(?:\(self\)| self)[ \t]*(?:#[^\r\n]*)?\r?\n/
|
|
13
|
+
RA_ROUTES = /^[ \t]*ReactiveAdmin\.routes\b/
|
|
14
|
+
PRESETS = %w[quick guided strict]
|
|
15
|
+
MCP_MODES = %w[off read_only full]
|
|
16
|
+
UI_MODES = %w[nobody admins everyone]
|
|
17
|
+
|
|
18
|
+
# Columns worth masking, by name. Secrets and identity numbers are proposed; contact details are only
|
|
19
|
+
# named, since operators usually need to see them.
|
|
20
|
+
SECRET = /password|passcode|secret|token|api_key|private_key|otp|_digest\z|crypt|\A(?:ssn|social_security\w*|tax_id|ein|passport\w*|drivers?_license\w*|mrn|medical_record\w*|dob|date_of_birth|birth_?date|birthday)\z/
|
|
21
|
+
CONTACT = /email|phone|mobile|\Afax\z|address|street|\Acity\z|zip|postal|postcode|first_name|last_name|middle_name|full_name|maiden_name/
|
|
22
|
+
NOT_A_VALUE = /_(?:at|on|count|type)\z/
|
|
23
|
+
FOREIGN_KEY = /_id\z/
|
|
24
|
+
|
|
25
|
+
namespace "reactiveadmin:install"
|
|
26
|
+
source_root File.expand_path("templates", __dir__)
|
|
27
|
+
desc "Sets ReactiveAdmin up: an initializer (and for guided and strict, a menu that decides what the API serves), " \
|
|
28
|
+
"the API routes, and optionally the new-admin switch. Prompts in a terminal; every answer is also a flag."
|
|
29
|
+
|
|
30
|
+
class_option :preset, type: :string, enum: PRESETS,
|
|
31
|
+
desc: "quick: serve everything ActiveAdmin registers. guided (default): serve what app/admin/menu.rb lists, generated with every registration to prune. strict: serve only what you list, plus the dashboard and anything marked `reactive { expose true }`"
|
|
32
|
+
class_option :namespace, type: :string, desc: "The ActiveAdmin namespace to serve. Defaults to the one config/initializers/active_admin.rb sets, else admin."
|
|
33
|
+
class_option :mask, type: :string, banner: "a,b",
|
|
34
|
+
desc: "Attributes to mask everywhere in the API, or --no-mask for none. Defaults to the secrets found in db/schema.rb"
|
|
35
|
+
class_option :mcp, type: :string, enum: MCP_MODES, desc: "The MCP endpoint for AI agents (default off)"
|
|
36
|
+
class_option :ui, type: :string, enum: UI_MODES, desc: "Who may switch to the new admin (default nobody)"
|
|
37
|
+
class_option :yes, type: :boolean, default: false, desc: "Take the default for every question instead of prompting"
|
|
38
|
+
class_option :skip_check, type: :boolean, default: false, desc: "Don't boot the app at the end to check the setup"
|
|
39
|
+
|
|
40
|
+
# Runs first, so nothing is written for a namespace the API can't serve.
|
|
41
|
+
def resolve_namespace
|
|
42
|
+
given = options[:namespace]
|
|
43
|
+
# Written into the initializer as a bare symbol, so anything but a plain name would break the app's boot.
|
|
44
|
+
raise Thor::Error, "--namespace must be a plain name (letters, digits, underscores), not #{given.inspect}." if given.present? && !given.match?(/\A[a-z_]\w*\z/i)
|
|
45
|
+
return if namespace_name
|
|
46
|
+
|
|
47
|
+
raise Thor::Error, "ActiveAdmin's default_namespace in config/initializers/active_admin.rb is #{aa_namespace[:raw]}, " \
|
|
48
|
+
"which ReactiveAdmin can't serve under a name. Rerun with --namespace NAME."
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def choose
|
|
52
|
+
@preset = pick(:preset, "How should ReactiveAdmin start?", PRESETS, "guided", <<~HELP)
|
|
53
|
+
quick serve everything ActiveAdmin registers, with the secure defaults
|
|
54
|
+
guided serve what app/admin/menu.rb lists; it's generated with every registration, to prune
|
|
55
|
+
strict serve only what you list (plus the dashboard), and no columns that a block doesn't name
|
|
56
|
+
HELP
|
|
57
|
+
@masked = masked_attributes_choice
|
|
58
|
+
@mcp = pick(:mcp, "Turn on the MCP endpoint for AI agents?", MCP_MODES, "off", <<~HELP)
|
|
59
|
+
off no agent access
|
|
60
|
+
read_only agents read and run GET actions, as the signed-in admin
|
|
61
|
+
full agents also create, update and delete, where your policy allows
|
|
62
|
+
HELP
|
|
63
|
+
@ui = pick(:ui, "Who may switch to the new admin?", UI_MODES, "nobody", <<~HELP)
|
|
64
|
+
nobody keep the classic admin for now
|
|
65
|
+
admins users whose admin? is true (adjust in the initializer)
|
|
66
|
+
everyone every signed-in admin user
|
|
67
|
+
HELP
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def create_initializer
|
|
71
|
+
if (existing = INITIALIZERS.find { exist?(it) })
|
|
72
|
+
@kept_initializer = existing
|
|
73
|
+
say_status :skip, existing, :yellow
|
|
74
|
+
else
|
|
75
|
+
template (@preset == "quick") ? "reactive_admin.rb.tt" : "reactive_admin_annotated.rb.tt", INITIALIZERS.first
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def create_menu
|
|
80
|
+
return if @preset == "quick" || @kept_initializer
|
|
81
|
+
return say_status(:skip, MENU, :yellow) if exist?(MENU)
|
|
82
|
+
|
|
83
|
+
template "menu.rb.tt", MENU
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def mount_routes
|
|
87
|
+
routes = read("config/routes.rb")
|
|
88
|
+
if routes.match?(RA_ROUTES)
|
|
89
|
+
say_status :identical, "ReactiveAdmin.routes(self)", :blue
|
|
90
|
+
elsif (line = routes[AA_ROUTES])
|
|
91
|
+
# Same indent and line ending as ActiveAdmin's line, so a CRLF file stays CRLF.
|
|
92
|
+
inject_into_file "config/routes.rb", "#{line[/\A[ \t]*/]}ReactiveAdmin.routes(self)#{line[/\r?\n\z/]}", after: AA_ROUTES
|
|
93
|
+
else
|
|
94
|
+
say_status :error, "ActiveAdmin.routes(self) not found in config/routes.rb. Install ActiveAdmin, then add ReactiveAdmin.routes(self) after it", :red
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# The switch lives on a classic page: the dashboard is where people land.
|
|
99
|
+
def add_ui_toggle
|
|
100
|
+
return if @ui == "nobody"
|
|
101
|
+
|
|
102
|
+
dashboard = read(DASHBOARD)
|
|
103
|
+
return say_status(:identical, "reactiveadmin_ui_toggle in #{DASHBOARD}", :blue) if uncommented(dashboard).include?("reactiveadmin_ui_toggle")
|
|
104
|
+
|
|
105
|
+
if (line = dashboard[DASHBOARD_CONTENT])
|
|
106
|
+
inject_into_file DASHBOARD, "#{line[/\A[ \t]*/]} text_node reactiveadmin_ui_toggle#{line[/\r?\n\z/]}", after: DASHBOARD_CONTENT
|
|
107
|
+
else
|
|
108
|
+
say_status :warning, "No `content do` block opening on its own line in #{DASHBOARD}. Add `text_node reactiveadmin_ui_toggle` to the page people land on; see #{DOCS}/rollout.md", :yellow
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def check_authorization_adapter
|
|
113
|
+
return unless adapter
|
|
114
|
+
# ActiveAdmin also takes the adapter's class name as a string.
|
|
115
|
+
return if active_admin_config.match?(/^\s*config\.authorization_adapter\s*=\s*(["']?)(?:::)?#{adapter}\1/)
|
|
116
|
+
|
|
117
|
+
say_status :warning, "#{authorization_gem} is bundled, but ActiveAdmin doesn't use it. ReactiveAdmin authorizes through ActiveAdmin's adapter; " \
|
|
118
|
+
"if your classic admin should too, set `config.authorization_adapter = #{adapter}` in config/initializers/active_admin.rb", :yellow
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def warn_about_mcp_writes
|
|
122
|
+
say_status :warning, "MCP agents can create, update and delete wherever your policy allows. Set `reactive { mcp :read_only }` on resources they shouldn't change", :yellow if @mcp == "full"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def check_boot
|
|
126
|
+
return if options[:skip_check] || !exist?("bin/rails")
|
|
127
|
+
|
|
128
|
+
output, ok = boot_report
|
|
129
|
+
if ok
|
|
130
|
+
say_status :ok, output.lines.last.to_s.strip, :green
|
|
131
|
+
else
|
|
132
|
+
say_status :warning, "The app didn't boot with this setup. Run `bin/rails runner 'ReactiveAdmin.config'` to see why. " \
|
|
133
|
+
"#{output.lines.grep(/Error/).first.to_s.strip}", :yellow
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def show_next_steps
|
|
138
|
+
say <<~TEXT
|
|
139
|
+
|
|
140
|
+
ReactiveAdmin is installed. Next:
|
|
141
|
+
|
|
142
|
+
#{exposure_step}
|
|
143
|
+
#{DOCS}/security.md#exposure
|
|
144
|
+
2. Start Rails, sign in to the classic admin, and open /api/#{namespace_name}/_manifest.
|
|
145
|
+
3. Set `config.doctor_user`, then measure coverage: bin/rails reactiveadmin:doctor
|
|
146
|
+
#{DOCS}/doctor.md
|
|
147
|
+
#{client_step}
|
|
148
|
+
#{ui_step}
|
|
149
|
+
#{DOCS}/rollout.md
|
|
150
|
+
TEXT
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
private
|
|
154
|
+
|
|
155
|
+
# A line that opens the block, ending in `do` (with block args or a comment): a one-line block is left alone.
|
|
156
|
+
DASHBOARD_CONTENT = /^[ \t]*content\b[^\r\n]*\bdo[ \t]*(?:\|[^|\r\n]*\|)?[ \t]*(?:#[^\r\n]*)?\r?\n/
|
|
157
|
+
BOOT_CHECK = <<~RUBY.freeze
|
|
158
|
+
Rails.application.reload_routes_unless_loaded
|
|
159
|
+
configs = ReactiveAdmin::Registry.resources + ReactiveAdmin::Registry.pages
|
|
160
|
+
exposed = configs.count { ReactiveAdmin::Exposure.allowed?(it) }
|
|
161
|
+
puts "ReactiveAdmin serves \#{ReactiveAdmin.config.mount_path}/\#{ReactiveAdmin.config.namespace}: \#{exposed} of \#{configs.size} resources and pages exposed"
|
|
162
|
+
RUBY
|
|
163
|
+
|
|
164
|
+
def boot_report
|
|
165
|
+
output, status = Open3.capture2e("bin/rails", "runner", BOOT_CHECK, chdir: destination_root)
|
|
166
|
+
[output, status.success?]
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def interactive? = !options[:yes] && $stdin.tty?
|
|
170
|
+
|
|
171
|
+
def pick(name, question, choices, default, help)
|
|
172
|
+
return options[name] if options[name]
|
|
173
|
+
return default unless interactive?
|
|
174
|
+
|
|
175
|
+
say "\n#{help}"
|
|
176
|
+
ask(question, limited_to: choices, default:)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def masked_attributes_choice
|
|
180
|
+
return [] if options.key?("mask") && options[:mask].nil?
|
|
181
|
+
return split(options[:mask]) if options[:mask]
|
|
182
|
+
return proposed_masks unless interactive?
|
|
183
|
+
|
|
184
|
+
say "\nIn db/schema.rb: #{schema_summary}" if schema_columns.any?
|
|
185
|
+
answer = ask("Attributes to mask everywhere in the API (comma-separated, or none):", default: proposed_masks.join(", ").presence || "none")
|
|
186
|
+
(answer.strip == "none") ? [] : split(answer)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def split(list) = list.split(/[\s,]+/).map { it.delete_prefix(":") }.reject(&:empty?).uniq
|
|
190
|
+
|
|
191
|
+
def schema_columns
|
|
192
|
+
# An `_id` column is a foreign key unless its name says it's an identity number (tax_id).
|
|
193
|
+
@schema_columns ||= read("db/schema.rb").scan(/^\s*t\.\w+\s+["'](\w+)["']/).flatten.uniq
|
|
194
|
+
.reject { it.match?(NOT_A_VALUE) || (it.match?(FOREIGN_KEY) && !it.match?(SECRET)) }
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Rails' filter_parameters are masked already (mask_filter_parameters), so only what they miss is proposed.
|
|
198
|
+
def proposed_masks = schema_columns.select { it.match?(SECRET) && !filtered?(it) }
|
|
199
|
+
|
|
200
|
+
# Only literal entries prove coverage, the way Rails matches them (anywhere in the name). A regexp, a
|
|
201
|
+
# constant or a method call proves nothing, so the column stays proposed.
|
|
202
|
+
def filtered?(column) = filter_parameters.any? { column.downcase.include?(it.downcase) }
|
|
203
|
+
|
|
204
|
+
def filter_parameters
|
|
205
|
+
@filter_parameters ||= begin
|
|
206
|
+
code = read("config/initializers/filter_parameter_logging.rb").gsub(/(^|[ \t])#[^\r\n]*/, "\\1")
|
|
207
|
+
lists = code.scan(/filter_parameters\s*(?:\+=|=|\.concat\(|\.push\(|<<)\s*(%[iw]\[[^\]]*\]|\[[^\]]*\]|:\w+|"[^"]*"|'[^']*')/m).flatten
|
|
208
|
+
lists.flat_map { |list| list.start_with?("%") ? list[3..-2].split : list.scan(/:(\w+)|"([^"]*)"|'([^']*)'/).flatten.compact }.reject(&:empty?)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def schema_summary
|
|
213
|
+
filtered = schema_columns.select { it.match?(SECRET) && filtered?(it) }
|
|
214
|
+
contact = schema_columns.select { it.match?(CONTACT) && !filtered?(it) }
|
|
215
|
+
[
|
|
216
|
+
("already masked by filter_parameters: #{filtered.join(", ")}" if filtered.any?),
|
|
217
|
+
("personal details operators usually need (add any they shouldn't see): #{contact.join(", ")}" if contact.any?)
|
|
218
|
+
].compact.join("\n ").presence || "no secrets found"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# What app/admin registers, read statically so the generator runs before the app boots.
|
|
222
|
+
def registrations
|
|
223
|
+
@registrations ||= Dir[File.join(destination_root, "app/admin/**/*.rb")].sort.flat_map do |path|
|
|
224
|
+
next [] if path.end_with?("/#{MENU.split("/").last}")
|
|
225
|
+
|
|
226
|
+
# Each registration runs from its own `ActiveAdmin.register` to the next, so a file can hold several.
|
|
227
|
+
File.read(path).split(/(?=^[ \t]*ActiveAdmin\.register)/).filter_map { registration(it) }
|
|
228
|
+
end.uniq
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
REGISTRATION = /\A\s*ActiveAdmin\.register(_page)?\s*\(?\s*(?:["']([^"']+)["']|([A-Z][\w:]*))/
|
|
232
|
+
REQUIRED_PARENT = /^\s*belongs_to\s+:\w+(?![^\r\n]*optional:\s*true)/
|
|
233
|
+
|
|
234
|
+
def registration(chunk)
|
|
235
|
+
match = chunk.match(REGISTRATION) or return
|
|
236
|
+
page, title, model = match.captures
|
|
237
|
+
call = chunk[/\A.*?(?:\bdo\b|\{)/m] || chunk
|
|
238
|
+
name = call[/\bas:\s*["']([^"']+)["']/, 1] || title || model
|
|
239
|
+
key = name.gsub("::", "/").tr(" ", "_").underscore.tr("/", "_")
|
|
240
|
+
{kind: page ? :page : :resource, key: page ? key : key.pluralize, nested: !page && chunk.match?(REQUIRED_PARENT)}
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def menu_resources = registrations.select { it[:kind] == :resource && !it[:nested] }.map { it[:key] }
|
|
244
|
+
|
|
245
|
+
def menu_pages = registrations.select { it[:kind] == :page }.map { it[:key] }
|
|
246
|
+
|
|
247
|
+
def nested_resources = registrations.select { it[:nested] }.map { it[:key] }
|
|
248
|
+
|
|
249
|
+
def authorization_gem
|
|
250
|
+
@authorization_gem ||= ADAPTERS.keys.find do |name|
|
|
251
|
+
read("Gemfile.lock").match?(/^ {4}#{name} \(/) || read("Gemfile").match?(/^\s*gem ["']#{name}["']/)
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def adapter = ADAPTERS[authorization_gem]
|
|
256
|
+
|
|
257
|
+
def docs = DOCS
|
|
258
|
+
|
|
259
|
+
def exist?(path) = File.exist?(File.join(destination_root, path))
|
|
260
|
+
|
|
261
|
+
def read(path) = exist?(path) ? File.read(File.join(destination_root, path)) : ""
|
|
262
|
+
|
|
263
|
+
def active_admin_config = read("config/initializers/active_admin.rb")
|
|
264
|
+
|
|
265
|
+
# `--namespace`, else the name ActiveAdmin's initializer assigns, else ActiveAdmin's default. Nil when that
|
|
266
|
+
# assignment is the root namespace (false or nil) or isn't a plain name, so nothing guesses one.
|
|
267
|
+
def namespace_name
|
|
268
|
+
return options[:namespace] if options[:namespace].present?
|
|
269
|
+
|
|
270
|
+
aa_namespace[:name]
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
NAME = /\A(?::(?:"(\w+)"|'(\w+)'|(\w+))|"(\w+)"|'(\w+)')\z/
|
|
274
|
+
|
|
275
|
+
def aa_namespace = @aa_namespace ||= read_aa_namespace
|
|
276
|
+
|
|
277
|
+
# More than one assignment (say, per environment) means the right one can't be told statically.
|
|
278
|
+
def read_aa_namespace
|
|
279
|
+
found = active_admin_config.scan(/^[ \t]*config\.default_namespace[ \t]*=[ \t]*([^#\r\n]+?)[ \t]*(?:#[^\r\n]*)?\r?$/).flatten.uniq
|
|
280
|
+
return {raw: found.join(" and "), name: nil} if found.size > 1
|
|
281
|
+
|
|
282
|
+
raw = found.first
|
|
283
|
+
{raw:, name: raw ? raw.match(NAME)&.captures&.compact&.first : "admin"}
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def uncommented(code) = code.gsub(/(^|[ \t])#[^\r\n]*/, "\\1")
|
|
287
|
+
|
|
288
|
+
def masked_line
|
|
289
|
+
return "# config.masked_attributes = [:api_key, /token/]" if @masked.empty?
|
|
290
|
+
|
|
291
|
+
"config.masked_attributes = %i[#{@masked.join(" ")}]"
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def ui_line
|
|
295
|
+
case @ui
|
|
296
|
+
when "admins" then "config.ui.available = ->(user) { user.try(:admin?) } # TODO(setup): who may switch to the new admin"
|
|
297
|
+
when "everyone" then "config.ui.available = ->(_user) { true }"
|
|
298
|
+
else "# config.ui.available = ->(user) { user.admin? }"
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# A released gem carries the client (vendor/client); a git checkout has the source to build it from instead.
|
|
303
|
+
def client_step
|
|
304
|
+
return "4. The gem ships a prebuilt client, so there's nothing to build." if packaged_client?
|
|
305
|
+
|
|
306
|
+
"4. Build the client (Node.js 24 and pnpm): bin/rails reactiveadmin:client:build"
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def ui_step
|
|
310
|
+
return "Then set `config.ui.available` and add `reactiveadmin_ui_toggle` to your dashboard." if @ui == "nobody" || @kept_initializer
|
|
311
|
+
|
|
312
|
+
"People switch from the dashboard's panel; `config.ui.available` decides who sees it."
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def packaged_client? = File.exist?(File.expand_path("../../../../vendor/client/manifest.json", __dir__))
|
|
316
|
+
|
|
317
|
+
def exposure_step
|
|
318
|
+
return <<~TEXT.chomp if @kept_initializer
|
|
319
|
+
1. Check exposure: #{@kept_initializer} was kept as it is. Set `config.expose = :listed` there unless you mean
|
|
320
|
+
to serve every registration (`:all` is the default).
|
|
321
|
+
TEXT
|
|
322
|
+
|
|
323
|
+
case @preset
|
|
324
|
+
when "quick" then <<~TEXT.chomp
|
|
325
|
+
1. Exposure: everything ActiveAdmin registers is served (`config.expose = :all`). To choose instead, set
|
|
326
|
+
`:listed` and place resources in `ReactiveAdmin.menu` (app/admin/menu.rb).
|
|
327
|
+
TEXT
|
|
328
|
+
when "strict" then <<~TEXT.chomp
|
|
329
|
+
1. Expose resources: only the dashboard (the namespace's root page) and anything marked
|
|
330
|
+
`reactive { expose true }` or placed by a menu hint is served yet. Uncomment what else the API should
|
|
331
|
+
serve in #{MENU}, then work through the TODO(setup) notes in the initializer, yourself or with an agent.
|
|
332
|
+
TEXT
|
|
333
|
+
else <<~TEXT.chomp
|
|
334
|
+
1. Prune #{MENU}: it lists every registration, and the API serves only what stays. Then work through
|
|
335
|
+
the TODO(setup) notes in the initializer, yourself or with an agent.
|
|
336
|
+
TEXT
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<% if @preset == "strict" -%>
|
|
2
|
+
# What the API serves under `config.expose = :listed`, and where the new admin's menu places it.
|
|
3
|
+
# Only the dashboard and anything marked `reactive { expose true }` or placed by a menu hint is served yet:
|
|
4
|
+
# uncomment what else should be. Groups, links and hiding: <%= docs %>/dsl.md#menu-overlay
|
|
5
|
+
ReactiveAdmin.menu do
|
|
6
|
+
<% menu_resources.each do |key| -%>
|
|
7
|
+
# resources :<%= key %>
|
|
8
|
+
<% end -%>
|
|
9
|
+
<% menu_pages.each do |key| -%>
|
|
10
|
+
# page :<%= key %>
|
|
11
|
+
<% end -%>
|
|
12
|
+
end
|
|
13
|
+
<% else -%>
|
|
14
|
+
# What the API serves under `config.expose = :listed`, and where the new admin's menu places it.
|
|
15
|
+
# Generated with every registration in app/admin: delete what the API shouldn't serve.
|
|
16
|
+
# Groups, links and hiding: <%= docs %>/dsl.md#menu-overlay
|
|
17
|
+
ReactiveAdmin.menu do
|
|
18
|
+
<% menu_resources.each do |key| -%>
|
|
19
|
+
resources :<%= key %>
|
|
20
|
+
<% end -%>
|
|
21
|
+
<% menu_pages.each do |key| -%>
|
|
22
|
+
page :<%= key %>
|
|
23
|
+
<% end -%>
|
|
24
|
+
end
|
|
25
|
+
<% end -%>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# ReactiveAdmin serves your ActiveAdmin namespace as a JSON API, an MCP server and a React client.
|
|
2
|
+
# Every option: <%= docs %>/configuration.md
|
|
3
|
+
ReactiveAdmin.configure do |config|
|
|
4
|
+
# The API lives at <mount_path>/<namespace>, here /api/<%= namespace_name %>.
|
|
5
|
+
config.namespace = :<%= namespace_name %>
|
|
6
|
+
config.mount_path = "/api"
|
|
7
|
+
|
|
8
|
+
# Serves every registration your policy permits. `:listed` serves only what ReactiveAdmin.menu,
|
|
9
|
+
# exposed_resources or `reactive { expose true }` names; see <%= docs %>/security.md#exposure
|
|
10
|
+
config.expose = :all
|
|
11
|
+
|
|
12
|
+
# Secure defaults; see <%= docs %>/security.md#checklist
|
|
13
|
+
config.implicit_defaults = :secure
|
|
14
|
+
config.authorize_custom_actions = true
|
|
15
|
+
config.require_lock = true
|
|
16
|
+
config.value_token = true
|
|
17
|
+
config.mask_filter_parameters = true
|
|
18
|
+
config.mask_csv = true
|
|
19
|
+
<%= masked_line %>
|
|
20
|
+
# config.sensitive_resources = [] # route keys whose display names identify a person
|
|
21
|
+
# config.html_trusted_hosts = [] # also allow them in your CSP; see <%= docs %>/security.md#content-security-policy
|
|
22
|
+
|
|
23
|
+
# Authorization runs through ActiveAdmin's config.authorization_adapter; see <%= docs %>/security.md#authorization
|
|
24
|
+
<% if adapter -%>
|
|
25
|
+
# <%= authorization_gem %> is bundled: ActiveAdmin uses it with `config.authorization_adapter = <%= adapter %>`.
|
|
26
|
+
<% end -%>
|
|
27
|
+
<% if authorization_gem == "pundit" -%>
|
|
28
|
+
# If your base controller runs Pundit's verify_authorized:
|
|
29
|
+
# config.after_authorize = ->(controller) { controller.skip_authorization }
|
|
30
|
+
<% else -%>
|
|
31
|
+
# config.after_authorize = ->(controller) { ... } # for base controllers that verify authorization
|
|
32
|
+
<% end -%>
|
|
33
|
+
|
|
34
|
+
# The user `rake reactiveadmin:doctor` samples pages as; see <%= docs %>/doctor.md
|
|
35
|
+
# config.doctor_user = -> { User.find_by!(email: "ops@example.com") }
|
|
36
|
+
|
|
37
|
+
# Serve the built client at the classic URLs; see <%= docs %>/rollout.md
|
|
38
|
+
<%= ui_line %>
|
|
39
|
+
# config.ui.default = :classic
|
|
40
|
+
|
|
41
|
+
# Bearer tokens and the MCP endpoint; see <%= docs %>/mcp.md
|
|
42
|
+
<% if @mcp == "off" -%>
|
|
43
|
+
# config.mcp.enabled = false
|
|
44
|
+
<% else -%>
|
|
45
|
+
config.mcp.enabled = true
|
|
46
|
+
config.mcp.default = :<%= @mcp %>
|
|
47
|
+
# TODO(setup): agents sign in with a bearer token; resolve it to a user.
|
|
48
|
+
<% end -%>
|
|
49
|
+
# config.auth = ReactiveAdmin::Auth.any(
|
|
50
|
+
# ReactiveAdmin::Auth::Session.new,
|
|
51
|
+
# ReactiveAdmin::Auth::Bearer.new { |token, request| ... } # nil, a user, or {user:, scopes:, client_id:}
|
|
52
|
+
# )
|
|
53
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# ReactiveAdmin serves your ActiveAdmin namespace as a JSON API, an MCP server and a React client.
|
|
2
|
+
#
|
|
3
|
+
# Every setting is listed with its default. Work through the TODO(setup) notes, yourself or with an agent;
|
|
4
|
+
# the rest are secure as they are. Every option: <%= docs %>/configuration.md
|
|
5
|
+
ReactiveAdmin.configure do |config|
|
|
6
|
+
# Where the API lives: <mount_path>/<namespace>, here /api/<%= namespace_name %>.
|
|
7
|
+
config.namespace = :<%= namespace_name %>
|
|
8
|
+
config.mount_path = "/api"
|
|
9
|
+
|
|
10
|
+
## What the API serves (<%= docs %>/security.md#exposure)
|
|
11
|
+
|
|
12
|
+
# :listed serves only what app/admin/menu.rb places, exposed_resources names, or `reactive { expose true }`
|
|
13
|
+
# marks; anything else answers 404. The default, :all, serves every registration the policy permits.
|
|
14
|
+
# TODO(setup): prune app/admin/menu.rb to what the API should serve.
|
|
15
|
+
config.expose = :listed
|
|
16
|
+
# Nested-only or hidden resources no menu places, by route key.
|
|
17
|
+
# config.exposed_resources = []
|
|
18
|
+
<% if nested_resources.any? -%>
|
|
19
|
+
# Nested under a required parent, so the menu can't place them: <%= nested_resources.join(", ") %>
|
|
20
|
+
<% end -%>
|
|
21
|
+
|
|
22
|
+
# Sections without a block show a safe subset of columns (no secrets, json and long text summarized).
|
|
23
|
+
# :all is ActiveAdmin's own behavior.
|
|
24
|
+
config.implicit_defaults = :secure
|
|
25
|
+
<% if @preset == "strict" -%>
|
|
26
|
+
# Sections without a block show nothing at all, so every column shown is one you named. Default false.
|
|
27
|
+
config.strict_defaults = true
|
|
28
|
+
<% else -%>
|
|
29
|
+
# true: sections without a block show nothing, so every column shown is one you named.
|
|
30
|
+
# config.strict_defaults = false
|
|
31
|
+
<% end -%>
|
|
32
|
+
|
|
33
|
+
## Masking (<%= docs %>/security.md#masking)
|
|
34
|
+
|
|
35
|
+
# Values of these attributes are masked in every index, show, form and export.
|
|
36
|
+
# TODO(setup): confirm the list; add anything operators shouldn't see.
|
|
37
|
+
<%= masked_line %>
|
|
38
|
+
# Also mask what Rails' filter_parameters names (passwords, tokens and the like).
|
|
39
|
+
config.mask_filter_parameters = true
|
|
40
|
+
# Mask the same attributes in CSV exports, classic and API alike.
|
|
41
|
+
config.mask_csv = true
|
|
42
|
+
# Route keys whose display names identify a person: their lookups are audited.
|
|
43
|
+
# TODO(setup): list resources whose names identify a person (patients, customers).
|
|
44
|
+
# config.sensitive_resources = []
|
|
45
|
+
|
|
46
|
+
## Writes and actions
|
|
47
|
+
|
|
48
|
+
# Check every custom member, collection and batch action through your authorization adapter.
|
|
49
|
+
config.authorize_custom_actions = true
|
|
50
|
+
# Updates must send back the form's lock, so two people can't overwrite each other.
|
|
51
|
+
config.require_lock = true
|
|
52
|
+
# JSON values open only through a short-lived signed link, issued per user, record and field.
|
|
53
|
+
config.value_token = true
|
|
54
|
+
|
|
55
|
+
## Authorization (<%= docs %>/security.md#authorization)
|
|
56
|
+
|
|
57
|
+
# ActiveAdmin's config.authorization_adapter decides every read, write and action.
|
|
58
|
+
<% if adapter -%>
|
|
59
|
+
# <%= authorization_gem %> is bundled: ActiveAdmin uses it with `config.authorization_adapter = <%= adapter %>`.
|
|
60
|
+
<% end -%>
|
|
61
|
+
<% if authorization_gem == "pundit" -%>
|
|
62
|
+
# If your base controller runs Pundit's verify_authorized:
|
|
63
|
+
# config.after_authorize = ->(controller) { controller.skip_authorization }
|
|
64
|
+
<% else -%>
|
|
65
|
+
# For base controllers that verify authorization themselves:
|
|
66
|
+
# config.after_authorize = ->(controller) { ... }
|
|
67
|
+
<% end -%>
|
|
68
|
+
|
|
69
|
+
## Limits (<%= docs %>/security.md#page-size-sorting-exports-and-rate-limits)
|
|
70
|
+
|
|
71
|
+
# config.max_per_page = 100
|
|
72
|
+
# config.max_export_rows = 10_000
|
|
73
|
+
# Requests per user in a window, by bucket (options, lookup, export, value, mcp, default).
|
|
74
|
+
# config.rate_limits = {export: [5, 1.minute]}
|
|
75
|
+
|
|
76
|
+
## Audit (<%= docs %>/security.md#audit-envelope)
|
|
77
|
+
|
|
78
|
+
# Publish an audit event for every API show and edit read. Default false.
|
|
79
|
+
# config.audit_views = true
|
|
80
|
+
|
|
81
|
+
## Coverage (<%= docs %>/doctor.md)
|
|
82
|
+
|
|
83
|
+
# TODO(setup): the user `rake reactiveadmin:doctor` samples pages as.
|
|
84
|
+
# config.doctor_user = -> { User.find_by!(email: "ops@example.com") }
|
|
85
|
+
|
|
86
|
+
## The new admin (<%= docs %>/rollout.md)
|
|
87
|
+
|
|
88
|
+
# Who may switch to the new admin at the classic URLs. Default: nobody.
|
|
89
|
+
<%= ui_line %>
|
|
90
|
+
# The UI an available user starts in, until they choose: :classic or :new.
|
|
91
|
+
# config.ui.default = :classic
|
|
92
|
+
|
|
93
|
+
## Agents (<%= docs %>/mcp.md)
|
|
94
|
+
|
|
95
|
+
<% if @mcp == "off" -%>
|
|
96
|
+
# The MCP endpoint at /api/<%= namespace_name %>/_mcp. Default false.
|
|
97
|
+
# config.mcp.enabled = false
|
|
98
|
+
<% else -%>
|
|
99
|
+
# The MCP endpoint at /api/<%= namespace_name %>/_mcp. Agents act as the signed-in user, through the same policy.
|
|
100
|
+
config.mcp.enabled = true
|
|
101
|
+
# What agents get of a resource without `reactive { mcp ... }`: :read_only, :none or :full.
|
|
102
|
+
config.mcp.default = :<%= @mcp %>
|
|
103
|
+
# TODO(setup): agents sign in with a bearer token; resolve it to a user in config.auth below.
|
|
104
|
+
<% end -%>
|
|
105
|
+
# Session sign-in, plus bearer tokens for agents and scripts.
|
|
106
|
+
# config.auth = ReactiveAdmin::Auth.any(
|
|
107
|
+
# ReactiveAdmin::Auth::Session.new,
|
|
108
|
+
# ReactiveAdmin::Auth::Bearer.new { |token, request| ... } # nil, a user, or {user:, scopes:, client_id:}
|
|
109
|
+
# )
|
|
110
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
module AA
|
|
3
|
+
module V3
|
|
4
|
+
# What AA's controllers hold: inherited_resources' record, the filtered collection and scope
|
|
5
|
+
# chain, and the names of the hooks our prepended modules override.
|
|
6
|
+
module Controller
|
|
7
|
+
def base_controller = ::ActiveAdmin::BaseController
|
|
8
|
+
|
|
9
|
+
def config_of(controller) = controller.send(:active_admin_config)
|
|
10
|
+
|
|
11
|
+
def resource(controller) = controller.send(:resource)
|
|
12
|
+
|
|
13
|
+
def build_resource(controller) = controller.send(:build_resource)
|
|
14
|
+
|
|
15
|
+
# The permitted attributes AA assigns on create and update, as the list `assign_attributes` takes.
|
|
16
|
+
def resource_params(controller) = controller.send(:resource_params)
|
|
17
|
+
|
|
18
|
+
# The record inherited_resources memoized, which a custom action may have set itself.
|
|
19
|
+
def resource_ivar(controller) = (controller.send(:get_resource_ivar) if controller.respond_to?(:get_resource_ivar, true))
|
|
20
|
+
|
|
21
|
+
# inherited_resources also memoizes the params it built the record from.
|
|
22
|
+
def reset_resource_ivar(controller)
|
|
23
|
+
controller.send(:set_resource_ivar, nil)
|
|
24
|
+
controller.instance_variable_set(:@resource_params, nil)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Applies AA's filtering, scoping, sorting and pagination; must run before `current_scope`
|
|
28
|
+
# and `collection_before_scope` have anything to report.
|
|
29
|
+
def collection(controller) = controller.send(:collection)
|
|
30
|
+
|
|
31
|
+
def current_scope(controller) = controller.send(:current_scope)
|
|
32
|
+
|
|
33
|
+
def collection_before_scope(controller) = controller.send(:collection_before_scope)
|
|
34
|
+
|
|
35
|
+
# The resource's base relation before authorization, filters and scopes, under its parent when nested.
|
|
36
|
+
def scoped_collection(controller) = controller.send(:scoped_collection).all
|
|
37
|
+
|
|
38
|
+
def scope_chain(controller, scope, chain) = controller.send(:scope_chain, scope, chain)
|
|
39
|
+
|
|
40
|
+
# A record found, decorated and authorized for reading the way AA's `resource` does.
|
|
41
|
+
def find_authorized_resource(controller)
|
|
42
|
+
record = controller.send(:apply_decorations, controller.send(:find_resource))
|
|
43
|
+
controller.send(:authorize_resource!, record)
|
|
44
|
+
record
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Looks a composite-key record up from its joined param: the last key part takes any remaining
|
|
48
|
+
# delimiters, since it is the one most likely to hold them (a timestamp, a slug). Nil when the
|
|
49
|
+
# key is a single column, which AA's own `find_resource` handles.
|
|
50
|
+
def find_composite_resource(controller)
|
|
51
|
+
klass = config_of(controller).resource_class
|
|
52
|
+
key = klass.primary_key
|
|
53
|
+
return unless key.is_a?(Array)
|
|
54
|
+
|
|
55
|
+
controller.send(:scoped_collection).find(controller.params[:id].to_s.split(klass.param_delimiter, key.size))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Formats the resource's controller answers, for resources that declare no download links.
|
|
59
|
+
def default_download_formats(config) = config.controller.formats
|
|
60
|
+
|
|
61
|
+
# Methods of AA's resource controller that refuse formats outside the download links.
|
|
62
|
+
def format_guard_names = %i[restrict_format_access!]
|
|
63
|
+
|
|
64
|
+
# The controller method AA asks which layout to render with.
|
|
65
|
+
def layout_hook = :determine_active_admin_layout
|
|
66
|
+
|
|
67
|
+
# Page and resource controllers are separate classes in AA, so each gets its own list.
|
|
68
|
+
def prepend_controller_extensions(page:, resource:)
|
|
69
|
+
{::ActiveAdmin::PageController => page, ::ActiveAdmin::ResourceController => resource}.each do |controller, mods|
|
|
70
|
+
mods.each { |mod| controller.prepend(mod) unless controller.include?(mod) }
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
module AA
|
|
3
|
+
module V3
|
|
4
|
+
# AA's form builder and the Formtastic inputs behind it.
|
|
5
|
+
module Forms
|
|
6
|
+
def form_builder = ::ActiveAdmin::FormBuilder
|
|
7
|
+
|
|
8
|
+
# The input Formtastic would render for `method`: AA's `as:` default unless `options[:as]` says otherwise.
|
|
9
|
+
def build_input(builder, view, method, options)
|
|
10
|
+
options[:as] ||= builder.send(:default_input_type, method, options)
|
|
11
|
+
builder.send(:namespaced_input_class, options[:as]).new(builder, view, builder.object, builder.object_name, method, options)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# :check_boxes and :hidden inputs name their params differently from the rest.
|
|
15
|
+
def input_kind(input)
|
|
16
|
+
case input
|
|
17
|
+
when ::Formtastic::Inputs::CheckBoxesInput then :check_boxes
|
|
18
|
+
when ::Formtastic::Inputs::HiddenInput then :hidden
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Columns `f.inputs` shows without a list: the model's, less `except` and what AA filters out.
|
|
23
|
+
def default_form_columns(builder, except: nil)
|
|
24
|
+
builder.send(:default_columns_for_object) - [*except, *filter_attributes]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|