Skip to content

Commit

Permalink
fix: Remove verification conflicts (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois authored Nov 10, 2023
1 parent 585fd97 commit 92fbf88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
1 change: 1 addition & 0 deletions config/initializers/extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "extends/helpers/decidim/meetings/directory/application_helper_extends"
require "extends/helpers/decidim/assemblies/assemblies_helper_extends"
require "extends/helpers/decidim/accountability/application_helper_extends"
require "extends/commands/decidim/verifications/authorize_user_extends"

def load_dir(directory)
files = Dir.glob("lib/extends/#{directory}/*.rb")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module AuthorizeUserExtends
extend ActiveSupport::Concern

included do
# Override commands to remove the verification conflict
def call
return broadcast(:invalid) if handler.invalid?

Decidim::Authorization.create_or_update_from(handler)

broadcast(:ok)
end
end
end

Decidim::Verifications::AuthorizeUser.class_eval do
include(AuthorizeUserExtends)
end
28 changes: 1 addition & 27 deletions spec/commands/decidim/verifications/authorize_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,7 @@ module Decidim::Verifications
end

it "saves conflicts" do
expect { subject.call }.to change(Decidim::Verifications::Conflict, :count).by(1)
end

it "increases conflicts times" do
subject.call

conflict = Decidim::Verifications::Conflict.last

expect(conflict.times).to eq(1)

subject.call

expect(conflict.reload.times).to eq(2)
end

it "sends notification to admins" do
allow(Decidim::EventsManager).to receive(:publish).and_call_original
subject.call

conflict = Decidim::Verifications::Conflict.last

expect(Decidim::EventsManager).to have_received(:publish).with(
event: "decidim.events.verifications.managed_user_error_event",
event_class: Decidim::Verifications::ManagedUserErrorEvent,
resource: conflict,
affected_users: Decidim::User.where(admin: true, organization: organization)
)
expect { subject.call }.not_to change(Decidim::Verifications::Conflict, :count)
end
end
end
Expand Down

0 comments on commit 92fbf88

Please sign in to comment.