app/models/decidim/initiative.rb in decidim-initiatives-0.9.1 vs app/models/decidim/initiative.rb in decidim-initiatives-0.11.0.pre1
- old
+ new
@@ -9,10 +9,13 @@
include Decidim::Publicable
include Decidim::Scopable
include Decidim::Comments::Commentable
include Decidim::Followable
include Decidim::HasAttachments
+ include Decidim::HasAttachmentCollections
+ include Decidim::Traceable
+ include Decidim::Loggable
include Decidim::Initiatives::InitiativeSlug
belongs_to :organization,
foreign_key: "decidim_organization_id",
class_name: "Decidim::Organization"
@@ -25,20 +28,21 @@
delegate :type, to: :scoped_type, allow_nil: true
delegate :scope, to: :scoped_type, allow_nil: true
has_many :votes,
foreign_key: "decidim_initiative_id",
- class_name: "Decidim::InitiativesVote", dependent: :destroy,
+ class_name: "Decidim::InitiativesVote",
+ dependent: :destroy,
inverse_of: :initiative
has_many :committee_members,
foreign_key: "decidim_initiatives_id",
class_name: "Decidim::InitiativesCommitteeMember",
dependent: :destroy,
inverse_of: :initiative
- has_many :features, as: :participatory_space
+ has_many :components, as: :participatory_space, dependent: :destroy
# This relationship exists only by compatibility reasons.
# Initiatives are not intended to have categories.
has_many :categories,
foreign_key: "decidim_participatory_space_id",
@@ -75,11 +79,11 @@
scope :order_by_most_recent, -> { order(created_at: :desc) }
scope :order_by_supports, -> { order("initiative_votes_count + coalesce(offline_votes, 0) desc") }
scope :order_by_most_commented, lambda {
select("decidim_initiatives.*")
- .joins(%q(LEFT OUTER JOIN "decidim_comments_comments" ON "decidim_comments_comments"."decidim_commentable_id" = "decidim_initiatives"."id" AND "decidim_comments_comments"."decidim_commentable_type" = 'Decidim::Initiative'))
+ .left_joins(:comments)
.group("decidim_initiatives.id")
.order("count(decidim_comments_comments.id) desc")
}
after_save :notify_state_change
@@ -90,10 +94,14 @@
connection.execute("SELECT setseed(#{connection.quote(seed)})")
select('"decidim_initiatives".*, RANDOM()').order("RANDOM()").load
end
end
+ def self.log_presenter_class_for(_log)
+ Decidim::Initiatives::AdminLog::InitiativePresenter
+ end
+
# PUBLIC
#
# Returns true when an initiative has been created by an individual person.
# False in case it has been created by an authorized organization.
#
@@ -179,29 +187,29 @@
# managed by the user and it will be enabled by default.
def scopes_enabled
true
end
- # Public: Publishes this feature
+ # Public: Publishes this initiative
#
# Returns true if the record was properly saved, false otherwise.
def publish!
return false if published?
- update_attributes(
+ update(
published_at: Time.current,
state: "published",
signature_start_time: DateTime.now.utc,
signature_end_time: DateTime.now.utc + Decidim::Initiatives.default_signature_time_period_length
)
end
#
- # Public: Unpublishes this feature
+ # Public: Unpublishes this initiative
#
# Returns true if the record was properly saved, false otherwise.
def unpublish!
return false unless published?
- update_attributes(published_at: nil, state: "discarded")
+ update(published_at: nil, state: "discarded")
end
# Public: Returns wether the signature interval is already defined or not.
def has_signature_interval_defined?
signature_end_time.present? && signature_start_time.present?