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,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
class MagicToken < ::ApplicationRecord
|
|
7
|
+
self.table_name = "decidim_rest_full_user_magic_tokens"
|
|
8
|
+
belongs_to :user, class_name: "Decidim::User"
|
|
9
|
+
|
|
10
|
+
validates :magic_token, presence: true, uniqueness: true
|
|
11
|
+
validates :expires_at, presence: true
|
|
12
|
+
|
|
13
|
+
before_validation :set_magic_token, if: -> { magic_token.blank? }
|
|
14
|
+
before_validation :set_expiration, if: -> { expires_at.blank? }
|
|
15
|
+
|
|
16
|
+
# Checks if the token is valid (not expired)
|
|
17
|
+
def valid_token?
|
|
18
|
+
expires_at > Time.current
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Alias mark_as_used to destroy
|
|
22
|
+
alias mark_as_used destroy
|
|
23
|
+
|
|
24
|
+
# Deletes expired tokens. Returns the number of deleted records.
|
|
25
|
+
def self.clean_expired!
|
|
26
|
+
where(expires_at: ...Time.current).delete_all
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def set_magic_token
|
|
32
|
+
loop do
|
|
33
|
+
self.magic_token = ::Base64.urlsafe_encode64(::Devise.friendly_token(20))
|
|
34
|
+
break unless self.class.exists?(magic_token:)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Sets the expiration time for the token to 5minutes
|
|
39
|
+
def set_expiration
|
|
40
|
+
self.expires_at = 5.minutes.from_now
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
class Permission < ::ApplicationRecord
|
|
7
|
+
self.table_name = "decidim_rest_full_api_client_permissions"
|
|
8
|
+
scope :events, -> { where(is_event: true) }
|
|
9
|
+
belongs_to :api_client, class_name: "Decidim::RestFull::Core::ApiClient"
|
|
10
|
+
|
|
11
|
+
validates :permission, presence: true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
# Satellite row for client metadata on any resource that includes HasExtendedData
|
|
7
|
+
# (same idea as Decidim::Forms::Questionnaire / Decidim::ResourcePermission).
|
|
8
|
+
class ResourceExtendedData < ::ApplicationRecord
|
|
9
|
+
self.table_name = "resource_extended_data"
|
|
10
|
+
|
|
11
|
+
# Bump parent updated_at so ResourceShowFingerprint / collection ETags invalidate.
|
|
12
|
+
belongs_to :resource, polymorphic: true, touch: true
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module RestFull
|
|
5
|
+
module Core
|
|
6
|
+
class WebhookRegistration < ApplicationRecord
|
|
7
|
+
self.table_name = "webhooks_tables"
|
|
8
|
+
belongs_to :api_client, class_name: "Decidim::RestFull::Core::ApiClient"
|
|
9
|
+
|
|
10
|
+
validates :url, presence: true
|
|
11
|
+
validates :subscriptions, presence: true
|
|
12
|
+
|
|
13
|
+
before_validation :generate_private_key
|
|
14
|
+
|
|
15
|
+
def send_webhook(event, timestamp)
|
|
16
|
+
# Serializer hash is JSON:API-shaped ({ "data" => resource }); unwrap for the envelope.
|
|
17
|
+
json_payload = {
|
|
18
|
+
type: event["type"],
|
|
19
|
+
data: event["data"]["data"]
|
|
20
|
+
}.to_json
|
|
21
|
+
signature = "v1=#{sign_payload(json_payload, timestamp)}"
|
|
22
|
+
|
|
23
|
+
headers = {
|
|
24
|
+
"Content-Type" => "application/json",
|
|
25
|
+
"X-Webhook-Signature" => signature,
|
|
26
|
+
"X-Webhook-Timestamp" => timestamp
|
|
27
|
+
}
|
|
28
|
+
uri = URI(url)
|
|
29
|
+
request = Net::HTTP::Post.new(uri, headers)
|
|
30
|
+
request.body = json_payload
|
|
31
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
32
|
+
http.request(request)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Raise an error if Status code is not >200 <300
|
|
36
|
+
# This will trigger a retry in active job mecanisms
|
|
37
|
+
# @see app/jobs/decidim/rest_full/core/webhook_job.rb
|
|
38
|
+
raise ::Decidim::RestFull::WebhookFailedError unless response.code.to_i.between?(200, 300)
|
|
39
|
+
|
|
40
|
+
response.body
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
##
|
|
46
|
+
# Sign the <timestamp>.<json_payload> with the private key
|
|
47
|
+
# This prevent replay attacks
|
|
48
|
+
def sign_payload(json_payload, timestamp)
|
|
49
|
+
data = "#{timestamp}.#{json_payload}"
|
|
50
|
+
OpenSSL::HMAC.hexdigest("SHA256", private_key, data)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def generate_private_key
|
|
54
|
+
return if private_key.present? && private_key.length == 64
|
|
55
|
+
|
|
56
|
+
self.private_key = SecureRandom.hex(32)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Deface::Override.new(
|
|
4
|
+
virtual_path: "decidim/system/organizations/edit",
|
|
5
|
+
name: "system_host_input",
|
|
6
|
+
replace: "erb[loud]:contains('f.text_field :host')",
|
|
7
|
+
text: <<-ERB
|
|
8
|
+
<%
|
|
9
|
+
unconfirmed_host_help_text = if f.object.unconfirmed_host && f.object.unconfirmed_host != f.object.host
|
|
10
|
+
t(
|
|
11
|
+
"unconfirmed_host_pending_warning_html",
|
|
12
|
+
scope: "decidim.rest_full.system.update_organization",
|
|
13
|
+
unconfirmed_host: f.object.unconfirmed_host,
|
|
14
|
+
host: f.object.host,
|
|
15
|
+
a_records: Decidim::RestFull.config.loadbalancer_ips.select { |ip|
|
|
16
|
+
IPAddr.new(ip).ipv4?
|
|
17
|
+
}.map { |ip| "\#{f.object.unconfirmed_host} A \#{ip}" }.join("<br />").html_safe,
|
|
18
|
+
aaa_records: Decidim::RestFull.config.loadbalancer_ips.select { |ip|
|
|
19
|
+
IPAddr.new(ip).ipv6?
|
|
20
|
+
}.map { |ip| "\#{f.object.unconfirmed_host} AAAA \#{ip}" }.join("<br />").html_safe
|
|
21
|
+
)
|
|
22
|
+
else
|
|
23
|
+
t(
|
|
24
|
+
"unconfirmed_host_explaination_html",
|
|
25
|
+
scope: "decidim.rest_full.system.update_organization",
|
|
26
|
+
unconfirmed_host: f.object.unconfirmed_host,
|
|
27
|
+
host: f.object.host,
|
|
28
|
+
a_records: Decidim::RestFull.config.loadbalancer_ips.select { |ip|
|
|
29
|
+
IPAddr.new(ip).ipv4?
|
|
30
|
+
}.map { |ip| "\#{f.object.unconfirmed_host} A \#{ip}" }.join("<br />").html_safe,
|
|
31
|
+
aaa_records: Decidim::RestFull.config.loadbalancer_ips.select { |ip|
|
|
32
|
+
IPAddr.new(ip).ipv6?
|
|
33
|
+
}.map { |ip| "\#{f.object.unconfirmed_host} AAAA \#{ip}" }.join("<br />").html_safe
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
%>
|
|
37
|
+
<%= f.text_field :unconfirmed_host, help_text: unconfirmed_host_help_text, label: t("unconfirmed_host_label", scope: "decidim.rest_full.system.update_organization") %>
|
|
38
|
+
<%= f.hidden_field :host %>
|
|
39
|
+
ERB
|
|
40
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
class ApplicationSerializer
|
|
8
|
+
include ::JSONAPI::Serializer
|
|
9
|
+
|
|
10
|
+
def self.translated_field(translated_value, locales)
|
|
11
|
+
translated_value = JSON.parse(translated_value) if translated_value.is_a?(String)
|
|
12
|
+
filter = locales || Decidim.available_locales.map(&:to_sym)
|
|
13
|
+
(translated_value || {}).select { |key| filter.include?(key.to_sym) }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
class AttachmentSerializer
|
|
8
|
+
include JSONAPI::Serializer
|
|
9
|
+
|
|
10
|
+
set_type :attachment
|
|
11
|
+
|
|
12
|
+
attribute :title do |object|
|
|
13
|
+
Core::AttachmentSerializer.localized_json(object.title)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attribute :description do |object|
|
|
17
|
+
Core::AttachmentSerializer.localized_json(object.description)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
attribute :weight, &:weight
|
|
21
|
+
|
|
22
|
+
attribute :attachment_collection_id, &:attachment_collection_id
|
|
23
|
+
|
|
24
|
+
attribute :file_type do |object|
|
|
25
|
+
if object.link?
|
|
26
|
+
"link"
|
|
27
|
+
elsif object.photo?
|
|
28
|
+
"image"
|
|
29
|
+
else
|
|
30
|
+
"document"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
attribute :content_type, &:content_type
|
|
35
|
+
|
|
36
|
+
attribute :url do |object|
|
|
37
|
+
next object.link if object.link?
|
|
38
|
+
|
|
39
|
+
Decidim::AttachmentPresenter.new(object).attachment_url
|
|
40
|
+
rescue StandardError
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
attribute :thumbnail_url do |object|
|
|
45
|
+
next unless object.photo?
|
|
46
|
+
|
|
47
|
+
Decidim::AttachmentPresenter.new(object).thumbnail_url
|
|
48
|
+
rescue StandardError
|
|
49
|
+
nil
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
attribute :attached_to do |object|
|
|
53
|
+
{
|
|
54
|
+
type: object.attached_to_type,
|
|
55
|
+
id: object.attached_to_id
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
attribute :created_at do |object|
|
|
60
|
+
object.created_at.iso8601
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
attribute :updated_at do |object|
|
|
64
|
+
object.updated_at.iso8601
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.localized_json(hash)
|
|
68
|
+
return hash unless hash.is_a?(Hash)
|
|
69
|
+
|
|
70
|
+
hash.slice(*Decidim.available_locales.map(&:to_s))
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
class ComponentSerializer < ApplicationSerializer
|
|
8
|
+
def self.db_fields
|
|
9
|
+
(attributes_to_serialize.keys || []).reject { |k| [:meta, :type].include? k }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.default_meta(component)
|
|
13
|
+
settings = settings_for(component)
|
|
14
|
+
scopes_enabled = false
|
|
15
|
+
scopes_enabled = settings["scopes_enabled"] if settings.has_key? "scopes_enabled"
|
|
16
|
+
{
|
|
17
|
+
published: component.published_at.present?,
|
|
18
|
+
scopes_enabled:
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.settings_for(comp)
|
|
23
|
+
settings = comp.settings
|
|
24
|
+
if settings.is_a?(String)
|
|
25
|
+
JSON.parse(settings)
|
|
26
|
+
else
|
|
27
|
+
comp.settings.attributes
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
attributes :manifest_name, :participatory_space_type
|
|
32
|
+
|
|
33
|
+
attribute :participatory_space_id do |comp|
|
|
34
|
+
comp.participatory_space_id.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
attribute :extended_data, if: proc { |_comp, params| params[:includes_extended] } do |comp, _params|
|
|
38
|
+
comp.respond_to?(:extended_data_hash) ? comp.extended_data_hash : {}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
attribute :name do |comp, params|
|
|
42
|
+
translated_field(comp.name, params[:locales])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
attribute :global_announcement do |comp, params|
|
|
46
|
+
settings = settings_for(comp)
|
|
47
|
+
announcement = {}
|
|
48
|
+
announcement = settings["announcement"] if settings.has_key? "announcement"
|
|
49
|
+
announcement = settings["global"]["announcement"] if settings.has_key? "global"
|
|
50
|
+
translated_field(announcement, params[:locales])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Format timestamps to ISO 8601
|
|
54
|
+
attribute :created_at do |component|
|
|
55
|
+
component.created_at.iso8601
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
attribute :updated_at do |component|
|
|
59
|
+
component.updated_at.iso8601
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
meta do |component|
|
|
63
|
+
default_meta(component)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
link :self do |object, params|
|
|
67
|
+
space = object.participatory_space_type.constantize.find(object.participatory_space_id)
|
|
68
|
+
{
|
|
69
|
+
href: "https://#{params[:host]}/components/#{object.manifest_name.singularize}_components/#{object.id}",
|
|
70
|
+
title: object.name[I18n.locale.to_s] || "Component Details",
|
|
71
|
+
rel: "resource",
|
|
72
|
+
meta: {
|
|
73
|
+
space_id: space.id.to_s,
|
|
74
|
+
space_manifest: space.manifest.name,
|
|
75
|
+
action_method: "GET"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
link :related do |object, params|
|
|
81
|
+
space = object.participatory_space_type.constantize.find(object.participatory_space_id)
|
|
82
|
+
{
|
|
83
|
+
href: "https://#{params[:host]}/spaces/#{space.manifest.name}/#{space.id}",
|
|
84
|
+
title: space.title[I18n.locale.to_s] || "Space Details",
|
|
85
|
+
rel: "resource",
|
|
86
|
+
meta: {
|
|
87
|
+
space_id: space.id.to_s,
|
|
88
|
+
space_manifest: space.manifest.name,
|
|
89
|
+
action_method: "GET"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
module Helpers
|
|
8
|
+
module ResourceLinksHelper
|
|
9
|
+
def link_infos_from_resource(resource)
|
|
10
|
+
component = resource.component
|
|
11
|
+
space = resource.participatory_space
|
|
12
|
+
{
|
|
13
|
+
component_id: component.id.to_s,
|
|
14
|
+
component_manifest: component.manifest_name,
|
|
15
|
+
space_id: space.id.to_s,
|
|
16
|
+
space_manifest: space.manifest.name,
|
|
17
|
+
resource_id: resource.id.to_s
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def link_for_resource(host, link_infos, resource_id)
|
|
22
|
+
raise "link_for_resource: missing host" unless host
|
|
23
|
+
|
|
24
|
+
"#{link_for_collection(host, link_infos)}/#{resource_id}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def link_for_collection(host, link_infos)
|
|
28
|
+
raise "link_for_collection: missing host" unless host
|
|
29
|
+
|
|
30
|
+
link_join(host, link_infos[:component_manifest])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def link_join(host, *url_parts)
|
|
34
|
+
raise "link_join: missing host" unless host
|
|
35
|
+
|
|
36
|
+
normalized_host = host.to_s.end_with?("/") ? host[0..-1] : host
|
|
37
|
+
portions = url_parts.map do |part|
|
|
38
|
+
part.to_s.split("/").first
|
|
39
|
+
end
|
|
40
|
+
path_prefix = portions.empty? ? "" : "/"
|
|
41
|
+
"https://#{normalized_host}/api/rest_full/v#{Decidim::RestFull.major_minor_version}#{path_prefix}#{portions.join("/")}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "helpers/resource_links_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Api
|
|
7
|
+
module RestFull
|
|
8
|
+
module Core
|
|
9
|
+
class MagicLinkRedirectSerializer < ApplicationSerializer
|
|
10
|
+
extend Helpers::ResourceLinksHelper
|
|
11
|
+
|
|
12
|
+
attribute :label do |_object|
|
|
13
|
+
"You are beeing redirected."
|
|
14
|
+
end
|
|
15
|
+
attribute :redirect_url do |_object, params|
|
|
16
|
+
::Decidim::Core::Engine.routes.url_helpers.root_url(host: params[:host])
|
|
17
|
+
end
|
|
18
|
+
link :magic_link do |_object, params|
|
|
19
|
+
{
|
|
20
|
+
href: link_join(params[:host], "me", "magic_links"),
|
|
21
|
+
title: "Generates a magic link ",
|
|
22
|
+
rel: "resource",
|
|
23
|
+
meta: {
|
|
24
|
+
action_method: "POST",
|
|
25
|
+
action_enctype: "application/x-www-form-urlencoded"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
link :self do |object, params|
|
|
30
|
+
{
|
|
31
|
+
href: link_join(params[:host], "me", "magic_links", object.magic_token),
|
|
32
|
+
title: "Sign in with magic link",
|
|
33
|
+
rel: "resource",
|
|
34
|
+
meta: {
|
|
35
|
+
action_method: "GET"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "helpers/resource_links_helper"
|
|
4
|
+
|
|
5
|
+
module Decidim
|
|
6
|
+
module Api
|
|
7
|
+
module RestFull
|
|
8
|
+
module Core
|
|
9
|
+
class MagicLinkSerializer < ApplicationSerializer
|
|
10
|
+
extend Helpers::ResourceLinksHelper
|
|
11
|
+
|
|
12
|
+
attribute :token, &:magic_token
|
|
13
|
+
attribute :label do |_object|
|
|
14
|
+
"My label"
|
|
15
|
+
end
|
|
16
|
+
attribute :redirect_url do |object|
|
|
17
|
+
object.redirect_url.presence
|
|
18
|
+
end
|
|
19
|
+
link :self do |_object, params|
|
|
20
|
+
{
|
|
21
|
+
href: link_join(params[:host], "me", "magic_links"),
|
|
22
|
+
title: "Generates a magic link",
|
|
23
|
+
rel: "resource",
|
|
24
|
+
meta: {
|
|
25
|
+
action_method: "POST",
|
|
26
|
+
action_enctype: "application/x-www-form-urlencoded"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
link :sign_in do |object, params|
|
|
31
|
+
{
|
|
32
|
+
href: link_join(params[:host], "me", "magic_links", object.magic_token),
|
|
33
|
+
title: "Sign in with magic link",
|
|
34
|
+
rel: "resource",
|
|
35
|
+
meta: {
|
|
36
|
+
action_method: "GET"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
# Serializer for organizations, exposing main configuration fields,
|
|
8
|
+
# translated attributes and optional extended_data for the REST API.
|
|
9
|
+
class OrganizationSerializer < ApplicationSerializer
|
|
10
|
+
def self.db_fields
|
|
11
|
+
(attributes_to_serialize.keys || []).reject { |k| [:meta, :id].include? k }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attributes :host, :secondary_hosts, :default_locale, :available_locales,
|
|
15
|
+
:enable_machine_translations,
|
|
16
|
+
:badges_enabled, :rich_text_editor_in_public_views,
|
|
17
|
+
:comments_max_length, :time_zone, :users_registration_mode,
|
|
18
|
+
:force_users_to_authenticate_before_access_organization,
|
|
19
|
+
:reference_prefix,
|
|
20
|
+
:send_welcome_notification
|
|
21
|
+
|
|
22
|
+
# Removed in Decidim 0.32; keep API keys for contract stability.
|
|
23
|
+
attribute :enable_participatory_space_filters do |_org|
|
|
24
|
+
false
|
|
25
|
+
end
|
|
26
|
+
attribute :user_groups_enabled do |_org|
|
|
27
|
+
false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
attribute :name do |org, params|
|
|
31
|
+
translated_field(org.name, params[:locales])
|
|
32
|
+
end
|
|
33
|
+
attribute :description do |org, params|
|
|
34
|
+
translated_field(org.description, params[:locales])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
attribute :extended_data do |org, params|
|
|
38
|
+
params[:includes_extended] ? org.extended_data_hash : {}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Format timestamps to ISO 8601
|
|
42
|
+
attribute :created_at do |org|
|
|
43
|
+
org.created_at.iso8601
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
attribute :updated_at do |org|
|
|
47
|
+
org.updated_at.iso8601
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
meta do |org, params|
|
|
51
|
+
metas = { locales: params[:locales] }
|
|
52
|
+
unconfirmed = org.extended_data_hash["unconfirmed_host"]
|
|
53
|
+
metas[:unconfirmed_host] = unconfirmed if unconfirmed
|
|
54
|
+
metas
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
class OrganizationWebhookSerializer < WebhookSerializer
|
|
8
|
+
def self.find_example_resource(organization, event_name:) # rubocop:disable Lint/UnusedMethodArgument
|
|
9
|
+
organization
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
protected
|
|
13
|
+
|
|
14
|
+
def resource_serializable_hash
|
|
15
|
+
OrganizationSerializer.new(resource, params: serializer_params(includes_extended: false)).serializable_hash
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Decidim
|
|
4
|
+
module Api
|
|
5
|
+
module RestFull
|
|
6
|
+
module Core
|
|
7
|
+
class PageComponentSerializer < ComponentSerializer
|
|
8
|
+
def self.resources_for(component, _act_as)
|
|
9
|
+
Decidim::Pages::Page.where(decidim_component_id: component.id)
|
|
10
|
+
end
|
|
11
|
+
has_many :resources, meta: (proc do |component, params|
|
|
12
|
+
{ count: resources_for(component, params[:act_as]).count }
|
|
13
|
+
end) do |component, params|
|
|
14
|
+
resources_for(component, params[:act_as]).limit(50)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|