Skip to content

Commit

Permalink
Update forms
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed May 29, 2024
1 parent bab7e18 commit 5dd17d0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 1 addition & 16 deletions app/forms/concerns/decidim/privacy/account_form_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5dd17d0

Please sign in to comment.