From 82f8d8facb987ec822f745e15006438827c10693 Mon Sep 17 00:00:00 2001 From: Joonas Date: Mon, 20 May 2024 14:53:06 +0300 Subject: [PATCH] Account privacy settings view --- .rubocop.yml | 92 -------- .../privacy/account_controller_extensions.rb | 47 ---- .../application_controller_extensions.rb | 8 +- .../privacy/profiles_controller_extensions.rb | 1 - .../account/_old_password_field.html.erb | 10 - .../decidim/account/_password_fields.html.erb | 9 - app/views/decidim/account/show.html.erb | 76 ++++--- .../notifications_settings/show.html.erb | 211 ++++++++++++------ .../decidim/privacy/message_block.html.erb | 4 +- .../decidim/privacy/privacy_block.html.erb | 4 +- .../privacy/privacy_settings/show.html.erb | 103 ++++++--- .../decidim/_decidim_javascript.html.erb | 20 ++ app/views/layouts/decidim/_user_menu.html.erb | 4 +- app/views/layouts/decidim/_wrapper.html.erb | 118 ---------- .../decidim/footer/_main_links.html.erb | 29 +++ .../header/_main_links_dropdown.html.erb | 47 ++++ .../layouts/decidim/user_profile.html.erb | 55 ++--- config/locales/en.yml | 13 +- lib/decidim/privacy/engine.rb | 3 - 19 files changed, 396 insertions(+), 458 deletions(-) delete mode 100644 app/controllers/concerns/decidim/privacy/account_controller_extensions.rb delete mode 100644 app/views/decidim/account/_old_password_field.html.erb delete mode 100644 app/views/decidim/account/_password_fields.html.erb create mode 100644 app/views/layouts/decidim/_decidim_javascript.html.erb delete mode 100644 app/views/layouts/decidim/_wrapper.html.erb create mode 100644 app/views/layouts/decidim/footer/_main_links.html.erb create mode 100644 app/views/layouts/decidim/header/_main_links_dropdown.html.erb diff --git a/.rubocop.yml b/.rubocop.yml index 13bc55c..928b486 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,94 +1,2 @@ inherit_gem: decidim-dev: rubocop-decidim.yml - -inherit_mode: - merge: - - Exclude - -AllCops: - Exclude: - - "decidim-initiatives/lib/gem_overrides/origami/date.rb" - -Naming/FileName: - Exclude: - - "decidim-dev/lib/decidim-dev.rb" - -Metrics/CyclomaticComplexity: - Exclude: - - "decidim-admin/app/queries/decidim/admin/newsletter_recipients.rb" - -Metrics/ParameterLists: - Exclude: - - "decidim-core/lib/decidim/filter_form_builder.rb" - -Metrics/PerceivedComplexity: - Exclude: - - "decidim-admin/app/queries/decidim/admin/newsletter_recipients.rb" - -RSpec/DescribeClass: - Exclude: - - decidim-core/spec/lib/global_engines_spec.rb - -RSpec/EmptyExampleGroup: - Exclude: - - decidim-core/spec/lib/participatory_space_manifest_spec.rb - -RSpec/MultipleMemoizedHelpers: - Exclude: - - decidim-assemblies/spec/forms/assembly_form_spec.rb - -Rails/Output: - Exclude: - - lib/decidim/git_backport_manager.rb - - lib/decidim/github_manager/poster.rb - - decidim-core/lib/decidim/core.rb - - decidim-core/lib/decidim/component_manifest.rb - - decidim-core/lib/decidim/participatory_space_manifest.rb - -Rails/Exit: - Exclude: - - lib/decidim/git_backport_manager.rb - -RSpec/NoExpectationExample: - Exclude: - - decidim-admin/spec/system/participatory_space_private_user_spec.rb - - decidim-comments/spec/services/decidim/comments/comment_creation_spec.rb - - decidim-conferences/spec/cells/decidim/conferences/conference_speaker_cell_spec.rb - - decidim-core/spec/cells/decidim/date_range_cell_spec.rb - - decidim-core/spec/commands/decidim/unsubscribe_settings_spec.rb - - decidim-core/spec/controllers/registrations_controller_spec.rb - - decidim-core/spec/lib/importers/import_manifest_spec.rb - - decidim-core/spec/lib/map/geocoding_spec.rb - - decidim-core/spec/lib/participatory_space_manifest_spec.rb - - decidim-core/spec/services/decidim/events_manager_spec.rb - - decidim-core/spec/services/decidim/settings_change_spec.rb - - decidim-core/spec/services/decidim/zip_stream/zip_stream_writer_spec.rb - - decidim-core/spec/tasks/decidim_tasks_right_to_be_forgotten_spec.rb - - decidim-elections/spec/lib/tasks/decidim_election_generate_identification_keys_spec.rb - - decidim-elections/spec/lib/tasks/decidim_election_scheduled_tasks_spec.rb - - decidim-elections/spec/shared/vote_examples.rb - - decidim-elections/spec/system/key_ceremony_spec.rb - - decidim-elections/spec/system/vote_online_inside_a_voting_spec.rb - - decidim-initiatives/spec/system/admin/update_initiative_spec.rb - - decidim-initiatives/spec/system/initiative_signing_spec.rb - - decidim-meetings/spec/commands/admin/export_meeting_registrations_spec.rb - - decidim-meetings/spec/system/explore_meeting_directory_spec.rb - - decidim-meetings/spec/system/explore_meetings_spec.rb - - decidim-proposals/spec/lib/decidim/proposals/markdown_to_proposals_spec.rb - - decidim-proposals/spec/shared/import_proposals_examples.rb - - decidim-proposals/spec/shared/proposals_wizards_examples.rb - - decidim-proposals/spec/system/admin/admin_manages_participatory_texts_spec.rb - - decidim-proposals/spec/system/participatory_texts_spec.rb - - decidim-participatory_processes/spec/system/participatory_processes_spec.rb - -# fix these rules later -Capybara/SpecificFinders: - Enabled: false - -RSpec/IndexedLet: - Enabled: false - -Rails/HelperInstanceVariable: - Enabled: false - -# EOF fix these rules later diff --git a/app/controllers/concerns/decidim/privacy/account_controller_extensions.rb b/app/controllers/concerns/decidim/privacy/account_controller_extensions.rb deleted file mode 100644 index 07a03a6..0000000 --- a/app/controllers/concerns/decidim/privacy/account_controller_extensions.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -# The following changes are related to "Ask old password for changing email/password(PR #11737)" -# These changes should be removed once it has been backported to v.27 -module Decidim - module Privacy - module AccountControllerExtensions - extend ActiveSupport::Concern - included do - def show - enforce_permission_to(:show, :user, current_user: current_user) - @account = form(AccountForm).from_model(current_user) - @account.password = nil - end - - def update - enforce_permission_to(:update, :user, current_user: current_user) - @account = form(AccountForm).from_params(account_params) - UpdateAccount.call(current_user, @account) do - on(:ok) do |email_is_unconfirmed| - flash[:notice] = if email_is_unconfirmed - t("account.update.success_with_email_confirmation", scope: "decidim") - else - t("account.update.success", scope: "decidim") - end - - bypass_sign_in(current_user) - redirect_to account_path(locale: current_user.reload.locale) - end - - on(:invalid) do |password| - fetch_entered_password(password) - flash[:alert] = t("account.update.error", scope: "decidim") - render action: :show - end - end - end - - private - - def fetch_entered_password(password) - @account.password = password - end - end - end - end -end diff --git a/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb b/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb index 586f2e2..f77c8fd 100644 --- a/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb +++ b/app/controllers/concerns/decidim/privacy/application_controller_extensions.rb @@ -13,12 +13,10 @@ module ApplicationControllerExtensions def privacy_modal_snippets return unless respond_to?(:snippets) - return if current_user && current_user.public? - snippets.add(:foot, helpers.javascript_pack_tag("decidim_account_publish_handler")) - return unless user_signed_in? - - snippets.add(:foot, helpers.cell("decidim/privacy/publish_account_modal", current_user)) + if current_user && !current_user.public? && user_signed_in? + snippets.add(:foot, helpers.cell("decidim/privacy/publish_account_modal", current_user)) + end end end end diff --git a/app/controllers/concerns/decidim/privacy/profiles_controller_extensions.rb b/app/controllers/concerns/decidim/privacy/profiles_controller_extensions.rb index 241edac..a340dd0 100644 --- a/app/controllers/concerns/decidim/privacy/profiles_controller_extensions.rb +++ b/app/controllers/concerns/decidim/privacy/profiles_controller_extensions.rb @@ -9,7 +9,6 @@ module ProfilesControllerExtensions before_action :add_nofollow_meta_tag def show - return redirect_to profile_timeline_path(nickname: params[:nickname]) if profile_holder == current_user return redirect_to profile_members_path if profile_holder.is_a?(Decidim::UserGroup) raise ActionController::RoutingError, "Not Found" if profile_holder.published_at.nil? diff --git a/app/views/decidim/account/_old_password_field.html.erb b/app/views/decidim/account/_old_password_field.html.erb deleted file mode 100644 index 41e5e4b..0000000 --- a/app/views/decidim/account/_old_password_field.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% -old_password_options = { - autocomplete: "current-password", - required: true -} -old_password_options[:help_text] = t("devise.passwords.edit.old_password_help") if local_assigns.has_key?(:show_help_text) && show_help_text -%> -
" id="old_password_field" data-toggler=".hide"> - <%= form.password_field :old_password, **old_password_options %> -
diff --git a/app/views/decidim/account/_password_fields.html.erb b/app/views/decidim/account/_password_fields.html.erb deleted file mode 100644 index 5fd3007..0000000 --- a/app/views/decidim/account/_password_fields.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
- <% if local_assigns.has_key?(:show_help_text) || local_assigns.has_key?(:user) %> - <%= form.password_field :password, password_field_options_for(user) %> - <%= form.password_field :password_confirmation, password_field_options_for(user).except(:help_text) %> - <% else %> - <%= form.password_field :password, autocomplete: "current-password", required: true %> - <%= form.password_field :password_confirmation, password_field_options_for(user).except(:help_text) %> - <% end %> -
diff --git a/app/views/decidim/account/show.html.erb b/app/views/decidim/account/show.html.erb index 2d66f81..a8800da 100644 --- a/app/views/decidim/account/show.html.erb +++ b/app/views/decidim/account/show.html.erb @@ -1,26 +1,30 @@ -<%= alert_box("", "account-notification hide", true) %> <% add_decidim_page_title(t("profile", scope: "layouts.decidim.user_menu")) %> <% content_for(:subtitle) { t("profile", scope: "layouts.decidim.user_menu") } %> -
- <%= decidim_form_for(@account, url: account_path, method: :put, html: { autocomplete: "on" }) do |f| %> -
- <%= f.upload :avatar %> +<%= render layout: "layouts/decidim/shared/layout_user_profile" do %> + <% if current_user.unconfirmed_email.present? %> + <%# NOTE: announcement cell clean_body method will purge the button %> +
+
+

