Class: Decidim::Proposals::Proposal

Inherits:
ApplicationRecord show all
Includes:
Authorable, Comments::Commentable, Followable, HasAttachments, HasCategory, HasFeature, HasReference, HasScope, Reportable, Resourceable
Defined in:
decidim-proposals/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



30
31
32
33
34
35
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 30

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.



63
64
65
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 63

def accepted?
  answered? && state == "accepted"
end

#accepts_new_comments?Boolean

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



87
88
89
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 87

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

#answered?Boolean

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

Returns Boolean.



56
57
58
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 56

def answered?
  answered_at.present?
end

#author_avatar_urlObject



42
43
44
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 42

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

#author_nameObject



37
38
39
40
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 37

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

#commentable?Boolean

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



82
83
84
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 82

def commentable?
  feature.settings.comments_enabled?
end

#comments_have_alignment?Boolean

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



92
93
94
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 92

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

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



97
98
99
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 97

def comments_have_votes?
  true
end

#evaluating?Boolean

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

Returns Boolean.



77
78
79
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 77

def evaluating?
  answered? && state == "evaluating"
end

#official?Boolean

Public: Whether the proposal is official or not.



113
114
115
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 113

def official?
  author.nil?
end

#rejected?Boolean

Public: Checks if the organization has rejected a proposal.

Returns Boolean.



70
71
72
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 70

def rejected?
  answered? && state == "rejected"
end

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



108
109
110
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 108

def reported_content_url
  ResourceLocatorPresenter.new(self).url
end

#users_to_notify_on_comment_createdObject

Public: Override Commentable concern method ‘users_to_notify_on_comment_created`



102
103
104
105
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 102

def users_to_notify_on_comment_created
  return (followers | feature.participatory_space.admins).uniq if official?
  followers
end

#voted_by?(user) ⇒ Boolean

Public: Check if the user has voted the proposal.

Returns Boolean.



49
50
51
# File 'decidim-proposals/app/models/decidim/proposals/proposal.rb', line 49

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