Skip to content

Commit

Permalink
Refactor command
Browse files Browse the repository at this point in the history
To simplify and increase readability
  • Loading branch information
sauloperez committed Apr 1, 2021
1 parent 7c19259 commit d8ff861
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lib/decidim/direct_verifications/revoke_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit d8ff861

Please sign in to comment.