Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use the following command in your rails console : `Decidim::User.find_each { |us

**Fixed**:

- **decidim-admin**: Add email validation to ManagedUserPromotionForm. [\#295](https://github.com/OpenSourcePolitics/decidim/pull/295)
- **decidim-budgets**: Fix display of budgets when votes count is activated. [\#268](https://github.com/OpenSourcePolitics/decidim/pull/268)
- **decidim-accountability**: Fix accountability progress to be between 0 and 100 if provided. [\#3952](https://github.com/decidim/decidim/pull/3952)
- **decidim-participatory_processes**: Fix hastag display on participatory processes. [\#200](https://github.com/OpenSourcePolitics/decidim/pull/200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ class ManagedUserPromotionForm < Form
attribute :email, String

validates :email, presence: true, 'valid_email_2/email': { disposable: true }
validate :unique_email

private

def unique_email
return true if Decidim::User.where(
organization: context.current_organization,
email: email
).where.not(id: context.current_user.id).empty?

errors.add :email, :taken
false
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module Decidim::Admin
ManagedUserPromotionForm.from_params(
form_params
).with_context(
current_organization: organization
current_organization: organization,
current_user: current_user
)
end
let!(:user) { create :user, :managed, organization: organization }
Expand Down
16 changes: 15 additions & 1 deletion decidim-admin/spec/forms/managed_user_promotion_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
module Decidim
module Admin
describe ManagedUserPromotionForm do
subject { described_class.from_params(attributes) }
subject do
described_class.from_params(attributes).with_context(
current_organization: current_organization,
current_user: user
)
end

let(:current_organization) { create(:organization) }
let!(:user) { create :user, :confirmed, organization: current_organization }

let(:email) { "foo@example.org" }
let(:attributes) do
Expand All @@ -25,6 +33,12 @@ module Admin

it { is_expected.to be_invalid }
end

context "when email already exist" do
let!(:another_user) { create :user, :confirmed, email: email, organization: current_organization }

it { is_expected.to be_invalid }
end
end
end
end