+ <%= t("decidim.account.email_change.title") %> +

+

+ <%= t("decidim.account.email_change.body1", unconfirmed_email: current_user.unconfirmed_email) %> +

+

+ <%== t( + "decidim.account.email_change.body2", + resend_link: link_to(t("decidim.account.email_change.send_again"), resend_confirmation_instructions_account_path, role: :button, method: :post, remote: true), + cancel_link: link_to(t("decidim.account.email_change.cancel"), cancel_email_change_account_path, role: :button, method: :post, remote: true)) %> +

+
+ <% end %> -
- <% if current_user.unconfirmed_email.present? %> -
-

<%= t("decidim.account.email_change.title") %>

-

<%= t("decidim.account.email_change.body1", unconfirmed_email: current_user.unconfirmed_email) %>

-

- <%== t( - "decidim.account.email_change.body2", - resend_link: link_to(t("decidim.account.email_change.send_again"), resend_confirmation_instructions_account_path, role: :button, method: :post, remote: true), - cancel_link: link_to(t("decidim.account.email_change.cancel"), cancel_email_change_account_path, role: :button, method: :post, remote: true)) %> -

-
- <% end %> + <%= decidim_form_for(@account, url: account_path, method: :put, html: { autocomplete: "on", class: "form-defaults edit_user" }) do |f| %> +
+ <%= f.upload :avatar, button_class: "button button__lg button__transparent-secondary w-full" %> <%= form_required_explanation %> @@ -34,27 +38,37 @@ :locale, @account.organization.available_locales, :to_s, - ->(locale) {locale_name(locale) } + ->(locale) { locale_name(locale) }, + help_text: t("available_locales_helper", scope:"decidim.account.show") ) %> -

