decidim-restfull-core 0.3.11
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/app/commands/decidim/rest_full/core/create_api_client.rb +40 -0
- data/app/commands/decidim/rest_full/core/impersonate_resource_owner_from_credentials.rb +151 -0
- data/app/commands/decidim/rest_full/core/syncronize_unconfirmed_host.rb +45 -0
- data/app/controllers/concerns/decidim/api/rest_full/async_api_job_enqueuing.rb +69 -0
- data/app/controllers/concerns/decidim/api/rest_full/collection_pagination.rb +78 -0
- data/app/controllers/concerns/decidim/api/rest_full/collection_pagination_meta.rb +25 -0
- data/app/controllers/concerns/decidim/api/rest_full/conditional_get_rendering.rb +49 -0
- data/app/controllers/concerns/decidim/api/rest_full/extended_data_endpoints.rb +96 -0
- data/app/controllers/concerns/decidim/api/rest_full/job_response_linking.rb +31 -0
- data/app/controllers/decidim/api/rest_full/application_controller.rb +245 -0
- data/app/controllers/decidim/api/rest_full/attachments/attachments_controller.rb +81 -0
- data/app/controllers/decidim/api/rest_full/components/component_extended_data_controller.rb +31 -0
- data/app/controllers/decidim/api/rest_full/components/components_controller.rb +68 -0
- data/app/controllers/decidim/api/rest_full/core/resources_controller.rb +142 -0
- data/app/controllers/decidim/api/rest_full/core.rb +11 -0
- data/app/controllers/decidim/api/rest_full/jobs/jobs_controller.rb +109 -0
- data/app/controllers/decidim/api/rest_full/organizations/organization_extended_data_controller.rb +31 -0
- data/app/controllers/decidim/api/rest_full/organizations/organizations_controller.rb +234 -0
- data/app/controllers/decidim/api/rest_full/roles/roles_controller.rb +125 -0
- data/app/controllers/decidim/api/rest_full/spaces/space_extended_data_controller.rb +29 -0
- data/app/controllers/decidim/api/rest_full/spaces/spaces_controller.rb +225 -0
- data/app/controllers/decidim/api/rest_full/users/magic_links_controller.rb +81 -0
- data/app/controllers/decidim/api/rest_full/users/user_extended_data_controller.rb +92 -0
- data/app/controllers/decidim/api/rest_full/users/users_controller.rb +40 -0
- data/app/controllers/decidim/api/rest_full/webhooks/webhook_events_controller.rb +33 -0
- data/app/controllers/decidim/api/rest_full/webhooks/webhook_registrations_controller.rb +106 -0
- data/app/controllers/decidim/rest_full/pages_controller.rb +9 -0
- data/app/controllers/decidim/rest_full/system/api_clients_controller.rb +69 -0
- data/app/controllers/decidim/rest_full/system/permissions_controller.rb +30 -0
- data/app/controllers/decidim/rest_full/system/webhook_registrations_controller.rb +49 -0
- data/app/forms/decidim/rest_full/core/admin/config_form.rb +49 -0
- data/app/forms/decidim/rest_full/core/api_client_form.rb +20 -0
- data/app/forms/decidim/rest_full/core/api_permissions.rb +18 -0
- data/app/forms/decidim/rest_full/core/magic_link_redirect_url_form.rb +114 -0
- data/app/forms/decidim/rest_full/core/webhook_event_form.rb +35 -0
- data/app/forms/decidim/rest_full/core/webhook_registration_form.rb +49 -0
- data/app/jobs/decidim/rest_full/application_job.rb +10 -0
- data/app/jobs/decidim/rest_full/core/space_webhook_job.rb +60 -0
- data/app/jobs/decidim/rest_full/core/syncronize_unconfirmed_host_job.rb +18 -0
- data/app/jobs/decidim/rest_full/core/webhook_job.rb +13 -0
- data/app/jobs/decidim/rest_full/execute_api_job_job.rb +55 -0
- data/app/models/decidim/rest_full/api_job.rb +74 -0
- data/app/models/decidim/rest_full/core/ability.rb +195 -0
- data/app/models/decidim/rest_full/core/api_client.rb +56 -0
- data/app/models/decidim/rest_full/core/magic_token.rb +45 -0
- data/app/models/decidim/rest_full/core/permission.rb +15 -0
- data/app/models/decidim/rest_full/core/resource_extended_data.rb +16 -0
- data/app/models/decidim/rest_full/core/webhook_registration.rb +61 -0
- data/app/overrides/system_host_input.rb +40 -0
- data/app/serializers/decidim/api/rest_full/core/application_serializer.rb +19 -0
- data/app/serializers/decidim/api/rest_full/core/assembly_serializer.rb +13 -0
- data/app/serializers/decidim/api/rest_full/core/attachment_serializer.rb +76 -0
- data/app/serializers/decidim/api/rest_full/core/awesome_iframe_component_serializer.rb +12 -0
- data/app/serializers/decidim/api/rest_full/core/awesome_map_component_serializer.rb +12 -0
- data/app/serializers/decidim/api/rest_full/core/component_serializer.rb +97 -0
- data/app/serializers/decidim/api/rest_full/core/helpers/resource_links_helper.rb +48 -0
- data/app/serializers/decidim/api/rest_full/core/magic_link_redirect_serializer.rb +43 -0
- data/app/serializers/decidim/api/rest_full/core/magic_link_serializer.rb +44 -0
- data/app/serializers/decidim/api/rest_full/core/organization_serializer.rb +60 -0
- data/app/serializers/decidim/api/rest_full/core/organization_webhook_serializer.rb +21 -0
- data/app/serializers/decidim/api/rest_full/core/page_component_serializer.rb +20 -0
- data/app/serializers/decidim/api/rest_full/core/page_serializer.rb +12 -0
- data/app/serializers/decidim/api/rest_full/core/participatory_process_serializer.rb +13 -0
- data/app/serializers/decidim/api/rest_full/core/resource_serializer.rb +84 -0
- data/app/serializers/decidim/api/rest_full/core/role_serializer.rb +21 -0
- data/app/serializers/decidim/api/rest_full/core/serializer_lookup.rb +55 -0
- data/app/serializers/decidim/api/rest_full/core/space_serializer.rb +117 -0
- data/app/serializers/decidim/api/rest_full/core/space_webhook_serializer.rb +64 -0
- data/app/serializers/decidim/api/rest_full/core/user_serializer.rb +43 -0
- data/app/serializers/decidim/api/rest_full/core/user_webhook_serializer.rb +21 -0
- data/app/serializers/decidim/api/rest_full/core/webhook_registration_serializer.rb +25 -0
- data/app/serializers/decidim/api/rest_full/core/webhook_serializer.rb +68 -0
- data/app/serializers/decidim/api/rest_full/core.rb +10 -0
- data/app/services/decidim/rest_full/core/api_system_operations.rb +505 -0
- data/app/services/decidim/rest_full/core/fire_webhook.rb +114 -0
- data/app/services/decidim/rest_full/core/participatory_process_step_activated_webhook_handler.rb +39 -0
- data/app/services/decidim/rest_full/participatory_space_visibility.rb +64 -0
- data/app/views/decidim/rest_full/core/admin/_organization_settings_tab.html.erb +35 -0
- data/app/views/decidim/rest_full/pages/show.html.erb +60 -0
- data/app/views/decidim/rest_full/system/api_clients/_edit_info_tab.erb +261 -0
- data/app/views/decidim/rest_full/system/api_clients/_edit_webhook_tab.erb +74 -0
- data/app/views/decidim/rest_full/system/api_clients/_form.html.erb +23 -0
- data/app/views/decidim/rest_full/system/api_clients/_permissions_scope.html.erb +22 -0
- data/app/views/decidim/rest_full/system/api_clients/edit.html.erb +53 -0
- data/app/views/decidim/rest_full/system/api_clients/index.html.erb +37 -0
- data/app/views/decidim/rest_full/system/api_clients/new.html.erb +13 -0
- data/app/views/decidim/rest_full/system/api_clients/show.html.erb +10 -0
- data/config/i18n-tasks.yml +381 -0
- data/config/locales/decidim_rest_full.en.yml +184 -0
- data/config/routes.rb +116 -0
- data/db/migrate/20241125061513_create_api_client_permissions.rb +12 -0
- data/db/migrate/20250112155305_create_proposal_application_id.rb +11 -0
- data/db/migrate/20250131155931_add_users_magic_token.rb +14 -0
- data/db/migrate/20250609083335_create_webhooks_table.rb +16 -0
- data/db/migrate/20250609091039_add_is_event_to_api_client_permissions.rb +7 -0
- data/db/migrate/20250624080106_create_organization_extended_data.rb +11 -0
- data/db/migrate/20260321120000_add_redirect_url_to_decidim_rest_full_user_magic_tokens.rb +7 -0
- data/db/migrate/20260511120000_create_decidim_rest_full_api_jobs.rb +23 -0
- data/db/migrate/20260515120000_add_poll_and_oauth_context_to_rest_full_api_jobs.rb +38 -0
- data/db/migrate/20260516153000_remove_poll_secret_from_decidim_rest_full_api_jobs.rb +7 -0
- data/db/migrate/20260516160000_add_org_status_index_to_rest_full_api_jobs.rb +9 -0
- data/db/migrate/20260805070000_create_resource_extended_data.rb +44 -0
- data/lib/decidim/rest_full/api_execution_context.rb +58 -0
- data/lib/decidim/rest_full/api_job_command_runner.rb +48 -0
- data/lib/decidim/rest_full/api_job_payload.rb +19 -0
- data/lib/decidim/rest_full/cli/base.rb +84 -0
- data/lib/decidim/rest_full/cli/create.rb +122 -0
- data/lib/decidim/rest_full/cli/delete.rb +48 -0
- data/lib/decidim/rest_full/cli/get.rb +53 -0
- data/lib/decidim/rest_full/cli/grant.rb +58 -0
- data/lib/decidim/rest_full/cli/revoke.rb +53 -0
- data/lib/decidim/rest_full/cli.rb +70 -0
- data/lib/decidim/rest_full/core/apartment_tenant_switch.rb +23 -0
- data/lib/decidim/rest_full/core/api_exception.rb +179 -0
- data/lib/decidim/rest_full/core/attachments_operations.rb +232 -0
- data/lib/decidim/rest_full/core/configuration.rb +116 -0
- data/lib/decidim/rest_full/core/definition_registry.rb +509 -0
- data/lib/decidim/rest_full/core/doorkeeper_config.rb +130 -0
- data/lib/decidim/rest_full/core/engine.rb +167 -0
- data/lib/decidim/rest_full/core/extended_data_at_path.rb +22 -0
- data/lib/decidim/rest_full/core/gem_spec_paths.rb +56 -0
- data/lib/decidim/rest_full/core/has_extended_data.rb +70 -0
- data/lib/decidim/rest_full/core/http_cache/collection_fingerprint.rb +97 -0
- data/lib/decidim/rest_full/core/http_cache/fingerprint_contributor_registry.rb +53 -0
- data/lib/decidim/rest_full/core/http_cache/request_oauth_context.rb +34 -0
- data/lib/decidim/rest_full/core/http_cache/resource_show_fingerprint.rb +74 -0
- data/lib/decidim/rest_full/core/menu.rb +18 -0
- data/lib/decidim/rest_full/core/module_availability.rb +181 -0
- data/lib/decidim/rest_full/core/open_api_definition_paths.rb +59 -0
- data/lib/decidim/rest_full/core/overrides/application_mailer_override.rb +50 -0
- data/lib/decidim/rest_full/core/overrides/organization_client_ids_override.rb +17 -0
- data/lib/decidim/rest_full/core/overrides/update_organization_command_override.rb +27 -0
- data/lib/decidim/rest_full/core/overrides/update_organization_form_override.rb +46 -0
- data/lib/decidim/rest_full/core/overrides/user_extended_data_ransack.rb +15 -0
- data/lib/decidim/rest_full/core/overrides/user_magic_token_override.rb +27 -0
- data/lib/decidim/rest_full/core/permission_registry.rb +65 -0
- data/lib/decidim/rest_full/core/ransackers.rb +99 -0
- data/lib/decidim/rest_full/core/rest_enhancement_builder.rb +115 -0
- data/lib/decidim/rest_full/core/rest_enhancement_registration.rb +21 -0
- data/lib/decidim/rest_full/core/roles/role_id_codec.rb +50 -0
- data/lib/decidim/rest_full/core/roles/roles_aggregator.rb +203 -0
- data/lib/decidim/rest_full/core/roles/roles_writer.rb +343 -0
- data/lib/decidim/rest_full/core/route_registry.rb +123 -0
- data/lib/decidim/rest_full/core/serializer_additions_registry.rb +100 -0
- data/lib/decidim/rest_full/core/settings_tab.rb +22 -0
- data/lib/decidim/rest_full/core/swagger_spec_paths.rb +61 -0
- data/lib/decidim/rest_full/core/tokens_availability.rb +23 -0
- data/lib/decidim/rest_full/core/webhook_dispatcher.rb +55 -0
- data/lib/decidim/rest_full/core/webhook_event_catalog.rb +136 -0
- data/lib/decidim/rest_full/extension.rb +276 -0
- data/lib/decidim/rest_full/rest_full.rb +12 -0
- data/lib/decidim/rest_full/routes.rb +58 -0
- data/lib/decidim/rest_full/routing.rb +53 -0
- data/lib/decidim/rest_full/sync_runner.rb +14 -0
- data/lib/decidim/rest_full/test/apartment.rb +52 -0
- data/lib/decidim/rest_full/test/definitions/README.md +96 -0
- data/lib/decidim/rest_full/test/definitions/attachment.rb +64 -0
- data/lib/decidim/rest_full/test/definitions/collection_meta.rb +20 -0
- data/lib/decidim/rest_full/test/definitions/component.rb +99 -0
- data/lib/decidim/rest_full/test/definitions/component_type.rb +8 -0
- data/lib/decidim/rest_full/test/definitions/core.rb +16 -0
- data/lib/decidim/rest_full/test/definitions/creation_date.rb +11 -0
- data/lib/decidim/rest_full/test/definitions/edition_date.rb +11 -0
- data/lib/decidim/rest_full/test/definitions/error.rb +40 -0
- data/lib/decidim/rest_full/test/definitions/filter_param.rb +105 -0
- data/lib/decidim/rest_full/test/definitions/grant_param.rb +82 -0
- data/lib/decidim/rest_full/test/definitions/health.rb +12 -0
- data/lib/decidim/rest_full/test/definitions/introspect_data.rb +67 -0
- data/lib/decidim/rest_full/test/definitions/job.rb +130 -0
- data/lib/decidim/rest_full/test/definitions/locales_param.rb +19 -0
- data/lib/decidim/rest_full/test/definitions/magic_link.rb +37 -0
- data/lib/decidim/rest_full/test/definitions/magic_link_redirect.rb +32 -0
- data/lib/decidim/rest_full/test/definitions/manifests.rb +28 -0
- data/lib/decidim/rest_full/test/definitions/oauth_token_response.rb +18 -0
- data/lib/decidim/rest_full/test/definitions/organization.rb +75 -0
- data/lib/decidim/rest_full/test/definitions/organization_extended_data.rb +19 -0
- data/lib/decidim/rest_full/test/definitions/publication_date.rb +11 -0
- data/lib/decidim/rest_full/test/definitions/relationship_identifier.rb +29 -0
- data/lib/decidim/rest_full/test/definitions/resource_extended_data.rb +20 -0
- data/lib/decidim/rest_full/test/definitions/role.rb +61 -0
- data/lib/decidim/rest_full/test/definitions/shared.rb +22 -0
- data/lib/decidim/rest_full/test/definitions/space.rb +112 -0
- data/lib/decidim/rest_full/test/definitions/tags/attachments_tag.rb +26 -0
- data/lib/decidim/rest_full/test/definitions/tags/component_tag.rb +26 -0
- data/lib/decidim/rest_full/test/definitions/tags/jobs_tag.rb +20 -0
- data/lib/decidim/rest_full/test/definitions/tags/oauth_tag.rb +28 -0
- data/lib/decidim/rest_full/test/definitions/tags/organization_extended_data_tag.rb +22 -0
- data/lib/decidim/rest_full/test/definitions/tags/organizations_tag.rb +24 -0
- data/lib/decidim/rest_full/test/definitions/tags/roles_tag.rb +14 -0
- data/lib/decidim/rest_full/test/definitions/tags/space_tag.rb +22 -0
- data/lib/decidim/rest_full/test/definitions/tags/users_tag.rb +14 -0
- data/lib/decidim/rest_full/test/definitions/tags/webhooks_tag.rb +31 -0
- data/lib/decidim/rest_full/test/definitions/tags.rb +12 -0
- data/lib/decidim/rest_full/test/definitions/time_zone.rb +10 -0
- data/lib/decidim/rest_full/test/definitions/translated_prop.rb +11 -0
- data/lib/decidim/rest_full/test/definitions/user.rb +93 -0
- data/lib/decidim/rest_full/test/definitions/user_extended_data.rb +14 -0
- data/lib/decidim/rest_full/test/definitions/webhook.rb +95 -0
- data/lib/decidim/rest_full/test/definitions.rb +15 -0
- data/lib/decidim/rest_full/test/factories/api_client.rb +16 -0
- data/lib/decidim/rest_full/test/factories/magic_token.rb +13 -0
- data/lib/decidim/rest_full/test/factories/webhook_registration.rb +10 -0
- data/lib/decidim/rest_full/test/factories.rb +5 -0
- data/lib/decidim/rest_full/test/global_context.rb +11 -0
- data/lib/decidim/rest_full/test/on_api_endpoint_methods.rb +190 -0
- data/lib/decidim/rest_full/test/open_api_tag_registry.rb +25 -0
- data/lib/decidim/rest_full/test/openapi_specs.rb +107 -0
- data/lib/decidim/rest_full/test/shared_examples/has_extended_data.rb +41 -0
- data/lib/decidim/rest_full/test/shared_examples.rb +345 -0
- data/lib/decidim/rest_full/version.rb +27 -0
- data/lib/decidim/rest_full.rb +99 -0
- data/lib/decidim-restfull-core.rb +3 -0
- data/lib/tasks/decidim/rest_full/fire_webhook.rake +52 -0
- data/lib/tasks/decidim/rest_full/integrator_sandbox.rake +37 -0
- data/lib/tasks/decidim/rest_full/rest_full_upgrade.rake +64 -0
- data/lib/tasks/decidim/rest_full/rest_full_webpacker.rake +58 -0
- data/spec/commands/decidim/rest_full/core/impersonate_resource_owner_from_credentials_spec.rb +159 -0
- data/spec/commands/decidim/rest_full/core/syncronize_unconfirmed_host_spec.rb +117 -0
- data/spec/controllers/concerns/decidim/api/rest_full/collection_pagination_spec.rb +128 -0
- data/spec/decidim/rest_full/core/configuration_engine_disabled_routes_spec.rb +24 -0
- data/spec/forms/decidim/rest_full/core/magic_link_redirect_url_form_spec.rb +69 -0
- data/spec/forms/decidim/rest_full/core/webhook_registration_form_spec.rb +42 -0
- data/spec/jobs/decidim/rest_full/core/space_webhook_job_spec.rb +62 -0
- data/spec/jobs/decidim/rest_full/core/syncronize_unconfirmed_host_job_spec.rb +34 -0
- data/spec/jobs/decidim/rest_full/core/webhook_job_spec.rb +29 -0
- data/spec/jobs/decidim/rest_full/execute_api_job_job_spec.rb +45 -0
- data/spec/lib/decidim/rest_full/core/apartment_tenant_switch_spec.rb +26 -0
- data/spec/lib/decidim/rest_full/core/api_exception/bad_request_spec.rb +62 -0
- data/spec/lib/decidim/rest_full/core/definition_registry_add_resource_relationships_spec.rb +19 -0
- data/spec/lib/decidim/rest_full/core/gem_spec_paths_spec.rb +27 -0
- data/spec/lib/decidim/rest_full/core/http_cache/collection_fingerprint_spec.rb +59 -0
- data/spec/lib/decidim/rest_full/core/http_cache/fingerprint_contributor_registry_spec.rb +60 -0
- data/spec/lib/decidim/rest_full/core/http_cache/resource_show_fingerprint_spec.rb +33 -0
- data/spec/lib/decidim/rest_full/core/module_availability_spec.rb +130 -0
- data/spec/lib/decidim/rest_full/core/open_api_definition_paths_spec.rb +54 -0
- data/spec/lib/decidim/rest_full/core/optional_feature_gems_spec.rb +172 -0
- data/spec/lib/decidim/rest_full/core/roles/role_id_codec_spec.rb +62 -0
- data/spec/lib/decidim/rest_full/core/roles/roles_aggregator_spec.rb +53 -0
- data/spec/lib/decidim/rest_full/core/roles/roles_writer_spec.rb +38 -0
- data/spec/lib/decidim/rest_full/core/route_registry_spec.rb +90 -0
- data/spec/lib/decidim/rest_full/core/serializer_additions_registry_spec.rb +100 -0
- data/spec/lib/decidim/rest_full/core/settings_tab_spec.rb +15 -0
- data/spec/lib/decidim/rest_full/core/swagger_spec_paths_spec.rb +50 -0
- data/spec/lib/decidim/rest_full/core/webhook_dispatcher_proposal_published_spec.rb +63 -0
- data/spec/lib/decidim/rest_full/core/webhook_event_catalog_spec.rb +34 -0
- data/spec/lib/decidim/rest_full/routing_spec.rb +62 -0
- data/spec/lib/decidim/rest_full/test/apartment_spec.rb +17 -0
- data/spec/models/decidim/rest_full/api_job_spec.rb +51 -0
- data/spec/models/decidim/rest_full/application_mailer_override_spec.rb +60 -0
- data/spec/models/decidim/rest_full/core/has_extended_data_spec.rb +16 -0
- data/spec/models/decidim/rest_full/core/magic_token_spec.rb +68 -0
- data/spec/models/decidim/rest_full/core/webhook_registration_spec.rb +161 -0
- data/spec/models/decidim/rest_full/user_magic_token_spec.rb +51 -0
- data/spec/requests/decidim/api/rest_full/application_controller_introspect_spec.rb +85 -0
- data/spec/requests/decidim/api/rest_full/application_controller_ropc_spec.rb +299 -0
- data/spec/requests/decidim/api/rest_full/application_controller_token_spec.rb +57 -0
- data/spec/requests/decidim/api/rest_full/attachments/attachments_controller_direct_upload_spec.rb +39 -0
- data/spec/requests/decidim/api/rest_full/attachments/attachments_controller_index_spec.rb +41 -0
- data/spec/requests/decidim/api/rest_full/attachments/attachments_controller_show_spec.rb +34 -0
- data/spec/requests/decidim/api/rest_full/components/component_extended_data_controller_spec.rb +78 -0
- data/spec/requests/decidim/api/rest_full/components/components_controller_search_spec.rb +197 -0
- data/spec/requests/decidim/api/rest_full/components/components_controller_search_sql_spec.rb +48 -0
- data/spec/requests/decidim/api/rest_full/jobs/api_jobs_async_and_conditional_get_spec.rb +209 -0
- data/spec/requests/decidim/api/rest_full/jobs/jobs_controller_destroy_spec.rb +58 -0
- data/spec/requests/decidim/api/rest_full/jobs/jobs_controller_index_spec.rb +126 -0
- data/spec/requests/decidim/api/rest_full/jobs/jobs_controller_show_spec.rb +89 -0
- data/spec/requests/decidim/api/rest_full/module_availability_gate_spec.rb +77 -0
- data/spec/requests/decidim/api/rest_full/organizations/organization_extended_data_controller_index_spec.rb +88 -0
- data/spec/requests/decidim/api/rest_full/organizations/organization_extended_data_controller_update_spec.rb +194 -0
- data/spec/requests/decidim/api/rest_full/organizations/organizations_controller_index_spec.rb +57 -0
- data/spec/requests/decidim/api/rest_full/organizations/organizations_controller_show_spec.rb +66 -0
- data/spec/requests/decidim/api/rest_full/organizations/organizations_controller_update_spec.rb +120 -0
- data/spec/requests/decidim/api/rest_full/roles/roles_controller_create_spec.rb +230 -0
- data/spec/requests/decidim/api/rest_full/roles/roles_controller_destroy_spec.rb +52 -0
- data/spec/requests/decidim/api/rest_full/roles/roles_controller_index_spec.rb +127 -0
- data/spec/requests/decidim/api/rest_full/roles/roles_controller_show_spec.rb +215 -0
- data/spec/requests/decidim/api/rest_full/routes_boot_spec.rb +58 -0
- data/spec/requests/decidim/api/rest_full/scenarios/upsert_user_by_phone_and_set_locale_spec.rb +69 -0
- data/spec/requests/decidim/api/rest_full/spaces/space_extended_data_controller_spec.rb +78 -0
- data/spec/requests/decidim/api/rest_full/spaces/spaces_controller_index_spec.rb +167 -0
- data/spec/requests/decidim/api/rest_full/spaces/spaces_controller_search_spec.rb +280 -0
- data/spec/requests/decidim/api/rest_full/spaces/spaces_controller_show_spec.rb +98 -0
- data/spec/requests/decidim/api/rest_full/users/magic_links_controller_create_spec.rb +124 -0
- data/spec/requests/decidim/api/rest_full/users/magic_links_controller_show_spec.rb +84 -0
- data/spec/requests/decidim/api/rest_full/users/user_extended_data_controller_index_spec.rb +74 -0
- data/spec/requests/decidim/api/rest_full/users/user_extended_data_controller_update_spec.rb +192 -0
- data/spec/requests/decidim/api/rest_full/users/users_controller_index_spec.rb +182 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_events_controller_show_spec.rb +52 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_registrations_controller_create_spec.rb +95 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_registrations_controller_destroy_spec.rb +34 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_registrations_controller_index_spec.rb +43 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_registrations_controller_show_spec.rb +51 -0
- data/spec/requests/decidim/api/rest_full/webhooks/webhook_registrations_controller_update_spec.rb +57 -0
- data/spec/requests/decidim/rest_full/system/api_clients_controller_spec.rb +69 -0
- data/spec/serializers/decidim/api/rest_full/core/organization_webhook_serializer_spec.rb +18 -0
- data/spec/serializers/decidim/api/rest_full/core/space_webhook_serializer_spec.rb +44 -0
- data/spec/serializers/decidim/api/rest_full/core/user_webhook_serializer_spec.rb +19 -0
- data/spec/services/decidim/rest_full/core/api_system_operations_resource_extended_data_update_spec.rb +35 -0
- data/spec/services/decidim/rest_full/core/fire_webhook_spec.rb +59 -0
- data/spec/services/decidim/rest_full/core/participatory_process_step_activated_webhook_handler_spec.rb +57 -0
- metadata +482 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
# System-scope mutating operations reused by sync controllers and ApiJob worker.
|
|
7
|
+
class ApiSystemOperations
|
|
8
|
+
include Decidim::FormFactory
|
|
9
|
+
|
|
10
|
+
def initialize(execution_context, params)
|
|
11
|
+
@ctx = execution_context
|
|
12
|
+
@params = params.is_a?(ActionController::Parameters) ? params : ActionController::Parameters.new(params)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def organizations_update!
|
|
16
|
+
org = organization_from_params!
|
|
17
|
+
forms = build_update_forms(org)
|
|
18
|
+
apply_updates(forms, org)
|
|
19
|
+
org = org.reload
|
|
20
|
+
::Decidim::Api::RestFull::Core::OrganizationSerializer.new(
|
|
21
|
+
org,
|
|
22
|
+
params: { locales: org.available_locales.map(&:to_sym) }
|
|
23
|
+
).serializable_hash
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def organization_extended_data_update!
|
|
27
|
+
assert_org_matches_ctx!
|
|
28
|
+
raw = @params.respond_to?(:to_unsafe_h) ? @params.to_unsafe_h : @params.to_h
|
|
29
|
+
@params = ActionController::Parameters.new(
|
|
30
|
+
raw.merge(
|
|
31
|
+
"resource_type" => "Decidim::Organization",
|
|
32
|
+
"resource_id" => current_org.id
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
resource_extended_data_update!
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def resource_extended_data_update!
|
|
39
|
+
resource = find_extended_data_resource!
|
|
40
|
+
ensure_extended_data_row(resource)
|
|
41
|
+
data = @params.require(:data)
|
|
42
|
+
data.permit! if data.is_a?(ActionController::Parameters)
|
|
43
|
+
|
|
44
|
+
merged = compact_blank_recursively(
|
|
45
|
+
merge_extended_data_hash(resource.extended_data_hash, data)
|
|
46
|
+
)
|
|
47
|
+
assert_extended_data_payload_size!(merged)
|
|
48
|
+
|
|
49
|
+
resource.extended_data.update(data: merged)
|
|
50
|
+
resource.reload
|
|
51
|
+
{ data: ExtendedDataAtPath.fetch(resource.extended_data_hash, object_path) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def user_extended_data_update!
|
|
55
|
+
u = user_from_token!
|
|
56
|
+
data = @params.require(:data)
|
|
57
|
+
data.permit! if data.is_a?(ActionController::Parameters)
|
|
58
|
+
merged = compact_blank_recursively(
|
|
59
|
+
merge_user_extended_data(u, data)
|
|
60
|
+
)
|
|
61
|
+
assert_extended_data_payload_size!(merged)
|
|
62
|
+
u.update!(extended_data: merged)
|
|
63
|
+
u.reload
|
|
64
|
+
{ data: extended_data_at_path_user(u) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def roles_create!
|
|
68
|
+
attrs = role_params_from_body
|
|
69
|
+
role = writer.create(attrs)
|
|
70
|
+
::Decidim::Api::RestFull::Core::RoleSerializer.new(role, params: serializer_params).serializable_hash
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def roles_destroy!
|
|
74
|
+
writer.destroy(@params.require(:id))
|
|
75
|
+
nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
attr_reader :ctx
|
|
81
|
+
|
|
82
|
+
delegate :organization, :available_locales, to: :ctx
|
|
83
|
+
|
|
84
|
+
def current_org
|
|
85
|
+
organization
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def assert_org_matches_ctx!
|
|
89
|
+
oid = (@params[:id] || @params[:organization_id]).presence
|
|
90
|
+
return if oid.blank?
|
|
91
|
+
|
|
92
|
+
raise Decidim::RestFull::Core::ApiException::Forbidden, "Organization mismatch" if oid.to_i != organization.id
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def organization_from_params!
|
|
96
|
+
org = Decidim::Organization.find_by(id: @params.require(:id))
|
|
97
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Organization Not Found" unless org
|
|
98
|
+
|
|
99
|
+
org
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def serializer_params
|
|
103
|
+
{ host: organization.host }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def writer
|
|
107
|
+
@writer ||= Decidim::RestFull::Core::Roles::RolesWriter.new(organization)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def user_from_token!
|
|
111
|
+
Decidim::User.find_by!(id: ctx.doorkeeper_token.resource_owner_id, organization:)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def role_params_from_body
|
|
115
|
+
data = @params.require(:data).to_unsafe_h
|
|
116
|
+
attrs = data["attributes"] || data[:attributes] || {}
|
|
117
|
+
{
|
|
118
|
+
resource_type: attrs["resource_type"] || attrs[:resource_type],
|
|
119
|
+
resource_id: attrs["resource_id"] || attrs[:resource_id],
|
|
120
|
+
user_id: attrs["user_id"] || attrs[:user_id],
|
|
121
|
+
type: attrs["type"] || attrs[:type]
|
|
122
|
+
}.compact
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def build_update_forms(org)
|
|
126
|
+
[system_update_form(org), admin_update_form(org)]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def system_update_form(org)
|
|
130
|
+
form = Decidim::System::UpdateOrganizationForm.from_model(org)
|
|
131
|
+
apply_system_form_updates!(form, org)
|
|
132
|
+
form.with_unconfirmed_host(org)
|
|
133
|
+
validate_form(form)
|
|
134
|
+
form
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def apply_system_form_updates!(form, org)
|
|
138
|
+
payload = organization_payload(org)
|
|
139
|
+
%w(host default_locale users_registration_mode force_users_to_authenticate_before_access_organization).each do |attr|
|
|
140
|
+
form.public_send("#{attr}=", payload[attr]) if payload.has_key?(attr)
|
|
141
|
+
end
|
|
142
|
+
form.secondary_hosts = payload["secondary_hosts"] if payload.has_key?("secondary_hosts")
|
|
143
|
+
apply_translated_form_updates!(form, org, payload, *translated_fields_for(org))
|
|
144
|
+
form.unconfirmed_host = payload["unconfirmed_host"] if payload.has_key?("unconfirmed_host")
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Assign full locale hashes onto the form so Decidim UpdateOrganization does not
|
|
148
|
+
# wipe unsubmitted locales (Admin form accessors often follow Decidim.available_locales only).
|
|
149
|
+
def apply_translated_form_updates!(form, org, payload, *fields)
|
|
150
|
+
fields.each do |field|
|
|
151
|
+
next unless org.respond_to?(field)
|
|
152
|
+
next unless form.respond_to?("#{field}=")
|
|
153
|
+
|
|
154
|
+
existing = org.public_send(field)
|
|
155
|
+
values = org.available_locales.index_with do |locale|
|
|
156
|
+
key = "#{field}_#{locale}"
|
|
157
|
+
if payload.has_key?(key)
|
|
158
|
+
payload[key]
|
|
159
|
+
else
|
|
160
|
+
locale_value(existing, locale) || locale_value(form.public_send(field), locale)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
form.public_send("#{field}=", values) if values.values.any?
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def locale_value(hash, locale)
|
|
168
|
+
return nil unless hash.is_a?(Hash)
|
|
169
|
+
|
|
170
|
+
hash[locale] || hash[locale.to_s] || hash[locale.to_sym]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def admin_update_form(org)
|
|
174
|
+
payload = organization_payload(org)
|
|
175
|
+
form = form(Decidim::Admin::OrganizationForm).from_params(payload).with_context(current_organization: org)
|
|
176
|
+
# Force merged translations: from_params may ignore locales outside Decidim.available_locales.
|
|
177
|
+
apply_translated_form_updates!(form, org, payload, :name, :description, :admin_terms_of_service_body)
|
|
178
|
+
preserve_decidim_029_booleans!(form, org, payload)
|
|
179
|
+
validate_form(form)
|
|
180
|
+
form
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# 0.29 Organization columns are NOT NULL; Admin forms default missing/unmapped booleans to nil.
|
|
184
|
+
def preserve_decidim_029_booleans!(form, org, payload)
|
|
185
|
+
%w(user_groups_enabled enable_participatory_space_filters).each do |attr|
|
|
186
|
+
next unless org.respond_to?(attr)
|
|
187
|
+
next unless form.respond_to?("#{attr}=")
|
|
188
|
+
|
|
189
|
+
value = if payload.has_key?(attr) || payload.has_key?(attr.to_sym)
|
|
190
|
+
payload[attr] || payload[attr.to_sym]
|
|
191
|
+
else
|
|
192
|
+
org.public_send(attr)
|
|
193
|
+
end
|
|
194
|
+
next if value.nil?
|
|
195
|
+
|
|
196
|
+
form.public_send("#{attr}=", value)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def apply_updates(forms, org)
|
|
201
|
+
snapshots = translation_snapshots(org)
|
|
202
|
+
system_form, admin_form = forms
|
|
203
|
+
system_ok = Decidim::System::UpdateOrganization.call(org.id, system_form)[:ok]
|
|
204
|
+
admin_ok = Decidim::Admin::UpdateOrganization.call(admin_form, org)[:ok]
|
|
205
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, "Failed to update organization" unless system_ok && admin_ok
|
|
206
|
+
|
|
207
|
+
org.reload
|
|
208
|
+
# ponytail: Admin TranslatableAttributes only define name_<locale> for Decidim.available_locales;
|
|
209
|
+
# org may have more locales — restore any wiped unsubmitted locale values.
|
|
210
|
+
restore_unsubmitted_translations!(org, snapshots)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def translation_snapshots(org)
|
|
214
|
+
translated_fields_for(org).index_with do |field|
|
|
215
|
+
stringify_locale_keys((org.public_send(field) || {}).except("machine_translations", :machine_translations))
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def restore_unsubmitted_translations!(org, snapshots)
|
|
220
|
+
dirty = false
|
|
221
|
+
snapshots.each do |field, before|
|
|
222
|
+
next if before.blank?
|
|
223
|
+
|
|
224
|
+
submitted = allowed_params[field] || allowed_params[field.to_s]
|
|
225
|
+
submitted = submitted.is_a?(Hash) ? stringify_locale_keys(submitted) : {}
|
|
226
|
+
merged = before.merge(submitted)
|
|
227
|
+
current = stringify_locale_keys((org.public_send(field) || {}).except("machine_translations", :machine_translations))
|
|
228
|
+
next if current == merged
|
|
229
|
+
|
|
230
|
+
org.public_send("#{field}=", merged)
|
|
231
|
+
dirty = true
|
|
232
|
+
end
|
|
233
|
+
org.save! if dirty
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def validate_form(form)
|
|
237
|
+
return if form.valid?
|
|
238
|
+
|
|
239
|
+
update_errors = form.errors.select { |err| allowed_form_attributes.include? err.attribute.to_s }
|
|
240
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, update_errors.map(&:full_message).join(". ") unless update_errors.empty?
|
|
241
|
+
|
|
242
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, "Failed to update organization"
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
def allowed_form_attributes
|
|
246
|
+
@allowed_form_attributes ||= transform_translated_params(transform_host_params(allowed_params)).keys
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def organization_payload(org)
|
|
250
|
+
updates = transform_host_params(allowed_params.deep_dup)
|
|
251
|
+
merged = stringify_top_keys(organization_baseline_attributes(org))
|
|
252
|
+
merge_translated_locale_updates!(merged, updates)
|
|
253
|
+
updates.each do |key, value|
|
|
254
|
+
next if translated_fields.include?(key.to_sym)
|
|
255
|
+
|
|
256
|
+
merged[key.to_s] = value
|
|
257
|
+
end
|
|
258
|
+
coerce_secondary_hosts!(merged)
|
|
259
|
+
transform_translated_params(merged)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Deep-merge locale hashes with string keys so partial updates (e.g. only +en+)
|
|
263
|
+
# keep existing locales (e.g. +fr+) instead of wiping them via key-type mismatch.
|
|
264
|
+
def merge_translated_locale_updates!(baseline, updates)
|
|
265
|
+
translated_fields.each do |field|
|
|
266
|
+
update_key = updates.keys.find { |k| k.to_sym == field }
|
|
267
|
+
next unless update_key
|
|
268
|
+
|
|
269
|
+
update_val = updates.delete(update_key)
|
|
270
|
+
next unless update_val.is_a?(Hash)
|
|
271
|
+
|
|
272
|
+
base_val = stringify_locale_keys(baseline[field.to_s] || {})
|
|
273
|
+
# Drop machine_translations from API merge surface; Decidim owns that key.
|
|
274
|
+
base_val = base_val.except("machine_translations")
|
|
275
|
+
baseline[field.to_s] = base_val.merge(stringify_locale_keys(update_val).except("machine_translations"))
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
def stringify_top_keys(hash)
|
|
280
|
+
hash.each_with_object({}) { |(key, value), acc| acc[key.to_s] = value }
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def stringify_locale_keys(hash)
|
|
284
|
+
hash.each_with_object({}) { |(locale, value), acc| acc[locale.to_s] = value }
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def organization_baseline_attributes(org)
|
|
288
|
+
hash = available_params.each_with_object({}) do |key, acc|
|
|
289
|
+
next unless org.respond_to?(key)
|
|
290
|
+
|
|
291
|
+
acc[key.to_s] = org.public_send(key)
|
|
292
|
+
end
|
|
293
|
+
hash["id"] = org.id
|
|
294
|
+
hash["users_registration_mode"] = org.users_registration_mode.to_s
|
|
295
|
+
hash["secondary_hosts"] = Array(org.secondary_hosts).join("\n")
|
|
296
|
+
hash["machine_translation_display_priority"] = org.machine_translation_display_priority
|
|
297
|
+
hash
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
def coerce_secondary_hosts!(payload)
|
|
301
|
+
return unless payload["secondary_hosts"].is_a?(Array)
|
|
302
|
+
|
|
303
|
+
payload["secondary_hosts"] = payload["secondary_hosts"].join("\n")
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def allowed_params
|
|
307
|
+
@allowed_params ||= @params.require(:data).permit!.to_h.with_indifferent_access.select { |key, _value| available_params.include?(key.to_sym) }
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
def transform_host_params(params)
|
|
311
|
+
return params unless params.has_key?(:host) || params.has_key?("host")
|
|
312
|
+
|
|
313
|
+
new_host = params.delete(:host)
|
|
314
|
+
new_host = params.delete("host") if new_host.nil? && params.has_key?("host")
|
|
315
|
+
params.merge("unconfirmed_host" => new_host)
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def transform_translated_params(params)
|
|
319
|
+
params.each_with_object({}) do |(key, value), result|
|
|
320
|
+
if translated_fields.include?(key.to_sym) && value.is_a?(Hash)
|
|
321
|
+
value.each do |locale, translated_value|
|
|
322
|
+
next if locale.to_s == "machine_translations"
|
|
323
|
+
|
|
324
|
+
result["#{key}_#{locale}".to_s.gsub("-", "__")] = translated_value
|
|
325
|
+
end
|
|
326
|
+
else
|
|
327
|
+
result[key.to_s] = value
|
|
328
|
+
end
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def translated_fields_for(org)
|
|
333
|
+
translated_fields.select { |field| org.respond_to?(field) }
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def translated_fields
|
|
337
|
+
[:name, :short_name, :description, :admin_terms_of_service_body]
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def available_params
|
|
341
|
+
[
|
|
342
|
+
:name,
|
|
343
|
+
:short_name,
|
|
344
|
+
:description,
|
|
345
|
+
:admin_terms_of_service_body,
|
|
346
|
+
:reference_prefix,
|
|
347
|
+
:secondary_hosts,
|
|
348
|
+
:default_locale,
|
|
349
|
+
:available_locales,
|
|
350
|
+
:send_welcome_notification,
|
|
351
|
+
:host,
|
|
352
|
+
:users_registration_mode,
|
|
353
|
+
:force_users_to_authenticate_before_access_organization,
|
|
354
|
+
:badges_enabled,
|
|
355
|
+
# Present on Decidim 0.29 (NOT NULL); removed from 0.32 models — baseline skips via respond_to?.
|
|
356
|
+
:user_groups_enabled,
|
|
357
|
+
:enable_participatory_space_filters,
|
|
358
|
+
:enable_machine_translations,
|
|
359
|
+
:time_zone,
|
|
360
|
+
:comments_max_length,
|
|
361
|
+
:rich_text_editor_in_public_views
|
|
362
|
+
]
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def ensure_extended_data_row(resource)
|
|
366
|
+
return if resource.extended_data
|
|
367
|
+
|
|
368
|
+
resource.create_extended_data!
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
def find_extended_data_resource!
|
|
372
|
+
type = @params.require(:resource_type).to_s
|
|
373
|
+
id = @params.require(:resource_id)
|
|
374
|
+
|
|
375
|
+
case type
|
|
376
|
+
when "Decidim::Organization"
|
|
377
|
+
raise Decidim::RestFull::Core::ApiException::Forbidden, "Organization mismatch" if id.to_i != organization.id
|
|
378
|
+
|
|
379
|
+
organization
|
|
380
|
+
when "Decidim::Component"
|
|
381
|
+
find_component_for_extended_data!(id)
|
|
382
|
+
when "Decidim::Proposals::Proposal"
|
|
383
|
+
find_proposal_for_extended_data!(id)
|
|
384
|
+
when "Decidim::Meetings::Meeting"
|
|
385
|
+
find_meeting_for_extended_data!(id)
|
|
386
|
+
else
|
|
387
|
+
find_space_for_extended_data!(type, id)
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def find_component_for_extended_data!(id)
|
|
392
|
+
component = Decidim::Component.find_by(id:)
|
|
393
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Component not found" unless component
|
|
394
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Component not found" unless component_in_organization?(component)
|
|
395
|
+
|
|
396
|
+
component
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
def find_proposal_for_extended_data!(id)
|
|
400
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Proposal not found" unless defined?(::Decidim::Proposals::Proposal)
|
|
401
|
+
|
|
402
|
+
proposal = ::Decidim::Proposals::Proposal.find_by(id:)
|
|
403
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Proposal not found" unless proposal
|
|
404
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Proposal not found" unless component_in_organization?(proposal.component)
|
|
405
|
+
|
|
406
|
+
proposal
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
def find_meeting_for_extended_data!(id)
|
|
410
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Meeting not found" unless defined?(::Decidim::Meetings::Meeting)
|
|
411
|
+
|
|
412
|
+
meeting = ::Decidim::Meetings::Meeting.find_by(id:)
|
|
413
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Meeting not found" unless meeting
|
|
414
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Meeting not found" unless component_in_organization?(meeting.component)
|
|
415
|
+
|
|
416
|
+
meeting
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def find_space_for_extended_data!(type, id)
|
|
420
|
+
klass = type.safe_constantize
|
|
421
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, "Unknown resource type" unless klass
|
|
422
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, "Unknown resource type" unless space_model?(klass)
|
|
423
|
+
|
|
424
|
+
space = klass.find_by(id:, organization:)
|
|
425
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Space not found" unless space
|
|
426
|
+
|
|
427
|
+
space
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def component_in_organization?(component)
|
|
431
|
+
return false unless component
|
|
432
|
+
|
|
433
|
+
space = component.participatory_space
|
|
434
|
+
return false unless space
|
|
435
|
+
|
|
436
|
+
org_id = if space.respond_to?(:decidim_organization_id)
|
|
437
|
+
space.decidim_organization_id
|
|
438
|
+
elsif space.respond_to?(:organization)
|
|
439
|
+
space.organization&.id
|
|
440
|
+
end
|
|
441
|
+
org_id == organization.id
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
def space_model?(klass)
|
|
445
|
+
Decidim.participatory_space_registry.manifests.any? do |manifest|
|
|
446
|
+
manifest.model_class_name == klass.name
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def merge_extended_data_hash(base_hash, obj)
|
|
451
|
+
merged_extra = base_hash.deep_dup
|
|
452
|
+
obj = obj.to_unsafe_h if obj.respond_to?(:to_unsafe_h)
|
|
453
|
+
obj = obj.deep_stringify_keys if obj.respond_to?(:deep_stringify_keys)
|
|
454
|
+
return merged_extra.merge(obj) if object_path == "."
|
|
455
|
+
|
|
456
|
+
parts = object_path.split(".")
|
|
457
|
+
selected = parts[..-2].reduce(merged_extra) do |current, key|
|
|
458
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "key #{object_path} not found" unless current.is_a?(Hash)
|
|
459
|
+
|
|
460
|
+
current[key] = {} unless current.has_key?(key)
|
|
461
|
+
current[key]
|
|
462
|
+
end
|
|
463
|
+
if selected[parts.last].is_a?(Hash)
|
|
464
|
+
selected[parts.last].merge!(obj)
|
|
465
|
+
else
|
|
466
|
+
selected[parts.last] = obj
|
|
467
|
+
end
|
|
468
|
+
merged_extra
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def compact_blank_recursively(hash)
|
|
472
|
+
hash.each_with_object({}) do |(key, value), result|
|
|
473
|
+
next if value.blank?
|
|
474
|
+
|
|
475
|
+
result[key] = value.is_a?(Hash) ? compact_blank_recursively(value) : value
|
|
476
|
+
result.delete(key) if result[key].blank?
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
|
|
480
|
+
def assert_extended_data_payload_size!(data)
|
|
481
|
+
max = Decidim::RestFull.config.max_extended_data_payload_bytes
|
|
482
|
+
return if max.blank? || !max.positive?
|
|
483
|
+
|
|
484
|
+
size = data.to_json.bytesize
|
|
485
|
+
return if size <= max
|
|
486
|
+
|
|
487
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest,
|
|
488
|
+
"extended_data exceeds maximum size of #{max} bytes"
|
|
489
|
+
end
|
|
490
|
+
|
|
491
|
+
def object_path
|
|
492
|
+
@object_path ||= @params.require(:object_path)
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
def merge_user_extended_data(user, obj)
|
|
496
|
+
merge_extended_data_hash(user.extended_data.deep_dup, obj)
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
def extended_data_at_path_user(user)
|
|
500
|
+
ExtendedDataAtPath.fetch(user.extended_data, object_path)
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
# Dev/integrator helper: POST a typed sample webhook envelope to an arbitrary URL.
|
|
7
|
+
class FireWebhook
|
|
8
|
+
# Short / Decidim-notification aliases → catalog event names.
|
|
9
|
+
ALIASES = {
|
|
10
|
+
"decidim.step_activated" => "participatory_process.step_activated.succeeded",
|
|
11
|
+
"decidim.events.participatory_process.step_activated" => "participatory_process.step_activated.succeeded",
|
|
12
|
+
"step_activated" => "participatory_process.step_activated.succeeded",
|
|
13
|
+
"phase_change" => "participatory_process.step_activated.succeeded",
|
|
14
|
+
"proposal_published" => "proposal_creation.succeeded",
|
|
15
|
+
"decidim.events.proposals.proposal_published" => "proposal_creation.succeeded",
|
|
16
|
+
"proposal_created" => "proposal_creation.succeeded"
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
Result = Struct.new(:event_name, :url, :status_code, :body, :secret, :payload, :timestamp, keyword_init: true)
|
|
20
|
+
|
|
21
|
+
def self.call(url:, event:, organization:, secret: nil)
|
|
22
|
+
new(url:, event:, organization:, secret:).call
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.resolve_event_name!(query)
|
|
26
|
+
q = query.to_s.strip
|
|
27
|
+
raise ArgumentError, "EVENT is required" if q.blank?
|
|
28
|
+
|
|
29
|
+
return ALIASES[q] if ALIASES.has_key?(q)
|
|
30
|
+
return q if WebhookEventCatalog.find(q)
|
|
31
|
+
|
|
32
|
+
matches = WebhookEventCatalog.all.select do |entry|
|
|
33
|
+
entry.event_name.include?(q) || entry.event_name.end_with?(q)
|
|
34
|
+
end
|
|
35
|
+
raise ArgumentError, "Unknown webhook event #{q.inspect}. Known: #{known_events.join(", ")}" if matches.empty?
|
|
36
|
+
raise ArgumentError, "Ambiguous event #{q.inspect}: #{matches.map(&:event_name).join(", ")}" if matches.size > 1
|
|
37
|
+
|
|
38
|
+
matches.first.event_name
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.known_events
|
|
42
|
+
WebhookEventCatalog.all.map(&:event_name)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.resolve_organization!(organization_id: nil, host: nil)
|
|
46
|
+
if organization_id.present?
|
|
47
|
+
Decidim::Organization.find(organization_id)
|
|
48
|
+
elsif host.present?
|
|
49
|
+
Decidim::Organization.find_by!(host:)
|
|
50
|
+
else
|
|
51
|
+
org = Decidim::Organization.first
|
|
52
|
+
raise ArgumentError, "No organization found — set HOST or ORGANIZATION_ID" unless org
|
|
53
|
+
|
|
54
|
+
org
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def initialize(url:, event:, organization:, secret: nil)
|
|
59
|
+
@url = url.to_s.strip
|
|
60
|
+
@event_query = event
|
|
61
|
+
@organization = organization
|
|
62
|
+
@secret = secret.to_s.presence || SecureRandom.hex(32)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def call
|
|
66
|
+
validate_url!
|
|
67
|
+
event_name = self.class.resolve_event_name!(@event_query)
|
|
68
|
+
envelope = WebhookEventCatalog.example_payload_for(event_name, organization: @organization)
|
|
69
|
+
timestamp = Time.current.to_i.to_s
|
|
70
|
+
json_payload = envelope.to_json
|
|
71
|
+
response = post!(json_payload, timestamp)
|
|
72
|
+
|
|
73
|
+
Result.new(
|
|
74
|
+
event_name:,
|
|
75
|
+
url: @url,
|
|
76
|
+
status_code: response.code.to_i,
|
|
77
|
+
body: response.body.to_s,
|
|
78
|
+
secret: @secret,
|
|
79
|
+
payload: envelope,
|
|
80
|
+
timestamp:
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def validate_url!
|
|
87
|
+
raise ArgumentError, "URL is required" if @url.blank?
|
|
88
|
+
|
|
89
|
+
uri = URI.parse(@url)
|
|
90
|
+
raise ArgumentError, "URL must be http(s)" unless %w(http https).include?(uri.scheme)
|
|
91
|
+
raise ArgumentError, "URL must include a host" if uri.host.blank?
|
|
92
|
+
rescue URI::InvalidURIError => e
|
|
93
|
+
raise ArgumentError, "Invalid URL: #{e.message}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def post!(json_payload, timestamp)
|
|
97
|
+
uri = URI.parse(@url)
|
|
98
|
+
signature = "v1=#{OpenSSL::HMAC.hexdigest("SHA256", @secret, "#{timestamp}.#{json_payload}")}"
|
|
99
|
+
headers = {
|
|
100
|
+
"Content-Type" => "application/json",
|
|
101
|
+
"X-Webhook-Signature" => signature,
|
|
102
|
+
"X-Webhook-Timestamp" => timestamp,
|
|
103
|
+
"User-Agent" => "decidim-restfull-fire-webhook/1"
|
|
104
|
+
}
|
|
105
|
+
request = Net::HTTP::Post.new(uri, headers)
|
|
106
|
+
request.body = json_payload
|
|
107
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
108
|
+
http.request(request)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
data/app/services/decidim/rest_full/core/participatory_process_step_activated_webhook_handler.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
# Dispatches when Decidim publishes +decidim.events.participatory_process.step_activated+.
|
|
7
|
+
module ParticipatoryProcessStepActivatedWebhookHandler
|
|
8
|
+
HANDLED_EVENT = "decidim.events.participatory_process.step_activated"
|
|
9
|
+
WEBHOOK_EVENT = "participatory_process.step_activated.succeeded"
|
|
10
|
+
|
|
11
|
+
def self.call(event_name, data)
|
|
12
|
+
return unless event_name == HANDLED_EVENT
|
|
13
|
+
|
|
14
|
+
payload = normalize_payload(data)
|
|
15
|
+
step = payload[:resource]
|
|
16
|
+
return unless step.is_a?(::Decidim::ParticipatoryProcessStep)
|
|
17
|
+
|
|
18
|
+
process = step.participatory_process
|
|
19
|
+
organization = process.organization
|
|
20
|
+
|
|
21
|
+
SpaceWebhookJob.perform_later(WEBHOOK_EVENT, process.id, organization.id, step.id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.normalize_payload(data)
|
|
25
|
+
case data
|
|
26
|
+
when Hash
|
|
27
|
+
data.symbolize_keys
|
|
28
|
+
when ActiveSupport::Notifications::Event
|
|
29
|
+
data.payload.symbolize_keys
|
|
30
|
+
else
|
|
31
|
+
{}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private_class_method :normalize_payload
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|