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,159 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::ImpersonateResourceOwnerFromCredentials do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: ["en"]) }
|
|
7
|
+
let(:api_client) do
|
|
8
|
+
api_client = create(:api_client, organization:, scopes: %w(oauth public))
|
|
9
|
+
api_client.permissions = [
|
|
10
|
+
api_client.permissions.build(permission: "oauth.impersonate")
|
|
11
|
+
]
|
|
12
|
+
api_client.save!
|
|
13
|
+
api_client.reload
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#validate_params!" do
|
|
17
|
+
let(:command) { described_class.new(api_client, params, organization) }
|
|
18
|
+
|
|
19
|
+
before do
|
|
20
|
+
allow(command).to receive(:ability).and_return(double(authorize!: true))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when user does not exist and register_on_missing is false" do
|
|
24
|
+
let(:params) do
|
|
25
|
+
{
|
|
26
|
+
username: "nonexistent_user",
|
|
27
|
+
meta: {
|
|
28
|
+
register_on_missing: false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "raises NotFound exception" do
|
|
34
|
+
expect do
|
|
35
|
+
command.send(:validate_params!)
|
|
36
|
+
end.to raise_error(Decidim::RestFull::Core::ApiException::NotFound, "User not found. To create one, user meta.register_on_missing")
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when user does not exist and register_on_missing is not set" do
|
|
41
|
+
let(:params) do
|
|
42
|
+
{
|
|
43
|
+
username: "nonexistent_user"
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "raises NotFound exception" do
|
|
48
|
+
expect do
|
|
49
|
+
command.send(:validate_params!)
|
|
50
|
+
end.to raise_error(Decidim::RestFull::Core::ApiException::NotFound, "User not found. To create one, user meta.register_on_missing")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "when user does not exist and register_on_missing is true" do
|
|
55
|
+
let(:params) do
|
|
56
|
+
{
|
|
57
|
+
username: "new_user",
|
|
58
|
+
meta: {
|
|
59
|
+
register_on_missing: true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "does not raise an exception" do
|
|
65
|
+
expect do
|
|
66
|
+
command.send(:validate_params!)
|
|
67
|
+
end.not_to raise_error
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "#call" do
|
|
73
|
+
let(:command) { described_class.new(api_client, params, organization) }
|
|
74
|
+
|
|
75
|
+
before do
|
|
76
|
+
allow(command).to receive(:ability).and_return(double(authorize!: true))
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "when user does not exist and register_on_missing is true" do
|
|
80
|
+
let(:params) do
|
|
81
|
+
{
|
|
82
|
+
username: "new_user",
|
|
83
|
+
meta: {
|
|
84
|
+
register_on_missing: true
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "creates a new user" do
|
|
90
|
+
expect do
|
|
91
|
+
command.call
|
|
92
|
+
end.to change(Decidim::User, :count).by(1)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "broadcasts :ok" do
|
|
96
|
+
expect(command.call).to broadcast(:ok)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "creates user with correct attributes" do
|
|
100
|
+
command.call
|
|
101
|
+
user = Decidim::User.find_by(nickname: "new_user", organization:)
|
|
102
|
+
expect(user).to be_present
|
|
103
|
+
expect(user.email).to eq("new_user@example.org")
|
|
104
|
+
expect(user.name).to eq("New User")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "when meta locale is an organization locale" do
|
|
109
|
+
let(:organization) { create(:organization, available_locales: %w(en fr), default_locale: "en") }
|
|
110
|
+
let(:params) do
|
|
111
|
+
{
|
|
112
|
+
username: "locale_user",
|
|
113
|
+
meta: {
|
|
114
|
+
register_on_missing: true,
|
|
115
|
+
locale: "fr"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "stores the locale on create" do
|
|
121
|
+
command.call
|
|
122
|
+
user = Decidim::User.find_by(nickname: "locale_user", organization:)
|
|
123
|
+
expect(user.locale).to eq("fr")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context "when the user already exists" do
|
|
128
|
+
let(:organization) { create(:organization, available_locales: %w(en fr), default_locale: "en") }
|
|
129
|
+
let!(:user) { create(:user, organization:, nickname: "known_user", locale: "en") }
|
|
130
|
+
let(:params) do
|
|
131
|
+
{
|
|
132
|
+
username: "known_user",
|
|
133
|
+
meta: { locale: "fr" }
|
|
134
|
+
}
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "updates the locale" do
|
|
138
|
+
command.call
|
|
139
|
+
expect(user.reload.locale).to eq("fr")
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
context "when meta locale is not available" do
|
|
144
|
+
let(:params) do
|
|
145
|
+
{
|
|
146
|
+
username: "bad_locale",
|
|
147
|
+
meta: {
|
|
148
|
+
register_on_missing: true,
|
|
149
|
+
locale: "de"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "broadcasts an error" do
|
|
155
|
+
expect(command.call).to broadcast(:error)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::SyncronizeUnconfirmedHost do
|
|
6
|
+
let(:unconfirmed_host) { "unconfirmed.host.org" }
|
|
7
|
+
let(:organization) do
|
|
8
|
+
org = create(:organization, host: "my.host.org")
|
|
9
|
+
org.extended_data.data["unconfirmed_host"] = unconfirmed_host
|
|
10
|
+
org.extended_data.save!
|
|
11
|
+
org
|
|
12
|
+
end
|
|
13
|
+
let(:ipv4_loadbalancer_ip) { Faker::Internet.ip_v4_address }
|
|
14
|
+
let(:ipv6_loadbalancer_ip) { Faker::Internet.ip_v6_address }
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
allow(Decidim::RestFull.config).to receive(:loadbalancer_ips).and_return([ipv4_loadbalancer_ip, ipv6_loadbalancer_ip])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#call" do
|
|
21
|
+
context "when Decidim::RestFull.config.loadbalancer_ips is empty" do
|
|
22
|
+
before do
|
|
23
|
+
allow(Decidim::RestFull.config).to receive(:loadbalancer_ips).and_return([])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "update immediately the host" do
|
|
27
|
+
expect { described_class.call(organization) }.to change(organization, :host).to(unconfirmed_host)
|
|
28
|
+
expect(organization.extended_data.data["unconfirmed_host"]).to be_nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "when the unconfirmed host is the same as the current host" do
|
|
33
|
+
let(:organization) do
|
|
34
|
+
org = create(:organization, host: unconfirmed_host)
|
|
35
|
+
org.extended_data.data["unconfirmed_host"] = unconfirmed_host
|
|
36
|
+
org.extended_data.save!
|
|
37
|
+
org
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "raise an bad request error" do
|
|
41
|
+
expect { described_class.call(organization) }.to raise_error(Decidim::RestFull::Core::ApiException::BadRequest)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "when Decidim::RestFull.config.loadbalancer_ips is set with a ipv4" do
|
|
46
|
+
before do
|
|
47
|
+
allow(Decidim::RestFull.config).to receive(:loadbalancer_ips).and_return([ipv4_loadbalancer_ip])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "when the IPv4 resolves to the unconfirmed host" do
|
|
51
|
+
before do
|
|
52
|
+
allow(Resolv).to receive(:getaddresses).with(unconfirmed_host).and_return([ipv4_loadbalancer_ip])
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "updates the host" do
|
|
56
|
+
expect { described_class.call(organization) }.to change(organization, :host).to(unconfirmed_host)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "when the IPv4 does not resolve to the unconfirmed host" do
|
|
61
|
+
before do
|
|
62
|
+
allow(Resolv).to receive(:getaddresses).with(unconfirmed_host).and_return([Faker::Internet.ip_v4_address])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "raise an not found error" do
|
|
66
|
+
expect { described_class.call(organization) }.to raise_error(Decidim::RestFull::Core::ApiException::NotFound)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "when Decidim::RestFull.config.loadbalancer_ips is set with a ipv6" do
|
|
72
|
+
before do
|
|
73
|
+
allow(Decidim::RestFull.config).to receive(:loadbalancer_ips).and_return([ipv6_loadbalancer_ip])
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "when the IPv6 resolves to the unconfirmed host" do
|
|
77
|
+
before do
|
|
78
|
+
allow(Resolv).to receive(:getaddresses).with(unconfirmed_host).and_return([ipv6_loadbalancer_ip])
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "updates the host" do
|
|
82
|
+
expect { described_class.call(organization) }.to change(organization, :host).to(unconfirmed_host)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "when the IPv6 does not resolve to the unconfirmed host" do
|
|
87
|
+
before do
|
|
88
|
+
allow(Resolv).to receive(:getaddresses).with(unconfirmed_host).and_return([Faker::Internet.ip_v6_address])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "raise an not found error" do
|
|
92
|
+
expect { described_class.call(organization) }.to raise_error(Decidim::RestFull::Core::ApiException::NotFound)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context "when the unconfirmed host is not linked to all of the loadbalancer ips" do
|
|
98
|
+
before do
|
|
99
|
+
allow(Resolv).to receive(:getaddresses).with(unconfirmed_host).and_return([Faker::Internet.ip_v4_address, Faker::Internet.ip_v6_address])
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "raise an not found error" do
|
|
103
|
+
expect { described_class.call(organization) }.to raise_error(Decidim::RestFull::Core::ApiException::NotFound)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context "when Decidim::RestFull.config.loadbalancer_ips is set with an invalid ip" do
|
|
108
|
+
before do
|
|
109
|
+
allow(Decidim::RestFull.config).to receive(:loadbalancer_ips).and_return([Faker::Name.name])
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "raise IPAddr::InvalidAddressError" do
|
|
113
|
+
expect { described_class.call(organization) }.to raise_error(IPAddr::InvalidAddressError)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Api
|
|
7
|
+
module RestFull
|
|
8
|
+
RSpec.describe CollectionPagination do
|
|
9
|
+
let(:host) do
|
|
10
|
+
Class.new do
|
|
11
|
+
include CollectionPagination
|
|
12
|
+
|
|
13
|
+
attr_accessor :params, :request
|
|
14
|
+
|
|
15
|
+
def initialize(params:, request:)
|
|
16
|
+
@params = params
|
|
17
|
+
@request = request
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def build_request(path: "/api/rest_full/v0.3/widgets", query: {})
|
|
23
|
+
req = ActionDispatch::TestRequest.create
|
|
24
|
+
req.path = path
|
|
25
|
+
req.host = "example.org"
|
|
26
|
+
req.query_parameters.replace(query.stringify_keys)
|
|
27
|
+
req
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def paginate(scope, page: nil, per_page: nil, query: {})
|
|
31
|
+
params = query.merge({ page:, per_page: }.compact)
|
|
32
|
+
request = build_request(query: params)
|
|
33
|
+
instance = host.new(
|
|
34
|
+
params: ActionController::Parameters.new(params),
|
|
35
|
+
request:
|
|
36
|
+
)
|
|
37
|
+
instance.send(:paginate_collection, scope)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "defaults page to 1 and per_page to 20" do
|
|
41
|
+
records, meta = paginate((1..25).to_a)
|
|
42
|
+
expect(records.size).to eq(20)
|
|
43
|
+
expect(meta[:page]).to eq(1)
|
|
44
|
+
expect(meta[:per_page]).to eq(20)
|
|
45
|
+
expect(meta[:has_more]).to be(true)
|
|
46
|
+
expect(meta[:next]).to include("page=2")
|
|
47
|
+
expect(meta[:next]).to include("per_page=20")
|
|
48
|
+
expect(meta[:prev]).to be_nil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "clamps per_page above 100 to 100" do
|
|
52
|
+
_records, meta = paginate((1..5).to_a, per_page: 200)
|
|
53
|
+
expect(meta[:per_page]).to eq(100)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "falls back invalid per_page and page" do
|
|
57
|
+
_records, meta = paginate((1..5).to_a, page: 0, per_page: -3)
|
|
58
|
+
expect(meta[:page]).to eq(1)
|
|
59
|
+
expect(meta[:per_page]).to eq(20)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "sets has_more false on last page and builds prev" do
|
|
63
|
+
records, meta = paginate((1..5).to_a, page: 2, per_page: 3)
|
|
64
|
+
expect(records).to eq([4, 5])
|
|
65
|
+
expect(meta[:has_more]).to be(false)
|
|
66
|
+
expect(meta[:next]).to be_nil
|
|
67
|
+
expect(meta[:prev]).to include("page=1")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "preserves filter query params in next/prev" do
|
|
71
|
+
_records, meta = paginate(
|
|
72
|
+
(1..5).to_a,
|
|
73
|
+
page: 1,
|
|
74
|
+
per_page: 2,
|
|
75
|
+
query: { "filter" => { "state_eq" => "accepted" }, "order" => "published_at" }
|
|
76
|
+
)
|
|
77
|
+
expect(meta[:next]).to include("filter")
|
|
78
|
+
expect(meta[:next]).to include("state_eq")
|
|
79
|
+
expect(meta[:next]).to include("order=published_at")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "paginates ActiveRecord::Relation with limit+1" do
|
|
83
|
+
relation = instance_double(ActiveRecord::Relation)
|
|
84
|
+
limited = instance_double(ActiveRecord::Relation)
|
|
85
|
+
allow(relation).to receive(:is_a?).with(ActiveRecord::Relation).and_return(true)
|
|
86
|
+
allow(relation).to receive(:offset).with(0).and_return(relation)
|
|
87
|
+
allow(relation).to receive(:limit).with(3).and_return(limited)
|
|
88
|
+
allow(limited).to receive(:to_a).and_return([1, 2, 3])
|
|
89
|
+
|
|
90
|
+
records, meta = paginate(relation, page: 1, per_page: 2)
|
|
91
|
+
expect(records).to eq([1, 2])
|
|
92
|
+
expect(meta[:has_more]).to be(true)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "always sets has_more true when order is rand" do
|
|
96
|
+
records, meta = paginate((1..2).to_a, page: 2, per_page: 1, query: { "order" => "rand" })
|
|
97
|
+
expect(records).to eq([2])
|
|
98
|
+
expect(meta[:has_more]).to be(true)
|
|
99
|
+
expect(meta[:next]).to include("page=3")
|
|
100
|
+
expect(meta[:next]).to include("order=rand")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "treats blank order as rand when default_order_column is rand" do
|
|
104
|
+
host_with_default = Class.new do
|
|
105
|
+
include CollectionPagination
|
|
106
|
+
|
|
107
|
+
attr_accessor :params, :request
|
|
108
|
+
|
|
109
|
+
def initialize(params:, request:)
|
|
110
|
+
@params = params
|
|
111
|
+
@request = request
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def default_order_column
|
|
115
|
+
"rand"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
params = ActionController::Parameters.new(page: 1, per_page: 10)
|
|
120
|
+
request = build_request(query: { "page" => 1, "per_page" => 10 })
|
|
121
|
+
instance = host_with_default.new(params:, request:)
|
|
122
|
+
_records, meta = instance.send(:paginate_collection, (1..3).to_a)
|
|
123
|
+
expect(meta[:has_more]).to be(true)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# Toggle off → HTTP 501 (routes stay mounted; runtime ModuleAvailability enforces).
|
|
6
|
+
RSpec.describe "disabled RestFull modules via Toggle", type: :request do
|
|
7
|
+
let(:organization) { create(:organization, host: "test.example.org") }
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
host!(organization.host)
|
|
11
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:raw_config)
|
|
12
|
+
.and_return({ enabled: true, proposals_enabled: false, blogs_enabled: false }.with_indifferent_access)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns 501 for proposals when proposals Toggle is off" do
|
|
16
|
+
get "/api/rest_full/v#{Decidim::RestFull.major_minor_version}/proposals"
|
|
17
|
+
expect(response).to have_http_status(:not_implemented)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns 501 for blogs when blogs Toggle is off" do
|
|
21
|
+
get "/api/rest_full/v#{Decidim::RestFull.major_minor_version}/blogs"
|
|
22
|
+
expect(response).to have_http_status(:not_implemented)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::MagicLinkRedirectUrlForm do
|
|
6
|
+
let(:errors_scope) { "decidim.rest_full.forms.magic_link_redirect_url.errors" }
|
|
7
|
+
|
|
8
|
+
let(:organization) do
|
|
9
|
+
create(:organization, host: "tenant.example", external_domain_allowlist: ["partner.example"])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def form_with(url)
|
|
13
|
+
described_class.new(redirect_url: url, organization:)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "validations" do
|
|
17
|
+
it "is valid without redirect_url" do
|
|
18
|
+
form = form_with(nil)
|
|
19
|
+
expect(form).to be_valid
|
|
20
|
+
expect(form.normalized_redirect_url).to be_nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "is valid with https URL on allowlisted host (www stripped)" do
|
|
24
|
+
form = form_with("https://www.partner.example/path?q=1")
|
|
25
|
+
expect(form).to be_valid
|
|
26
|
+
expect(form.normalized_redirect_url).to eq("https://www.partner.example/path?q=1")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "is valid when host matches organization host" do
|
|
30
|
+
form = form_with("https://tenant.example/")
|
|
31
|
+
expect(form).to be_valid
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "is valid for secondary_hosts" do
|
|
35
|
+
organization.update!(secondary_hosts: ["alt.example"])
|
|
36
|
+
form = form_with("https://alt.example/foo")
|
|
37
|
+
expect(form).to be_valid
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "rejects http" do
|
|
41
|
+
form = form_with("http://partner.example/")
|
|
42
|
+
expect(form).not_to be_valid
|
|
43
|
+
expect(form.errors[:redirect_url]).to include(I18n.t("#{errors_scope}.redirect_url.https_only"))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "rejects non-ASCII" do
|
|
47
|
+
form = form_with("https://partner.example/caf\u00e9")
|
|
48
|
+
expect(form).not_to be_valid
|
|
49
|
+
expect(form.errors[:redirect_url]).to include(I18n.t("#{errors_scope}.redirect_url.ascii_only"))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "rejects host not in allowlist" do
|
|
53
|
+
form = form_with("https://evil.example/")
|
|
54
|
+
expect(form).not_to be_valid
|
|
55
|
+
expect(form.errors[:redirect_url]).to include(I18n.t("#{errors_scope}.redirect_url.host_not_allowed"))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "rejects userinfo in URL" do
|
|
59
|
+
form = form_with("https://user:pass@partner.example/")
|
|
60
|
+
expect(form).not_to be_valid
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "is invalid without organization" do
|
|
64
|
+
form = described_class.new(redirect_url: "https://partner.example/", organization: nil)
|
|
65
|
+
expect(form).not_to be_valid
|
|
66
|
+
expect(form.errors[:organization]).to include(I18n.t("#{errors_scope}.organization_required"))
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::WebhookRegistrationForm do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:api_client) { create(:api_client, organization:, scopes: ["webhooks"]) }
|
|
8
|
+
let(:event_key) { "proposal_creation.succeeded" }
|
|
9
|
+
let(:subscriptions) { [event_key] }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
api_client.permissions.create!(permission: event_key, is_event: true)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def form_with(url:, subscriptions: self.subscriptions)
|
|
16
|
+
described_class
|
|
17
|
+
.from_params(url:, subscriptions:)
|
|
18
|
+
.with_context(api_client:)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "url schema" do
|
|
22
|
+
it "is valid with an https URL" do
|
|
23
|
+
expect(form_with(url: "https://example.org/hooks")).to be_valid
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "is valid with an http URL" do
|
|
27
|
+
expect(form_with(url: "http://internal.example/hooks")).to be_valid
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "rejects ftp URLs" do
|
|
31
|
+
form = form_with(url: "ftp://example.org/hooks")
|
|
32
|
+
expect(form).not_to be_valid
|
|
33
|
+
expect(form.errors[:url]).to include("must be a valid HTTP or HTTPS URL")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "rejects URLs without a host" do
|
|
37
|
+
form = form_with(url: "http:///hooks")
|
|
38
|
+
expect(form).not_to be_valid
|
|
39
|
+
expect(form.errors[:url]).to include("must be a valid HTTP or HTTPS URL")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::SpaceWebhookJob do
|
|
6
|
+
let(:organization) { create(:organization) }
|
|
7
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
8
|
+
let(:step) { participatory_process.steps.first }
|
|
9
|
+
let(:event_name) { "participatory_process.step_activated.succeeded" }
|
|
10
|
+
let(:api_client) { create(:api_client, organization:, scopes: ["public"]) }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
allow(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later).and_return(true)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "dispatches subscribed webhooks" do
|
|
17
|
+
api_client.permissions.create!(permission: event_name, is_event: true)
|
|
18
|
+
webhooks = create_list(:webhook_registration, 2, api_client:, subscriptions: [event_name])
|
|
19
|
+
create(:webhook_registration, api_client:, subscriptions: ["other.event"])
|
|
20
|
+
|
|
21
|
+
expect(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later) do |registration, _payload, _timestamp|
|
|
22
|
+
expect(webhooks).to include(registration)
|
|
23
|
+
end.at_least(:once)
|
|
24
|
+
|
|
25
|
+
described_class.perform_now(event_name, participatory_process.id, organization.id, step.id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "uses active_step when step_id is omitted" do
|
|
29
|
+
api_client.permissions.create!(permission: event_name, is_event: true)
|
|
30
|
+
create(:webhook_registration, api_client:, subscriptions: [event_name])
|
|
31
|
+
|
|
32
|
+
expect(Decidim::RestFull::Core::WebhookJob).to receive(:perform_later).at_least(:once)
|
|
33
|
+
described_class.perform_now(event_name, participatory_process.id, organization.id)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "skips when the event form is invalid" do
|
|
37
|
+
api_client.permissions.create!(permission: event_name, is_event: true)
|
|
38
|
+
create(:webhook_registration, api_client:, subscriptions: [event_name])
|
|
39
|
+
|
|
40
|
+
allow_any_instance_of(Decidim::Api::RestFull::Core::SpaceWebhookSerializer).to receive(:event_attributes).and_return( # rubocop:disable RSpec/AnyInstance
|
|
41
|
+
type: event_name,
|
|
42
|
+
data: { "data" => { "id" => "1" } },
|
|
43
|
+
timestamp: Time.current.to_i
|
|
44
|
+
)
|
|
45
|
+
form = instance_double(
|
|
46
|
+
Decidim::RestFull::Core::WebhookEventForm,
|
|
47
|
+
valid?: false,
|
|
48
|
+
errors: instance_double(ActiveModel::Errors, full_messages: ["bad"])
|
|
49
|
+
)
|
|
50
|
+
allow(Decidim::RestFull::Core::WebhookEventForm).to receive(:new).and_return(form)
|
|
51
|
+
allow(form).to receive(:with_context).and_return(form)
|
|
52
|
+
|
|
53
|
+
expect(Decidim::RestFull::Core::WebhookJob).not_to receive(:perform_later)
|
|
54
|
+
expect(Rails.logger).to receive(:warn).with(/Invalid space webhook event/)
|
|
55
|
+
described_class.perform_now(event_name, participatory_process.id, organization.id, step.id)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "no-ops when no api client has the event permission" do
|
|
59
|
+
expect(Decidim::RestFull::Core::WebhookJob).not_to receive(:perform_later)
|
|
60
|
+
described_class.perform_now(event_name, participatory_process.id, organization.id, step.id)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::SyncronizeUnconfirmedHostJob do
|
|
6
|
+
let(:organization) { create(:organization, available_locales: ["en"]) }
|
|
7
|
+
let(:organization_id) { organization.id }
|
|
8
|
+
|
|
9
|
+
it "syncronizes the unconfirmed host" do
|
|
10
|
+
expect(Decidim::RestFull::Core::SyncronizeUnconfirmedHost).to receive(:call).with(organization)
|
|
11
|
+
described_class.perform_now(organization_id)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "retries the job on Decidim::RestFull::Core::ApiException::NotFound" do
|
|
15
|
+
allow(Decidim::RestFull::Core::SyncronizeUnconfirmedHost).to receive(:call).and_raise(Decidim::RestFull::Core::ApiException::NotFound)
|
|
16
|
+
described_class.perform_now(organization_id)
|
|
17
|
+
|
|
18
|
+
expect(described_class).to have_been_enqueued.with(organization_id)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "discards the job on IPAddr::InvalidAddressError" do
|
|
22
|
+
allow(Decidim::RestFull::Core::SyncronizeUnconfirmedHost).to receive(:call).and_raise(IPAddr::InvalidAddressError)
|
|
23
|
+
described_class.perform_now(organization_id)
|
|
24
|
+
|
|
25
|
+
expect(described_class).not_to have_been_enqueued.with(organization_id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "discards the job on Decidim::RestFull::Core::ApiException::BadRequest" do
|
|
29
|
+
allow(Decidim::RestFull::Core::SyncronizeUnconfirmedHost).to receive(:call).and_raise(Decidim::RestFull::Core::ApiException::BadRequest)
|
|
30
|
+
described_class.perform_now(organization_id)
|
|
31
|
+
|
|
32
|
+
expect(described_class).not_to have_been_enqueued.with(organization_id)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::WebhookJob do
|
|
6
|
+
let(:webhook) { create(:webhook_registration) }
|
|
7
|
+
let(:event) { { "type" => "test.event", "data" => { "data" => { "id" => 1 } } } }
|
|
8
|
+
let(:timestamp) { Time.current.to_i.to_s }
|
|
9
|
+
|
|
10
|
+
it "sends a webhook" do
|
|
11
|
+
expect(webhook).to receive(:send_webhook).with(event, timestamp)
|
|
12
|
+
described_class.perform_now(webhook, event, timestamp)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "retries the job on WebhookFailedError" do
|
|
16
|
+
allow(webhook).to receive(:send_webhook).and_raise(Decidim::RestFull::WebhookFailedError)
|
|
17
|
+
|
|
18
|
+
described_class.perform_now(webhook, event, timestamp)
|
|
19
|
+
expect(described_class).to have_been_enqueued.with(webhook, event, timestamp)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "fails the job on StandardError" do
|
|
23
|
+
allow(webhook).to receive(:send_webhook).and_raise(StandardError)
|
|
24
|
+
expect do
|
|
25
|
+
described_class.perform_now(webhook, event, timestamp)
|
|
26
|
+
end.to raise_error(StandardError)
|
|
27
|
+
expect(described_class).not_to have_been_enqueued.with(webhook, event, timestamp)
|
|
28
|
+
end
|
|
29
|
+
end
|