Adds admin setting 'months to archive proposals'

This commit is contained in:
Alberto Garcia Cabeza
2016-09-09 18:02:02 +02:00
parent fa3b503c47
commit 3bbc2862d2
6 changed files with 10 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ class Proposal < ActiveRecord::Base
scope :sort_by_relevance, -> { all } scope :sort_by_relevance, -> { all }
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_archival_date, -> { archived.order(created_at: :desc) } scope :sort_by_archival_date, -> { archived.order(created_at: :desc) }
scope :archived, -> { where("proposals.created_at <= ?", 12.months.ago)} scope :archived, -> { where("proposals.created_at <= ?", Setting["months_to_archive_proposals"].to_i.months.ago)}
scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)}
scope :retired, -> { where.not(retired_at: nil) } scope :retired, -> { where.not(retired_at: nil) }
scope :not_retired, -> { where(retired_at: nil) } scope :not_retired, -> { where(retired_at: nil) }
@@ -158,7 +158,7 @@ class Proposal < ActiveRecord::Base
end end
def archived? def archived?
self.created_at <= 12.months.ago self.created_at <= Setting["months_to_archive_proposals"].to_i.months.ago
end end
def notifications def notifications

View File

@@ -11,6 +11,7 @@ en:
max_votes_for_debate_edit: "Number of votes from which a Debate can no longer be edited" max_votes_for_debate_edit: "Number of votes from which a Debate can no longer be edited"
proposal_code_prefix: "Prefix for Proposal codes" proposal_code_prefix: "Prefix for Proposal codes"
votes_for_proposal_success: "Number of votes necessary for approval of a Proposal" votes_for_proposal_success: "Number of votes necessary for approval of a Proposal"
months_to_archive_proposals: "Months to archive Proposals"
email_domain_for_officials: "Email domain for public officials" email_domain_for_officials: "Email domain for public officials"
per_page_code: "Code to be included on every page" per_page_code: "Code to be included on every page"
feature: feature:

View File

@@ -11,6 +11,7 @@ es:
max_votes_for_debate_edit: "Número de votos en que un Debate deja de poderse editar" max_votes_for_debate_edit: "Número de votos en que un Debate deja de poderse editar"
proposal_code_prefix: "Prefijo para los códigos de Propuestas" proposal_code_prefix: "Prefijo para los códigos de Propuestas"
votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta" votes_for_proposal_success: "Número de votos necesarios para aprobar una Propuesta"
months_to_archive_proposals: "Meses para archivar las Propuestas"
email_domain_for_officials: "Dominio de email para cargos públicos" email_domain_for_officials: "Dominio de email para cargos públicos"
per_page_code: "Código a incluir en cada página" per_page_code: "Código a incluir en cada página"
feature: feature:

View File

@@ -13,6 +13,7 @@ Setting.create(key: 'max_votes_for_debate_edit', value: '1000')
Setting.create(key: 'max_votes_for_proposal_edit', value: '1000') Setting.create(key: 'max_votes_for_proposal_edit', value: '1000')
Setting.create(key: 'proposal_code_prefix', value: 'MAD') Setting.create(key: 'proposal_code_prefix', value: 'MAD')
Setting.create(key: 'votes_for_proposal_success', value: '100') Setting.create(key: 'votes_for_proposal_success', value: '100')
Setting.create(key: 'months_to_archive_proposals', value: '12')
Setting.create(key: 'comments_body_max_length', value: '1000') Setting.create(key: 'comments_body_max_length', value: '1000')
Setting.create(key: 'twitter_handle', value: '@consul_dev') Setting.create(key: 'twitter_handle', value: '@consul_dev')

View File

@@ -31,6 +31,9 @@ Setting["proposal_code_prefix"] = 'MAD'
# Number of votes needed for proposal success # Number of votes needed for proposal success
Setting["votes_for_proposal_success"] = 53726 Setting["votes_for_proposal_success"] = 53726
# Months to archive proposals
Setting["months_to_archive_proposals"] = 12
# Users with this email domain will automatically be marked as level 1 officials # Users with this email domain will automatically be marked as level 1 officials
# Emails under the domain's subdomains will also be included # Emails under the domain's subdomains will also be included
Setting["email_domain_for_officials"] = '' Setting["email_domain_for_officials"] = ''

View File

@@ -193,8 +193,8 @@ module CommonActions
end end
def create_archived_proposals def create_archived_proposals
[create(:proposal, title: "This is an expired proposal", created_at: Time.now - 12.month), [create(:proposal, title: "This is an expired proposal", created_at: Time.now - Setting["months_to_archive_proposals"].to_i.month),
create(:proposal, title: "This is an oldest expired proposal", created_at: Time.now - 14.month)] create(:proposal, title: "This is an oldest expired proposal", created_at: Time.now - Setting["months_to_archive_proposals"].to_i.month - 2.month)]
end end
def tag_names(tag_cloud) def tag_names(tag_cloud)