<%= t(".available_locales_helper") %>

- - <% if @account.errors[:password].any? || @account.errors[:password_confirmation].any? || @account.errors[:old_password].any?%> + <% if @account.password.present? %> <%= render partial: "password_fields", locals: { form: f, user: current_user } %> - <%= render partial: "old_password_field", locals: { form: f, show_help_text: true, unhide: false } %> - <% else %> - <% if current_organization.sign_in_enabled? %> -

- -

-
+ <%= render partial: "old_password_field", locals: { form: f, show_help_text: true } %> + <% elsif current_organization.sign_in_enabled? %> +
+ <%= button_tag( + class: "text-lg font-semibold text-secondary underline block cursor-pointer", + id: "accordion-trigger-panel-password", + type: "button", + data: { controls: "panel-password" } + ) do %> + <%= t("change_password", scope:"decidim.account.show") %> + <% end %> +
<%= render partial: "password_fields", locals: { form: f, user: current_user } %>
+
+ + <%= content_tag :div, id: "panel-old-password", class: @account.errors[:old_password].any? ? nil : "hidden" do %> <%= render partial: "old_password_field", locals: { form: f, show_help_text: true } %> <% end %> <% end %> - <%= f.submit t(".update_account") %> +
+ <%= f.submit t("update_account", scope:"decidim.account.show"), class: "button button__sm md:button__lg button__secondary mr-auto !ml-0" %> +
<% end %> -
+<% end %> + <%= append_javascript_pack_tag("decidim_privacy_user_form")%> diff --git a/app/views/decidim/notifications_settings/show.html.erb b/app/views/decidim/notifications_settings/show.html.erb index c5b609a..a8c2ac2 100644 --- a/app/views/decidim/notifications_settings/show.html.erb +++ b/app/views/decidim/notifications_settings/show.html.erb @@ -1,77 +1,162 @@ -<% add_decidim_page_title(t("notifications_settings", scope: "layouts.decidim.user_profile")) %> -<% content_for(:subtitle) { t("notifications_settings", scope: "layouts.decidim.user_profile") } %> - -<%= form_for(@notifications_settings, url: notifications_settings_path, method: :put, class: "user-form") do |f| %> -

