permission_forge 0.14.1 → 0.15.1
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 +4 -4
- data/CHANGELOG.md +2433 -0
- data/README.md +76 -25
- data/app/controllers/concerns/permission_forge/api/crud_actions.rb +3 -2
- data/app/controllers/concerns/permission_forge/api/input_shapes.rb +200 -0
- data/app/controllers/concerns/permission_forge/api/pagination.rb +12 -5
- data/app/controllers/concerns/permission_forge/api/response_renderer.rb +42 -1
- data/app/controllers/concerns/permission_forge/api_authentication.rb +13 -2
- data/app/controllers/concerns/permission_forge/cache_confirmation.rb +42 -11
- data/app/controllers/concerns/permission_forge/change_review.rb +42 -0
- data/app/controllers/concerns/permission_forge/copy_refusal.rb +39 -0
- data/app/controllers/concerns/permission_forge/param_shapes.rb +207 -7
- data/app/controllers/concerns/permission_forge/save_notice.rb +69 -0
- data/app/controllers/permission_forge/api/audit_events_controller.rb +10 -1
- data/app/controllers/permission_forge/api/base_controller.rb +163 -12
- data/app/controllers/permission_forge/api/dashboard_controller.rb +29 -4
- data/app/controllers/permission_forge/api/permission_set_group_users_controller.rb +5 -2
- data/app/controllers/permission_forge/api/permission_set_groups_controller.rb +5 -4
- data/app/controllers/permission_forge/api/permission_set_rules_controller.rb +7 -5
- data/app/controllers/permission_forge/api/permission_set_users_controller.rb +80 -19
- data/app/controllers/permission_forge/api/permission_sets_controller.rb +12 -6
- data/app/controllers/permission_forge/api/resource_actions_controller.rb +1 -1
- data/app/controllers/permission_forge/api/resource_fields_controller.rb +3 -4
- data/app/controllers/permission_forge/api/resources_controller.rb +26 -12
- data/app/controllers/permission_forge/api/unmatched_routes_controller.rb +20 -0
- data/app/controllers/permission_forge/application_controller.rb +39 -5
- data/app/controllers/permission_forge/assignments_controller.rb +36 -34
- data/app/controllers/permission_forge/audit_events_controller.rb +11 -0
- data/app/controllers/permission_forge/bulk_assignments_controller.rb +8 -4
- data/app/controllers/permission_forge/field_lookups_controller.rb +1 -1
- data/app/controllers/permission_forge/maintenance_controller.rb +6 -2
- data/app/controllers/permission_forge/people_controller.rb +17 -15
- data/app/controllers/permission_forge/permission_set_editor.rb +22 -6
- data/app/controllers/permission_forge/permission_set_group_users_controller.rb +3 -1
- data/app/controllers/permission_forge/permission_set_groups_controller.rb +23 -9
- data/app/controllers/permission_forge/permission_set_rules_controller.rb +20 -10
- data/app/controllers/permission_forge/permission_sets_controller.rb +31 -67
- data/app/controllers/permission_forge/resource_actions_controller.rb +11 -6
- data/app/controllers/permission_forge/resource_fields_controller.rb +37 -19
- data/app/controllers/permission_forge/resources_controller.rb +12 -11
- data/app/frontend/permission_forge/pf_admin.css +154 -19
- data/app/frontend/permission_forge/pf_admin.js +109 -0
- data/app/helpers/permission_forge/application_helper.rb +23 -72
- data/app/helpers/permission_forge/audit_attribution_helper.rb +77 -0
- data/app/helpers/permission_forge/audit_helper.rb +57 -119
- data/app/helpers/permission_forge/audit_records_helper.rb +103 -0
- data/app/helpers/permission_forge/audit_sentences_helper.rb +56 -2
- data/app/helpers/permission_forge/badges_helper.rb +74 -17
- data/app/helpers/permission_forge/changes_helper.rb +24 -6
- data/app/helpers/permission_forge/conditions_helper.rb +119 -0
- data/app/helpers/permission_forge/labels_helper.rb +134 -0
- data/app/helpers/permission_forge/people_helper.rb +11 -19
- data/app/helpers/permission_forge/rule_problems_helper.rb +73 -0
- data/app/helpers/permission_forge/sentences_helper.rb +119 -98
- data/app/helpers/permission_forge/set_summaries_helper.rb +144 -0
- data/app/helpers/permission_forge/settings_helper.rb +2 -2
- data/app/helpers/permission_forge/ui_helper.rb +69 -7
- data/app/models/permission_forge/audit_event.rb +5 -1
- data/app/models/permission_forge/permission_set.rb +208 -18
- data/app/models/permission_forge/permission_set_group.rb +10 -4
- data/app/models/permission_forge/permission_set_group_user.rb +3 -1
- data/app/models/permission_forge/permission_set_rule.rb +254 -17
- data/app/models/permission_forge/permission_set_user.rb +38 -3
- data/app/models/permission_forge/resource.rb +18 -8
- data/app/models/permission_forge/resource_action.rb +15 -6
- data/app/models/permission_forge/resource_field.rb +97 -11
- data/app/views/permission_forge/assignments/confirm_destroy.html.erb +4 -4
- data/app/views/permission_forge/assignments/new.html.erb +10 -6
- data/app/views/permission_forge/audit_events/index.html.erb +1 -1
- data/app/views/permission_forge/audit_events/show.html.erb +16 -9
- data/app/views/permission_forge/audit_events/unavailable.html.erb +7 -0
- data/app/views/permission_forge/bulk_assignments/confirm_revoke.html.erb +3 -3
- data/app/views/permission_forge/bulk_assignments/new.html.erb +3 -3
- data/app/views/permission_forge/field_lookups/show.html.erb +2 -2
- data/app/views/permission_forge/home/_broken_rules_card.html.erb +35 -0
- data/app/views/permission_forge/home/_conditions_card.html.erb +28 -0
- data/app/views/permission_forge/home/_ending_card.html.erb +11 -5
- data/app/views/permission_forge/home/_expired_card.html.erb +1 -1
- data/app/views/permission_forge/home/_mask_strategies_card.html.erb +27 -0
- data/app/views/permission_forge/home/_privacy_card.html.erb +21 -7
- data/app/views/permission_forge/home/_rules_card.html.erb +1 -1
- data/app/views/permission_forge/home/_secret_rules_card.html.erb +33 -0
- data/app/views/permission_forge/home/_stale_card.html.erb +7 -5
- data/app/views/permission_forge/home/_tidy_card.html.erb +1 -1
- data/app/views/permission_forge/home/index.html.erb +5 -6
- data/app/views/permission_forge/people/_access_tab.html.erb +26 -19
- data/app/views/permission_forge/people/_audit_tab.html.erb +12 -8
- data/app/views/permission_forge/people/_effective_field_source.html.erb +13 -7
- data/app/views/permission_forge/people/_effective_tab.html.erb +16 -15
- data/app/views/permission_forge/people/_effective_why.html.erb +20 -16
- data/app/views/permission_forge/people/_why_item.html.erb +1 -1
- data/app/views/permission_forge/people/confirm_remove_all.html.erb +3 -3
- data/app/views/permission_forge/people/erasure_preview.html.erb +1 -1
- data/app/views/permission_forge/permission_set_groups/confirm_destroy.html.erb +3 -3
- data/app/views/permission_forge/permission_set_groups/index.html.erb +3 -3
- data/app/views/permission_forge/permission_set_groups/show.html.erb +28 -19
- data/app/views/permission_forge/permission_set_rules/_builder.html.erb +35 -15
- data/app/views/permission_forge/permission_set_rules/_preview.html.erb +17 -0
- data/app/views/permission_forge/permission_set_rules/confirm_destroy.html.erb +3 -3
- data/app/views/permission_forge/permission_set_rules/preview.html.erb +12 -0
- data/app/views/permission_forge/permission_sets/_assignments_tab.html.erb +37 -22
- data/app/views/permission_forge/permission_sets/_audit_tab.html.erb +8 -4
- data/app/views/permission_forge/permission_sets/_condition_problems.html.erb +15 -0
- data/app/views/permission_forge/permission_sets/_conditions_tab.html.erb +14 -8
- data/app/views/permission_forge/permission_sets/_header.html.erb +6 -5
- data/app/views/permission_forge/permission_sets/_overview_body.html.erb +58 -0
- data/app/views/permission_forge/permission_sets/_records_summary.html.erb +2 -2
- data/app/views/permission_forge/permission_sets/_resources_tab.html.erb +4 -4
- data/app/views/permission_forge/permission_sets/_set_summary_cells.html.erb +53 -0
- data/app/views/permission_forge/permission_sets/_set_summary_links.html.erb +14 -0
- data/app/views/permission_forge/permission_sets/confirm_destroy.html.erb +4 -4
- data/app/views/permission_forge/permission_sets/confirm_switch_mode.html.erb +3 -3
- data/app/views/permission_forge/permission_sets/index.html.erb +25 -19
- data/app/views/permission_forge/permission_sets/new.html.erb +2 -2
- data/app/views/permission_forge/permission_sets/overview.html.erb +24 -0
- data/app/views/permission_forge/permission_sets/review.html.erb +13 -3
- data/app/views/permission_forge/permission_sets/show.html.erb +7 -5
- data/app/views/permission_forge/resource_actions/_across_sets.html.erb +7 -10
- data/app/views/permission_forge/resource_actions/_effect.html.erb +5 -5
- data/app/views/permission_forge/resource_actions/_form.html.erb +1 -1
- data/app/views/permission_forge/resource_actions/_managed_note.html.erb +5 -3
- data/app/views/permission_forge/resource_actions/confirm_destroy.html.erb +1 -1
- data/app/views/permission_forge/resource_actions/new.html.erb +1 -1
- data/app/views/permission_forge/resource_actions/show.html.erb +2 -2
- data/app/views/permission_forge/resource_fields/_explain.html.erb +19 -15
- data/app/views/permission_forge/resource_fields/show.html.erb +21 -12
- data/app/views/permission_forge/resources/_actions_tab.html.erb +4 -4
- data/app/views/permission_forge/resources/_fields_tab.html.erb +17 -9
- data/app/views/permission_forge/resources/_rules_tab.html.erb +9 -6
- data/app/views/permission_forge/resources/_sync.html.erb +8 -5
- data/app/views/permission_forge/resources/confirm_destroy.html.erb +3 -3
- data/app/views/permission_forge/resources/new.html.erb +3 -2
- data/app/views/permission_forge/resources/show.html.erb +6 -6
- data/app/views/permission_forge/settings/_row.html.erb +2 -2
- data/app/views/permission_forge/settings/show.html.erb +10 -1
- data/app/views/permission_forge/shared/_across_sets.html.erb +8 -9
- data/app/views/permission_forge/shared/_audit_events.html.erb +2 -2
- data/app/views/permission_forge/shared/_audit_footer.html.erb +13 -2
- data/app/views/permission_forge/shared/_audit_unavailable.html.erb +2 -0
- data/app/views/permission_forge/shared/_crud_cell.html.erb +6 -6
- data/app/views/permission_forge/shared/_mode_banners.html.erb +1 -1
- data/app/views/permission_forge/shared/_savebar.html.erb +4 -2
- data/config/locales/permission_forge.en.yml +594 -69
- data/config/locales/permission_forge.mk.yml +616 -79
- data/config/locales/permission_forge.sq.yml +626 -80
- data/config/routes.rb +39 -23
- data/lib/generators/permission_forge/install/install_generator.rb +21 -0
- data/lib/generators/permission_forge/install/templates/initializer.rb.tt +35 -34
- data/lib/generators/permission_forge/install/templates/migration.rb.tt +5 -5
- data/lib/permission_forge/activation_conditions.rb +200 -0
- data/lib/permission_forge/admin/action_label.rb +33 -0
- data/lib/permission_forge/admin/action_rows.rb +3 -1
- data/lib/permission_forge/admin/actor_label.rb +52 -0
- data/lib/permission_forge/admin/attention_items.rb +152 -31
- data/lib/permission_forge/admin/audit_log.rb +4 -7
- data/lib/permission_forge/admin/audit_trail.rb +33 -17
- data/lib/permission_forge/admin/bulk_people_matcher.rb +32 -14
- data/lib/permission_forge/admin/chain_entries.rb +42 -0
- data/lib/permission_forge/admin/change_set.rb +12 -1
- data/lib/permission_forge/admin/change_set_parts/base.rb +5 -4
- data/lib/permission_forge/admin/change_set_parts/context.rb +3 -1
- data/lib/permission_forge/admin/change_set_parts/field_edit.rb +4 -1
- data/lib/permission_forge/admin/change_set_parts/field_levels.rb +1 -1
- data/lib/permission_forge/admin/change_set_parts/new_actions.rb +1 -1
- data/lib/permission_forge/admin/change_set_parts/new_fields.rb +38 -11
- data/lib/permission_forge/admin/change_set_parts/resource_edit.rb +17 -1
- data/lib/permission_forge/admin/change_set_parts/resource_flags.rb +1 -1
- data/lib/permission_forge/admin/change_set_parts/set_attrs.rb +4 -0
- data/lib/permission_forge/admin/change_set_parts/values.rb +10 -4
- data/lib/permission_forge/admin/column_fields.rb +22 -21
- data/lib/permission_forge/admin/conditions_form.rb +47 -15
- data/lib/permission_forge/admin/controller_catalog.rb +42 -14
- data/lib/permission_forge/admin/editable_lock.rb +83 -3
- data/lib/permission_forge/admin/effective_access.rb +147 -48
- data/lib/permission_forge/admin/effective_fields.rb +75 -67
- data/lib/permission_forge/admin/error_sentence.rb +47 -0
- data/lib/permission_forge/admin/expiry_presets.rb +17 -0
- data/lib/permission_forge/admin/exports/holdings.rb +6 -3
- data/lib/permission_forge/admin/field_across_sets.rb +7 -4
- data/lib/permission_forge/admin/field_chain.rb +109 -0
- data/lib/permission_forge/admin/field_detail.rb +24 -11
- data/lib/permission_forge/admin/field_label.rb +109 -0
- data/lib/permission_forge/admin/field_level.rb +4 -68
- data/lib/permission_forge/admin/field_provenance.rb +132 -0
- data/lib/permission_forge/admin/field_rows.rb +26 -11
- data/lib/permission_forge/admin/last_changes.rb +15 -1
- data/lib/permission_forge/admin/list_sentence.rb +32 -0
- data/lib/permission_forge/admin/mask_strategy_choices.rb +57 -0
- data/lib/permission_forge/admin/model_catalog.rb +83 -39
- data/lib/permission_forge/admin/model_label.rb +66 -0
- data/lib/permission_forge/admin/people_candidates.rb +21 -9
- data/lib/permission_forge/admin/people_directory.rb +23 -5
- data/lib/permission_forge/admin/permission_set_factory.rb +6 -15
- data/lib/permission_forge/admin/permission_set_list.rb +62 -0
- data/lib/permission_forge/admin/person_label.rb +105 -16
- data/lib/permission_forge/admin/prefill.rb +92 -0
- data/lib/permission_forge/admin/record_name.rb +45 -0
- data/lib/permission_forge/admin/rule_builder.rb +77 -3
- data/lib/permission_forge/admin/rule_form.rb +44 -10
- data/lib/permission_forge/admin/rule_form_input.rb +27 -11
- data/lib/permission_forge/admin/rule_notes.rb +43 -0
- data/lib/permission_forge/admin/rule_preview.rb +96 -0
- data/lib/permission_forge/admin/sensitive_columns.rb +10 -62
- data/lib/permission_forge/admin/set_overview.rb +100 -0
- data/lib/permission_forge/admin/set_summaries.rb +174 -0
- data/lib/permission_forge/admin/settings_catalog.rb +64 -12
- data/lib/permission_forge/admin/state_label.rb +99 -0
- data/lib/permission_forge/admin_method_override.rb +44 -0
- data/lib/permission_forge/api/schema.rb +324 -0
- data/lib/permission_forge/api/serializers/base_serializer.rb +87 -1
- data/lib/permission_forge/api/serializers/permission_set_group_user_serializer.rb +1 -1
- data/lib/permission_forge/api/serializers/permission_set_rule_serializer.rb +1 -1
- data/lib/permission_forge/api/serializers/permission_set_serializer.rb +5 -2
- data/lib/permission_forge/api/serializers/permission_set_user_serializer.rb +1 -1
- data/lib/permission_forge/api/serializers/resource_action_serializer.rb +1 -1
- data/lib/permission_forge/api/serializers/resource_field_serializer.rb +1 -1
- data/lib/permission_forge/api/serializers/resource_serializer.rb +1 -1
- data/lib/permission_forge/api_authorizations.rb +59 -0
- data/lib/permission_forge/api_only_admin.rb +81 -0
- data/lib/permission_forge/audit/actor_codes.rb +32 -0
- data/lib/permission_forge/audit/actor_resolver.rb +1 -2
- data/lib/permission_forge/audit/audited_views.rb +20 -2
- data/lib/permission_forge/audit/boot_warnings.rb +29 -9
- data/lib/permission_forge/audit/event_catalog.rb +16 -6
- data/lib/permission_forge/audit/event_query.rb +3 -3
- data/lib/permission_forge/audit/reason_codes.rb +25 -0
- data/lib/permission_forge/audit/runtime.rb +9 -2
- data/lib/permission_forge/audit/settings_observer.rb +2 -2
- data/lib/permission_forge/audit/unmasked_without_user.rb +169 -0
- data/lib/permission_forge/audit.rb +24 -10
- data/lib/permission_forge/boot_checks.rb +180 -63
- data/lib/permission_forge/cache/base.rb +10 -0
- data/lib/permission_forge/cache/null_cache.rb +5 -0
- data/lib/permission_forge/cache/outcome.rb +119 -0
- data/lib/permission_forge/cache/rails_cache.rb +29 -6
- data/lib/permission_forge/cache/report.rb +150 -0
- data/lib/permission_forge/cache/user_keys.rb +8 -4
- data/lib/permission_forge/cache_warnings.rb +140 -0
- data/lib/permission_forge/concerns/auto_permission_scoping.rb +19 -2
- data/lib/permission_forge/concerns/has_tenant_scoping.rb +1 -1
- data/lib/permission_forge/concerns/has_uuid.rb +1 -1
- data/lib/permission_forge/concerns/keeps_copied_values.rb +48 -0
- data/lib/permission_forge/concerns/masked_attributes/alias_access.rb +40 -4
- data/lib/permission_forge/concerns/masked_attributes/virtual_readers.rb +6 -4
- data/lib/permission_forge/concerns/masked_attributes.rb +150 -34
- data/lib/permission_forge/concerns/normalizes_label.rb +78 -0
- data/lib/permission_forge/concerns/permission_cache_accessor.rb +3 -3
- data/lib/permission_forge/concerns/permission_scoped_findable.rb +121 -29
- data/lib/permission_forge/concerns/permissioned_user.rb +1 -1
- data/lib/permission_forge/concerns/records_audit_events.rb +13 -6
- data/lib/permission_forge/concerns/requires_name.rb +37 -0
- data/lib/permission_forge/concerns/validates_column_lengths.rb +24 -0
- data/lib/permission_forge/concerns/validates_dependency.rb +5 -2
- data/lib/permission_forge/concerns/validates_required_columns.rb +74 -0
- data/lib/permission_forge/conditional_sets.rb +13 -6
- data/lib/permission_forge/configuration/admin_ui_settings.rb +18 -4
- data/lib/permission_forge/configuration/audit_settings.rb +2 -1
- data/lib/permission_forge/configuration/controller_action_settings.rb +5 -4
- data/lib/permission_forge/configuration/masked_attributes_settings.rb +73 -19
- data/lib/permission_forge/configuration/presets.rb +20 -11
- data/lib/permission_forge/configuration/query_scoping_settings.rb +55 -0
- data/lib/permission_forge/configuration/strategy_values.rb +2 -1
- data/lib/permission_forge/configuration.rb +41 -18
- data/lib/permission_forge/controller_actions/managed_index.rb +8 -7
- data/lib/permission_forge/database_reach.rb +93 -0
- data/lib/permission_forge/deprecation.rb +1 -1
- data/lib/permission_forge/docs/api_samples.rb +250 -0
- data/lib/permission_forge/docs/configuration_reference.rb +172 -0
- data/lib/permission_forge/encrypted_attributes.rb +150 -0
- data/lib/permission_forge/engine.rb +46 -14
- data/lib/permission_forge/execution_state/restore.rb +74 -0
- data/lib/permission_forge/execution_state.rb +8 -1
- data/lib/permission_forge/field_level.rb +123 -0
- data/lib/permission_forge/field_names.rb +145 -0
- data/lib/permission_forge/field_variants.rb +96 -0
- data/lib/permission_forge/generated_text.rb +95 -0
- data/lib/permission_forge/inspection_filters.rb +83 -0
- data/lib/permission_forge/managed_fields.rb +66 -0
- data/lib/permission_forge/masked_models.rb +25 -19
- data/lib/permission_forge/masking_sync.rb +100 -25
- data/lib/permission_forge/model_bindings.rb +30 -19
- data/lib/permission_forge/model_lookup.rb +42 -0
- data/lib/permission_forge/operators/encrypted_alias.rb +67 -0
- data/lib/permission_forge/operators/registry.rb +6 -0
- data/lib/permission_forge/operators/rule_column.rb +242 -27
- data/lib/permission_forge/operators/rule_path.rb +179 -0
- data/lib/permission_forge/operators/rule_problem.rb +309 -0
- data/lib/permission_forge/operators/rule_sources.rb +96 -0
- data/lib/permission_forge/operators/value_casters/postgresql_types.rb +237 -0
- data/lib/permission_forge/operators/value_casters/temporal.rb +9 -20
- data/lib/permission_forge/operators/value_casters.rb +61 -13
- data/lib/permission_forge/operators/value_typing.rb +83 -7
- data/lib/permission_forge/query_scoping_warnings.rb +22 -17
- data/lib/permission_forge/rake_audit.rb +5 -4
- data/lib/permission_forge/rake_dry_run.rb +32 -0
- data/lib/permission_forge/rake_output.rb +189 -0
- data/lib/permission_forge/record_read_access.rb +51 -0
- data/lib/permission_forge/resource_chain.rb +14 -2
- data/lib/permission_forge/schema_read/ordered_types.rb +72 -0
- data/lib/permission_forge/schema_read.rb +335 -0
- data/lib/permission_forge/secret_columns.rb +49 -0
- data/lib/permission_forge/sensitive_columns.rb +114 -0
- data/lib/permission_forge/services/attribute_access_guard.rb +22 -14
- data/lib/permission_forge/services/bulk_permission_set_assignment.rb +16 -8
- data/lib/permission_forge/services/concerns/clonable.rb +9 -0
- data/lib/permission_forge/services/concerns/settles_cache.rb +58 -0
- data/lib/permission_forge/services/consent_withdrawal_handler.rb +37 -19
- data/lib/permission_forge/services/data_subject_erasure.rb +83 -45
- data/lib/permission_forge/services/expired_assignment_cleaner.rb +62 -25
- data/lib/permission_forge/services/extra_field_defaults.rb +1 -1
- data/lib/permission_forge/services/field_permission_merger.rb +44 -17
- data/lib/permission_forge/services/filters_response_attributes.rb +20 -5
- data/lib/permission_forge/services/gdpr_field_auditor/text_report.rb +33 -5
- data/lib/permission_forge/services/gdpr_field_auditor.rb +68 -48
- data/lib/permission_forge/services/host_key_guard.rb +8 -5
- data/lib/permission_forge/services/mask_value.rb +72 -11
- data/lib/permission_forge/services/permission_cache_clearer.rb +36 -15
- data/lib/permission_forge/services/permission_hash_builder.rb +48 -19
- data/lib/permission_forge/services/permission_rule_applier.rb +131 -68
- data/lib/permission_forge/services/permission_set_cloner.rb +32 -8
- data/lib/permission_forge/services/permission_set_condition_evaluator.rb +38 -36
- data/lib/permission_forge/services/permission_set_group_cloner.rb +2 -1
- data/lib/permission_forge/services/permits_attributes/result.rb +31 -0
- data/lib/permission_forge/services/permits_attributes.rb +48 -27
- data/lib/permission_forge/services/resource_field_generator/row_builder.rb +96 -0
- data/lib/permission_forge/services/resource_field_generator.rb +71 -42
- data/lib/permission_forge/services/resource_with_fields_builder.rb +2 -1
- data/lib/permission_forge/services/rls_operator_sql.rb +83 -24
- data/lib/permission_forge/services/rls_policy_generator.rb +83 -39
- data/lib/permission_forge/services/rls_read_access_sql.rb +131 -0
- data/lib/permission_forge/services/security_audit/action_check.rb +49 -5
- data/lib/permission_forge/services/security_audit/assignment_check.rb +2 -1
- data/lib/permission_forge/services/security_audit/audit_trail_check.rb +1 -3
- data/lib/permission_forge/services/security_audit/conditions_check.rb +92 -0
- data/lib/permission_forge/services/security_audit/config_check.rb +41 -18
- data/lib/permission_forge/services/security_audit/integrity_check.rb +71 -4
- data/lib/permission_forge/services/security_audit/masking_without_user.rb +66 -0
- data/lib/permission_forge/services/security_audit/personal_data_check.rb +7 -11
- data/lib/permission_forge/services/security_audit/rule_check.rb +180 -50
- data/lib/permission_forge/services/security_audit/text_report.rb +14 -2
- data/lib/permission_forge/services/security_audit/unmanaged_actions.rb +145 -0
- data/lib/permission_forge/services/security_audit/user_model_check.rb +4 -3
- data/lib/permission_forge/services/security_audit.rb +16 -4
- data/lib/permission_forge/services/stale_assignment_auditor.rb +8 -5
- data/lib/permission_forge/timestamp_fields.rb +60 -0
- data/lib/permission_forge/unique_conflict.rb +117 -0
- data/lib/permission_forge/version.rb +1 -1
- data/lib/permission_forge/virtual_fields/discovery.rb +2 -1
- data/lib/permission_forge/virtual_fields.rb +15 -5
- data/lib/permission_forge/warnings.rb +263 -0
- data/lib/permission_forge/web_request.rb +248 -0
- data/lib/permission_forge.rb +57 -0
- data/lib/tasks/permission_forge.rake +26 -6
- data/lib/tasks/permission_forge_audit_events.rake +8 -4
- data/lib/tasks/permission_forge_cache.rake +12 -12
- data/lib/tasks/permission_forge_docs.rake +48 -0
- data/lib/tasks/permission_forge_expiration.rake +11 -5
- data/lib/tasks/permission_forge_gdpr.rake +36 -20
- metadata +94 -1
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'warnings'
|
|
4
|
+
require_relative 'api_only_admin'
|
|
5
|
+
require_relative 'database_reach'
|
|
6
|
+
require_relative 'api_authorizations'
|
|
7
|
+
|
|
3
8
|
module PermissionForge
|
|
4
9
|
# What the engine checks while the host app boots: run (from
|
|
5
10
|
# config.after_initialize) and ensure_tenancy_gem! (from an initializer).
|
|
6
11
|
#
|
|
7
12
|
# The configuration checks need nothing. The database steps are advisory
|
|
8
13
|
# warnings or idempotent work, and they must never abort a boot: a Docker
|
|
9
|
-
# build precompiles assets with no database, a
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
+
# build precompiles assets with no database, a fresh `rails new
|
|
15
|
+
# --skip-kamal` app has no production database file until the deploy sets
|
|
16
|
+
# DATABASE_URL, a worker can start while the database fails over. The
|
|
17
|
+
# database is pinged once (DatabaseReach.problem: whatever connecting
|
|
18
|
+
# raises, an adapter's refusal of its configuration included); a step that
|
|
19
|
+
# loses it midway is skipped (DATABASE_STEP_ERRORS) and the next step runs.
|
|
20
|
+
# Anything else a step raises (a ConfigurationError) still stops the boot.
|
|
21
|
+
#
|
|
22
|
+
# A process that runs nothing but asset tasks (asset_build?:
|
|
23
|
+
# `bin/rails assets:precompile`, the Dockerfile's build step) runs the
|
|
24
|
+
# configuration checks only: it reads no data and serves nothing, and a
|
|
25
|
+
# build has no database to ping (an unreachable host could hold the build
|
|
26
|
+
# for a TCP timeout).
|
|
27
|
+
#
|
|
28
|
+
# Every warning goes through Warnings.emit, which decides the channel (the
|
|
29
|
+
# log; the terminal where the log is not read) and writes nothing while a
|
|
30
|
+
# generator boots the app (Warnings.generator_running?): `bin/rails
|
|
31
|
+
# generate permission_forge:install` boots before it writes the
|
|
32
|
+
# initializer, so its warnings described a configuration the app was about
|
|
33
|
+
# to stop having (the defaults, e.g. cache_backend :memory) — the first
|
|
34
|
+
# lines a new user read in log/development.log. Nothing is checked then
|
|
35
|
+
# either (run returns before the database steps). The next server, console
|
|
36
|
+
# or task boot checks the configuration the app has.
|
|
14
37
|
#
|
|
15
38
|
# @api private
|
|
16
39
|
module BootChecks
|
|
17
|
-
# Errors that mean "the database is not there (yet)"
|
|
18
|
-
# created, not migrated.
|
|
19
|
-
DATABASE_STEP_ERRORS =
|
|
40
|
+
# Errors that mean "the database is not there (yet)" once it answered the
|
|
41
|
+
# ping: gone, refused, not created, not migrated (DatabaseReach::READ_ERRORS).
|
|
42
|
+
DATABASE_STEP_ERRORS = DatabaseReach::READ_ERRORS
|
|
43
|
+
|
|
44
|
+
# The asset tasks of Propshaft and Sprockets (each boots the app through
|
|
45
|
+
# :environment). A process whose Rake top-level tasks are all among them
|
|
46
|
+
# is an asset build (asset_build?).
|
|
47
|
+
ASSET_TASKS = %w[assets:precompile assets:clean assets:clobber].freeze
|
|
20
48
|
|
|
21
49
|
# The boot steps that read the database, in order. Each runs on its
|
|
22
50
|
# own: one that loses the database is skipped (database_step).
|
|
@@ -34,16 +62,47 @@ module PermissionForge
|
|
|
34
62
|
masked_attributes: ->(_config) { MaskingSync.boot! }
|
|
35
63
|
}.freeze
|
|
36
64
|
|
|
65
|
+
# The commands `bin/rails generate` and `bin/rails destroy` run (the one
|
|
66
|
+
# definition is the emitter's: Warnings::GENERATOR_COMMANDS).
|
|
67
|
+
GENERATOR_COMMANDS = Warnings::GENERATOR_COMMANDS
|
|
68
|
+
|
|
37
69
|
class << self
|
|
38
70
|
# @param config [Configuration]
|
|
39
71
|
def run(config)
|
|
40
72
|
config.validate_gdpr_explicit_choice!
|
|
73
|
+
return MaskingSync.reset! if generator_running?
|
|
74
|
+
|
|
41
75
|
warn_configuration(config)
|
|
42
|
-
return
|
|
76
|
+
return MaskingSync.reset! if asset_build?
|
|
77
|
+
|
|
78
|
+
problem = database_problem
|
|
79
|
+
return database_unreachable(problem) if problem
|
|
43
80
|
|
|
44
81
|
DATABASE_STEPS.each { |name, step| database_step(name) { step.call(config) } }
|
|
45
82
|
end
|
|
46
83
|
|
|
84
|
+
# Whether this boot is that of a generator (`bin/rails generate` or
|
|
85
|
+
# `bin/rails destroy`): Warnings.generator_running?, which also keeps
|
|
86
|
+
# every warning quiet then.
|
|
87
|
+
#
|
|
88
|
+
# @return [Boolean]
|
|
89
|
+
def generator_running?
|
|
90
|
+
Warnings.generator_running?
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Whether this process runs nothing but asset tasks (ASSET_TASKS): the
|
|
94
|
+
# tasks Rake was asked for on the command line (`bin/rails
|
|
95
|
+
# assets:precompile`), not a task that only depends on one. False
|
|
96
|
+
# outside Rake.
|
|
97
|
+
#
|
|
98
|
+
# @return [Boolean]
|
|
99
|
+
def asset_build?
|
|
100
|
+
return false unless defined?(::Rake.application)
|
|
101
|
+
|
|
102
|
+
tasks = ::Rake.application.top_level_tasks.map { |task| task.sub(/\[.*\z/m, '') }
|
|
103
|
+
tasks.any? && tasks.all? { |task| ASSET_TASKS.include?(task) }
|
|
104
|
+
end
|
|
105
|
+
|
|
47
106
|
# HasTenantScoping silently skips the scope when the gem is absent,
|
|
48
107
|
# which would leave every tenant's permission data visible to every
|
|
49
108
|
# other tenant — refuse to boot instead.
|
|
@@ -71,13 +130,13 @@ module PermissionForge
|
|
|
71
130
|
return unless conditional_sets.exists?
|
|
72
131
|
return unless resolved_context(config).empty?
|
|
73
132
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
Warnings.emit(:conditional_sets_without_context,
|
|
134
|
+
"#{conditional_sets.count} permission set(s) use activation conditions " \
|
|
135
|
+
'(session flag, allowed_ips, or login hours) but request_context_resolver ' \
|
|
136
|
+
'returns empty context. These sets will evaluate as unconditional ' \
|
|
137
|
+
'(ALWAYS ACTIVE) — IP/hours/consent restrictions are NOT enforced. ' \
|
|
138
|
+
'Configure config.request_context_resolver, or set ' \
|
|
139
|
+
'config.conditional_sets_strict_mode = true to fail closed.', severity: :security)
|
|
81
140
|
rescue ActiveRecord::StatementInvalid
|
|
82
141
|
# Tables don't exist yet (pre-migration)
|
|
83
142
|
end
|
|
@@ -87,88 +146,146 @@ module PermissionForge
|
|
|
87
146
|
return if config.api_require_authorization
|
|
88
147
|
return if config.api_action_authorization && config.api_assignment_authorization
|
|
89
148
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
149
|
+
Warnings.emit(:api_authorization_gap,
|
|
150
|
+
'API is enabled, config.api_require_authorization is false and ' \
|
|
151
|
+
'api_action_authorization / api_assignment_authorization is not set. ' \
|
|
152
|
+
'api_auth only proves identity — any authenticated caller can create ' \
|
|
153
|
+
'permission sets and assign them (privilege escalation). Configure both ' \
|
|
154
|
+
'authorization lambdas, or remove api_require_authorization = false ' \
|
|
155
|
+
'(the default, true, denies mutations until they are set).', severity: :security, audience: :server)
|
|
97
156
|
end
|
|
98
157
|
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
158
|
+
# The API is on and api_auth admits callers, but a lambda the API
|
|
159
|
+
# needs is unset (ApiAuthorizations.unset): what it guards is refused
|
|
160
|
+
# (403). It fails closed; the note says so before the first refused
|
|
161
|
+
# request does. Under api_require_authorization = false the missing
|
|
162
|
+
# change and assignment lambdas are api_authorization_gap's instead.
|
|
163
|
+
#
|
|
164
|
+
# @param config [Configuration]
|
|
165
|
+
def warn_api_authorizations_unset(config)
|
|
166
|
+
lines = ApiAuthorizations.lines(config)
|
|
167
|
+
return if lines.empty?
|
|
168
|
+
|
|
169
|
+
Warnings.emit(:api_authorization_unset,
|
|
170
|
+
'The JSON API is on and api_auth admits callers, but these authorization lambdas are not ' \
|
|
171
|
+
"set, so the API refuses (403, naming the option) what each guards — #{lines.join('; ')}. " \
|
|
172
|
+
'Set each one in config/initializers/permission_forge.rb (docs/admin-api.md#requiring-authorization-lambdas).',
|
|
173
|
+
audience: :server)
|
|
174
|
+
end
|
|
104
175
|
|
|
105
|
-
|
|
106
|
-
|
|
176
|
+
# One query for the distinct names of the rows in the clear that reach
|
|
177
|
+
# someone's hash (in effect, in a granting set; no record is built),
|
|
178
|
+
# and one more for the resource of the first match. What counts as
|
|
179
|
+
# personal data is PermissionForge::SensitiveColumns' answer, as for
|
|
180
|
+
# the GDPR audit and the admin.
|
|
181
|
+
def warn_unmasked_gdpr_fields(config)
|
|
182
|
+
sensitive = PermissionForge::SensitiveColumns.new(configuration: config)
|
|
183
|
+
in_clear = PermissionForge::ResourceField.in_effect.merge(PermissionForge::PermissionSet.granting).exposing_unacknowledged
|
|
184
|
+
name, match = first_sensitive(in_clear.distinct.pluck(:name), sensitive)
|
|
107
185
|
return unless name
|
|
108
186
|
|
|
109
|
-
resource =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
187
|
+
resource = in_clear.where(name: name).first&.resource
|
|
188
|
+
Warnings.emit(:unmasked_gdpr_fields,
|
|
189
|
+
"GDPR warning: field '#{name}' on resource '#{resource&.name}' #{matched_by(match)} " \
|
|
190
|
+
'but is not masked. Consider enabling gdpr_defaults or masking this field manually.')
|
|
113
191
|
rescue ActiveRecord::StatementInvalid
|
|
114
192
|
# Table doesn't exist yet (pre-migration)
|
|
115
193
|
end
|
|
116
194
|
|
|
195
|
+
# The admin screens in a `rails new --api` application: without the
|
|
196
|
+
# cookies, session and flash middlewares every admin page that renders
|
|
197
|
+
# a form is a 500 (ApiOnlyAdmin says which ones to add). Skipped when
|
|
198
|
+
# config.api_only_admin_warning is false.
|
|
199
|
+
#
|
|
200
|
+
# @param application [Rails::Application]
|
|
201
|
+
# @param config [Configuration]
|
|
202
|
+
def warn_api_only_admin(application = Rails.application, config: PermissionForge.configuration)
|
|
203
|
+
return unless config.api_only_admin_warning
|
|
204
|
+
|
|
205
|
+
missing = ApiOnlyAdmin.missing_middlewares(application)
|
|
206
|
+
return if missing.empty?
|
|
207
|
+
|
|
208
|
+
Warnings.emit(:api_only_admin, ApiOnlyAdmin.message(missing), severity: :config, audience: :server)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# The engine's after_routes_loaded hook: the api_only_admin warning,
|
|
212
|
+
# once per process (a development reload draws the routes again).
|
|
213
|
+
#
|
|
214
|
+
# @param application [Rails::Application]
|
|
215
|
+
def routes_loaded(application)
|
|
216
|
+
return if @routes_checked
|
|
217
|
+
|
|
218
|
+
@routes_checked = true
|
|
219
|
+
warn_api_only_admin(application)
|
|
220
|
+
end
|
|
221
|
+
|
|
117
222
|
private
|
|
118
223
|
|
|
119
|
-
#
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
224
|
+
# [name, SensitiveColumns::Match] of the first name that looks like personal data.
|
|
225
|
+
def first_sensitive(names, sensitive)
|
|
226
|
+
names.lazy.filter_map { |name| (match = sensitive.match(name)) && [name, match] }.first
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# What made the field personal data (SensitiveColumns::Match#source).
|
|
230
|
+
def matched_by(match)
|
|
231
|
+
match.filter_parameter? ? "is named by the application's filter_parameters" : "matches the GDPR pattern '#{match.pattern}'"
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# What connecting to the gem's database raised, nil when it answered
|
|
235
|
+
# (DatabaseReach.problem).
|
|
236
|
+
#
|
|
237
|
+
# @return [Exception, nil]
|
|
238
|
+
def database_problem
|
|
239
|
+
DatabaseReach.problem
|
|
127
240
|
end
|
|
128
241
|
|
|
129
242
|
def database_step(name)
|
|
130
243
|
yield
|
|
131
244
|
rescue *DATABASE_STEP_ERRORS => e
|
|
132
|
-
|
|
245
|
+
Warnings.emit(:"boot_check_skipped.#{name}",
|
|
246
|
+
"Boot check #{name} skipped: the database could not be read (#{e.class}).")
|
|
133
247
|
end
|
|
134
248
|
|
|
135
249
|
# The boot step did not run: the first request or job that reaches the
|
|
136
|
-
# database applies auto-applied masking (MaskingSync).
|
|
137
|
-
|
|
250
|
+
# database applies auto-applied masking (MaskingSync). The cause is
|
|
251
|
+
# named: "not configured" (an adapter's ArgumentError) reads otherwise
|
|
252
|
+
# than "refused". The ping loads the gem's models (and Active Record
|
|
253
|
+
# with them, as Rails' lazy load would): an error raised there — a
|
|
254
|
+
# host's on_load(:active_record) hook — is named the same way.
|
|
255
|
+
def database_unreachable(problem)
|
|
138
256
|
MaskingSync.reset!
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
257
|
+
Warnings.emit(:database_unreachable,
|
|
258
|
+
"The database could not be reached at boot, or the gem's models could not be loaded " \
|
|
259
|
+
"(#{problem.class}: #{problem.message.lines.first&.strip}); " \
|
|
260
|
+
'the boot checks that read it (security warnings) were skipped. Auto-applied masking is ' \
|
|
261
|
+
'applied at the first request or job that reaches the database.')
|
|
142
262
|
end
|
|
143
263
|
|
|
144
264
|
# The boot warnings that only read the configuration.
|
|
145
265
|
def warn_configuration(config)
|
|
146
|
-
|
|
266
|
+
CacheWarnings.call(config)
|
|
147
267
|
warn_basic_auth_without_credentials(config)
|
|
148
268
|
warn_api_authorization_gap(config)
|
|
149
|
-
config
|
|
269
|
+
warn_api_authorizations_unset(config)
|
|
270
|
+
config.tenantless_admin_warning&.then { |message| warn_tenantless_admin(message) }
|
|
150
271
|
QueryScopingWarnings.warn_unscoped_detection_raise_in_production(config)
|
|
272
|
+
WebRequest::StackCheck.check(config)
|
|
151
273
|
end
|
|
152
274
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
'Permissions will be inconsistent across Puma workers. ' \
|
|
158
|
-
'Configure config.cache_backend = :rails_cache with Redis, Memcached, or SolidCache.'
|
|
275
|
+
# AdminUiSettings#tenantless_admin_warning is the text; the emitter
|
|
276
|
+
# puts the prefix on.
|
|
277
|
+
def warn_tenantless_admin(message)
|
|
278
|
+
Warnings.emit(:tenantless_admin, message, severity: :security, audience: :server)
|
|
159
279
|
end
|
|
160
280
|
|
|
161
281
|
def warn_basic_auth_without_credentials(config)
|
|
162
282
|
return unless config.http_basic_auth_enabled
|
|
163
283
|
return if config.http_basic_auth_user.present? && config.http_basic_auth_password.present?
|
|
164
284
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def gdpr_match?(field_name, patterns)
|
|
171
|
-
patterns.any? { |regex, _| field_name.match?(regex) }
|
|
285
|
+
Warnings.emit(:basic_auth_without_credentials,
|
|
286
|
+
'HTTP Basic Auth is enabled but credentials are not configured. The admin UI will return ' \
|
|
287
|
+
'401 for all requests. Set config.http_basic_auth_user and config.http_basic_auth_password.',
|
|
288
|
+
audience: :server)
|
|
172
289
|
end
|
|
173
290
|
|
|
174
291
|
# Taken as the per-read selection takes it: a Hash, or anything with
|
|
@@ -46,6 +46,16 @@ module PermissionForge
|
|
|
46
46
|
false
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
+
# Whether the store keeps what is written to it. A store that keeps
|
|
50
|
+
# nothing (cache_backend = :null, a :null_store) caches no permission
|
|
51
|
+
# hash, and cannot carry the token MaskingSync tells other processes
|
|
52
|
+
# about a newly masked model with.
|
|
53
|
+
#
|
|
54
|
+
# @return [Boolean]
|
|
55
|
+
def keeps_entries?
|
|
56
|
+
true
|
|
57
|
+
end
|
|
58
|
+
|
|
49
59
|
# Writes an entry that never expires — not even under a default expiry
|
|
50
60
|
# the store applies to every entry (a Rails cache configured with
|
|
51
61
|
# expires_in). Here a write without a TTL, which is that already.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PermissionForge
|
|
4
|
+
module Cache
|
|
5
|
+
# What one cache-touching operation did to the cached permissions, as
|
|
6
|
+
# every surface reports it — the terminal (RakeOutput), the admin flash
|
|
7
|
+
# (CacheConfirmation), the API body and the summary audit event:
|
|
8
|
+
#
|
|
9
|
+
# - `confirmed`: true when the store confirmed every removal the
|
|
10
|
+
# operation asked for (Cache::Failure reported nothing), false when it
|
|
11
|
+
# did not (the old permissions may be served until cache_ttl), nil when
|
|
12
|
+
# that is not known where the outcome is made — the invalidation
|
|
13
|
+
# follows the surrounding transaction's commit (Cache::Settlement), or
|
|
14
|
+
# the summary event is written before the cache work runs;
|
|
15
|
+
# - `process_local`: the store lives in each process
|
|
16
|
+
# (Cache::Base#process_local?: `cache_backend = :memory`, or Rails.cache a
|
|
17
|
+
# `:memory_store`), so only the process that ran the operation saw it;
|
|
18
|
+
# - `in_request`: the operation ran in a server process (the admin or
|
|
19
|
+
# the API: Audit::Source 'admin_ui' / 'api', or any code of a web
|
|
20
|
+
# server process, a host controller among it: Report.in_request?), so
|
|
21
|
+
# on a process-local store that server process did see it and the
|
|
22
|
+
# *other* web workers and the job processes kept theirs; false for a
|
|
23
|
+
# rake task, a runner, a console or a job process, where every other
|
|
24
|
+
# process kept theirs;
|
|
25
|
+
# - `unconfirmed`: how many users the store did not confirm (nil when not
|
|
26
|
+
# known yet);
|
|
27
|
+
# - `work`: false when the operation did no cache work at all — a dry run
|
|
28
|
+
# (.none: `confirmed` nil, `unconfirmed` 0); true otherwise. Only an
|
|
29
|
+
# outcome without work carries the key in #to_h (`work: false`), so
|
|
30
|
+
# every answer of an operation that did its work keeps its four keys.
|
|
31
|
+
# A dry run used to answer `confirmed: true` for work it never did
|
|
32
|
+
# (field test round 7, E#55).
|
|
33
|
+
#
|
|
34
|
+
# Made by Cache::Report, the one way a service measures an invalidation.
|
|
35
|
+
#
|
|
36
|
+
# @api private
|
|
37
|
+
Outcome = Data.define(:confirmed, :process_local, :unconfirmed, :in_request, :work) do
|
|
38
|
+
# @param work [Boolean] false only for an operation that did no cache work (.none)
|
|
39
|
+
def initialize(confirmed:, process_local:, unconfirmed:, in_request:, work: true)
|
|
40
|
+
super
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The outcome of an operation that did no cache work (every dry run):
|
|
44
|
+
# nothing asked of the store, so nothing confirmed and nobody left
|
|
45
|
+
# unconfirmed; the store's scope and the origin as measured.
|
|
46
|
+
#
|
|
47
|
+
# @param process_local [Boolean]
|
|
48
|
+
# @param in_request [Boolean]
|
|
49
|
+
# @return [Outcome]
|
|
50
|
+
def self.none(process_local:, in_request:)
|
|
51
|
+
new(confirmed: nil, process_local: process_local, unconfirmed: 0, in_request: in_request, work: false)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# The outcome before the cache work has run, or where its result is not
|
|
55
|
+
# known: nothing confirmed yet, the store's scope and the origin known
|
|
56
|
+
# already.
|
|
57
|
+
#
|
|
58
|
+
# @param process_local [Boolean]
|
|
59
|
+
# @param in_request [Boolean]
|
|
60
|
+
# @return [Outcome]
|
|
61
|
+
def self.deferred(process_local:, in_request:)
|
|
62
|
+
new(confirmed: nil, process_local: process_local, unconfirmed: nil, in_request: in_request)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# An Outcome from what a service answered under `cache:` (its Hash, or
|
|
66
|
+
# the Outcome itself).
|
|
67
|
+
#
|
|
68
|
+
# @param value [Outcome, Hash]
|
|
69
|
+
# @return [Outcome]
|
|
70
|
+
def self.wrap(value)
|
|
71
|
+
return value if value.is_a?(self)
|
|
72
|
+
|
|
73
|
+
hash = value.to_h.transform_keys(&:to_sym)
|
|
74
|
+
new(confirmed: hash[:confirmed], process_local: hash[:process_local] == true, unconfirmed: hash[:unconfirmed],
|
|
75
|
+
in_request: hash[:in_request] == true, work: hash[:work] != false)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# What a summary event records (string keys, as event data is stored).
|
|
79
|
+
#
|
|
80
|
+
# @return [Hash]
|
|
81
|
+
def event_data
|
|
82
|
+
{ 'cache_confirmed' => confirmed, 'process_local' => process_local, 'in_request' => in_request, 'unconfirmed' => unconfirmed }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def process_local? = process_local == true
|
|
86
|
+
def in_request? = in_request == true
|
|
87
|
+
def confirmed? = confirmed == true
|
|
88
|
+
# No cache work was done (.none: a dry run).
|
|
89
|
+
def none? = work == false
|
|
90
|
+
|
|
91
|
+
# The outcome as a service answers it: the four keys, and `work: false`
|
|
92
|
+
# for an operation that did no cache work (#none?).
|
|
93
|
+
#
|
|
94
|
+
# @return [Hash]
|
|
95
|
+
def to_h
|
|
96
|
+
none? ? super : super.except(:work)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# A flash: an alert only when the store said no; a confirmation that is
|
|
100
|
+
# not known yet is not a failure to announce.
|
|
101
|
+
#
|
|
102
|
+
# @return [Symbol] :notice or :alert
|
|
103
|
+
def flash_kind = confirmed == false ? :alert : :notice
|
|
104
|
+
|
|
105
|
+
# Which processes kept their cached permissions: `:none` (a shared
|
|
106
|
+
# store), `:other_processes` (a process-local store, the operation ran
|
|
107
|
+
# in a server process: the other web workers and the job processes),
|
|
108
|
+
# `:servers` (a process-local store, the operation ran elsewhere: every
|
|
109
|
+
# web and job process).
|
|
110
|
+
#
|
|
111
|
+
# @return [Symbol]
|
|
112
|
+
def kept_by
|
|
113
|
+
return :none unless process_local?
|
|
114
|
+
|
|
115
|
+
in_request? ? :other_processes : :servers
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -22,13 +22,30 @@ module PermissionForge
|
|
|
22
22
|
cache_store.read_multi(*keys.map { |key| prefixed_key(key) }).transform_values { |value| deep_symbolize(value) }
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# Classes and modules whose #write_multi_entries is no batch whose
|
|
26
|
+
# answer says the entries were written, by name (none is loaded for the
|
|
27
|
+
# asking). ActiveSupport's LocalCache strategy (Rails 8.2) only forgets
|
|
28
|
+
# the request's copies and hands the entries on. Rails 8.2's Memcached
|
|
29
|
+
# store does send one batch, but answers nil whether it was written or
|
|
30
|
+
# not and hands its errors to no handler: it is written key by key, as
|
|
31
|
+
# on earlier versions, where each #write answers.
|
|
32
|
+
UNJUDGED_BATCHES = %w[
|
|
33
|
+
ActiveSupport::Cache::Strategy::LocalCache
|
|
34
|
+
ActiveSupport::Cache::MemCacheStore
|
|
35
|
+
].freeze
|
|
36
|
+
|
|
25
37
|
# Whether the store writes many entries in one call of its own, rather
|
|
26
|
-
# than ActiveSupport's default loop (which ignores each write's answer)
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
# than ActiveSupport's default loop (which ignores each write's answer):
|
|
39
|
+
# the first #write_multi_entries along its ancestors that is not one of
|
|
40
|
+
# `unjudged` is not ActiveSupport's own. Anything that is not an
|
|
41
|
+
# ActiveSupport store (a wrapper) is written key by key through its
|
|
42
|
+
# #write.
|
|
43
|
+
def self.multi_write?(store, unjudged: UNJUDGED_BATCHES)
|
|
44
|
+
return false unless store.is_a?(ActiveSupport::Cache::Store)
|
|
45
|
+
|
|
46
|
+
writer = store.class.instance_method(:write_multi_entries)
|
|
47
|
+
writer = writer.super_method while writer && unjudged.include?(writer.owner.name)
|
|
48
|
+
!writer.nil? && writer.owner != ActiveSupport::Cache::Store
|
|
32
49
|
end
|
|
33
50
|
|
|
34
51
|
def initialize(prefix: 'pf', store: nil)
|
|
@@ -83,6 +100,12 @@ module PermissionForge
|
|
|
83
100
|
cache_store.is_a?(ActiveSupport::Cache::MemoryStore)
|
|
84
101
|
end
|
|
85
102
|
|
|
103
|
+
# A :null_store keeps nothing (the Rails 7.1/7.2 development default
|
|
104
|
+
# without `bin/rails dev:cache`).
|
|
105
|
+
def keeps_entries?
|
|
106
|
+
!cache_store.is_a?(ActiveSupport::Cache::NullStore)
|
|
107
|
+
end
|
|
108
|
+
|
|
86
109
|
# An explicit `expires_in: nil` overrides the store's default expiry.
|
|
87
110
|
def write_permanent(key, value)
|
|
88
111
|
cache_store.write(prefixed_key(key), value, expires_in: nil)
|