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,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# rubocop:disable RSpec/DescribeClass -- cross-cutting optional-gem integration
|
|
6
|
+
RSpec.describe "optional decidim-restfull feature gems" do
|
|
7
|
+
describe Decidim::RestFull::Core::DoorkeeperConfig do
|
|
8
|
+
it "advertises only core scopes without registered feature scopes" do
|
|
9
|
+
allow(Decidim::RestFull::Extension).to receive(:doorkeeper_optional_scopes).and_return([])
|
|
10
|
+
|
|
11
|
+
expect(described_class.advertised_scopes).not_to include(:blogs, :proposals)
|
|
12
|
+
expect(described_class::CORE_OPTIONAL_SCOPES).not_to include(:meetings, :debates)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "filters advertised_scopes_for when feature gem scopes are absent" do
|
|
16
|
+
organization = create(:organization)
|
|
17
|
+
allow(Decidim::RestFull::Extension).to receive(:doorkeeper_optional_scopes).and_return([])
|
|
18
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:raw_config)
|
|
19
|
+
.with(organization).and_return({ enabled: true }.with_indifferent_access)
|
|
20
|
+
|
|
21
|
+
expect(described_class.advertised_scopes_for(organization)).not_to include(:proposals, :blogs)
|
|
22
|
+
expect(described_class.advertised_scopes_for(organization)).to include(:public, :oauth)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe Decidim::RestFull::Core::Configuration do
|
|
27
|
+
it "defaults to core permissions only; feature gems merge via Extension.register" do
|
|
28
|
+
expect(described_class.default_available_permissions).not_to include("blogs", "proposals", "meetings")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "receives events_for_proposals from the proposals gem when loaded" do
|
|
32
|
+
skip "decidim-restfull-proposals not in bundle" unless Gem.loaded_specs.has_key?("decidim-restfull-proposals")
|
|
33
|
+
|
|
34
|
+
expect(described_class.events_for_proposals).to include("proposal_creation.succeeded")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "receives events_for_meetings from the meetings gem when loaded" do
|
|
38
|
+
skip "decidim-restfull-meetings not in bundle" unless Gem.loaded_specs.has_key?("decidim-restfull-meetings")
|
|
39
|
+
|
|
40
|
+
expect(described_class.events_for_meetings).to eq(%w(meetings.upcoming_reminder.succeeded))
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe Decidim::RestFull::Core::PermissionRegistry do
|
|
45
|
+
it "exposes no proposals permission group when nothing was registered for that scope" do
|
|
46
|
+
# Missing feature gem ⇒ Extension.register never ran ⇒ empty scope.
|
|
47
|
+
expect(described_class.by_scope(:proposals_missing_gem_probe)).to eq([])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "does not register unimplemented system.users / system.server abilities" do
|
|
51
|
+
keys = described_class.by_scope(:system).map(&:key)
|
|
52
|
+
|
|
53
|
+
expect(keys).to include("oauth.read")
|
|
54
|
+
expect(keys).not_to include(
|
|
55
|
+
"system.users.update",
|
|
56
|
+
"system.users.destroy",
|
|
57
|
+
"system.server.restart",
|
|
58
|
+
"system.server.exec"
|
|
59
|
+
)
|
|
60
|
+
expect(described_class.by_scope_and_group(:system, :rails)).to eq([])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "lists extension-only scopes for the System API client permissions UI" do
|
|
64
|
+
described_class.register(:whatsapp, "whatsapp.read", group: :whatsapp)
|
|
65
|
+
|
|
66
|
+
expect(described_class.extension_ui_scopes).to include("whatsapp")
|
|
67
|
+
expect(described_class.extension_ui_scopes).not_to include("proposals", "blogs")
|
|
68
|
+
expect(described_class.extension_ui_groups(:whatsapp)).to eq(["whatsapp"])
|
|
69
|
+
ensure
|
|
70
|
+
described_class.send(:registry).delete("whatsapp.read")
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe Decidim::RestFull::Core::WebhookEventCatalog do
|
|
75
|
+
it "sync_from_configuration registers only core oauth/system events" do
|
|
76
|
+
snapshot = described_class.entries.dup
|
|
77
|
+
described_class.clear!
|
|
78
|
+
described_class.sync_from_configuration!
|
|
79
|
+
|
|
80
|
+
expect(described_class.all.map(&:scope).uniq).to match_array(%w(oauth system))
|
|
81
|
+
expect(described_class.all.map(&:schema_key)).to all(start_with("wh_"))
|
|
82
|
+
ensure
|
|
83
|
+
described_class.instance_variable_set(:@entries, snapshot)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe Decidim::RestFull::Core::WebhookDispatcher do
|
|
88
|
+
it "no-ops proposal events when the proposals webhook job is not available" do
|
|
89
|
+
dispatcher = described_class.instance
|
|
90
|
+
allow(dispatcher).to receive(:proposals_webhook_job_defined?).and_return(false)
|
|
91
|
+
|
|
92
|
+
expect(Decidim::RestFull::Proposals::ProposalWebhookJob).not_to receive(:perform_later) if defined?(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
93
|
+
|
|
94
|
+
expect do
|
|
95
|
+
dispatcher.handle_proposals("decidim.proposals.create_proposal:after", resource: nil)
|
|
96
|
+
end.not_to raise_error
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe Decidim::RestFull::Core::Admin::ConfigForm do
|
|
101
|
+
let(:organization) { create(:organization) }
|
|
102
|
+
let(:form) { described_class.from_model(organization).with_context(current_organization: organization) }
|
|
103
|
+
|
|
104
|
+
it "disables proposals_enabled when the proposals gem is absent" do
|
|
105
|
+
form.enabled = true
|
|
106
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:feature_gem_present?)
|
|
107
|
+
.and_return(true)
|
|
108
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:feature_gem_present?)
|
|
109
|
+
.with(:proposals).and_return(false)
|
|
110
|
+
|
|
111
|
+
expect(form.attribute_disabled?(:proposals_enabled)).to be(true)
|
|
112
|
+
expect(form.attribute_disabled?(:attachments_enabled)).to be(false)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "omits disabled missing-gem attributes from to_h" do
|
|
116
|
+
form.enabled = true
|
|
117
|
+
form.proposals_enabled = true
|
|
118
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:feature_gem_present?)
|
|
119
|
+
.and_return(true)
|
|
120
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:feature_gem_present?)
|
|
121
|
+
.with(:proposals).and_return(false)
|
|
122
|
+
|
|
123
|
+
expect(form.to_h).not_to have_key(:proposals_enabled)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe Decidim::RestFull::Core::Ransackers do
|
|
128
|
+
it "registers core ransackers without decidim-proposals loaded" do
|
|
129
|
+
expect { described_class.register_ransackers! }.not_to raise_error
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
describe Decidim::Api::RestFull::Core::SerializerLookup do
|
|
134
|
+
it "falls back to a typed ComponentSerializer subclass when the adapter gem is absent" do
|
|
135
|
+
allow(described_class).to receive(:safe_constant_defined?).and_return(false)
|
|
136
|
+
klass = described_class.component_serializer_class_for("proposals")
|
|
137
|
+
expect(klass).to be < Decidim::Api::RestFull::Core::ComponentSerializer
|
|
138
|
+
expect(klass.record_type).to eq(:proposal_component)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "resolves meetings serializer when decidim-restfull-meetings is loaded" do
|
|
142
|
+
skip "decidim-restfull-meetings not in bundle" unless defined?(Decidim::Api::RestFull::Meetings::MeetingComponentSerializer)
|
|
143
|
+
|
|
144
|
+
expect(described_class.component_serializer_class_for("meetings")).to eq(
|
|
145
|
+
Decidim::Api::RestFull::Meetings::MeetingComponentSerializer
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "resolves page serializer from core without a feature gem" do
|
|
150
|
+
expect(described_class.component_serializer_class_for("pages")).to eq(
|
|
151
|
+
Decidim::Api::RestFull::Core::PageComponentSerializer
|
|
152
|
+
)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe Decidim::RestFull::Core::Ability do
|
|
157
|
+
let(:organization) { create(:organization) }
|
|
158
|
+
let(:api_client) do
|
|
159
|
+
create(:api_client, organization:, scopes: %w(meetings)).tap do |client|
|
|
160
|
+
client.permissions.create!(permission: "meetings.read")
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it "does not reference proposals when only meetings scope is used" do
|
|
165
|
+
ability = described_class.new(api_client)
|
|
166
|
+
skip "decidim-meetings not in bundle" unless defined?(Decidim::Meetings::Meeting)
|
|
167
|
+
|
|
168
|
+
expect(ability.can?(:read, Decidim::Meetings::Meeting)).to be(true)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
# rubocop:enable RSpec/DescribeClass
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module RestFull
|
|
7
|
+
module Core
|
|
8
|
+
module Roles
|
|
9
|
+
RSpec.describe RoleIdCodec do
|
|
10
|
+
describe ".encode" do
|
|
11
|
+
it "produces URL-safe base64 without padding" do
|
|
12
|
+
id = described_class.encode(
|
|
13
|
+
resource_type: "Decidim::Organization",
|
|
14
|
+
resource_id: 1,
|
|
15
|
+
user_id: 2,
|
|
16
|
+
invited_at: nil,
|
|
17
|
+
type: "general_admin"
|
|
18
|
+
)
|
|
19
|
+
expect(id).to match(/\A[A-Za-z0-9_-]+\z/)
|
|
20
|
+
expect(id).not_to include("+", "/", "=")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe ".decode" do
|
|
25
|
+
it "round-trips with encode" do
|
|
26
|
+
payload = {
|
|
27
|
+
resource_type: "Decidim::ParticipatoryProcess",
|
|
28
|
+
resource_id: 10,
|
|
29
|
+
user_id: 20,
|
|
30
|
+
invited_at: nil,
|
|
31
|
+
type: "space_administrator"
|
|
32
|
+
}
|
|
33
|
+
id = described_class.encode(**payload)
|
|
34
|
+
decoded = described_class.decode(id)
|
|
35
|
+
expect(decoded[:resource_type]).to eq("Decidim::ParticipatoryProcess")
|
|
36
|
+
expect(decoded[:resource_id]).to eq(10)
|
|
37
|
+
expect(decoded[:user_id]).to eq(20)
|
|
38
|
+
expect(decoded[:type]).to eq("space_administrator")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "returns nil for invalid or garbage id" do
|
|
42
|
+
expect(described_class.decode("not-valid-base64!!!")).to be_nil
|
|
43
|
+
expect(described_class.decode("")).to be_nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe ".normalize_invited_at" do
|
|
48
|
+
it "returns nil for nil or blank" do
|
|
49
|
+
expect(described_class.normalize_invited_at(nil)).to be_nil
|
|
50
|
+
expect(described_class.normalize_invited_at("")).to be_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "returns iso8601 string for Time" do
|
|
54
|
+
t = Time.utc(2024, 1, 15, 12, 0, 0)
|
|
55
|
+
expect(described_class.normalize_invited_at(t)).to eq("2024-01-15T12:00:00Z")
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module RestFull
|
|
7
|
+
module Core
|
|
8
|
+
module Roles
|
|
9
|
+
RSpec.describe RolesAggregator do
|
|
10
|
+
describe "SPACE_ROLE_MAP" do
|
|
11
|
+
it "maps Decidim roles to API types" do
|
|
12
|
+
expect(described_class::SPACE_ROLE_MAP["admin"]).to eq("space_administrator")
|
|
13
|
+
expect(described_class::SPACE_ROLE_MAP["moderator"]).to eq("space_moderator")
|
|
14
|
+
expect(described_class::SPACE_ROLE_MAP["valuator"]).to eq("space_valuator")
|
|
15
|
+
expect(described_class::SPACE_ROLE_MAP["evaluator"]).to eq("space_valuator")
|
|
16
|
+
expect(described_class::SPACE_ROLE_MAP["collaborator"]).to eq("space_private_member")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe ".for_organization" do
|
|
21
|
+
it "returns role views and includes general_admin for admin users" do
|
|
22
|
+
organization = create(:organization, available_locales: ["en"])
|
|
23
|
+
admin = create(:user, :admin, organization:)
|
|
24
|
+
roles = described_class.for_organization(organization)
|
|
25
|
+
expect(roles).to be_an(Array)
|
|
26
|
+
expect(roles.first).to be_a(described_class::RoleView) if roles.any?
|
|
27
|
+
general = roles.find { |r| r.type == "general_admin" && r.user_id == admin.id }
|
|
28
|
+
expect(general).to be_present
|
|
29
|
+
expect(RoleIdCodec.decode(general.id)[:user_id]).to eq(admin.id)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "find_by_id returns the role when id is valid" do
|
|
33
|
+
organization = create(:organization, available_locales: ["en"])
|
|
34
|
+
admin = create(:user, :admin, organization:)
|
|
35
|
+
aggregator = described_class.new(organization)
|
|
36
|
+
id = RoleIdCodec.encode(
|
|
37
|
+
resource_type: "Decidim::Organization",
|
|
38
|
+
resource_id: organization.id,
|
|
39
|
+
user_id: admin.id,
|
|
40
|
+
invited_at: nil,
|
|
41
|
+
type: "general_admin"
|
|
42
|
+
)
|
|
43
|
+
role = aggregator.find_by(id:)
|
|
44
|
+
expect(role).to be_present
|
|
45
|
+
expect(role.type).to eq("general_admin")
|
|
46
|
+
expect(role.user_id).to eq(admin.id)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module RestFull
|
|
7
|
+
module Core
|
|
8
|
+
module Roles
|
|
9
|
+
RSpec.describe RolesWriter do
|
|
10
|
+
describe "API_TO_DECIDIM_ROLE" do
|
|
11
|
+
it "maps API types to Decidim roles" do
|
|
12
|
+
expect(described_class::API_TO_DECIDIM_ROLE["space_administrator"]).to eq("admin")
|
|
13
|
+
expect(described_class::API_TO_DECIDIM_ROLE["space_moderator"]).to eq("moderator")
|
|
14
|
+
expect(described_class::API_TO_DECIDIM_ROLE["space_private_member"]).to eq("collaborator")
|
|
15
|
+
expect(described_class.valuator_role_name).to be_in(%w(valuator evaluator))
|
|
16
|
+
expect(described_class.decidim_role_for("space_valuator")).to eq(described_class.valuator_role_name)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe "#create" do
|
|
21
|
+
it "raises ArgumentError for invalid role type" do
|
|
22
|
+
organization = create(:organization, available_locales: ["en"])
|
|
23
|
+
user = create(:user, organization:)
|
|
24
|
+
writer = described_class.new(organization)
|
|
25
|
+
attrs = {
|
|
26
|
+
resource_type: "Decidim::Organization",
|
|
27
|
+
resource_id: organization.id,
|
|
28
|
+
user_id: user.id,
|
|
29
|
+
type: "invalid_type"
|
|
30
|
+
}
|
|
31
|
+
expect { writer.create(attrs) }.to raise_error(ArgumentError, /Invalid role type/)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# RouteRegistry: API route blocks are registered with draw_api_routes and drawn in
|
|
4
|
+
# the api/rest_full/vX scope when apply! is called. These specs use an isolated
|
|
5
|
+
# RouteSet so we don't touch the real app routes.
|
|
6
|
+
|
|
7
|
+
require "spec_helper"
|
|
8
|
+
|
|
9
|
+
module Decidim
|
|
10
|
+
module RestFull
|
|
11
|
+
module Core
|
|
12
|
+
RSpec.describe RouteRegistry do
|
|
13
|
+
after { described_class.reset! }
|
|
14
|
+
|
|
15
|
+
describe ".draw_api_routes" do
|
|
16
|
+
it "appends the block to route_blocks" do
|
|
17
|
+
block = proc {}
|
|
18
|
+
described_class.draw_api_routes(&block)
|
|
19
|
+
expect(described_class.route_blocks).to include(block)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe ".apply! with isolated RouteSet" do
|
|
24
|
+
it "runs registered blocks in the api scope and adds routes" do
|
|
25
|
+
described_class.draw_api_routes do
|
|
26
|
+
get "/_spec_ping", to: "/decidim/rest_full/pages#show"
|
|
27
|
+
end
|
|
28
|
+
isolated = ActionDispatch::Routing::RouteSet.new
|
|
29
|
+
described_class.apply!(isolated) do
|
|
30
|
+
get "/", to: "/decidim/rest_full/pages#show"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
path_specs = isolated.routes.map { |r| r.path.spec.to_s }
|
|
34
|
+
expect(path_specs).to include(include("_spec_ping"))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "preserves pre-existing routes (e.g. Doorkeeper /oauth/token at org root)" do
|
|
38
|
+
isolated = ActionDispatch::Routing::RouteSet.new
|
|
39
|
+
isolated.draw do
|
|
40
|
+
post "/oauth/token", to: "doorkeeper/tokens#create"
|
|
41
|
+
end
|
|
42
|
+
count_before = isolated.routes.count
|
|
43
|
+
|
|
44
|
+
described_class.apply!(isolated) do
|
|
45
|
+
get "/", to: "/decidim/rest_full/pages#show"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
path_specs = isolated.routes.map { |r| r.path.spec.to_s }
|
|
49
|
+
expect(isolated.routes.count).to be > count_before
|
|
50
|
+
expect(path_specs).to include("/oauth/token(.:format)")
|
|
51
|
+
expect(path_specs).to include(a_string_matching(%r{/api/rest_full/v[\d.]+(\(\.:format\)|/)}))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "appends routes registered after the first apply!" do
|
|
55
|
+
isolated = ActionDispatch::Routing::RouteSet.new
|
|
56
|
+
described_class.apply!(isolated) { get "/", to: "/decidim/rest_full/pages#show" }
|
|
57
|
+
|
|
58
|
+
described_class.draw_api_routes do
|
|
59
|
+
get "/_spec_late", to: "/decidim/rest_full/pages#show"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
described_class.append_pending!(isolated)
|
|
63
|
+
|
|
64
|
+
path_specs = isolated.routes.map { |r| r.path.spec.to_s }
|
|
65
|
+
expect(path_specs).to include(include("_spec_late"))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "raises DuplicateRouteBlockError when the same block is registered twice" do
|
|
69
|
+
block = proc { get "/_spec_dup", to: "/decidim/rest_full/pages#show" }
|
|
70
|
+
described_class.draw_api_routes(&block)
|
|
71
|
+
described_class.draw_api_routes(&block)
|
|
72
|
+
|
|
73
|
+
isolated = ActionDispatch::Routing::RouteSet.new
|
|
74
|
+
expect do
|
|
75
|
+
described_class.apply!(isolated) { get "/", to: "/decidim/rest_full/pages#show" }
|
|
76
|
+
end.to raise_error(Decidim::RestFull::Core::DuplicateRouteBlockError, /already applied/)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe ".reset!" do
|
|
81
|
+
it "clears route_blocks" do
|
|
82
|
+
described_class.draw_api_routes { get "/x", to: "x#y" }
|
|
83
|
+
described_class.reset!
|
|
84
|
+
expect(described_class.route_blocks).to eq([])
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::SerializerAdditionsRegistry do
|
|
6
|
+
let(:widget_serializer) do
|
|
7
|
+
Class.new(Decidim::Api::RestFull::Core::ApplicationSerializer) do
|
|
8
|
+
set_type :widget
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:item_serializer) do
|
|
13
|
+
Class.new(Decidim::Api::RestFull::Core::ApplicationSerializer) do
|
|
14
|
+
set_type :item
|
|
15
|
+
|
|
16
|
+
meta do |_record, _params|
|
|
17
|
+
{ base_meta: true }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
before do
|
|
23
|
+
Decidim::RestFull::Core::SerializerAdditionsRegistry.reset!
|
|
24
|
+
Decidim::RestFull::Core::HttpCache::FingerprintContributorRegistry.reset!
|
|
25
|
+
stub_const("RestFullSpec::WidgetSerializer", widget_serializer)
|
|
26
|
+
stub_const("RestFullSpec::ItemSerializer", item_serializer)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def build_registration(extension_name:, serializer_name:, &block)
|
|
30
|
+
builder = Decidim::RestFull::Core::RestEnhancementBuilder.new(
|
|
31
|
+
extension_name:,
|
|
32
|
+
serializer_name:,
|
|
33
|
+
http_cache_profile: nil
|
|
34
|
+
)
|
|
35
|
+
builder.instance_eval(&block) if block
|
|
36
|
+
builder.validate_http_cache_strictness!
|
|
37
|
+
builder.to_registration
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe ".register" do
|
|
41
|
+
it "raises when two extensions declare the same relationship name" do
|
|
42
|
+
described_class.reset!
|
|
43
|
+
described_class.register(
|
|
44
|
+
build_registration(extension_name: :a, serializer_name: "RestFullSpec::ItemSerializer") do
|
|
45
|
+
has_many(:widgets, serializer: RestFullSpec::WidgetSerializer) { |_r, _p| [] }
|
|
46
|
+
end
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
expect do
|
|
50
|
+
described_class.register(
|
|
51
|
+
build_registration(extension_name: :b, serializer_name: "RestFullSpec::ItemSerializer") do
|
|
52
|
+
has_many(:widgets, serializer: RestFullSpec::WidgetSerializer) { |_r, _p| [] }
|
|
53
|
+
end
|
|
54
|
+
)
|
|
55
|
+
end.to raise_error(ArgumentError, /relationship conflict/)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe ".apply!" do
|
|
60
|
+
it "does not raise when the serializer constant is not yet defined" do
|
|
61
|
+
described_class.reset!
|
|
62
|
+
described_class.register(
|
|
63
|
+
build_registration(extension_name: :ghost, serializer_name: "RestFullSpec::NoSuchSerializer") do
|
|
64
|
+
meta { { ghost: true } }
|
|
65
|
+
end
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect { described_class.apply! }.not_to raise_error
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "applies has_many once and stays idempotent across repeated apply!" do
|
|
72
|
+
described_class.reset!
|
|
73
|
+
described_class.register(
|
|
74
|
+
build_registration(extension_name: :demo, serializer_name: "RestFullSpec::ItemSerializer") do
|
|
75
|
+
has_many(:widgets, serializer: RestFullSpec::WidgetSerializer) { |_r, _p| [] }
|
|
76
|
+
end
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
2.times { described_class.apply! }
|
|
80
|
+
|
|
81
|
+
rel = RestFullSpec::ItemSerializer.relationships_to_serialize[:widgets]
|
|
82
|
+
expect(rel).to be_present
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "merges meta without clobbering the base serializer meta" do
|
|
86
|
+
described_class.reset!
|
|
87
|
+
described_class.register(
|
|
88
|
+
build_registration(extension_name: :demo, serializer_name: "RestFullSpec::ItemSerializer") do
|
|
89
|
+
meta { |_record, _params| { addon: 1 } }
|
|
90
|
+
end
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
described_class.apply!
|
|
94
|
+
|
|
95
|
+
item = Struct.new(:id).new(1)
|
|
96
|
+
hash = RestFullSpec::ItemSerializer.new(item, params: {}).serializable_hash
|
|
97
|
+
expect(hash[:data][:meta]).to include(base_meta: true, addon: 1)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::SettingsTab do
|
|
6
|
+
it "registers a form_layout_partial that accepts Toggle locals" do
|
|
7
|
+
path = Decidim::RestFull::Core::Engine.root.join(
|
|
8
|
+
"app/views/decidim/rest_full/core/admin/_organization_settings_tab.html.erb"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
expect(File.read(path).lines.first).to match(
|
|
12
|
+
/<%#\s*locals:\s*\(organization:,\s*tab:\)\s*%>/
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module RestFull
|
|
7
|
+
module Core
|
|
8
|
+
RSpec.describe SwaggerSpecPaths do
|
|
9
|
+
around do |example|
|
|
10
|
+
described_class.reset!
|
|
11
|
+
old = ENV.fetch("DECIDIM_REST_FULL_SWAGGER_SPEC_PATHS", nil)
|
|
12
|
+
ENV.delete("DECIDIM_REST_FULL_SWAGGER_SPEC_PATHS")
|
|
13
|
+
example.run
|
|
14
|
+
ENV["DECIDIM_REST_FULL_SWAGGER_SPEC_PATHS"] = old
|
|
15
|
+
described_class.reset!
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "has no default paths (specs live in feature gems)" do
|
|
19
|
+
expect(described_class.rspec_paths).to eq([])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "expands request spec globs to concrete files" do
|
|
23
|
+
described_class.register(
|
|
24
|
+
File.join("decidim-restfull-core", "spec/requests/**/*_spec.rb")
|
|
25
|
+
)
|
|
26
|
+
paths = described_class.rspec_paths
|
|
27
|
+
expect(paths).not_to be_empty
|
|
28
|
+
expect(paths).to all(end_with("_spec.rb"))
|
|
29
|
+
expect(paths.join).to include("organizations_controller_index_spec.rb")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "omits globs with no matching files" do
|
|
33
|
+
described_class.register("decidim-restfull-accountabilities/spec/requests/**/*_spec.rb")
|
|
34
|
+
expect(described_class.rspec_paths).to eq([])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "merges env paths when files exist" do
|
|
38
|
+
core_spec = Dir.glob(
|
|
39
|
+
File.join(GemSpecPaths.monorepo_root, "decidim-restfull-core/spec/requests/**/*_spec.rb")
|
|
40
|
+
).first
|
|
41
|
+
skip "no core request specs in tree" unless core_spec
|
|
42
|
+
|
|
43
|
+
rel = core_spec.delete_prefix("#{GemSpecPaths.monorepo_root}/")
|
|
44
|
+
ENV["DECIDIM_REST_FULL_SWAGGER_SPEC_PATHS"] = rel
|
|
45
|
+
expect(described_class.rspec_paths).to eq([core_spec])
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::WebhookDispatcher do
|
|
6
|
+
include ActiveJob::TestHelper
|
|
7
|
+
|
|
8
|
+
let(:organization) { create(:organization) }
|
|
9
|
+
let(:component) { create(:proposal_component, organization:) }
|
|
10
|
+
let(:dispatcher) { described_class.instance }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:module_enabled?)
|
|
14
|
+
.with(organization, :proposals).and_return(true)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def handle(name, proposal)
|
|
18
|
+
allow(proposal).to receive(:organization).and_return(organization)
|
|
19
|
+
dispatcher.handle_proposals(name, { resource: proposal })
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "maps proposal_published to proposal_creation.succeeded" do
|
|
23
|
+
proposal = create(:proposal, :published, component:)
|
|
24
|
+
expect { handle("decidim.events.proposals.proposal_published", proposal) }
|
|
25
|
+
.to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
26
|
+
.with("proposal_creation.succeeded", proposal.id, organization.id)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "maps draft create to draft_proposal_creation.succeeded" do
|
|
30
|
+
proposal = create(:proposal, component:, published_at: nil)
|
|
31
|
+
expect { handle("decidim.proposals.create_proposal:after", proposal) }
|
|
32
|
+
.to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
33
|
+
.with("draft_proposal_creation.succeeded", proposal.id, organization.id)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "maps draft update to draft_proposal_update.succeeded" do
|
|
37
|
+
proposal = create(:proposal, component:, published_at: nil)
|
|
38
|
+
expect { handle("decidim.proposals.update_proposal:after", proposal) }
|
|
39
|
+
.to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
40
|
+
.with("draft_proposal_update.succeeded", proposal.id, organization.id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "maps published update to proposal_update.succeeded" do
|
|
44
|
+
proposal = create(:proposal, :published, component:)
|
|
45
|
+
expect { handle("decidim.proposals.update_proposal:after", proposal) }
|
|
46
|
+
.to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
47
|
+
.with("proposal_update.succeeded", proposal.id, organization.id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "ignores unknown notification names" do
|
|
51
|
+
proposal = create(:proposal, :published, component:)
|
|
52
|
+
expect { handle("decidim.events.unknown", proposal) }
|
|
53
|
+
.not_to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "no-ops when proposals module is disabled" do
|
|
57
|
+
proposal = create(:proposal, :published, component:)
|
|
58
|
+
allow(Decidim::RestFull::Core::ModuleAvailability).to receive(:module_enabled?)
|
|
59
|
+
.with(organization, :proposals).and_return(false)
|
|
60
|
+
expect { handle("decidim.events.proposals.proposal_published", proposal) }
|
|
61
|
+
.not_to have_enqueued_job(Decidim::RestFull::Proposals::ProposalWebhookJob)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Decidim::RestFull::Core::WebhookEventCatalog do
|
|
6
|
+
describe ".example_payload_for" do
|
|
7
|
+
let(:organization) { create(:organization, available_locales: ["en"]) }
|
|
8
|
+
let(:participatory_process) { create(:participatory_process, :with_steps, organization:) }
|
|
9
|
+
let(:component) { create(:proposal_component, participatory_space: participatory_process) }
|
|
10
|
+
let!(:proposal) { create(:proposal, :published, component:) }
|
|
11
|
+
|
|
12
|
+
it "serializes a real proposal via ProposalWebhookSerializer" do
|
|
13
|
+
payload = described_class.example_payload_for("proposal_creation.succeeded", organization:)
|
|
14
|
+
|
|
15
|
+
expect(payload["type"]).to eq("proposal_creation.succeeded")
|
|
16
|
+
expect(payload["data"]["type"]).to eq("proposal")
|
|
17
|
+
expect(payload["data"]["id"]).to eq(proposal.id.to_s)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "raises for unknown events" do
|
|
21
|
+
expect do
|
|
22
|
+
described_class.example_payload_for("does.not.exist", organization:)
|
|
23
|
+
end.to raise_error(KeyError)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "raises when no sample resource exists" do
|
|
27
|
+
empty_org = create(:organization, available_locales: ["en"])
|
|
28
|
+
|
|
29
|
+
expect do
|
|
30
|
+
described_class.example_payload_for("proposal_creation.succeeded", organization: empty_org)
|
|
31
|
+
end.to raise_error(ActiveRecord::RecordNotFound)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|