Implements story #136

Adds draft state for proposals
This commit is contained in:
Juan Salvador Pérez García
2018-06-07 12:19:26 +02:00
parent 83b8127b72
commit 77dd60427d
17 changed files with 176 additions and 38 deletions

View File

@@ -71,11 +71,26 @@ class Proposal < ActiveRecord::Base
scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) }
scope :public_for_api, -> { all }
scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) }
scope :published, -> { where.not(published_at: nil) }
scope :draft, -> { where(published_at: nil) }
scope :created_by, ->(author) { unscoped.where(hidden_at: nil, author: author) }
def url
proposal_path(self)
end
def publish
update(published_at: Time.now)
end
def published?
!published_at.nil?
end
def draft?
published_at.nil?
end
def self.recommendations(user)
tagged_with(user.interests, any: true)
.where("author_id != ?", user.id)