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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e3e6299fd7301d95f23bd037f513cd022c35cfeaf20d68b5a4606713670b9754
|
|
4
|
+
data.tar.gz: b0ff1f73f40d6be978e1d7aab95aae28c09d573f3d94f9501414d132fa8834d9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6c06066d32d4fda3fa70a3f02c55de253739f1984d7f5bcc47067a67cd21bcbf64d35ab9f1846e16bb5d24bb5fcc6d58ff9fe6492b60d150c6150b742cfe4ecd
|
|
7
|
+
data.tar.gz: 93ae3cfdd29e1c9e04142044239f33da156d6e64efd31e84e1e6b89870de3cc575491189e15efaf569d6885b0263a1c4edd9c7f8c23cdef1cab2ce52c71f5b33
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
# Creates an ApiClient.
|
|
7
|
+
class CreateApiClient < Decidim::Command
|
|
8
|
+
# Initializes the command.
|
|
9
|
+
#
|
|
10
|
+
# form - The source fo data for this ApiClient.
|
|
11
|
+
def initialize(form)
|
|
12
|
+
@form = form
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
return broadcast(:invalid) unless @form.valid?
|
|
17
|
+
|
|
18
|
+
api_client = Decidim.traceability.create!(
|
|
19
|
+
Decidim::RestFull::Core::ApiClient,
|
|
20
|
+
@form.current_user,
|
|
21
|
+
**api_client_attributes
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
broadcast(:ok, api_client)
|
|
25
|
+
rescue ActiveRecord::RecordInvalid
|
|
26
|
+
broadcast(:invalid)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def api_client_attributes
|
|
30
|
+
{
|
|
31
|
+
organization: @form.current_organization,
|
|
32
|
+
name: @form.name,
|
|
33
|
+
decidim_organization_id: @form.decidim_organization_id,
|
|
34
|
+
scopes: @form.scopes.push("public").uniq
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
class ImpersonateResourceOwnerFromCredentials < Decidim::Command
|
|
7
|
+
attr_reader :api_client, :params, :current_organization
|
|
8
|
+
|
|
9
|
+
def initialize(api_client, params, current_organization)
|
|
10
|
+
@api_client = api_client
|
|
11
|
+
@params = params
|
|
12
|
+
@current_organization = current_organization
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
ability.authorize! :impersonate, Decidim::RestFull::Core::ApiClient
|
|
17
|
+
validate_params!
|
|
18
|
+
user = user_from_params
|
|
19
|
+
if user
|
|
20
|
+
# Update meta data
|
|
21
|
+
user.update!(
|
|
22
|
+
{
|
|
23
|
+
extended_data: (user.extended_data || {}).merge(
|
|
24
|
+
extra
|
|
25
|
+
)
|
|
26
|
+
}.merge(locale_attributes)
|
|
27
|
+
)
|
|
28
|
+
else
|
|
29
|
+
# Create user
|
|
30
|
+
user = create_user_from_params!
|
|
31
|
+
end
|
|
32
|
+
broadcast(:ok, user)
|
|
33
|
+
rescue StandardError => e
|
|
34
|
+
broadcast(:error, e.message)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def validate_params!
|
|
40
|
+
has_id = params.has_key? :id
|
|
41
|
+
has_username = params.has_key? :username
|
|
42
|
+
wants_register = meta["register_on_missing"]
|
|
43
|
+
user_exists = user_from_params
|
|
44
|
+
|
|
45
|
+
return true if user_exists
|
|
46
|
+
|
|
47
|
+
# It does not exists, and do not want to register.
|
|
48
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "User not found. To create one, user meta.register_on_missing" unless wants_register
|
|
49
|
+
|
|
50
|
+
# It does not exists, want to register, but has no username
|
|
51
|
+
raise StandardError, "Param .username required. Check your impersonation payload" unless has_username
|
|
52
|
+
# It does not exists, want to register, but already gave an id
|
|
53
|
+
raise StandardError, "Param .id forbidden. Check your impersonation payload" if has_id
|
|
54
|
+
|
|
55
|
+
true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def create_user_from_params!
|
|
59
|
+
email = meta.delete("email") || "#{username}@example.org"
|
|
60
|
+
name = meta.delete("name") || username.titleize
|
|
61
|
+
|
|
62
|
+
user = current_organization.users.build(
|
|
63
|
+
email:,
|
|
64
|
+
name:,
|
|
65
|
+
nickname: username,
|
|
66
|
+
extended_data: extra
|
|
67
|
+
)
|
|
68
|
+
user.accepted_tos_version = if meta["accept_tos_on_register"]
|
|
69
|
+
current_organization.tos_version + 1.hour
|
|
70
|
+
else
|
|
71
|
+
# Will need to revalidate tos
|
|
72
|
+
current_organization.tos_version - 1.hour
|
|
73
|
+
end
|
|
74
|
+
user.tos_agreement = true
|
|
75
|
+
user.assign_attributes(locale_attributes)
|
|
76
|
+
|
|
77
|
+
password = begin
|
|
78
|
+
special_chars = ["@", "#", "$", "%", "^", "&", "*", "-", "_", "+", "=", "~"]
|
|
79
|
+
part1 = ::Devise.friendly_token.first((20 + 1) / 2)
|
|
80
|
+
special_part = special_chars.sample(2).join
|
|
81
|
+
part2 = ::Devise.friendly_token.first((20 + 1) / 2)
|
|
82
|
+
|
|
83
|
+
# Combine parts to form the final password
|
|
84
|
+
password = part1 + special_part + part2
|
|
85
|
+
password.chars.shuffle.join
|
|
86
|
+
end
|
|
87
|
+
user.password = user.password_confirmation = password
|
|
88
|
+
user.skip_confirmation! if meta["skip_confirmation_on_register"]
|
|
89
|
+
|
|
90
|
+
raise StandardError, user.errors.full_messages unless user.valid?
|
|
91
|
+
|
|
92
|
+
user.save!
|
|
93
|
+
user
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def user_from_params
|
|
97
|
+
@user_from_params ||= if params.has_key? "id"
|
|
98
|
+
Decidim::User.find_by(
|
|
99
|
+
id: params[:id],
|
|
100
|
+
organization: current_organization
|
|
101
|
+
)
|
|
102
|
+
else
|
|
103
|
+
Decidim::User.find_by(
|
|
104
|
+
nickname: username,
|
|
105
|
+
organization: current_organization
|
|
106
|
+
)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def extra
|
|
111
|
+
@extra ||= params[:extra] || {}
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def locale_attributes
|
|
115
|
+
code = meta["locale"].to_s.strip
|
|
116
|
+
return {} if code.blank?
|
|
117
|
+
|
|
118
|
+
allowed = current_organization.available_locales.map(&:to_s)
|
|
119
|
+
raise StandardError, "Locale #{code} is not available" unless allowed.include?(code)
|
|
120
|
+
|
|
121
|
+
{ locale: code }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def default_meta
|
|
125
|
+
{
|
|
126
|
+
"register_on_missing" => false,
|
|
127
|
+
"accept_tos_on_register" => false,
|
|
128
|
+
"skip_confirmation_on_register" => false
|
|
129
|
+
}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def meta
|
|
133
|
+
@meta ||= begin
|
|
134
|
+
user_meta = (params[:meta] || {}).to_h.stringify_keys
|
|
135
|
+
default_meta.merge(user_meta)
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def username
|
|
140
|
+
raise StandardError, "Username params required" unless params[:username]
|
|
141
|
+
|
|
142
|
+
@username ||= params[:username]
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def ability
|
|
146
|
+
@ability ||= Decidim::RestFull::Core::Ability.new(api_client)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
class SyncronizeUnconfirmedHost < Decidim::Command
|
|
7
|
+
attr_accessor :unconfirmed_host, :organization
|
|
8
|
+
|
|
9
|
+
def initialize(organization)
|
|
10
|
+
@organization = organization
|
|
11
|
+
@unconfirmed_host = organization.extended_data.data["unconfirmed_host"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# Do a reverse dns lookup over unconfirmed_host and check if it is linked to all of the loadbalancer_ips.
|
|
16
|
+
def call
|
|
17
|
+
return if unconfirmed_host.blank?
|
|
18
|
+
raise Decidim::RestFull::Core::ApiException::BadRequest, "The unconfirmed host cannot be the same as the current host." if organization.host == unconfirmed_host
|
|
19
|
+
|
|
20
|
+
ips = Decidim::RestFull.config.loadbalancer_ips.map { |ip| IPAddr.new(ip) }
|
|
21
|
+
return update_host! if ips.empty?
|
|
22
|
+
|
|
23
|
+
# DNS lookup for unconfirmed_host
|
|
24
|
+
dns_lookup = Resolv.getaddresses(unconfirmed_host)
|
|
25
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Unconfirmed host #{unconfirmed_host} does not resolve." if dns_lookup.empty?
|
|
26
|
+
# For each ip, check if the reverse dns lookup is the unconfirmed_host
|
|
27
|
+
if ips.any? { |ip| dns_lookup.exclude?(ip.to_s) }
|
|
28
|
+
raise Decidim::RestFull::Core::ApiException::NotFound, "Unconfirmed host #{unconfirmed_host} does not resolve to all of the loadbalancer ips."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# If all is good, update the host
|
|
32
|
+
update_host!
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def update_host!
|
|
38
|
+
organization.update!(host: unconfirmed_host)
|
|
39
|
+
organization.extended_data.data["unconfirmed_host"] = nil
|
|
40
|
+
organization.extended_data.save!
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# Enqueues ApiJob with minimal queue args (job uuid only).
|
|
7
|
+
module AsyncApiJobEnqueuing
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
include JobResponseLinking
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def enqueue_rest_full_api_job!(command_key)
|
|
15
|
+
token = doorkeeper_token
|
|
16
|
+
raise Decidim::RestFull::Core::ApiException::Unauthorized, "The access token is invalid" unless token&.accessible?
|
|
17
|
+
|
|
18
|
+
job = Decidim::RestFull::ApiJob.compat_create!(
|
|
19
|
+
decidim_organization_id: current_organization.id,
|
|
20
|
+
doorkeeper_access_token_id: token.id,
|
|
21
|
+
oauth_application_id: token.application_id,
|
|
22
|
+
resource_owner_id: token.resource_owner_id,
|
|
23
|
+
command_key:,
|
|
24
|
+
status: "pending",
|
|
25
|
+
payload: rest_full_api_job_payload
|
|
26
|
+
)
|
|
27
|
+
Decidim::RestFull::ExecuteApiJobJob.perform_later(job.id)
|
|
28
|
+
|
|
29
|
+
render json: {
|
|
30
|
+
job_id: job.id,
|
|
31
|
+
status: job.status,
|
|
32
|
+
data: nil,
|
|
33
|
+
return_value: nil,
|
|
34
|
+
poll_url: rest_full_job_poll_url(job.id),
|
|
35
|
+
links: rest_full_job_links(job.id)
|
|
36
|
+
}, status: :accepted
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def rest_full_api_job_payload
|
|
40
|
+
path = request.path_parameters.stringify_keys.except("controller", "action", "format")
|
|
41
|
+
extras = params.permit(
|
|
42
|
+
:id, :proposal_id, :object_path, :space_manifest, :space_id, :component_id,
|
|
43
|
+
:manifest_name, :organization_id, :resource_type, :resource_id
|
|
44
|
+
).to_h.stringify_keys
|
|
45
|
+
data_params = if params.has_key?(:data)
|
|
46
|
+
params[:data].respond_to?(:permit!) ? params[:data].permit!.to_h : params[:data].to_unsafe_h
|
|
47
|
+
else
|
|
48
|
+
{}
|
|
49
|
+
end
|
|
50
|
+
filter_params = if params[:filter].present?
|
|
51
|
+
fp = params[:filter]
|
|
52
|
+
fp.respond_to?(:permit!) ? fp.permit!.to_h : fp.to_unsafe_h
|
|
53
|
+
else
|
|
54
|
+
{}
|
|
55
|
+
end
|
|
56
|
+
{
|
|
57
|
+
"path" => path.merge(extras),
|
|
58
|
+
"data" => data_params,
|
|
59
|
+
"filter" => filter_params
|
|
60
|
+
}.compact
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def api_execution_context
|
|
64
|
+
@api_execution_context ||= Decidim::RestFull::ApiExecutionContext.from_controller(self)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# Offset pagination for collection/index responses (limit+1, no COUNT).
|
|
7
|
+
# Returns [records, meta] with page, per_page, has_more, next, prev.
|
|
8
|
+
#
|
|
9
|
+
# When sorting with +rand+ / +RANDOM()+, page offsets are not stable across
|
|
10
|
+
# requests, so +has_more+ is always +true+ (clients should stop when a page
|
|
11
|
+
# returns fewer than +per_page+ rows if they need a finite walk).
|
|
12
|
+
module CollectionPagination
|
|
13
|
+
extend ActiveSupport::Concern
|
|
14
|
+
|
|
15
|
+
DEFAULT_PER_PAGE = 20
|
|
16
|
+
MAX_PER_PAGE = 100
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
# @param scope [ActiveRecord::Relation, Enumerable]
|
|
21
|
+
# @return [Array(Array, Hash)] records and pagination meta
|
|
22
|
+
def paginate_collection(scope)
|
|
23
|
+
page = normalize_collection_page(params[:page])
|
|
24
|
+
per = normalize_collection_per_page(params[:per_page])
|
|
25
|
+
fetch_limit = per + 1
|
|
26
|
+
offset = (page - 1) * per
|
|
27
|
+
|
|
28
|
+
rows = if scope.is_a?(ActiveRecord::Relation)
|
|
29
|
+
scope.offset(offset).limit(fetch_limit).to_a
|
|
30
|
+
else
|
|
31
|
+
Array(scope).slice(offset, fetch_limit) || []
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
overflow = rows.size > per
|
|
35
|
+
records = overflow ? rows.first(per) : rows
|
|
36
|
+
# RANDOM() order is not stable across pages — never claim a last page.
|
|
37
|
+
has_more = random_collection_order? || overflow
|
|
38
|
+
|
|
39
|
+
meta = {
|
|
40
|
+
page:,
|
|
41
|
+
per_page: per,
|
|
42
|
+
has_more:,
|
|
43
|
+
next: has_more ? collection_page_url(page + 1, per) : nil,
|
|
44
|
+
prev: page > 1 ? collection_page_url(page - 1, per) : nil
|
|
45
|
+
}
|
|
46
|
+
[records, meta]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def random_collection_order?
|
|
50
|
+
explicit = params[:order].presence
|
|
51
|
+
explicit = default_order_column if explicit.blank? && respond_to?(:default_order_column, true)
|
|
52
|
+
explicit.to_s == "rand"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def normalize_collection_page(raw)
|
|
56
|
+
value = Integer(raw, exception: false)
|
|
57
|
+
return 1 if value.nil? || value < 1
|
|
58
|
+
|
|
59
|
+
value
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def normalize_collection_per_page(raw)
|
|
63
|
+
value = Integer(raw, exception: false)
|
|
64
|
+
return DEFAULT_PER_PAGE if value.nil? || value < 1
|
|
65
|
+
|
|
66
|
+
[value, MAX_PER_PAGE].min
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def collection_page_url(page, per_page)
|
|
70
|
+
query = request.query_parameters.merge("page" => page, "per_page" => per_page)
|
|
71
|
+
query_string = query.to_query
|
|
72
|
+
base = "#{request.base_url}#{request.path}"
|
|
73
|
+
query_string.present? ? "#{base}?#{query_string}" : base
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# MIN/MAX/COUNT for collection navigation meta without loading all primary keys.
|
|
7
|
+
module CollectionPaginationMeta
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def collection_pagination_bounds(relation_scope)
|
|
13
|
+
table_name = model_class.table_name
|
|
14
|
+
base = relation_scope.except(:select, :order, :limit, :offset, :reorder)
|
|
15
|
+
row = base.pick(
|
|
16
|
+
Arel.sql("MIN(#{table_name}.id)"),
|
|
17
|
+
Arel.sql("MAX(#{table_name}.id)"),
|
|
18
|
+
Arel.sql("COUNT(#{table_name}.id)")
|
|
19
|
+
)
|
|
20
|
+
{ first: row&.first, last: row&.second, count: row&.third.to_i }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# Shared conditional GET (ETag / Last-Modified) before +render json:+.
|
|
7
|
+
# Subclasses override +conditional_get_fingerprint+ or pass +fingerprint:+ explicitly.
|
|
8
|
+
module ConditionalGetRendering
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
# @param payload [Hash] JSON body for +render json:+
|
|
14
|
+
# @param fingerprint [Object, nil] object responding to +etag+ and +last_modified+
|
|
15
|
+
# @param status [Symbol] HTTP status when rendering body (default +:ok+)
|
|
16
|
+
# @param [Hash{Symbol => Object}] render_opts
|
|
17
|
+
def render_json_with_conditional_get(payload, fingerprint: conditional_get_fingerprint, status: :ok, **render_opts)
|
|
18
|
+
if fingerprint && !stale?(
|
|
19
|
+
etag: fingerprint.etag,
|
|
20
|
+
last_modified: fingerprint.last_modified,
|
|
21
|
+
public: false,
|
|
22
|
+
template: false
|
|
23
|
+
)
|
|
24
|
+
return
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
render json: payload, status:, **render_opts
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Optional hook for +show+ (and similar) actions. Return +nil+ to skip validators.
|
|
31
|
+
def conditional_get_fingerprint
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def collection_fingerprint_for(relation, extra: nil)
|
|
36
|
+
Decidim::RestFull::Core::HttpCache::CollectionFingerprint.for_request(
|
|
37
|
+
self,
|
|
38
|
+
relation:,
|
|
39
|
+
extra:
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def resource_fingerprint_for(record)
|
|
44
|
+
Decidim::RestFull::Core::HttpCache::ResourceShowFingerprint.for_request(self, record)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# Shared GET/PUT(/sync) behaviour for resources that include HasExtendedData.
|
|
7
|
+
module ExtendedDataEndpoints
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
included do
|
|
11
|
+
include Decidim::Api::RestFull::AsyncApiJobEnqueuing
|
|
12
|
+
|
|
13
|
+
before_action :ensure_resource_extended_data
|
|
14
|
+
|
|
15
|
+
before_action only: [:index] do
|
|
16
|
+
authorize! :read_extended_data, extended_data_subject_class
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
before_action only: [:update, :update_sync] do
|
|
20
|
+
authorize! :update_extended_data, extended_data_subject_class
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def index
|
|
25
|
+
payload = { data: extended_data_at_path }
|
|
26
|
+
render_json_with_conditional_get(
|
|
27
|
+
payload,
|
|
28
|
+
fingerprint: resource_fingerprint_for(extended_data_resource)
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update
|
|
33
|
+
enqueue_rest_full_api_job!(extended_data_job_name)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def update_sync
|
|
37
|
+
render json: (Decidim::RestFull::SyncRunner.call do
|
|
38
|
+
Decidim::RestFull::Core::ApiSystemOperations.new(
|
|
39
|
+
api_execution_context,
|
|
40
|
+
extended_data_operation_params
|
|
41
|
+
).resource_extended_data_update!
|
|
42
|
+
end)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def ensure_resource_extended_data
|
|
48
|
+
return if extended_data_resource.extended_data
|
|
49
|
+
|
|
50
|
+
extended_data_resource.create_extended_data!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def extended_data_at_path
|
|
54
|
+
Decidim::RestFull::Core::ExtendedDataAtPath.fetch(extended_data_hash, object_path)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def object_path
|
|
58
|
+
@object_path ||= params.require(:object_path)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def extended_data_hash
|
|
62
|
+
extended_data_resource.extended_data_hash
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def extended_data_job_name
|
|
66
|
+
"resource_extended_data#update"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def extended_data_operation_params
|
|
70
|
+
params.merge(
|
|
71
|
+
resource_type: extended_data_resource.class.name,
|
|
72
|
+
resource_id: extended_data_resource.id
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def rest_full_api_job_payload
|
|
77
|
+
base = super
|
|
78
|
+
base["path"] = (base["path"] || {}).merge(
|
|
79
|
+
"resource_type" => extended_data_resource.class.name,
|
|
80
|
+
"resource_id" => extended_data_resource.id.to_s
|
|
81
|
+
)
|
|
82
|
+
base
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Override in each controller.
|
|
86
|
+
def extended_data_resource
|
|
87
|
+
raise NotImplementedError
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def extended_data_subject_class
|
|
91
|
+
extended_data_resource.class
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
# Absolute URLs and +links+ for async API jobs (hypermedia controls, RMM level 3).
|
|
7
|
+
module JobResponseLinking
|
|
8
|
+
extend ActiveSupport::Concern
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def rest_full_job_poll_url(job_id)
|
|
13
|
+
v = Decidim::RestFull.major_minor_version
|
|
14
|
+
"#{request.protocol}#{current_organization.host}/api/rest_full/v#{v}/jobs/#{job_id}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def rest_full_job_links(job_id)
|
|
18
|
+
href = rest_full_job_poll_url(job_id)
|
|
19
|
+
{
|
|
20
|
+
self: {
|
|
21
|
+
href:,
|
|
22
|
+
title: "API job status",
|
|
23
|
+
rel: "resource",
|
|
24
|
+
meta: { action_method: "GET" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|