<%= t(".receive_notifications_about") %>

-
- <%= f.label :notifications_from_own_activity do %> - <%= f.check_box :notifications_from_own_activity, label: false, class: "switch-input" %> - - <%= t(".own_activity") %> - <% end %> -
-
- <%= f.label :notifications_from_followed do %> - <%= f.check_box :notifications_from_followed, label: false, class: "switch-input" %> - - <%= t(".everything_followed") %> - <% end %> -
- -

<%= t(".notifications_sending_frequency") %>

- <%= f.collection_radio_buttons :notifications_sending_frequency, frequencies_collection, :first, :last, { checked: @notifications_settings.notifications_sending_frequency || "daily" } %> - -

<%= t(".newsletters") %>

- +<%= render layout: "layouts/decidim/shared/layout_user_profile" do %> + <% add_decidim_page_title(t("notifications_settings", scope: "layouts.decidim.user_profile")) %> + <% content_for(:subtitle) { t("notifications_settings", scope: "layouts.decidim.user_profile") } %> + <%= form_for(@notifications_settings, url: notifications_settings_path, method: :put) do |f| %> +
+ +
+
+ +
+
+ +
+
- <% if current_user.moderator? %> -

<%= t(".administrators") %>

- +
+ <%= f.collection_radio_buttons :notifications_sending_frequency, frequencies_collection, :first, :last do |option| + option.label(class: "form__wrapper-checkbox-label first-of-type:mt-0 md:first-of-type:-mt-4 md:-mt-4 text-black") { option.radio_button + option.text } + end %> +
- <% Decidim.notification_settings_registry.manifests.filter{ |a| a.settings_area == :administrators }.each do |manifest| %> -
-