diff --git a/lib/decidim/direct_verifications/revoke_user.rb b/lib/decidim/direct_verifications/revoke_user.rb index cce4423..551f51d 100644 --- a/lib/decidim/direct_verifications/revoke_user.rb +++ b/lib/decidim/direct_verifications/revoke_user.rb @@ -7,36 +7,37 @@ def initialize(email, organization, instrumenter) @email = email @organization = organization @instrumenter = instrumenter + @user = find_user end def call - if (u = find_user) - auth = authorization(u) - return unless auth.granted? - - Verification::DestroyUserAuthorization.call(auth) do - on(:ok) do - instrumenter.add_processed :revoked, email - end - on(:invalid) do - add_error :revoked, email - end - end - else + unless user instrumenter.add_error :revoked, email + return + end + + return unless authorization.granted? + + Verification::DestroyUserAuthorization.call(authorization) do + on(:ok) do + instrumenter.add_processed :revoked, email + end + on(:invalid) do + add_error :revoked, email + end end end private - attr_reader :email, :organization, :instrumenter + attr_reader :email, :organization, :instrumenter, :user def find_user User.find_by(email: email, decidim_organization_id: organization.id) end - def authorization(user) - Authorization.find_or_initialize_by( + def authorization + @authorization ||= Authorization.find_or_initialize_by( user: user, name: :direct_verifications )