Class: Decidim::Proposals::Proposal

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::Commentable, HasCategory, HasFeature, HasReference, HasScope, Reportable, Resourceable
Defined in:
app/models/decidim/proposals/proposal.rb

Overview

The data store for a Proposal in the Decidim::Proposals component.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.order_randomly(seed) ⇒ Object



28
29
30
31
32
33
# File 'app/models/decidim/proposals/proposal.rb', line 28

def self.order_randomly(seed)
  transaction do
    connection.execute("SELECT setseed(#{connection.quote(seed)})")
    order("RANDOM()").load
  end
end

Instance Method Details

#accepted?Boolean

Public: Checks if the organization has accepted a proposal.

Returns Boolean.



60
61
62
# File 'app/models/decidim/proposals/proposal.rb', line 60

def accepted?
  state == "accepted"
end

#accepts_new_comments?Boolean

Public: Overrides the ‘accepts_new_comments?` Commentable concern method.



84
85
86
# File 'app/models/decidim/proposals/proposal.rb', line 84

def accepts_new_comments?
  commentable? && !feature.active_step_settings.comments_blocked
end

#answered?Boolean

Public: Checks if the organization has given an answer for the proposal.

Returns Boolean.



53
54
55
# File 'app/models/decidim/proposals/proposal.rb', line 53

def answered?
  answered_at.present?
end

#author_avatar_urlObject



39
40
41
# File 'app/models/decidim/proposals/proposal.rb', line 39

def author_avatar_url
  author&.avatar&.url || ActionController::Base.helpers.asset_path("decidim/default-avatar.svg")
end

#author_nameObject



35
36
37
# File 'app/models/decidim/proposals/proposal.rb', line 35

def author_name
  user_group&.name || author&.name || I18n.t("decidim.proposals.models.proposal.fields.official_proposal")
end

#commentable?Boolean

Public: Overrides the ‘commentable?` Commentable concern method.



79
80
81
# File 'app/models/decidim/proposals/proposal.rb', line 79

def commentable?
  feature.settings.comments_enabled?
end

#comments_have_alignment?Boolean

Public: Overrides the ‘comments_have_alignment?` Commentable concern method.



89
90
91
# File 'app/models/decidim/proposals/proposal.rb', line 89

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

Public: Overrides the ‘comments_have_votes?` Commentable concern method.



94
95
96
# File 'app/models/decidim/proposals/proposal.rb', line 94

def comments_have_votes?
  true
end

#evaluating?Boolean

Public: Checks if the organization has marked the proposal as evaluating it.

Returns Boolean.



74
75
76
# File 'app/models/decidim/proposals/proposal.rb', line 74

def evaluating?
  state == "evaluating"
end

#notifiable?(context) ⇒ Boolean

Public: Overrides the ‘notifiable?` Notifiable concern method. When a proposal is commented the proposal’s author is notified if it is not the same who has commented the proposal and if the proposal’s author has comment notifications enabled.



106
107
108
# File 'app/models/decidim/proposals/proposal.rb', line 106

def notifiable?(context)
  context[:author] != author && author.comments_notifications?
end

#rejected?Boolean

Public: Checks if the organization has rejected a proposal.

Returns Boolean.



67
68
69
# File 'app/models/decidim/proposals/proposal.rb', line 67

def rejected?
  state == "rejected"
end

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



99
100
101
# File 'app/models/decidim/proposals/proposal.rb', line 99

def reported_content_url
  ResourceLocatorPresenter.new(self).url
end

#users_to_notifyObject

Public: Overrides the ‘users_to_notify` Notifiable concern method.



111
112
113
# File 'app/models/decidim/proposals/proposal.rb', line 111

def users_to_notify
  [author]
end

#voted_by?(user) ⇒ Boolean

Public: Check if the user has voted the proposal.

Returns Boolean.



46
47
48
# File 'app/models/decidim/proposals/proposal.rb', line 46

def voted_by?(user)
  votes.where(author: user).any?
end