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



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

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.

Returns:

  • (Boolean)


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

def accepted?
  state == "accepted"
end

#accepts_new_comments?Boolean

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

Returns:

  • (Boolean)


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

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.

Returns:

  • (Boolean)


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

def answered?
  answered_at.present?
end

#author_avatar_urlObject



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

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

#author_nameObject



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

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.

Returns:

  • (Boolean)


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

def commentable?
  feature.settings.comments_enabled?
end

#comments_have_alignment?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_alignment?
  true
end

#comments_have_votes?Boolean

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

Returns:

  • (Boolean)


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

def comments_have_votes?
  true
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.

Returns:

  • (Boolean)


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

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

#rejected?Boolean

Public: Checks if the organization has rejected a proposal.

Returns Boolean.

Returns:

  • (Boolean)


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

def rejected?
  state == "rejected"
end

#reported_content_urlObject

Public: Overrides the ‘reported_content_url` Reportable concern method.



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

def reported_content_url
  ResourceLocatorPresenter.new(self).url
end

#users_to_notifyObject

Public: Overrides the ‘users_to_notify` Notifiable concern method.



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

def users_to_notify
  [author]
end

#voted_by?(user) ⇒ Boolean

Public: Check if the user has voted the proposal.

Returns Boolean.

Returns:

  • (Boolean)


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

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