decidim-core 0.26.5 → 0.27.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/cells/decidim/amendable/announcement_cell.rb +4 -9
- data/app/cells/decidim/announcement_cell.rb +1 -1
- data/app/cells/decidim/author_cell.rb +1 -1
- data/app/cells/decidim/card_m_cell.rb +1 -1
- data/app/cells/decidim/content_blocks/cta/show.erb +1 -1
- data/app/cells/decidim/content_blocks/footer_sub_hero/show.erb +1 -1
- data/app/cells/decidim/content_blocks/hero/show.erb +1 -1
- data/app/cells/decidim/content_blocks/highlighted_content_banner/show.erb +4 -4
- data/app/cells/decidim/content_blocks/highlighted_elements_cell.rb +1 -1
- data/app/cells/decidim/content_blocks/how_to_participate/show.erb +1 -1
- data/app/cells/decidim/content_blocks/last_activity/show.erb +1 -1
- data/app/cells/decidim/content_blocks/last_activity_cell.rb +3 -3
- data/app/cells/decidim/content_blocks/stats_cell.rb +4 -5
- data/app/cells/decidim/content_blocks/sub_hero/show.erb +1 -1
- data/app/cells/decidim/data_consent/category.erb +64 -0
- data/app/cells/decidim/data_consent/dialog.erb +29 -0
- data/app/cells/decidim/data_consent/modal.erb +39 -0
- data/app/cells/decidim/data_consent/show.erb +3 -0
- data/app/cells/decidim/data_consent_cell.rb +21 -0
- data/app/cells/decidim/follow_button_cell.rb +5 -7
- data/app/cells/decidim/newsletter_templates/base_cell.rb +0 -8
- data/app/cells/decidim/newsletter_templates/basic_only_text/show.erb +4 -4
- data/app/cells/decidim/newsletter_templates/image_text_cta/show.erb +4 -4
- data/app/cells/decidim/profile_sidebar_cell.rb +1 -1
- data/app/cells/decidim/search_results_cell.rb +1 -1
- data/app/cells/decidim/tos_page/refuse_btn_modal.erb +1 -1
- data/app/cells/decidim/upload_modal/files.erb +52 -0
- data/app/cells/decidim/upload_modal/modal.erb +49 -0
- data/app/cells/decidim/upload_modal/show.erb +3 -0
- data/app/cells/decidim/upload_modal_cell.rb +205 -0
- data/app/cells/decidim/user_conversation/reply.erb +1 -1
- data/app/cells/decidim/user_conversations/add_conversation_users.erb +5 -3
- data/app/cells/decidim/version_cell.rb +2 -13
- data/app/cells/decidim/versions_list_cell.rb +2 -13
- data/app/cells/decidim/versions_list_item_cell.rb +2 -13
- data/app/commands/decidim/accept_group_invitation.rb +1 -1
- data/app/commands/decidim/accept_user_group_join_request.rb +1 -1
- data/app/commands/decidim/amendable/accept.rb +1 -1
- data/app/commands/decidim/amendable/create_draft.rb +1 -1
- data/app/commands/decidim/amendable/destroy_draft.rb +1 -1
- data/app/commands/decidim/amendable/promote.rb +1 -1
- data/app/commands/decidim/amendable/publish_draft.rb +1 -1
- data/app/commands/decidim/amendable/reject.rb +1 -1
- data/app/commands/decidim/amendable/update_draft.rb +1 -1
- data/app/commands/decidim/amendable/withdraw.rb +1 -1
- data/app/commands/decidim/attachment_methods.rb +3 -2
- data/app/commands/decidim/create_editor_image.rb +1 -1
- data/app/commands/decidim/create_follow.rb +1 -1
- data/app/commands/decidim/create_omniauth_registration.rb +2 -3
- data/app/commands/decidim/create_registration.rb +1 -2
- data/app/commands/decidim/create_report.rb +1 -1
- data/app/commands/decidim/create_user_group.rb +2 -2
- data/app/commands/decidim/create_user_report.rb +5 -3
- data/app/commands/decidim/delete_follow.rb +1 -1
- data/app/commands/decidim/demote_membership.rb +1 -1
- data/app/commands/decidim/destroy_account.rb +1 -1
- data/app/commands/decidim/endorse_resource.rb +1 -1
- data/app/commands/decidim/gallery_methods.rb +45 -10
- data/app/commands/decidim/invite_user.rb +1 -3
- data/app/commands/decidim/invite_user_again.rb +1 -1
- data/app/commands/decidim/invite_user_to_group.rb +1 -1
- data/app/commands/decidim/join_user_group.rb +1 -1
- data/app/commands/decidim/leave_user_group.rb +8 -2
- data/app/commands/decidim/messaging/reply_to_conversation.rb +2 -2
- data/app/commands/decidim/messaging/start_conversation.rb +2 -2
- data/app/commands/decidim/multiple_attachments_methods.rb +44 -5
- data/app/commands/decidim/promote_membership.rb +1 -1
- data/app/commands/decidim/reject_group_invitation.rb +1 -1
- data/app/commands/decidim/reject_user_group_join_request.rb +1 -1
- data/app/commands/decidim/remove_user_from_group.rb +1 -1
- data/app/commands/decidim/resend_confirmation_instructions.rb +18 -0
- data/app/commands/decidim/search.rb +10 -9
- data/app/commands/decidim/unendorse_resource.rb +2 -2
- data/app/commands/decidim/unsubscribe_settings.rb +1 -1
- data/app/commands/decidim/update_account.rb +2 -2
- data/app/commands/decidim/update_notifications_settings.rb +3 -2
- data/app/commands/decidim/update_password.rb +31 -0
- data/app/commands/decidim/update_user_group.rb +2 -2
- data/app/commands/decidim/update_user_interests.rb +1 -1
- data/app/commands/decidim/validate_upload.rb +15 -0
- data/app/controllers/concerns/decidim/devise_controllers.rb +0 -1
- data/app/controllers/concerns/decidim/filter_resource.rb +23 -24
- data/app/controllers/concerns/decidim/force_authentication.rb +1 -2
- data/app/controllers/concerns/decidim/http_caching_disabler.rb +1 -1
- data/app/controllers/concerns/decidim/needs_password_change.rb +43 -0
- data/app/controllers/concerns/decidim/needs_tos_accepted.rb +3 -3
- data/app/controllers/concerns/decidim/orderable.rb +1 -1
- data/app/controllers/concerns/decidim/participatory_space_context.rb +2 -2
- data/app/controllers/concerns/decidim/resource_versions_concern.rb +0 -4
- data/app/controllers/decidim/account_controller.rb +45 -0
- data/app/controllers/decidim/application_controller.rb +1 -1
- data/app/controllers/decidim/devise/invitations_controller.rb +4 -9
- data/app/controllers/decidim/devise/passwords_controller.rb +33 -0
- data/app/controllers/decidim/devise/registrations_controller.rb +3 -5
- data/app/controllers/decidim/devise/sessions_controller.rb +2 -0
- data/app/controllers/decidim/{data_portability_controller.rb → download_your_data_controller.rb} +8 -8
- data/app/controllers/decidim/groups_controller.rb +5 -5
- data/app/controllers/decidim/last_activities_controller.rb +7 -9
- data/app/controllers/decidim/links_controller.rb +2 -4
- data/app/controllers/decidim/manifests_controller.rb +11 -0
- data/app/controllers/decidim/newsletters_controller.rb +1 -1
- data/app/controllers/decidim/notifications_subscriptions_controller.rb +16 -0
- data/app/controllers/decidim/offline_controller.rb +7 -0
- data/app/controllers/decidim/profiles_controller.rb +2 -2
- data/app/controllers/decidim/searches_controller.rb +4 -3
- data/app/controllers/decidim/short_links_controller.rb +35 -0
- data/app/controllers/decidim/upload_validations_controller.rb +44 -0
- data/app/controllers/decidim/user_activities_controller.rb +32 -16
- data/app/controllers/decidim/user_interests_controller.rb +0 -2
- data/app/controllers/decidim/user_timeline_controller.rb +6 -8
- data/app/events/decidim/change_nickname_event.rb +21 -0
- data/app/events/decidim/resource_endorsed_event.rb +1 -2
- data/app/forms/decidim/account_form.rb +3 -3
- data/app/forms/decidim/amendable/form.rb +1 -2
- data/app/forms/decidim/form.rb +1 -1
- data/app/forms/decidim/messaging/conversation_form.rb +1 -1
- data/app/forms/decidim/notifications_settings_form.rb +8 -2
- data/app/forms/decidim/password_form.rb +10 -0
- data/app/forms/decidim/registration_form.rb +2 -2
- data/app/forms/decidim/upload_validation_form.rb +54 -0
- data/app/forms/decidim/user_group_form.rb +1 -1
- data/app/forms/decidim/user_interest_scope_form.rb +1 -1
- data/app/forms/decidim/user_interests_form.rb +1 -1
- data/app/forms/translatable_presence_validator.rb +2 -2
- data/app/forms/url_validator.rb +1 -1
- data/app/helpers/decidim/application_helper.rb +2 -2
- data/app/helpers/decidim/attachments_helper.rb +1 -1
- data/app/helpers/decidim/cells_paginate_helper.rb +1 -1
- data/app/helpers/decidim/datalist_select_helper.rb +40 -0
- data/app/helpers/decidim/decidim_form_helper.rb +1 -1
- data/app/helpers/decidim/filters_helper.rb +1 -5
- data/app/helpers/decidim/followable_helper.rb +1 -1
- data/app/helpers/decidim/icon_helper.rb +4 -4
- data/app/helpers/decidim/layout_helper.rb +15 -1
- data/app/helpers/decidim/map_helper.rb +12 -8
- data/app/helpers/decidim/meta_tags_helper.rb +0 -2
- data/app/helpers/decidim/newsletters_helper.rb +0 -1
- data/app/helpers/decidim/notifications_settings_helper.rb +15 -0
- data/app/helpers/decidim/passwords_helper.rb +41 -0
- data/app/helpers/decidim/sanitize_helper.rb +1 -0
- data/app/helpers/decidim/searches_helper.rb +6 -6
- data/app/helpers/decidim/short_link_helper.rb +28 -0
- data/app/helpers/decidim/translations_helper.rb +2 -2
- data/app/jobs/decidim/{data_portability_export_job.rb → download_your_data_export_job.rb} +5 -5
- data/app/jobs/decidim/email_notifications_digest_generator_job.rb +21 -0
- data/app/jobs/decidim/notification_generator_for_recipient_job.rb +5 -3
- data/app/jobs/decidim/reminder_generator_job.rb +12 -0
- data/app/jobs/decidim/resend_confirmation_instructions_job.rb +11 -0
- data/app/jobs/decidim/user_report_job.rb +2 -2
- data/app/mailers/concerns/decidim/multitenant_asset_host.rb +11 -3
- data/app/mailers/decidim/application_mailer.rb +1 -1
- data/app/mailers/decidim/block_user_mailer.rb +8 -7
- data/app/mailers/decidim/export_mailer.rb +2 -2
- data/app/mailers/decidim/newsletter_mailer.rb +5 -12
- data/app/mailers/decidim/newsletters_opt_in_mailer.rb +7 -5
- data/app/mailers/decidim/notification_mailer.rb +0 -1
- data/app/mailers/decidim/notifications_digest_mailer.rb +23 -0
- data/app/mailers/decidim/user_report_mailer.rb +10 -11
- data/app/models/decidim/action_log.rb +95 -11
- data/app/models/decidim/amendment.rb +0 -1
- data/app/models/decidim/area.rb +1 -2
- data/app/models/decidim/area_type.rb +5 -0
- data/app/models/decidim/attachment.rb +6 -0
- data/app/models/decidim/attachment_collection.rb +5 -0
- data/app/models/decidim/category.rb +9 -4
- data/app/models/decidim/coauthorship.rb +0 -2
- data/app/models/decidim/contextual_help_section.rb +5 -1
- data/app/models/decidim/follow.rb +2 -2
- data/app/models/decidim/gamification/badge_score.rb +0 -1
- data/app/models/decidim/identity.rb +2 -2
- data/app/models/decidim/messaging/conversation.rb +4 -4
- data/app/models/decidim/messaging/message.rb +1 -2
- data/app/models/decidim/messaging/participation.rb +0 -2
- data/app/models/decidim/messaging/receipt.rb +0 -2
- data/app/models/decidim/newsletter.rb +0 -28
- data/app/models/decidim/notification.rb +5 -2
- data/app/models/decidim/oauth_application.rb +12 -1
- data/app/models/decidim/organization.rb +7 -7
- data/app/models/decidim/participatory_space_private_user.rb +4 -2
- data/app/models/decidim/permission_action.rb +1 -0
- data/app/models/decidim/reminder.rb +10 -0
- data/app/models/decidim/reminder_delivery.rb +7 -0
- data/app/models/decidim/reminder_record.rb +29 -0
- data/app/models/decidim/report.rb +2 -2
- data/app/models/decidim/scope.rb +3 -4
- data/app/models/decidim/scope_type.rb +5 -0
- data/app/models/decidim/share_token.rb +0 -2
- data/app/models/decidim/short_link.rb +162 -0
- data/app/models/decidim/user.rb +36 -6
- data/app/models/decidim/user_base_entity.rb +1 -4
- data/app/models/decidim/user_block.rb +2 -2
- data/app/models/decidim/user_group.rb +4 -4
- data/app/models/decidim/user_moderation.rb +0 -2
- data/app/models/decidim/user_report.rb +2 -2
- data/app/packs/entrypoints/decidim_core.js +2 -2
- data/app/packs/entrypoints/decidim_sw.js +1 -0
- data/app/packs/images/decidim/gamification/badges/decidim_gamification_badges_invitations.svg +1 -0
- data/app/packs/src/decidim/autocomplete.js +298 -0
- data/app/packs/src/decidim/cookie_consent/consent_manager.js +133 -0
- data/app/packs/src/decidim/cookie_consent/cookie_consent.js +103 -0
- data/app/packs/src/decidim/datalist_select.js +36 -0
- data/app/packs/src/decidim/direct_uploads/upload_field.js +117 -0
- data/app/packs/src/decidim/direct_uploads/upload_modal.js +264 -0
- data/app/packs/src/decidim/direct_uploads/upload_utility.js +49 -0
- data/app/packs/src/decidim/direct_uploads/uploader.js +89 -0
- data/app/packs/src/decidim/editor/linebreak_module.js +8 -0
- data/app/packs/src/decidim/editor.js +2 -9
- data/app/packs/src/decidim/external_domain_warning.js +1 -1
- data/app/packs/src/decidim/external_link.js +14 -3
- data/app/packs/src/decidim/external_link.test.js +64 -0
- data/app/packs/src/decidim/form_filter.component.test.js +5 -148
- data/app/packs/src/decidim/form_filter.js +4 -26
- data/app/packs/src/decidim/geocoding.js +10 -35
- data/app/packs/src/decidim/identity_selector_dialog.js +1 -1
- data/app/packs/src/decidim/impersonation.js +3 -3
- data/app/packs/src/decidim/input_character_counter.js +177 -7
- data/app/packs/src/decidim/input_multiple_mentions.js +87 -187
- data/app/packs/src/decidim/map/icon.js +2 -1
- data/app/packs/src/decidim/map/svg-icon.js +248 -0
- data/app/packs/src/decidim/security/selfxss_warning.js +5 -1
- data/app/packs/src/decidim/session_timeouter.js +15 -15
- data/app/packs/src/decidim/sw/a2hs.js +28 -0
- data/app/packs/src/decidim/sw/index.js +3 -0
- data/app/packs/src/decidim/sw/loader.js +18 -0
- data/app/packs/src/decidim/sw/push-permissions.js +87 -0
- data/app/packs/src/decidim/sw/sw.js +80 -0
- data/app/packs/src/decidim/vizzs/areachart.js +33 -28
- data/app/packs/src/decidim/vizzs/linechart.js +23 -18
- data/app/packs/src/decidim/vizzs/rowchart.js +15 -11
- data/app/packs/stylesheets/decidim/email.scss +66 -7
- data/app/packs/stylesheets/decidim/layouts/_user.scss +8 -0
- data/app/packs/stylesheets/decidim/modules/_autocomplete.scss +99 -0
- data/app/packs/stylesheets/decidim/modules/_cards.scss +0 -2
- data/app/packs/stylesheets/decidim/modules/_comments.scss +0 -2
- data/app/packs/stylesheets/decidim/modules/_cookie-consent.scss +115 -0
- data/app/packs/stylesheets/decidim/modules/_footer.scss +4 -0
- data/app/packs/stylesheets/decidim/modules/_forms.scss +0 -5
- data/app/packs/stylesheets/decidim/modules/_input-multiple-mentions.scss +29 -2
- data/app/packs/stylesheets/decidim/modules/_modules.scss +3 -1
- data/app/packs/stylesheets/decidim/modules/_reveal.scss +15 -0
- data/app/packs/stylesheets/decidim/modules/_upload_modal.scss +143 -0
- data/app/packs/stylesheets/decidim/utils/_fontface.scss +3 -0
- data/app/permissions/decidim/permissions.rb +4 -8
- data/app/presenters/decidim/admin_log/area_type_presenter.rb +34 -0
- data/app/presenters/decidim/admin_log/attachment_collection_presenter.rb +35 -0
- data/app/presenters/decidim/admin_log/attachment_presenter.rb +27 -0
- data/app/presenters/decidim/admin_log/category_presenter.rb +36 -0
- data/app/presenters/decidim/admin_log/component_presenter.rb +35 -3
- data/app/presenters/decidim/admin_log/contextual_help_section_presenter.rb +33 -0
- data/app/presenters/decidim/admin_log/organization_presenter.rb +9 -4
- data/app/presenters/decidim/admin_log/scope_type_presenter.rb +34 -0
- data/app/presenters/decidim/admin_log/user_group_presenter.rb +1 -1
- data/app/presenters/decidim/admin_log/user_moderation_presenter.rb +1 -1
- data/app/presenters/decidim/home_stats_presenter.rb +8 -13
- data/app/presenters/decidim/log/base_presenter.rb +1 -1
- data/app/presenters/decidim/menu_item_presenter.rb +1 -1
- data/app/presenters/decidim/metric_charts_presenter.rb +7 -1
- data/app/presenters/decidim/nil_presenter.rb +3 -1
- data/app/presenters/decidim/notification_to_mailer_presenter.rb +39 -0
- data/app/presenters/decidim/notifications_digest_presenter.rb +42 -0
- data/app/presenters/decidim/official_author_presenter.rb +4 -0
- data/app/presenters/decidim/organization_presenter.rb +22 -0
- data/app/presenters/decidim/push_notification_presenter.rb +24 -0
- data/app/presenters/decidim/stats_presenter.rb +9 -8
- data/app/presenters/decidim/user_presenter.rb +4 -12
- data/app/presenters/decidim/validation_errors_presenter.rb +1 -1
- data/app/queries/decidim/messaging/user_conversations.rb +1 -1
- data/app/queries/decidim/metric_manage.rb +1 -1
- data/app/queries/decidim/own_activities.rb +11 -0
- data/app/queries/decidim/participatory_processes_with_user_role.rb +1 -1
- data/app/{services/decidim/activity_search.rb → queries/decidim/public_activities.rb} +35 -78
- data/app/queries/decidim/public_components.rb +1 -1
- data/app/queries/decidim/similar_emendations.rb +1 -1
- data/app/queries/decidim/stats_users_count.rb +1 -1
- data/app/queries/decidim/user_groups/accepted_memberships.rb +1 -1
- data/app/queries/decidim/user_groups/accepted_user_groups.rb +1 -1
- data/app/queries/decidim/user_groups/accepted_users.rb +1 -1
- data/app/queries/decidim/user_groups/admin_memberships.rb +1 -1
- data/app/queries/decidim/user_groups/invited_memberships.rb +1 -1
- data/app/queries/decidim/user_groups/manageable_user_groups.rb +1 -1
- data/app/queries/decidim/user_groups/member_memberships.rb +1 -1
- data/app/services/decidim/{data_portability_exporter.rb → download_your_data_exporter.rb} +6 -6
- data/app/services/decidim/email_notification_generator.rb +2 -2
- data/app/services/decidim/engine_resolver.rb +66 -0
- data/app/services/decidim/events_manager.rb +1 -1
- data/app/services/decidim/iframe_disabler.rb +31 -0
- data/app/services/decidim/notification_generator_for_recipient.rb +1 -1
- data/app/services/decidim/notifications_digest_sending_decider.rb +18 -0
- data/app/services/decidim/notifications_subscriptions_persistor.rb +37 -0
- data/app/services/decidim/open_data_exporter.rb +1 -1
- data/app/services/decidim/resource_search.rb +17 -164
- data/app/services/decidim/send_push_notification.rb +59 -0
- data/app/services/decidim/traceability.rb +1 -1
- data/app/uploaders/decidim/application_uploader.rb +2 -12
- data/app/uploaders/decidim/cw/attachment_uploader.rb +1 -1
- data/app/uploaders/decidim/cw/{data_portability_uploader.rb → download_your_data_uploader.rb} +3 -3
- data/app/uploaders/decidim/cw/image_uploader.rb +2 -2
- data/app/uploaders/decidim/organization_favicon_uploader.rb +3 -2
- data/app/validators/etiquette_validator.rb +3 -7
- data/app/validators/passthru_validator.rb +29 -21
- data/app/validators/password_validator.rb +25 -4
- data/app/validators/uploader_image_dimensions_validator.rb +1 -1
- data/app/views/decidim/account/_account_notification.js.erb +20 -0
- data/app/views/decidim/account/_password_fields.html.erb +2 -2
- data/app/views/decidim/account/cancel_email_change.js.erb +6 -0
- data/app/views/decidim/account/resend_confirmation_instructions.erb +1 -0
- data/app/views/decidim/account/show.html.erb +19 -6
- data/app/views/decidim/application/{_attachments.html.erb → _attachments.erb} +2 -2
- data/app/views/decidim/application/_collection.html.erb +1 -1
- data/app/views/decidim/application/{_documents.html.erb → _documents.erb} +2 -2
- data/app/views/decidim/devise/confirmations/new.html.erb +1 -1
- data/app/views/decidim/devise/invitations/edit.html.erb +3 -4
- data/app/views/decidim/devise/omniauth_registrations/new.html.erb +3 -3
- data/app/views/decidim/devise/passwords/edit.html.erb +7 -5
- data/app/views/decidim/devise/passwords/new.html.erb +1 -1
- data/app/views/decidim/devise/registrations/edit.html.erb +41 -0
- data/app/views/decidim/devise/registrations/new.html.erb +5 -5
- data/app/views/decidim/devise/sessions/new.html.erb +2 -2
- data/app/views/decidim/{data_portability → download_your_data}/show.html.erb +2 -2
- data/app/views/decidim/export_mailer/download_your_data_export.html.erb +7 -0
- data/app/views/decidim/last_activities/index.html.erb +1 -1
- data/app/views/decidim/manifests/show.json.erb +31 -0
- data/app/views/decidim/messaging/conversations/_add_conversation_users.html.erb +5 -3
- data/app/views/decidim/messaging/conversations/_reply.html.erb +1 -1
- data/app/views/decidim/messaging/conversations/_start.html.erb +1 -3
- data/app/views/decidim/messaging/conversations/create.js.erb +1 -0
- data/app/views/decidim/newsletter_mailer/newsletter.html.erb +3 -3
- data/app/views/decidim/newsletters/show.html.erb +1 -1
- data/app/views/decidim/notification_mailer/event_received.html.erb +1 -1
- data/app/views/decidim/notifications_digest_mailer/_email_content.html.erb +11 -0
- data/app/views/decidim/notifications_digest_mailer/digest_mail.erb +27 -0
- data/app/views/decidim/notifications_settings/show.html.erb +79 -52
- data/app/views/decidim/offline/show.html.erb +9 -0
- data/app/views/decidim/pages/_standalone.html.erb +1 -1
- data/app/views/decidim/reported_mailer/hide.html.erb +1 -1
- data/app/views/decidim/reported_mailer/report.html.erb +1 -1
- data/app/views/decidim/scopes/picker.html.erb +1 -1
- data/app/views/decidim/searches/_filters.html.erb +2 -2
- data/app/views/decidim/shared/participatory_space_filters/_filters.html.erb +3 -3
- data/app/views/decidim/user_interests/show.html.erb +13 -11
- data/app/views/decidim/user_report_mailer/notify.html.erb +10 -3
- data/app/views/devise/mailer/confirmation_instructions.html.erb +3 -1
- data/app/views/layouts/decidim/_application.html.erb +6 -3
- data/app/views/layouts/decidim/_cookie_warning.html.erb +8 -8
- data/app/views/layouts/decidim/_decidim_javascript.html.erb +12 -0
- data/app/views/layouts/decidim/_head.html.erb +4 -2
- data/app/views/layouts/decidim/_js_configuration.html.erb +5 -1
- data/app/views/layouts/decidim/_mailer_logo.html.erb +2 -2
- data/app/views/layouts/decidim/_main_footer.html.erb +1 -0
- data/app/views/layouts/decidim/_offline_banner.html.erb +11 -0
- data/app/views/layouts/decidim/newsletter_base.html.erb +2 -2
- data/app/views/layouts/decidim/widget.html.erb +2 -2
- data/config/assets.rb +1 -0
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +76 -41
- data/config/locales/bg.yml +42 -36
- data/config/locales/ca.yml +222 -55
- data/config/locales/cs.yml +221 -51
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +53 -100
- data/config/locales/el.yml +42 -34
- data/config/locales/en.yml +207 -40
- data/config/locales/eo.yml +4 -6
- data/config/locales/es-MX.yml +212 -45
- data/config/locales/es-PY.yml +212 -45
- data/config/locales/es.yml +222 -55
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +63 -62
- data/config/locales/fi-plain.yml +208 -41
- data/config/locales/fi.yml +209 -42
- data/config/locales/fr-CA.yml +199 -43
- data/config/locales/fr.yml +206 -50
- data/config/locales/ga-IE.yml +10 -8
- data/config/locales/gl.yml +75 -32
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +90 -209
- data/config/locales/id-ID.yml +43 -34
- data/config/locales/is-IS.yml +8 -17
- data/config/locales/it.yml +52 -42
- data/config/locales/ja.yml +213 -58
- data/config/locales/ko.yml +1 -0
- data/config/locales/lb.yml +42 -32
- data/config/locales/lt.yml +1 -1776
- data/config/locales/lv.yml +41 -33
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +54 -36
- data/config/locales/no.yml +53 -38
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +94 -37
- data/config/locales/pt-BR.yml +46 -35
- data/config/locales/pt.yml +43 -33
- data/config/locales/ro-RO.yml +45 -41
- data/config/locales/ru.yml +20 -31
- data/config/locales/si-LK.yml +1 -0
- data/config/locales/sk.yml +44 -35
- data/config/locales/sl.yml +1 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +1 -0
- data/config/locales/sv.yml +95 -36
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +44 -35
- data/config/locales/uk.yml +18 -32
- data/config/locales/val-ES.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +43 -33
- data/config/locales/zh-TW.yml +1 -0
- data/config/routes.rb +19 -22
- data/db/migrate/20180508111710_add_accepted_tos_version_field_to_users.rb +1 -0
- data/db/migrate/20181030090144_destroy_deleted_users_follows.rb +1 -0
- data/db/migrate/20190412131728_fix_user_names.rb +4 -4
- data/db/migrate/20210831181634_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
- data/db/migrate/20210831181635_create_active_storage_variant_records.active_storage.rb +14 -0
- data/db/migrate/20211208155453_create_decidim_reminders.rb +11 -0
- data/db/migrate/20211209121025_create_decidim_reminder_records.rb +11 -0
- data/db/migrate/20211209121040_create_decidim_reminder_deliveries.rb +10 -0
- data/db/migrate/20220118121921_change_required_description_categories.rb +7 -0
- data/db/migrate/20220127113419_add_notification_settings_to_users.rb +7 -0
- data/db/migrate/20220203121137_add_notifications_sending_frequency_to_users.rb +7 -0
- data/db/migrate/20220215172439_add_digest_sent_at_to_users.rb +7 -0
- data/db/migrate/20220323195258_add_index_to_decidim_users_notifications_sending_frequency.rb +7 -0
- data/db/migrate/20220427142214_drop_emails_on_notifications_flag_from_user.rb +15 -0
- data/db/migrate/20220518094535_add_previous_passwords_to_users.rb +20 -0
- data/db/migrate/20220524195530_create_decidim_short_links.rb +23 -0
- data/db/seeds.rb +17 -18
- data/lib/decidim/acts_as_tree.rb +47 -0
- data/lib/decidim/api/input_sorts/component_input_sort.rb +2 -1
- data/lib/decidim/api/interfaces/authorable_interface.rb +6 -5
- data/lib/decidim/api/types/localized_string_type.rb +0 -9
- data/lib/decidim/api/types/translated_field_type.rb +5 -20
- data/lib/decidim/asset_router.rb +80 -0
- data/lib/decidim/attachment_attributes.rb +8 -8
- data/lib/decidim/attribute_object/form.rb +174 -0
- data/lib/decidim/attribute_object/model.rb +148 -0
- data/lib/decidim/attribute_object/nested_validator.rb +22 -0
- data/lib/decidim/attribute_object/type_map.rb +14 -0
- data/lib/decidim/attribute_object/type_resolver.rb +91 -0
- data/lib/decidim/attribute_object.rb +26 -0
- data/lib/decidim/attributes/array.rb +62 -0
- data/lib/decidim/attributes/blob.rb +20 -0
- data/lib/decidim/attributes/clean_string.rb +12 -6
- data/lib/decidim/attributes/hash.rb +36 -0
- data/lib/decidim/attributes/integer.rb +17 -0
- data/lib/decidim/attributes/localized_date.rb +8 -14
- data/lib/decidim/attributes/model.rb +24 -0
- data/lib/decidim/attributes/object.rb +28 -0
- data/lib/decidim/attributes/symbol.rb +23 -0
- data/lib/decidim/attributes/time_with_zone.rb +7 -17
- data/lib/decidim/attributes.rb +29 -0
- data/lib/decidim/authorable.rb +21 -6
- data/lib/decidim/authorization_form_builder.rb +9 -11
- data/lib/decidim/carrier_wave_migrator_service.rb +15 -15
- data/lib/decidim/coauthorable.rb +22 -4
- data/lib/decidim/command.rb +44 -0
- data/lib/decidim/common_passwords.rb +1 -1
- data/lib/decidim/component_manifest.rb +5 -5
- data/lib/decidim/component_validator.rb +2 -2
- data/lib/decidim/content_block_manifest.rb +1 -1
- data/lib/decidim/content_parsers/hashtag_parser.rb +2 -2
- data/lib/decidim/content_parsers/resource_parser.rb +1 -1
- data/lib/decidim/content_parsers/user_group_parser.rb +1 -1
- data/lib/decidim/content_parsers/user_parser.rb +4 -4
- data/lib/decidim/content_renderers/hashtag_renderer.rb +1 -1
- data/lib/decidim/content_renderers/link_renderer.rb +2 -2
- data/lib/decidim/content_renderers/user_group_renderer.rb +1 -1
- data/lib/decidim/content_renderers/user_renderer.rb +1 -1
- data/lib/decidim/controller_helpers.rb +41 -0
- data/lib/decidim/core/engine.rb +35 -19
- data/lib/decidim/core/test/factories.rb +54 -21
- data/lib/decidim/core/test/shared_examples/admin_resource_gallery_examples.rb +16 -4
- data/lib/decidim/core/test/shared_examples/amendable/amendment_form_examples.rb +1 -1
- data/lib/decidim/core/test/shared_examples/authorable_interface_examples.rb +15 -2
- data/lib/decidim/core/test/shared_examples/coauthorable_interface_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/comments_examples.rb +203 -0
- data/lib/decidim/core/test/shared_examples/localised_email.rb +1 -1
- data/lib/decidim/core/test/shared_examples/logo_email.rb +1 -1
- data/lib/decidim/core/test/shared_examples/map_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/preview_component_with_share_token_examples.rb +0 -6
- data/lib/decidim/core/test/shared_examples/resource_search_examples.rb +120 -40
- data/lib/decidim/core/test/shared_examples/resourceable.rb +0 -6
- data/lib/decidim/core/test/shared_examples/searchable_participatory_space_examples.rb +1 -1
- data/lib/decidim/core/test/shared_examples/searchable_resources_shared_context.rb +1 -1
- data/lib/decidim/core/test/shared_examples/system_endorse_resource_examples.rb +3 -3
- data/lib/decidim/core/test/shared_examples/translated_event_examples.rb +2 -2
- data/lib/decidim/core/test/shared_examples/with_endorsable_permissions_examples.rb +1 -1
- data/lib/decidim/core/test.rb +0 -3
- data/lib/decidim/core/version.rb +1 -1
- data/lib/decidim/core.rb +108 -14
- data/lib/decidim/{data_portability.rb → download_your_data.rb} +3 -3
- data/lib/decidim/{data_portability_serializers/data_portability_conversation_serializer.rb → download_your_data_serializers/download_your_data_conversation_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_follow_serializer.rb → download_your_data_serializers/download_your_data_follow_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_identity_serializer.rb → download_your_data_serializers/download_your_data_identity_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_notification_serializer.rb → download_your_data_serializers/download_your_data_notification_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_participatory_space_private_user_serializer.rb → download_your_data_serializers/download_your_data_participatory_space_private_user_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_report_serializer.rb → download_your_data_serializers/download_your_data_report_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_user_group_serializer.rb → download_your_data_serializers/download_your_data_user_group_serializer.rb} +2 -2
- data/lib/decidim/{data_portability_serializers/data_portability_user_serializer.rb → download_your_data_serializers/download_your_data_user_serializer.rb} +3 -3
- data/lib/decidim/download_your_data_serializers.rb +23 -0
- data/lib/decidim/engine_router.rb +7 -1
- data/lib/decidim/env.rb +56 -0
- data/lib/decidim/event_recorder.rb +25 -0
- data/lib/decidim/events/base_event.rb +10 -14
- data/lib/decidim/events/simple_event.rb +6 -5
- data/lib/decidim/exporters/export_data.rb +1 -1
- data/lib/decidim/exporters/export_manifest.rb +2 -1
- data/lib/decidim/file_validator_humanizer.rb +24 -1
- data/lib/decidim/filterable_resource.rb +55 -0
- data/lib/decidim/fingerprint_calculator.rb +2 -4
- data/lib/decidim/form_builder.rb +160 -139
- data/lib/decidim/gamification/badge.rb +2 -3
- data/lib/decidim/gamification/badge_scorer.rb +1 -0
- data/lib/decidim/has_area.rb +27 -0
- data/lib/decidim/has_attachments.rb +2 -2
- data/lib/decidim/has_category.rb +36 -0
- data/lib/decidim/has_resource_permission.rb +2 -0
- data/lib/decidim/importers/import_manifest.rb +3 -21
- data/lib/decidim/jsonb_attributes.rb +6 -4
- data/lib/decidim/manifest_messages.rb +23 -0
- data/lib/decidim/map/autocomplete.rb +6 -4
- data/lib/decidim/map/frontend.rb +2 -2
- data/lib/decidim/map/provider/dynamic_map/here.rb +1 -46
- data/lib/decidim/map/provider/geocoding/here.rb +5 -5
- data/lib/decidim/map/provider/here.rb +3 -0
- data/lib/decidim/map/provider/osm.rb +3 -0
- data/lib/decidim/map.rb +4 -4
- data/lib/decidim/menu.rb +1 -1
- data/lib/decidim/metric_manifest.rb +2 -2
- data/lib/decidim/nicknamizable.rb +1 -1
- data/lib/decidim/notification_setting_manifest.rb +19 -0
- data/lib/decidim/organization_settings.rb +8 -7
- data/lib/decidim/participatory_space_context_manifest.rb +2 -2
- data/lib/decidim/participatory_space_manifest.rb +2 -2
- data/lib/decidim/participatory_space_resourceable.rb +1 -7
- data/lib/decidim/processes_file_locally.rb +31 -0
- data/lib/decidim/query.rb +84 -0
- data/lib/decidim/record_encryptor.rb +29 -8
- data/lib/decidim/reminder_manifest.rb +75 -0
- data/lib/decidim/reminder_registry.rb +67 -0
- data/lib/decidim/resource_manifest.rb +1 -1
- data/lib/decidim/resourceable.rb +15 -5
- data/lib/decidim/scopable.rb +15 -0
- data/lib/decidim/settings_manifest.rb +4 -4
- data/lib/decidim/spring.rb +16 -0
- data/lib/decidim/translatable_attributes.rb +13 -16
- data/lib/decidim/url_option_resolver.rb +50 -0
- data/lib/decidim/view_hooks.rb +1 -1
- data/lib/decidim/view_model.rb +5 -1
- data/lib/decidim/webpacker/thread_safe_compiler.rb +30 -0
- data/lib/decidim/webpacker/webpack/custom.js +15 -3
- data/lib/decidim/webpacker/webpacker.yml +1 -1
- data/lib/decidim/webpacker.rb +2 -0
- data/lib/devise/models/decidim_validatable.rb +1 -1
- data/lib/tasks/decidim_active_storage_migration_tasks.rake +1 -3
- data/lib/tasks/{decidim_data_portability_tasks.rake → decidim_download_your_data_tasks.rake} +9 -9
- data/lib/tasks/decidim_mailers_tasks.rake +23 -0
- data/lib/tasks/decidim_metrics_tasks.rake +1 -1
- data/lib/tasks/decidim_pwa_tasks.rake +18 -0
- data/lib/tasks/decidim_reminders_tasks.rake +17 -0
- data/lib/tasks/decidim_tasks.rake +6 -1
- data/lib/tasks/decidim_webpacker_tasks.rake +1 -1
- data/lib/tasks/upgrade/decidim_fix_nickname_uniqueness.rake +51 -0
- metadata +186 -92
- data/app/controllers/decidim/cookie_policy_controller.rb +0 -24
- data/app/helpers/decidim/cookies_helper.rb +0 -11
- data/app/packs/src/decidim/editor/clipboard_override.js +0 -143
- data/app/packs/src/decidim/editor/clipboard_utilities.js +0 -119
- data/app/packs/src/decidim/vizzs/renders.js +0 -9
- data/app/packs/src/decidim/vizzs.js +0 -1
- data/app/packs/stylesheets/decidim/modules/_cookie-bar.scss +0 -26
- data/app/services/decidim/home_activity_search.rb +0 -80
- data/app/services/decidim/participatory_space_search.rb +0 -54
- data/app/views/decidim/cookie_policy/accept.js.erb +0 -3
- data/app/views/decidim/export_mailer/data_portability_export.html.erb +0 -7
- data/config/locales/gn-PY.yml +0 -1
- data/config/locales/ka-GE.yml +0 -1
- data/config/locales/lo-LA.yml +0 -1
- data/config/locales/oc-FR.yml +0 -1
- data/lib/decidim/core/test/shared_examples/mcell_examples.rb +0 -17
- data/lib/decidim/core/test/shared_examples/resource_endorsed_event_examples.rb +0 -60
- data/lib/decidim/core/test/shared_examples/versions_controller_examples.rb +0 -40
- data/lib/decidim/data_portability_serializers.rb +0 -23
- data/lib/decidim/middleware/rails_cookies.rb +0 -23
- /data/app/packs/src/decidim/vizzs/{metrics.js → index.js} +0 -0
- /data/app/views/decidim/application/{_document.html.erb → _document.erb} +0 -0
- /data/app/views/decidim/application/{_photos.html.erb → _photos.erb} +0 -0
- /data/app/views/decidim/{data_portability → download_your_data}/export.html.erb +0 -0
@@ -3,14 +3,14 @@
|
|
3
3
|
require "active_support/concern"
|
4
4
|
|
5
5
|
module Decidim
|
6
|
-
# A set of convenience methods to deal with attachment attributes for
|
6
|
+
# A set of convenience methods to deal with attachment attributes for
|
7
7
|
# models that may set the attachment records through the original model
|
8
8
|
# (Decidim::Attachment) or through the user submitted form data (String).
|
9
9
|
module AttachmentAttributes
|
10
10
|
extend ActiveSupport::Concern
|
11
11
|
|
12
12
|
class_methods do
|
13
|
-
# Public: Mirrors
|
13
|
+
# Public: Mirrors the `attribute` interface to define attachment
|
14
14
|
# attributes for form objects.
|
15
15
|
#
|
16
16
|
# name - The attribute's name
|
@@ -20,14 +20,14 @@ module Decidim
|
|
20
20
|
#
|
21
21
|
# attachment_attribute :photos
|
22
22
|
# # This will create two attributes of the following types:
|
23
|
-
# # attribute :photos, Array[
|
23
|
+
# # attribute :photos, Array[Integer]
|
24
24
|
# # attribute :add_photos, Array
|
25
25
|
# # In addition, it will generate the getter method for the attribute
|
26
26
|
# # returning an array of the Decidim::Attachment records.
|
27
27
|
#
|
28
28
|
# Returns nothing.
|
29
29
|
def attachments_attribute(name)
|
30
|
-
attribute name, Array[
|
30
|
+
attribute name, Array[Integer]
|
31
31
|
attribute "add_#{name}".to_sym, Array
|
32
32
|
|
33
33
|
# Define the getter method that fetches the attachment records based on
|
@@ -37,13 +37,13 @@ module Decidim
|
|
37
37
|
define_method name do
|
38
38
|
return instance_variable_get(variable_name) if instance_variable_defined?(variable_name)
|
39
39
|
|
40
|
-
original =
|
41
|
-
return original
|
40
|
+
original = @attributes[name.to_s].value_before_type_cast
|
41
|
+
return original if original && !original.is_a?(Array)
|
42
42
|
|
43
43
|
instance_variable_set(
|
44
44
|
variable_name,
|
45
|
-
|
46
|
-
if attachment.is_a?(
|
45
|
+
super().map do |attachment|
|
46
|
+
if attachment.is_a?(Integer)
|
47
47
|
Decidim::Attachment.find_by(id: attachment)
|
48
48
|
else
|
49
49
|
attachment
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module AttributeObject
|
5
|
+
# This is the main Form class that provides the functionality for all core
|
6
|
+
# forms that take in user input from the user interface forms and converts
|
7
|
+
# the inputs to expected formats.
|
8
|
+
#
|
9
|
+
# This replaces the Rectify::Form classes in Decidim which used to provide
|
10
|
+
# similar functionality. The API provided by this class is largely
|
11
|
+
# compatible with `Rectify::Form`.
|
12
|
+
class Form
|
13
|
+
include Decidim::AttributeObject::Model
|
14
|
+
include ActiveModel::Validations
|
15
|
+
|
16
|
+
attr_reader :context
|
17
|
+
|
18
|
+
def self.mimic(model_name)
|
19
|
+
@model_name = model_name.to_s.underscore.to_sym
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.mimicked_model_name
|
23
|
+
@model_name || infer_model_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.infer_model_name
|
27
|
+
return :form unless name
|
28
|
+
|
29
|
+
class_name = name.split("::").last
|
30
|
+
return :form if class_name == "Form"
|
31
|
+
|
32
|
+
class_name.chomp("Form").underscore.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
# Converts the mimicked name to ActiveModel naming.
|
36
|
+
def self.model_name
|
37
|
+
ActiveModel::Name.new(self, nil, mimicked_model_name.to_s)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.from_model(model)
|
41
|
+
form_attributes = attribute_types.keys.each_with_object({}) do |key, attrs|
|
42
|
+
next unless model.respond_to?(key)
|
43
|
+
|
44
|
+
value = model.send(key)
|
45
|
+
attrs[key] =
|
46
|
+
case value
|
47
|
+
when ActiveStorage::Attached::One
|
48
|
+
value.attachment.try(:blob)
|
49
|
+
when ActiveStorage::Attached::Many
|
50
|
+
value.attachments.map(&:blob)
|
51
|
+
else
|
52
|
+
value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
form = new(form_attributes)
|
57
|
+
form.map_model(model)
|
58
|
+
|
59
|
+
form
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.from_params(params, additional_params = {})
|
63
|
+
params_hash = hash_from(params)
|
64
|
+
mimicked_params = ensure_hash(params_hash[mimicked_model_name])
|
65
|
+
|
66
|
+
attributes_hash = params_hash.merge(mimicked_params).merge(additional_params)
|
67
|
+
|
68
|
+
new(attributes_hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.hash_from(params)
|
72
|
+
params = params.to_unsafe_h if params.respond_to?(:to_unsafe_h)
|
73
|
+
params.with_indifferent_access
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.ensure_hash(object)
|
77
|
+
if object.is_a?(Hash)
|
78
|
+
object
|
79
|
+
else
|
80
|
+
{}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def persisted?
|
85
|
+
id.present? && id.to_i.positive?
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_key
|
89
|
+
[id]
|
90
|
+
end
|
91
|
+
|
92
|
+
# Required for the active model naming to work correctly to form the HTML
|
93
|
+
# class attributes for the form elements (e.g. edit_account instead
|
94
|
+
# of edit_account_form).
|
95
|
+
def to_model
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def to_param
|
100
|
+
id.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
# Use the map_model method within the form implementations to map any
|
104
|
+
# custom form-specific attributes from the model to the form.
|
105
|
+
def map_model(_model); end
|
106
|
+
|
107
|
+
def with_context(new_context)
|
108
|
+
@context = if new_context.is_a?(Hash)
|
109
|
+
OpenStruct.new(new_context)
|
110
|
+
else
|
111
|
+
new_context
|
112
|
+
end
|
113
|
+
|
114
|
+
attributes.each do |_name, value|
|
115
|
+
case value
|
116
|
+
when Array
|
117
|
+
value.each do |v|
|
118
|
+
next unless v.respond_to?(:with_context)
|
119
|
+
|
120
|
+
v.with_context(context)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
next unless value.respond_to?(:with_context)
|
124
|
+
|
125
|
+
value.with_context(context)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
# Although we are running the nested attributes validations through the
|
133
|
+
# NestedValidator, we still need to check for the errors in the nested
|
134
|
+
# attributes after the main validations are run in case the main
|
135
|
+
# validations are adding errors to some of the nested attributes.
|
136
|
+
#
|
137
|
+
# An example of such form is the Decidim::Budgets::Admin::ComponentForm
|
138
|
+
# which adds errors to the sub-attribute "settings" during its own
|
139
|
+
# validations. Because these errors are not added to the main form object,
|
140
|
+
# the main form object would be interpreted as valid without checking the
|
141
|
+
# sub-attribute validations.
|
142
|
+
#
|
143
|
+
# This preserves the backwards compatibility with Rectify::Form which
|
144
|
+
# did the validations in this order and fails the main record validation
|
145
|
+
# in case one of the nested attributes is not valid. This is needed e.g.
|
146
|
+
# for the customized component validations (e.g. Budgets component form).
|
147
|
+
def valid?(_context = nil)
|
148
|
+
super && self.class.attribute_types.none? do |name, type|
|
149
|
+
value = public_send(name)
|
150
|
+
|
151
|
+
if value.is_a?(Decidim::AttributeObject::Model) || (type.respond_to?(:validate_nested?) && type.validate_nested?)
|
152
|
+
_value_has_errors?(value)
|
153
|
+
else
|
154
|
+
false
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
def _value_has_errors?(value)
|
162
|
+
if value.is_a?(Array)
|
163
|
+
value.any? { |v| _value_has_errors?(v) }
|
164
|
+
elsif value.is_a?(Hash)
|
165
|
+
_value_has_errors?(value.values)
|
166
|
+
elsif value.respond_to?(:errors)
|
167
|
+
value.errors.any?
|
168
|
+
else
|
169
|
+
false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Make sure the custom attributes are defined
|
4
|
+
require "decidim/attributes"
|
5
|
+
|
6
|
+
module Decidim
|
7
|
+
module AttributeObject
|
8
|
+
# This provides a dummy model implementation for replacing the Virtus models
|
9
|
+
# using ActiveModel. This class is a lightweight version of
|
10
|
+
# `ActiveModel::Model` with the `ActiveModel::Attributes` module and its
|
11
|
+
# overridden methods.
|
12
|
+
#
|
13
|
+
# The main purpose of this class is to provide a backwards compatible API
|
14
|
+
# for defining classes that hold attributes, such as the form classes.
|
15
|
+
#
|
16
|
+
# Usage:
|
17
|
+
# Replace all instances of `Virtus.model` with `Decidim::AttributeObject::Model`.
|
18
|
+
module Model
|
19
|
+
extend ActiveSupport::Concern
|
20
|
+
|
21
|
+
include ActiveModel::AttributeAssignment
|
22
|
+
include ActiveModel::Attributes
|
23
|
+
include Decidim::AttributeObject::TypeMap
|
24
|
+
|
25
|
+
included do
|
26
|
+
extend ActiveModel::Naming
|
27
|
+
extend ActiveModel::Translation
|
28
|
+
|
29
|
+
# Default attributes for all models
|
30
|
+
attribute :id
|
31
|
+
end
|
32
|
+
|
33
|
+
class_methods do
|
34
|
+
def attribute(name, type = ActiveModel::Type::Value.new, **options)
|
35
|
+
typedef = AttributeObject.types.resolve(type, **options)
|
36
|
+
|
37
|
+
super(name, typedef[:type], **typedef[:options])
|
38
|
+
|
39
|
+
# Create the boolean method alias with the question mark at the end
|
40
|
+
# which is used in some places. This was a default behavior of
|
41
|
+
# Virtus but not a feature in ActiveModel::Attributes.
|
42
|
+
alias_method :"#{name}?", name if typedef[:type] == :boolean
|
43
|
+
|
44
|
+
# Add the nested validation in case validations module is loaded and
|
45
|
+
# the type reports it needs nested validations.
|
46
|
+
return unless include?(ActiveModel::Validations)
|
47
|
+
|
48
|
+
# The nested validator should be only added for those attributes that
|
49
|
+
# inherit from the AttributeObject::Model type. Otherwise this would
|
50
|
+
# be also added e.g. for ActiveRecord objects which would cause
|
51
|
+
# unexpected validation errors.
|
52
|
+
finaltype = attribute_types[name.to_s]
|
53
|
+
return unless finaltype.respond_to?(:validate_nested?)
|
54
|
+
return unless finaltype.validate_nested?
|
55
|
+
|
56
|
+
validates_with(
|
57
|
+
Decidim::AttributeObject::NestedValidator,
|
58
|
+
_merge_attributes([name])
|
59
|
+
)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(attributes = {})
|
64
|
+
# Parentheses needed not to pass the arguments.
|
65
|
+
super()
|
66
|
+
|
67
|
+
return unless attributes
|
68
|
+
|
69
|
+
# Make sure the attributes is a hash
|
70
|
+
base_attributes =
|
71
|
+
if attributes.is_a?(Hash)
|
72
|
+
attributes
|
73
|
+
else
|
74
|
+
attributes.to_h
|
75
|
+
end
|
76
|
+
|
77
|
+
# Only pass the existing attribute keys to assign_attributes
|
78
|
+
# The regular expression matching makes sure we also include the "multi"
|
79
|
+
# parameters, such as date fields passed from the view which are
|
80
|
+
# formatted as date(1i), date(2i), date(3i). These are converted to
|
81
|
+
# hashes below which are handled by the ActiveModel::Attributes types,
|
82
|
+
# such as :date.
|
83
|
+
correct_attributes = {}.tap do |attrs|
|
84
|
+
base_attributes.each do |k, v|
|
85
|
+
# Handle "multi" parameter attributes, such as date(1i), date(2i),
|
86
|
+
# date(3i). This converts these three attributes to a single hash
|
87
|
+
# attribute formatted as:
|
88
|
+
# { "date" => { 1 => ..., 2 => ..., 3 => ... } }
|
89
|
+
mp = k.to_s.match(/(.*)\(([0-9]+i)\)$/)
|
90
|
+
if mp
|
91
|
+
next unless attribute_names.include?(mp[1])
|
92
|
+
|
93
|
+
attrs[mp[1]] ||= {}
|
94
|
+
attrs[mp[1]][mp[2].to_i] = v
|
95
|
+
else
|
96
|
+
next unless attribute_names.include?(k.to_s)
|
97
|
+
|
98
|
+
attrs[k] = v
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
assign_attributes(correct_attributes)
|
104
|
+
end
|
105
|
+
|
106
|
+
# This provides backwards compatibility for accessing the attributes
|
107
|
+
# through symbols by calling `obj.attributes[:key]` or
|
108
|
+
# `obj.attributes.slice(:key1, :key2)`. In the legacy Virtus models, this
|
109
|
+
# returned a hash with symbol keys.
|
110
|
+
#
|
111
|
+
# Deprecated:
|
112
|
+
# Attributes access through symbols is deprecated and may be removed in
|
113
|
+
# future versions. Please refactor all your attributes calls to access the
|
114
|
+
# attributes through string keys.
|
115
|
+
def attributes
|
116
|
+
super.with_indifferent_access
|
117
|
+
end
|
118
|
+
|
119
|
+
# Convenience method for accessing the attributes through
|
120
|
+
# model[:attr_name] which is used in multiple places across the code.
|
121
|
+
def [](attribute_name)
|
122
|
+
public_send(attribute_name) if respond_to?(attribute_name)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Convenience method for settings the attributes through
|
126
|
+
# model[:attr_name] = "foo" which is used in some places across the code.
|
127
|
+
def []=(attribute_name, value)
|
128
|
+
public_send("#{attribute_name}=", value) if respond_to?("#{attribute_name}=")
|
129
|
+
end
|
130
|
+
|
131
|
+
# Convenience method used in initiatives
|
132
|
+
def attributes_with_values
|
133
|
+
to_h.compact
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_h
|
137
|
+
hash = attributes.to_h.symbolize_keys
|
138
|
+
hash.delete(:id) if hash.has_key?(:id) && hash[:id].blank?
|
139
|
+
|
140
|
+
hash
|
141
|
+
end
|
142
|
+
|
143
|
+
# The to_hash alias is needed for the as_json call which calls this method
|
144
|
+
# if defined.
|
145
|
+
alias to_hash to_h
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module AttributeObject
|
5
|
+
class NestedValidator < ActiveModel::EachValidator # :nodoc:
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
value = value.values if value.is_a?(Hash)
|
8
|
+
return unless Array(value).reject { |r| valid_object?(r) }.any?
|
9
|
+
|
10
|
+
record.errors.add(attribute, :invalid, **options.merge(value: value))
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def valid_object?(record)
|
16
|
+
return true unless record.respond_to?(:valid?)
|
17
|
+
|
18
|
+
record.valid?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module AttributeObject
|
5
|
+
# Backwards compatibility for legacy types. Provides accessors for the
|
6
|
+
# legacy Virtus type classes that are mapped to ActiveModel types.
|
7
|
+
module TypeMap
|
8
|
+
# rubocop:disable Naming/ConstantName
|
9
|
+
Boolean = :boolean
|
10
|
+
Decimal = :decimal
|
11
|
+
# rubocop:enable Naming/ConstantName
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Make sure the custom attributes are defined
|
4
|
+
require "decidim/attributes"
|
5
|
+
|
6
|
+
module Decidim
|
7
|
+
module AttributeObject
|
8
|
+
# This resolves the ActiveModel::Attributes types from the Decidim's own
|
9
|
+
# type definitions format inspired by Virtus.
|
10
|
+
class TypeResolver
|
11
|
+
def resolve(type, **options)
|
12
|
+
case type
|
13
|
+
when Symbol, ActiveModel::Type::Value
|
14
|
+
{
|
15
|
+
type: type,
|
16
|
+
options: options
|
17
|
+
}
|
18
|
+
when Class
|
19
|
+
resolve_class(type, **options)
|
20
|
+
when Hash
|
21
|
+
resolve_hash(type, **options)
|
22
|
+
when Array
|
23
|
+
resolve_array(type, **options)
|
24
|
+
else
|
25
|
+
resolve_default(type, **options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def exists?(type)
|
30
|
+
# This needs to be changed after upgrade to Rails 7.0 as follows:
|
31
|
+
# ActiveModel::Type.registry.send(:registrations).has_key?(type)
|
32
|
+
ActiveModel::Type.registry.send(:registrations).any? { |t| t.send(:name) == type }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def resolve_class(type, **options)
|
38
|
+
if type.include?(Decidim::AttributeObject::Model) || type <= ActiveRecord::Base
|
39
|
+
{
|
40
|
+
type: :model,
|
41
|
+
options: options.merge(primitive: type)
|
42
|
+
}
|
43
|
+
elsif type == Hash
|
44
|
+
resolve_hash({ Symbol => Object }, **options)
|
45
|
+
elsif type == Array
|
46
|
+
resolve_array(Array[Object], **options)
|
47
|
+
else
|
48
|
+
resolve_default(type, **options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def resolve_hash(type, **options)
|
53
|
+
key_type = type.keys.first || Symbol
|
54
|
+
val_type = type.values.first || Object
|
55
|
+
options[:default] ||= {}
|
56
|
+
|
57
|
+
{
|
58
|
+
type: :hash,
|
59
|
+
options: options.merge(key_type: key_type, value_type: val_type)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def resolve_array(type, **options)
|
64
|
+
options[:default] ||= []
|
65
|
+
|
66
|
+
{
|
67
|
+
type: :array,
|
68
|
+
options: options.merge(value_type: type.first)
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def resolve_default(type, **options)
|
73
|
+
type_symbol = type.to_s.underscore.to_sym
|
74
|
+
|
75
|
+
if exists?(type_symbol)
|
76
|
+
# Off the bat, this handles the basic types from:
|
77
|
+
# https://github.com/rails/rails/tree/main/activemodel/lib/active_model/type
|
78
|
+
{
|
79
|
+
type: type_symbol,
|
80
|
+
options: options
|
81
|
+
}
|
82
|
+
else
|
83
|
+
{
|
84
|
+
type: :object,
|
85
|
+
options: options.merge(primitive: type)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
# This module provides functionality to create objects with attributes that
|
5
|
+
# are not attached to any database objects and have type coercions for the
|
6
|
+
# types of their objects. This is a similar concept as Virtus used to provide
|
7
|
+
# for the core objects, such as Forms and manifest classes. The programming
|
8
|
+
# API is backwards compatible with Virtus on most parts.
|
9
|
+
module AttributeObject
|
10
|
+
autoload :Form, "decidim/attribute_object/form"
|
11
|
+
autoload :Model, "decidim/attribute_object/model"
|
12
|
+
autoload :NestedValidator, "decidim/attribute_object/nested_validator"
|
13
|
+
autoload :TypeMap, "decidim/attribute_object/type_map"
|
14
|
+
autoload :TypeResolver, "decidim/attribute_object/type_resolver"
|
15
|
+
|
16
|
+
def self.types
|
17
|
+
@types ||= TypeResolver.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.type(type, **options)
|
21
|
+
typedef = types.resolve(type, **options)
|
22
|
+
|
23
|
+
ActiveModel::Type.lookup(typedef[:type], **typedef[:options])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Attributes
|
5
|
+
# Custom attributes value to represent an Array.
|
6
|
+
class Array < ActiveModel::Type::Value
|
7
|
+
attr_reader :value_type, :default
|
8
|
+
|
9
|
+
def initialize(value_type: ::Object, default: [])
|
10
|
+
@value_type = value_type
|
11
|
+
@default = default
|
12
|
+
end
|
13
|
+
|
14
|
+
def type # :nodoc:
|
15
|
+
:array
|
16
|
+
end
|
17
|
+
|
18
|
+
# The value would not be cast in case it is nil by default. We also want
|
19
|
+
# to cast the nil values to the default values.
|
20
|
+
def cast(value)
|
21
|
+
cast_value(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
# The nested validator should be only added for those attributes that
|
25
|
+
# inherit from the AttributeObject::Model type. Otherwise this would be
|
26
|
+
# also added e.g. for ActiveRecord objects which would cause unexpected
|
27
|
+
# validation errors.
|
28
|
+
#
|
29
|
+
# The hash type inherits from the array type, so this covers both cases.
|
30
|
+
def validate_nested?
|
31
|
+
return false unless value_type.is_a?(Class)
|
32
|
+
|
33
|
+
(value_type < Decidim::AttributeObject::Model) == true
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def cast_value(value)
|
39
|
+
value ||= default.dup
|
40
|
+
|
41
|
+
if value.is_a?(::Hash)
|
42
|
+
value = value.values
|
43
|
+
elsif !value.is_a?(::Array)
|
44
|
+
value =
|
45
|
+
if value.respond_to?(:to_a)
|
46
|
+
value.to_a
|
47
|
+
else
|
48
|
+
[value]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
value.map { |v| primitive_value(v, value_type) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def primitive_value(value, type)
|
56
|
+
return type.cast(value) if type.is_a?(ActiveModel::Type::Value)
|
57
|
+
|
58
|
+
Decidim::AttributeObject.type(type).cast(value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Attributes
|
5
|
+
# Custom attributes value to make conversion from signed id (String) to ActiveStorage::Blob easier.
|
6
|
+
class Blob < ActiveModel::Type::Value
|
7
|
+
def type
|
8
|
+
:"decidim/attributes/blob"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def cast_value(value)
|
14
|
+
return value unless value.is_a?(String)
|
15
|
+
|
16
|
+
ActiveStorage::Blob.find_signed(value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -2,16 +2,22 @@
|
|
2
2
|
|
3
3
|
module Decidim
|
4
4
|
module Attributes
|
5
|
-
# Custom
|
6
|
-
# that are sent through user entered forms. This strips out the
|
7
|
-
# return characters from the strings in order to avoid validation
|
8
|
-
# with the string lengths between the frontend and the backend.
|
5
|
+
# Custom attributes value to "standardize" the newline characters within
|
6
|
+
# strings that are sent through user entered forms. This strips out the
|
7
|
+
# carriage return characters from the strings in order to avoid validation
|
8
|
+
# mismatches with the string lengths between the frontend and the backend.
|
9
9
|
#
|
10
10
|
# This type should be used with forms that have:
|
11
11
|
# - A user input defined with the <textarea> element
|
12
12
|
# - The input element having the `maxlength` attribute defined for it
|
13
13
|
# - The backend having a maximum length validation for the input
|
14
|
-
class CleanString <
|
14
|
+
class CleanString < ActiveModel::Type::Value
|
15
|
+
def type # :nodoc:
|
16
|
+
:"decidim/attributes/clean_string"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
15
21
|
# When using Windows or copying texts from existing documents, the text
|
16
22
|
# can contain the carriage return characters (\r) that the front-end
|
17
23
|
# character counter does not consider as actual characters. This happens
|
@@ -27,7 +33,7 @@ module Decidim
|
|
27
33
|
# are included in the data that gets sent to the server. In order to fix
|
28
34
|
# this mismatch, remove the carriage return characters from the text
|
29
35
|
# using this attribute type.
|
30
|
-
def
|
36
|
+
def cast_value(value)
|
31
37
|
return value unless value.is_a?(String)
|
32
38
|
|
33
39
|
value.gsub(/\r/, "")
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Attributes
|
5
|
+
# Custom attributes value to represent a Hash.
|
6
|
+
class Hash < Decidim::Attributes::Array
|
7
|
+
attr_reader :key_type
|
8
|
+
|
9
|
+
def initialize(key_type: ::Symbol, value_type: ::Object, default: {})
|
10
|
+
@key_type = key_type
|
11
|
+
@value_type = value_type
|
12
|
+
@default = default
|
13
|
+
end
|
14
|
+
|
15
|
+
def type # :nodoc:
|
16
|
+
:hash
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def cast_value(value)
|
22
|
+
value ||= default.dup
|
23
|
+
value = value.to_h if !value.is_a?(::Hash) && value.respond_to?(:to_h)
|
24
|
+
|
25
|
+
# This preserves backwards compatibility for non-hash values e.g. with
|
26
|
+
# the admin hero content block which expects the images container object
|
27
|
+
# as the default value when building the admin form.
|
28
|
+
return value unless value.is_a?(::Hash)
|
29
|
+
|
30
|
+
value.to_h do |k, v|
|
31
|
+
[primitive_value(k, key_type), primitive_value(v, value_type)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|