Class: Decidim::ActionDelegator::Delegation

Inherits:
ApplicationRecord show all
Defined in:
app/models/decidim/action_delegator/delegation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.granted_to?(user, consultation) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/decidim/action_delegator/delegation.rb', line 27

def self.granted_to?(user, consultation)
  GranteeDelegations.for(consultation, user).exists?
end

Instance Method Details

#grantee_voted?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'app/models/decidim/action_delegator/delegation.rb', line 31

def grantee_voted?
  return false unless consultation.questions.any?

  @grantee_voted ||= begin
    granter_votes = Decidim::Consultations::Vote.where(author: granter, question: consultation.questions)
    granter_votes&.detect { |vote| vote.versions.exists?(whodunnit: grantee&.id) } ? true : false
  end
end