From 5dd17d04caae9da7b5e8e41d6e349cb2ec948292 Mon Sep 17 00:00:00 2001 From: Joonas Date: Wed, 29 May 2024 08:40:55 +0300 Subject: [PATCH] Update forms --- .../privacy/privacy_settings_controller.rb | 6 +++--- .../decidim/privacy/account_form_extensions.rb | 17 +---------------- .../privacy/user_group_form_extensions.rb | 4 ++-- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/app/controllers/decidim/privacy/privacy_settings_controller.rb b/app/controllers/decidim/privacy/privacy_settings_controller.rb index c712af9..8e04e32 100644 --- a/app/controllers/decidim/privacy/privacy_settings_controller.rb +++ b/app/controllers/decidim/privacy/privacy_settings_controller.rb @@ -6,12 +6,12 @@ class PrivacySettingsController < ::Decidim::ApplicationController include Decidim::UserProfile def show - enforce_permission_to :read, :user, current_user: current_user + enforce_permission_to :read, :user, current_user: @privacy_settings = form(::Decidim::Privacy::PrivacySettingsForm).from_model(current_user) end def update - enforce_permission_to :read, :user, current_user: current_user + enforce_permission_to :read, :user, current_user: @privacy_settings = form(::Decidim::Privacy::PrivacySettingsForm).from_params(params) UpdatePrivacySettings.call(current_user, @privacy_settings) do @@ -28,7 +28,7 @@ def update end def update_publicity - enforce_permission_to :read, :user, current_user: current_user + enforce_permission_to :read, :user, current_user: @form = form(::Decidim::Privacy::PublishAccountForm).from_params(params) UpdateAccountPublicity.call(current_user, @form) do diff --git a/app/forms/concerns/decidim/privacy/account_form_extensions.rb b/app/forms/concerns/decidim/privacy/account_form_extensions.rb index f56919e..9d250ce 100644 --- a/app/forms/concerns/decidim/privacy/account_form_extensions.rb +++ b/app/forms/concerns/decidim/privacy/account_form_extensions.rb @@ -9,7 +9,7 @@ module AccountFormExtensions def unique_email return true if Decidim::UserBaseEntity.entire_collection.where( organization: context.current_organization, - email: email + email: ).where.not(id: context.current_user.id).empty? errors.add :email, :taken @@ -26,21 +26,6 @@ def unique_nickname errors.add :nickname, :taken false end - - # 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 - attribute :old_password - validate :validate_old_password - - def validate_old_password - user = context.current_user - if user.email != email || password.present? - return true if user.valid_password?(old_password) - - errors.add :old_password, :invalid - false - end - end end end end diff --git a/app/forms/concerns/decidim/privacy/user_group_form_extensions.rb b/app/forms/concerns/decidim/privacy/user_group_form_extensions.rb index fd4dd5b..49a9c70 100644 --- a/app/forms/concerns/decidim/privacy/user_group_form_extensions.rb +++ b/app/forms/concerns/decidim/privacy/user_group_form_extensions.rb @@ -10,9 +10,9 @@ def unique_nickname .entire_collection .where( organization: context.current_organization, - nickname: nickname + nickname: ) - .where.not(id: id) + .where.not(id:) .empty? errors.add :nickname, :taken