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,547 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
4
|
+
module ReactiveAdmin
|
|
5
|
+
# Everything the new admin still leans on classic ActiveAdmin for, as a checklist that can shrink:
|
|
6
|
+
# custom views behind the ladder, classic-only actions and forms, degradations, html-heavy views,
|
|
7
|
+
# skipped filters and classic menu links. Items name resources, actions and structural paths,
|
|
8
|
+
# never record values. `api` guard declarations and menu overlay links are decisions, so they are not listed.
|
|
9
|
+
# `rake reactiveadmin:legacy` prints it and holds it to a baseline.
|
|
10
|
+
class LegacyInventory
|
|
11
|
+
VERSION = 1
|
|
12
|
+
IMPACTS = %w[high med low].freeze
|
|
13
|
+
HTML_THRESHOLD = 0.10
|
|
14
|
+
MIN_HTML_LEAVES = 2
|
|
15
|
+
|
|
16
|
+
# category => [label, suggested WP]
|
|
17
|
+
CATEGORIES = {
|
|
18
|
+
"view_unsupported" => ["Views answering 501 (classic only)", nil],
|
|
19
|
+
"view_iframe" => ["Views in an iframe", nil],
|
|
20
|
+
"view_frame" => ["Views in a frame", nil],
|
|
21
|
+
"view_custom" => ["Views rendered by a host component", nil],
|
|
22
|
+
"action_unsupported" => ["Classic-only actions and links", "S7"],
|
|
23
|
+
"form_not_submittable" => ["Forms that cannot be submitted", "S7"],
|
|
24
|
+
"degradation" => ["Degradations", nil],
|
|
25
|
+
"html_heavy" => ["Html-heavy views", "L1"],
|
|
26
|
+
"filter_skipped" => ["Filters with no inferable control", "S5"],
|
|
27
|
+
"typeahead_scan_capped" => ["Scan-capped typeaheads", nil],
|
|
28
|
+
"menu_link" => ["Menu items linking to classic", "MENU"],
|
|
29
|
+
"not_exposed" => ["Permitted but not exposed", nil],
|
|
30
|
+
"nested_no_entry" => ["Nested resources without an entry point", nil]
|
|
31
|
+
}.freeze
|
|
32
|
+
|
|
33
|
+
DEGRADATION_WP = {"sidebar_dropped" => "S5", "sidebar_failed" => "S5"}.freeze
|
|
34
|
+
IGNORED_DIAGNOSTICS = %w[implicit_view form_unsupported form_partial html_unmapped_tag unknown_layout_class inline_style_ignored].freeze
|
|
35
|
+
DEGRADATION_IMPACT = {"page_iframe_fallback" => "low", "form_field_html" => "high"}.freeze
|
|
36
|
+
# Already reported as a view or a form that cannot be submitted.
|
|
37
|
+
COVERED_KINDS = %w[page_frame form_partial form_unsupported].freeze
|
|
38
|
+
FORM_REASON = /several forms|raw form controls|form builder call|markup beyond simple wrappers|forms render as frame nodes/
|
|
39
|
+
RECORD_ID = %r{/(?:\d+|\h{8}-\h{4}-\h{4}-\h{4}-\h{12})(?=/|\z)}
|
|
40
|
+
|
|
41
|
+
Item = Data.define(:category, :key, :item, :mode, :reason, :impact, :fix, :wp) do
|
|
42
|
+
def id = [category, key, item].join("|")
|
|
43
|
+
|
|
44
|
+
def to_h = super.merge(id:)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.run(**) = new(**).run
|
|
48
|
+
|
|
49
|
+
# user: who to sample as (defaults to config.doctor_user); without one only declarations are read.
|
|
50
|
+
def initialize(user: nil, sample: true, html_threshold: HTML_THRESHOLD)
|
|
51
|
+
@user = user || ReactiveAdmin.config.doctor_user&.call
|
|
52
|
+
@sample = sample && !@user.nil?
|
|
53
|
+
@html_threshold = html_threshold
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
attr_reader :sampled
|
|
57
|
+
|
|
58
|
+
# What changed against a baseline written by `.baseline`: new items and the cleared ones.
|
|
59
|
+
def self.compare(items, baseline)
|
|
60
|
+
before = baseline.fetch("items", {})
|
|
61
|
+
current = items.to_h { [it.id, it.impact] }
|
|
62
|
+
{new: items.reject { before.key?(it.id) }, cleared: (before.keys - current.keys).sort.map { |id| cleared(id, before[id]) }}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.cleared(id, impact)
|
|
66
|
+
category, key, item = id.split("|", 3)
|
|
67
|
+
{id:, category:, key:, item:, impact:}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.baseline(items)
|
|
71
|
+
{"version" => VERSION, "summary" => items.group_by(&:category).transform_values(&:size).sort.to_h,
|
|
72
|
+
"items" => items.sort_by(&:id).to_h { [it.id, it.impact] }}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.category_counts(baseline) = baseline.fetch("items", {}).keys.map { it.split("|", 2).first }.tally
|
|
76
|
+
|
|
77
|
+
def run
|
|
78
|
+
Rails.application.reload_routes_unless_loaded
|
|
79
|
+
@items = []
|
|
80
|
+
@degradation_kinds = Set.new
|
|
81
|
+
@sampled = @sample
|
|
82
|
+
ActiveRecord::Base.while_preventing_writes { silence { StyleSources.trace { collect } } }
|
|
83
|
+
merged.sort_by { [IMPACTS.index(it.impact), it.key, it.category, it.item] }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
# Repeats of one finding (a kind at many paths) collapse into the first, with a count.
|
|
89
|
+
def merged
|
|
90
|
+
@items.group_by(&:id).values.map do |list|
|
|
91
|
+
(list.size > 1) ? list.first.with(reason: "#{list.first.reason} (+#{list.size - 1} more)") : list.first
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def collect
|
|
96
|
+
report = Doctor.run(user: @user, sample: false)
|
|
97
|
+
report[:resources].each { resource(it) }
|
|
98
|
+
report[:pages].each { page(it) }
|
|
99
|
+
partials
|
|
100
|
+
menu if @sample
|
|
101
|
+
diagnostics
|
|
102
|
+
nested
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def add(category, key, item, impact:, fix:, mode: nil, reason: nil, wp: CATEGORIES.fetch(category).last)
|
|
106
|
+
@items << Item.new(category:, key: key.to_s, item:, mode:, reason: reason&.to_s&.tr("`", "'")&.truncate(160), impact:, fix:, wp:)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def silence
|
|
110
|
+
stdout = $stdout
|
|
111
|
+
$stdout = StringIO.new
|
|
112
|
+
yield
|
|
113
|
+
ensure
|
|
114
|
+
$stdout = stdout
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def sampler(config) = Doctor::Sample.new(config, @user)
|
|
118
|
+
|
|
119
|
+
# A section that raises is the doctor's finding, not this inventory's.
|
|
120
|
+
def fetch(config, action, path_params: {}, query: {})
|
|
121
|
+
sampler(config).call(action, path_params:, query:)
|
|
122
|
+
rescue
|
|
123
|
+
[nil, {}]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def exposed_resources = Registry.resources.select { Exposure.allowed?(it) && !ApiGuards.fully_denied?(it) }
|
|
127
|
+
|
|
128
|
+
def first_record(config) = (config.resource_class.first unless Paths.nested?(config))
|
|
129
|
+
|
|
130
|
+
# -- resources ------------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
def resource(row)
|
|
133
|
+
config = Registry.find(row[:key]) or return
|
|
134
|
+
key = row[:key]
|
|
135
|
+
row[:actions].each { action(config, key, it) }
|
|
136
|
+
row[:filters][:skipped].each do |name|
|
|
137
|
+
add("filter_skipped", key, "filter #{name}", impact: "med", fix: "declare the filter with `as:` or a collection so a control can be built")
|
|
138
|
+
end
|
|
139
|
+
sample_resource(config, key) if @sample && !Paths.nested?(config)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def action(config, key, row)
|
|
143
|
+
return unless row[:mode].in?(%w[frame iframe custom])
|
|
144
|
+
|
|
145
|
+
decision = Ladder.action(config, row[:name])
|
|
146
|
+
verbs = declared_verbs(config, row[:name])
|
|
147
|
+
view(key, "action #{row[:name]}", decision.mode, decision.reason, write: write?(verbs, decision, texts(config, decision)))
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def declared_verbs(config, name)
|
|
151
|
+
declared = AA.custom_actions(config)
|
|
152
|
+
declaration = declared.find { it.name.to_s == name.to_s }
|
|
153
|
+
Array.wrap(declaration&.http_verb).map(&:to_s)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def texts(config, decision)
|
|
157
|
+
decision.template ? Ladder.sources_for(config, decision.template).map(&:last) : []
|
|
158
|
+
rescue
|
|
159
|
+
[]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def write?(verbs, decision, texts)
|
|
163
|
+
verbs.any? { it != "get" } || decision.reason.match?(FORM_REASON) ||
|
|
164
|
+
texts.join.then { it.match?(Ladder::FORM_FOR) || it.match?(Ladder::RAW_CONTROLS) }
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
VIEW_FIXES = {
|
|
168
|
+
/own JS/ => "port to a custom view (`reactive { render_as :custom, custom_key: }`) or drop the script",
|
|
169
|
+
/several forms/ => "split into one `semantic_form_for` per action",
|
|
170
|
+
/raw form controls/ => "convert the template to `semantic_form_for` (`method: :get` to its own path for a filter form)",
|
|
171
|
+
/markup beyond simple wrappers/ => "keep only simple wrappers around the Formtastic form",
|
|
172
|
+
/form builder call/ => "limit the form block to Formtastic calls (input, inputs, actions)",
|
|
173
|
+
/forms render as frame nodes/ => "move the form to a member or collection action rendered with `semantic_form_for`, or make a filter form `method: :get` to the page's own path",
|
|
174
|
+
/no Formtastic form/ => "raw controls or actions in the template: accept the frame, or rebuild with `semantic_form_for` or action items",
|
|
175
|
+
/template not found/ => "add the template or fix its name",
|
|
176
|
+
/render_as/ => "remove the `render_as` override once the view converts",
|
|
177
|
+
/rendered content is/ => "load the page as the sample user: its content raised or needs a frame"
|
|
178
|
+
}.freeze
|
|
179
|
+
|
|
180
|
+
def view(key, item, mode, reason, write:)
|
|
181
|
+
category = (mode == "custom") ? "view_custom" : "view_#{mode}"
|
|
182
|
+
impact = if mode == "custom" then "low"
|
|
183
|
+
elsif write then "high"
|
|
184
|
+
else
|
|
185
|
+
(mode == "iframe") ? "med" : "low"
|
|
186
|
+
end
|
|
187
|
+
fix = view_fix(mode, reason, write)
|
|
188
|
+
add(category, key, item, mode:, reason:, impact:, fix:)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def view_fix(mode, reason, write)
|
|
192
|
+
return "keep the host component, or convert to typed nodes" if mode == "custom"
|
|
193
|
+
return "convert the template to `semantic_form_for` so it renders natively" if write && reason.to_s.include?("no Formtastic form")
|
|
194
|
+
|
|
195
|
+
VIEW_FIXES.find { |pattern, _| reason.to_s.match?(pattern) }&.last || "add `reactive { render_as :native }` once the view is Formtastic-only"
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def sample_resource(config, key)
|
|
199
|
+
record = first_record(config)
|
|
200
|
+
index(config, key)
|
|
201
|
+
show(config, key, record) if record
|
|
202
|
+
form(config, key, record)
|
|
203
|
+
member_native_actions(config, key, record)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def index(config, key)
|
|
207
|
+
return unless Registry.actions(config).include?(:index)
|
|
208
|
+
|
|
209
|
+
status, payload = fetch(config, :index, query: {per_page: 5})
|
|
210
|
+
return unless status == 200
|
|
211
|
+
|
|
212
|
+
scan(key, "index", payload)
|
|
213
|
+
html_heavy(key, "index", Doctor::Tally.nodes(payload["rows"].flat_map { [*it["cells"].values, *it["layout"]] }))
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def show(config, key, record)
|
|
217
|
+
return unless Registry.actions(config).include?(:show)
|
|
218
|
+
|
|
219
|
+
status, payload = fetch(config, :show, path_params: {id: record.to_param})
|
|
220
|
+
return unless status == 200
|
|
221
|
+
|
|
222
|
+
scan(key, "show", payload)
|
|
223
|
+
html_heavy(key, "show", Doctor::Tally.nodes(payload["layout"]))
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def fetch_form(config, record)
|
|
227
|
+
if Registry.actions(config).include?(:new)
|
|
228
|
+
fetch(config, :new, path_params: Paths.parent_params(config, record))
|
|
229
|
+
elsif record && Registry.actions(config).include?(:edit)
|
|
230
|
+
fetch(config, :edit, path_params: {id: record.to_param})
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
def form(config, key, record)
|
|
235
|
+
status, payload = fetch_form(config, record)
|
|
236
|
+
return unless status == 200
|
|
237
|
+
|
|
238
|
+
scan(key, "form", payload)
|
|
239
|
+
sections = payload.dig("form", "sections") || []
|
|
240
|
+
html_heavy(key, "form", Doctor::Tally.fields(sections))
|
|
241
|
+
not_submittable(key, "form", payload) if payload["submittable"] == false
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def not_submittable(key, item, payload)
|
|
245
|
+
kinds = Array(payload["degraded"]).pluck("kind")
|
|
246
|
+
partial = kinds.include?("form_partial")
|
|
247
|
+
add("form_not_submittable", key, item, mode: partial ? "form partial" : "raw inputs", reason: payload["unsupported_reason"].presence || "the form cannot be submitted faithfully",
|
|
248
|
+
impact: "high", fix: partial ? "replace `form partial:` with a `form do |f|` block of Formtastic inputs" : "replace raw html inputs with Formtastic `f.input` calls")
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# GET template actions the ladder calls native, answered for real: a 501 means classic only.
|
|
252
|
+
def member_native_actions(config, key, record)
|
|
253
|
+
[*config.member_actions.map { [it, true] }, *config.collection_actions.map { [it, false] }].each do |declaration, member|
|
|
254
|
+
name = declaration.name.to_s
|
|
255
|
+
next unless Array.wrap(declaration.http_verb).first.to_s == "get" && Ladder.action(config, name)&.native?
|
|
256
|
+
next if member && record.nil?
|
|
257
|
+
|
|
258
|
+
status, payload = fetch(config, name, path_params: (member ? {id: record.to_param} : {}))
|
|
259
|
+
case status
|
|
260
|
+
when 501 then add("view_unsupported", key, "action #{name}", mode: "unsupported", reason: "answers 501: renders no usable Formtastic form",
|
|
261
|
+
impact: "high", fix: "convert the template to `semantic_form_for` (a GET form must target this same action), or `render_as :frame`")
|
|
262
|
+
when 200
|
|
263
|
+
scan(key, "action #{name}", payload)
|
|
264
|
+
not_submittable(key, "action #{name}", payload) if payload["submittable"] == false
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# -- payloads -------------------------------------------------------------------------------
|
|
270
|
+
|
|
271
|
+
def scan(key, section, payload)
|
|
272
|
+
Array(payload["degraded"]).each do |entry|
|
|
273
|
+
kind = entry["kind"].to_s
|
|
274
|
+
next if kind.in?(COVERED_KINDS)
|
|
275
|
+
|
|
276
|
+
@degradation_kinds << kind
|
|
277
|
+
reason = [entry["where"], entry["reason"]].compact.join(": ")
|
|
278
|
+
add("degradation", key, "#{section}: #{kind}", mode: kind, reason:,
|
|
279
|
+
impact: degradation_impact(kind, "med"), fix: "see the reason; rework the view so the server can represent it", wp: DEGRADATION_WP[kind])
|
|
280
|
+
end
|
|
281
|
+
each_hash(payload) { |hash| unsupported_action(key, section, hash) if hash["supported"] == false && hash.key?("label") && !hash["api_denied"] }
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def degradation_impact(kind, default)
|
|
285
|
+
DEGRADATION_IMPACT.fetch(kind) { kind.start_with?("implicit_") ? "low" : default }
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def each_hash(value, &block)
|
|
289
|
+
case value
|
|
290
|
+
when Array then value.each { each_hash(it, &block) }
|
|
291
|
+
when Hash
|
|
292
|
+
yield value
|
|
293
|
+
value.each_value { each_hash(it, &block) }
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def unsupported_action(key, section, hash)
|
|
298
|
+
verb = hash["method"].to_s.presence || "get"
|
|
299
|
+
path = hash["href"].to_s.split("?").first.to_s.gsub(RECORD_ID, "/:id")
|
|
300
|
+
write = verb != "get"
|
|
301
|
+
add("action_unsupported", key, "#{section}: #{hash["placement"] || "action"} #{verb.upcase} #{path.presence || "(no href)"}", mode: "classic", reason: hash["disabled_reason"],
|
|
302
|
+
impact: write ? "high" : "med",
|
|
303
|
+
fix: write ? "register the target as a member or collection action, or port it to a page action" : "link to a registered resource or page")
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def html_heavy(key, section, tally)
|
|
307
|
+
html = tally[:html].to_i
|
|
308
|
+
total = tally[:typed].to_i + html
|
|
309
|
+
return if html < MIN_HTML_LEAVES || html.fdiv(total) <= @html_threshold
|
|
310
|
+
|
|
311
|
+
add("html_heavy", key, section, mode: "html", reason: "#{html} of #{total} leaves are html (#{(html * 100.0 / total).round}%)", impact: "low",
|
|
312
|
+
fix: "replace raw markup with typed nodes (status_tag, attributes_table, panel, toolbar)")
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# -- pages ----------------------------------------------------------------------------------
|
|
316
|
+
|
|
317
|
+
def page(row)
|
|
318
|
+
config = Registry.find_page(row[:key]) or return
|
|
319
|
+
mode = row[:mode]
|
|
320
|
+
reason = row[:reason]
|
|
321
|
+
payload = {}
|
|
322
|
+
if @sample && !Paths.nested?(config)
|
|
323
|
+
status, payload = fetch(config, :reactiveadmin_page, query: Doctor.page_query(config))
|
|
324
|
+
payload = {} unless status == 200
|
|
325
|
+
mode = payload.dig("view", "mode") || mode
|
|
326
|
+
reason = "the rendered content is #{mode} (the source reads as #{row[:mode]})" if mode != row[:mode]
|
|
327
|
+
end
|
|
328
|
+
scan("page #{row[:key]}", "page", payload)
|
|
329
|
+
html_heavy("page #{row[:key]}", "page", Doctor::Tally.nodes(payload["layout"])) if payload.key?("layout")
|
|
330
|
+
row[:actions].each { page_action(config, row[:key], it) }
|
|
331
|
+
return if mode.in?(%w[native api])
|
|
332
|
+
|
|
333
|
+
view("page #{row[:key]}", "content", mode, reason, write: reason.to_s.match?(FORM_REASON) || page_form?(config) || row[:actions].any? { it[:verb] != "get" })
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def page_form?(config)
|
|
337
|
+
content = Ladder.block_source(AA.page_presenter(config, :index)&.block).to_s
|
|
338
|
+
[content, *Ladder.partial_texts(config, content)].join.then { it.match?(Ladder::FORM_FOR) || it.match?(Ladder::RAW_CONTROLS) }
|
|
339
|
+
rescue
|
|
340
|
+
false
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def page_action(config, key, row)
|
|
344
|
+
return unless row[:mode].in?(%w[frame iframe custom])
|
|
345
|
+
|
|
346
|
+
decision = Ladder.action(config, row[:name])
|
|
347
|
+
view("page #{key}", "action #{row[:name]}", decision.mode, decision.reason, write: write?(declared_verbs(config, row[:name]), decision, texts(config, decision)))
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# -- menu, diagnostics, exposure ------------------------------------------------------------
|
|
351
|
+
|
|
352
|
+
def menu
|
|
353
|
+
controller = Struct.new(:controller).new(ReactiveAdmin::ManifestController)
|
|
354
|
+
status, payload = fetch(controller, :show)
|
|
355
|
+
return unless status == 200
|
|
356
|
+
|
|
357
|
+
links = []
|
|
358
|
+
walk_menu(payload["menu"], [], links, MenuOverlay.links.pluck(:id))
|
|
359
|
+
links.each do |path|
|
|
360
|
+
add("menu_link", "menu", path.join(" > "), mode: "classic", reason: "links to a classic URL", impact: "med",
|
|
361
|
+
fix: "map the URL to a resource or page, or add an overlay entry for it")
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# Overlay links are the host's explicit decision; only links inherited from AA's menu are legacy.
|
|
366
|
+
def walk_menu(nodes, path, links, explicit)
|
|
367
|
+
Array(nodes).each do |node|
|
|
368
|
+
here = [*path, node["label"].to_s]
|
|
369
|
+
links << here if node["kind"] == "link" && node["url"].to_s.start_with?("/") && !node["api_denied"] && explicit.exclude?(node["id"])
|
|
370
|
+
walk_menu(node["children"], here, links, explicit)
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
def diagnostics
|
|
375
|
+
entries = ReactiveAdmin.diagnostics.entries
|
|
376
|
+
entries.select { it[:kind] == :exposure_permitted_not_exposed }.flat_map { it[:keys].to_s.split(", ") }.each do |key|
|
|
377
|
+
add("not_exposed", key, "resource or page", mode: "classic", reason: "permitted by the policy but not exposed to the API", impact: "med",
|
|
378
|
+
fix: "place it in the menu overlay or `config.exposed_resources` once its views are ready")
|
|
379
|
+
end
|
|
380
|
+
names = Registry.resources.to_h { [it.resource_name.to_s, Registry.route_key(it)] }
|
|
381
|
+
entries.reject { it[:kind] == :exposure_permitted_not_exposed || it[:kind].to_s.in?(IGNORED_DIAGNOSTICS) || it[:kind].to_s.in?(@degradation_kinds) }
|
|
382
|
+
.group_by { [it[:kind].to_s, (it[:resource] || it[:source] || it[:key] || "menu").to_s] }.each do |(kind, name), entries|
|
|
383
|
+
key = names.fetch(name, name)
|
|
384
|
+
details = entries.map { |entry| entry.except(:kind, :resource).map { |k, v| "#{k}=#{v}" }.join(" ") }.first(3).join("; ")
|
|
385
|
+
if kind == "scan_capped"
|
|
386
|
+
add("typeahead_scan_capped", key, "typeahead scan cap", mode: kind, reason: details, impact: "low",
|
|
387
|
+
fix: "add `reactive { search :column }` on the target resource, or an option source")
|
|
388
|
+
else
|
|
389
|
+
add("degradation", key, "diagnostic: #{kind}", mode: kind, reason: "#{entries.size} occurrence(s): #{details}",
|
|
390
|
+
impact: degradation_impact(kind, "low"), fix: "see the reason in `rake reactiveadmin:doctor FORMAT=json`", wp: DEGRADATION_WP[kind])
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
# A `form partial:` is recorded into fields like any form, so only one the form's own
|
|
396
|
+
# `submittable` rejects is listed. Resources sampled in full are covered by their form check.
|
|
397
|
+
def partials
|
|
398
|
+
exposed_resources.each do |config|
|
|
399
|
+
next unless AA.page_presenter(config, :form)&.options&.[](:partial)
|
|
400
|
+
next if @sample && !Paths.nested?(config)
|
|
401
|
+
|
|
402
|
+
status, payload = fetch_form(config, first_record(config))
|
|
403
|
+
not_submittable(Registry.route_key(config), "form", payload) if status == 200 && payload["submittable"] == false
|
|
404
|
+
end
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# Resources whose parent has no show page to reach them from.
|
|
408
|
+
def nested
|
|
409
|
+
exposed_resources.each do |config|
|
|
410
|
+
next unless Paths.nested?(config)
|
|
411
|
+
|
|
412
|
+
parent = config.belongs_to_config.target
|
|
413
|
+
next if AA.resource?(parent) && Registry.actions(parent).include?(:show)
|
|
414
|
+
|
|
415
|
+
add("nested_no_entry", Registry.route_key(config), "nested under #{parent.try(:resource_name) || parent}", impact: "med",
|
|
416
|
+
mode: "nested", reason: "the parent has no show page to link from", fix: "give the parent a show page with a link to the children")
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# Markdown and JSON renderings of an inventory, with trends against a baseline.
|
|
421
|
+
class Report
|
|
422
|
+
def initialize(items, sampled:, baseline: nil, generated_at: nil)
|
|
423
|
+
@items = items
|
|
424
|
+
@sampled = sampled
|
|
425
|
+
@baseline = baseline
|
|
426
|
+
@diff = LegacyInventory.compare(items, baseline) if baseline
|
|
427
|
+
@generated_at = generated_at
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
attr_reader :items
|
|
431
|
+
|
|
432
|
+
def new_items = @diff ? @diff[:new] : []
|
|
433
|
+
|
|
434
|
+
def cleared = @diff ? @diff[:cleared] : []
|
|
435
|
+
|
|
436
|
+
def summary
|
|
437
|
+
before = @baseline && LegacyInventory.category_counts(@baseline)
|
|
438
|
+
categories = CATEGORIES.keys.filter_map do |category|
|
|
439
|
+
mine = items.select { it.category == category }
|
|
440
|
+
next if mine.empty? && !before&.key?(category)
|
|
441
|
+
|
|
442
|
+
[category, IMPACTS.to_h { |impact| [impact, mine.count { it.impact == impact }] }.merge("total" => mine.size, "trend" => trend(mine.size, before&.fetch(category, 0)))]
|
|
443
|
+
end
|
|
444
|
+
{total: items.size, impact: IMPACTS.to_h { |impact| [impact, items.count { it.impact == impact }] }, categories: categories.to_h,
|
|
445
|
+
new: new_items.size, cleared: cleared.size}
|
|
446
|
+
end
|
|
447
|
+
|
|
448
|
+
def to_h
|
|
449
|
+
{version: VERSION, generated_at: @generated_at || Time.current.iso8601, sampled: @sampled, summary:, items: items.map(&:to_h),
|
|
450
|
+
new: new_items.map(&:id), cleared: cleared.pluck(:id)}
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def to_json(*) = JSON.pretty_generate(to_h)
|
|
454
|
+
|
|
455
|
+
def to_markdown
|
|
456
|
+
[header, table, *IMPACTS.filter_map { checklist(it) }, cleared_section].compact.join("\n\n") + "\n"
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
private
|
|
460
|
+
|
|
461
|
+
def trend(now, before)
|
|
462
|
+
return "n/a" if before.nil?
|
|
463
|
+
|
|
464
|
+
case now <=> before
|
|
465
|
+
when 1 then "▲ +#{now - before}"
|
|
466
|
+
when -1 then "▼ -#{before - now}"
|
|
467
|
+
else "="
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def header
|
|
472
|
+
s = summary
|
|
473
|
+
counts = IMPACTS.map { "#{s[:impact][it]} #{it}" }.join(", ")
|
|
474
|
+
["# Legacy inventory",
|
|
475
|
+
"Everything the new admin still relies on classic ActiveAdmin for#{" (static: no sample user)" unless @sampled}. " \
|
|
476
|
+
"Regenerate with `rake reactiveadmin:legacy`; tick items off by fixing them, not by editing this file.",
|
|
477
|
+
"**#{s[:total]} open** (#{counts})#{", #{s[:new]} new, #{s[:cleared]} cleared since the baseline" if @baseline}."].join("\n\n")
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
def table
|
|
481
|
+
rows = summary[:categories].map do |category, c|
|
|
482
|
+
"| #{CATEGORIES.fetch(category).first} (`#{category}`) | #{c["total"]} | #{c["high"]} | #{c["med"]} | #{c["low"]} | #{c["trend"]} |"
|
|
483
|
+
end
|
|
484
|
+
["## Summary", "| Category | Open | High | Med | Low | Trend |", "| --- | ---: | ---: | ---: | ---: | --- |", *rows].join("\n")
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
def checklist(impact)
|
|
488
|
+
mine = items.select { it.impact == impact }
|
|
489
|
+
return if mine.empty?
|
|
490
|
+
|
|
491
|
+
title = {"high" => "High impact", "med" => "Medium impact", "low" => "Low impact"}.fetch(impact)
|
|
492
|
+
groups = mine.group_by(&:key).sort.map do |key, list|
|
|
493
|
+
["### #{key}", *list.sort_by { [it.category, it.item] }.map { bullet(it) }].join("\n")
|
|
494
|
+
end
|
|
495
|
+
["## #{title} (#{mine.size})", *groups].join("\n\n")
|
|
496
|
+
end
|
|
497
|
+
|
|
498
|
+
def bullet(item)
|
|
499
|
+
detail = [item.reason&.then { "`#{it}`." }, ("Fix: #{item.fix}." if item.fix), ("[#{item.wp}]" if item.wp)].compact.join(" ")
|
|
500
|
+
"- [ ] `#{item.category}` #{item.item}#{" (#{item.mode})" if item.mode}: #{detail}"
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
def cleared_section
|
|
504
|
+
return unless @baseline
|
|
505
|
+
|
|
506
|
+
lines = cleared.map { "- [x] `#{it[:category]}` #{it[:key]}: #{it[:item]} (#{it[:impact]})" }
|
|
507
|
+
["## Recently cleared", lines.presence&.join("\n") || "Nothing cleared since the baseline."].join("\n\n")
|
|
508
|
+
end
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
# The rake task's driver; options come from the environment so they pass through `rake`.
|
|
512
|
+
module CLI
|
|
513
|
+
HEADER = "# Legacy inventory baseline: every item is already known; new ones fail the ratchet.\n" \
|
|
514
|
+
"# Regenerate on purpose with WRITE_BASELINE=path bundle exec rake reactiveadmin:legacy\n".freeze
|
|
515
|
+
|
|
516
|
+
module_function
|
|
517
|
+
|
|
518
|
+
# Number of new legacy items against BASELINE; 0 without one.
|
|
519
|
+
def run(env = ENV, out: $stdout)
|
|
520
|
+
inventory = LegacyInventory.new(sample: env["SAMPLE"] != "0", html_threshold: Float(env.fetch("HTML_THRESHOLD", HTML_THRESHOLD)))
|
|
521
|
+
items = inventory.run
|
|
522
|
+
baseline = YAML.safe_load_file(env["BASELINE"]) if env["BASELINE"].present?
|
|
523
|
+
report = Report.new(items, sampled: inventory.sampled, baseline:)
|
|
524
|
+
text = (env["FORMAT"] == "json") ? report.to_json : report.to_markdown
|
|
525
|
+
emit(text, env["OUT"], report, out)
|
|
526
|
+
write_baseline(items, env["WRITE_BASELINE"], out)
|
|
527
|
+
report.new_items.each { out.puts("new legacy item: #{it.id}") }
|
|
528
|
+
report.new_items.size
|
|
529
|
+
end
|
|
530
|
+
|
|
531
|
+
def emit(text, path, report, out)
|
|
532
|
+
return out.puts(text) unless path.present?
|
|
533
|
+
|
|
534
|
+
File.write(path, text)
|
|
535
|
+
s = report.summary
|
|
536
|
+
out.puts("legacy inventory written to #{path}: #{s[:total]} open (#{IMPACTS.map { "#{s[:impact][it]} #{it}" }.join(", ")})")
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
def write_baseline(items, path, out)
|
|
540
|
+
return unless path.present?
|
|
541
|
+
|
|
542
|
+
File.write(path, HEADER + LegacyInventory.baseline(items).to_yaml)
|
|
543
|
+
out.puts("baseline written to #{path}")
|
|
544
|
+
end
|
|
545
|
+
end
|
|
546
|
+
end
|
|
547
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Where a redirect points, as a resource reference when it lands on one of our resources.
|
|
3
|
+
module Location
|
|
4
|
+
VIEWS = %w[index show new edit].freeze
|
|
5
|
+
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def for(url, host:)
|
|
9
|
+
uri = URI.parse(url.to_s)
|
|
10
|
+
return {url: url.to_s} if uri.host.present? && uri.host != host
|
|
11
|
+
|
|
12
|
+
location = {url: [uri.path, uri.query].compact.join("?")}
|
|
13
|
+
route = Rails.application.routes.recognize_path(uri.path)
|
|
14
|
+
config = Registry.for_controller_path(route[:controller])
|
|
15
|
+
return location unless config && VIEWS.include?(route[:action]) && Exposure.allowed?(config)
|
|
16
|
+
|
|
17
|
+
location.merge(resource: Registry.route_key(config), id: route[:id]&.to_s, view: route[:action]).compact
|
|
18
|
+
rescue URI::InvalidURIError, ActionController::RoutingError
|
|
19
|
+
{url: url.to_s}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Lookups (typeahead search, option resolution, `_labels`) are background requests, not page views,
|
|
3
|
+
# yet an author's name is sensitive wherever it appears. When the records returned belong to a sensitive resource
|
|
4
|
+
# (`config.sensitive_resources` or `reactive { sensitive true }`), each request emits one `lookup.reactiveadmin`
|
|
5
|
+
# event: who, where, how many. Never the search term and never a returned name.
|
|
6
|
+
module LookupAudit
|
|
7
|
+
module_function
|
|
8
|
+
|
|
9
|
+
def sensitive?(model)
|
|
10
|
+
config = model && AA.resource_for(Registry.namespace, model)
|
|
11
|
+
return false unless config
|
|
12
|
+
|
|
13
|
+
sensitive_resource?(config)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def sensitive_resource?(config)
|
|
17
|
+
config.reactive_options.fetch(:sensitive) { ReactiveAdmin.config.sensitive_resources.map(&:to_s).include?(Registry.route_key(config)) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Never raises: the lookup has been answered, and an audit hiccup must not turn it into a 500.
|
|
21
|
+
def record(controller, model:, kind:, result_count:, field: nil)
|
|
22
|
+
return unless sensitive?(model)
|
|
23
|
+
|
|
24
|
+
Audit.instrument("lookup", controller, {resource: WriteAudit.resource_key(controller), field:, kind:,
|
|
25
|
+
target: Registry.route_key(AA.resource_for(Registry.namespace, model)), result_count:, user_id: ReactiveAdmin.current_user(controller)&.id})
|
|
26
|
+
rescue => e
|
|
27
|
+
Rails.logger.error("[reactiveadmin] lookup audit failed: #{e.class}")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Labels for the selected values of several fields at once (`_options/lookup`), so opening a form
|
|
3
|
+
# with many typeaheads costs one request and one build of the form. Same sources, authorization
|
|
4
|
+
# and policy scoping as `_options`.
|
|
5
|
+
class LookupPayload
|
|
6
|
+
MAX_VALUES = 100
|
|
7
|
+
|
|
8
|
+
def initialize(controller)
|
|
9
|
+
@controller = controller
|
|
10
|
+
@params = controller.params
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def as_json(*)
|
|
14
|
+
requested = values_by_field
|
|
15
|
+
sources = OptionsPayload.sources(@controller, @params[:context], requested.keys)
|
|
16
|
+
{lookups: requested.to_h { |field, values| [field, lookup(sources.fetch(field), field, values)] }}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def lookup(source, field, values)
|
|
22
|
+
source.lookup(values).tap do
|
|
23
|
+
LookupAudit.record(@controller, model: source.try(:model), kind: :lookup, field:, result_count: it.size)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def values_by_field
|
|
28
|
+
fields = @params.require(:fields)
|
|
29
|
+
raise ApiErrors::BadRequest, "fields must map field names to values" unless fields.respond_to?(:to_unsafe_h)
|
|
30
|
+
|
|
31
|
+
fields = fields.to_unsafe_h
|
|
32
|
+
raise ApiErrors::BadRequest, "fields must map field names to values" unless fields.values.all? { it.is_a?(String) || it.is_a?(Array) }
|
|
33
|
+
|
|
34
|
+
requested = fields.transform_values { OptionsPayload.split_values(it) }.reject { |_, values| values.empty? }
|
|
35
|
+
raise ApiErrors::BadRequest, "Too many values (max #{MAX_VALUES})" if requested.values.sum(&:size) > MAX_VALUES
|
|
36
|
+
raise ActionController::ParameterMissing, :fields if requested.empty?
|
|
37
|
+
|
|
38
|
+
requested
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ReactiveAdmin
|
|
2
|
+
# Everything the shell needs on load. Per-resource details (filters, scopes, ...) come from
|
|
3
|
+
# ResourceMeta, so this stays cheap however many resources are registered.
|
|
4
|
+
class Manifest
|
|
5
|
+
SCHEMA_VERSION = 2
|
|
6
|
+
|
|
7
|
+
def initialize(controller, authorizer: Authorizer.for(controller))
|
|
8
|
+
@controller = controller
|
|
9
|
+
@authorizer = authorizer
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def as_json(*)
|
|
13
|
+
resources = self.resources
|
|
14
|
+
menu = menu(resources)
|
|
15
|
+
{schema_version: SCHEMA_VERSION, site: Site.new(@controller, menu), menu:, resources:}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The summaries of the resources the user may open, in registration order.
|
|
19
|
+
def resources = Registry.resources.filter_map { resource(it) }
|
|
20
|
+
|
|
21
|
+
def menu(resources) = Menu.new(@controller.view_context, @authorizer, resources.pluck(:key), user: ReactiveAdmin.current_user(@controller))
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def resource(config)
|
|
26
|
+
return unless Exposure.allowed?(config) && Registry.actions(config).include?(:index) && !ApiGuards.denies?(config, "index")
|
|
27
|
+
|
|
28
|
+
summary = ResourceSummary.new(config, @authorizer)
|
|
29
|
+
summary.as_json if summary.permissions[:index]
|
|
30
|
+
rescue => e
|
|
31
|
+
Rails.logger.warn("[reactiveadmin] skipped #{config.resource_name} in manifest: #{e.class} at #{e.backtrace&.first}")
|
|
32
|
+
Degradation.record(kind: :manifest_resource_dropped, where: "manifest/resource[#{config.resource_name}]", reason: "Resource raised #{e.class}; left out of the manifest")
|
|
33
|
+
nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|