Use double quotes in models
This commit is contained in:
@@ -8,7 +8,7 @@ module Abilities
|
|||||||
can [:read, :update, :valuate], SpendingProposal
|
can [:read, :update, :valuate], SpendingProposal
|
||||||
can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.assigned_investment_ids
|
can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.assigned_investment_ids
|
||||||
can [:valuate], Budget::Investment, { id: valuator.assigned_investment_ids, valuation_finished: false }
|
can [:valuate], Budget::Investment, { id: valuator.assigned_investment_ids, valuation_finished: false }
|
||||||
cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: 'finished' }
|
cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: "finished" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ class Activity < ActiveRecord::Base
|
|||||||
|
|
||||||
validates :action, inclusion: {in: VALID_ACTIONS}
|
validates :action, inclusion: {in: VALID_ACTIONS}
|
||||||
|
|
||||||
scope :on_proposals, -> { where(actionable_type: 'Proposal') }
|
scope :on_proposals, -> { where(actionable_type: "Proposal") }
|
||||||
scope :on_debates, -> { where(actionable_type: 'Debate') }
|
scope :on_debates, -> { where(actionable_type: "Debate") }
|
||||||
scope :on_users, -> { where(actionable_type: 'User') }
|
scope :on_users, -> { where(actionable_type: "User") }
|
||||||
scope :on_comments, -> { where(actionable_type: 'Comment') }
|
scope :on_comments, -> { where(actionable_type: "Comment") }
|
||||||
scope :on_budget_investments, -> { where(actionable_type: 'Budget::Investment') }
|
scope :on_budget_investments, -> { where(actionable_type: "Budget::Investment") }
|
||||||
scope :on_system_emails, -> { where(actionable_type: 'ProposalNotification') }
|
scope :on_system_emails, -> { where(actionable_type: "ProposalNotification") }
|
||||||
scope :for_render, -> { includes(user: [:moderator, :administrator]).includes(:actionable) }
|
scope :for_render, -> { includes(user: [:moderator, :administrator]).includes(:actionable) }
|
||||||
|
|
||||||
def self.log(user, action, actionable)
|
def self.log(user, action, actionable)
|
||||||
|
|||||||
@@ -147,11 +147,11 @@ class Budget < ActiveRecord::Base
|
|||||||
|
|
||||||
def investments_orders
|
def investments_orders
|
||||||
case phase
|
case phase
|
||||||
when 'accepting', 'reviewing'
|
when "accepting", "reviewing"
|
||||||
%w{random}
|
%w{random}
|
||||||
when 'publishing_prices', 'balloting', 'reviewing_ballots'
|
when "publishing_prices", "balloting", "reviewing_ballots"
|
||||||
%w{random price}
|
%w{random price}
|
||||||
when 'finished'
|
when "finished"
|
||||||
%w{random}
|
%w{random}
|
||||||
else
|
else
|
||||||
%w{random confidence_score}
|
%w{random confidence_score}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Budget
|
|||||||
include Milestoneable
|
include Milestoneable
|
||||||
include Randomizable
|
include Randomizable
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :heading
|
belongs_to :heading
|
||||||
belongs_to :group
|
belongs_to :group
|
||||||
belongs_to :budget
|
belongs_to :budget
|
||||||
@@ -39,8 +39,8 @@ class Budget
|
|||||||
has_many :valuator_group_assignments, dependent: :destroy
|
has_many :valuator_group_assignments, dependent: :destroy
|
||||||
has_many :valuator_groups, through: :valuator_group_assignments
|
has_many :valuator_groups, through: :valuator_group_assignments
|
||||||
|
|
||||||
has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment'
|
has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: "Comment"
|
||||||
has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment'
|
has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: "Comment"
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
@@ -75,7 +75,7 @@ class Budget
|
|||||||
scope :unfeasible, -> { where(feasibility: "unfeasible") }
|
scope :unfeasible, -> { where(feasibility: "unfeasible") }
|
||||||
scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") }
|
scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") }
|
||||||
scope :undecided, -> { where(feasibility: "undecided") }
|
scope :undecided, -> { where(feasibility: "undecided") }
|
||||||
scope :with_supports, -> { where('cached_votes_up > 0') }
|
scope :with_supports, -> { where("cached_votes_up > 0") }
|
||||||
scope :selected, -> { feasible.where(selected: true) }
|
scope :selected, -> { feasible.where(selected: true) }
|
||||||
scope :compatible, -> { where(incompatible: false) }
|
scope :compatible, -> { where(incompatible: false) }
|
||||||
scope :incompatible, -> { where(incompatible: true) }
|
scope :incompatible, -> { where(incompatible: true) }
|
||||||
@@ -133,10 +133,10 @@ class Budget
|
|||||||
|
|
||||||
def self.advanced_filters(params, results)
|
def self.advanced_filters(params, results)
|
||||||
ids = []
|
ids = []
|
||||||
ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?('feasible')
|
ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?("feasible")
|
||||||
ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?('selected')
|
ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?("selected")
|
||||||
ids += results.undecided.pluck(:id) if params[:advanced_filters].include?('undecided')
|
ids += results.undecided.pluck(:id) if params[:advanced_filters].include?("undecided")
|
||||||
ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?('unfeasible')
|
ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?("unfeasible")
|
||||||
results.where("budget_investments.id IN (?)", ids)
|
results.where("budget_investments.id IN (?)", ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -173,11 +173,11 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
author.username => 'B',
|
author.username => "B",
|
||||||
heading.try(:name) => 'B',
|
heading.try(:name) => "B",
|
||||||
tag_list.join(' ') => 'B',
|
tag_list.join(" ") => "B",
|
||||||
description => 'C'
|
description => "C"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.by_heading(heading)
|
def self.by_heading(heading)
|
||||||
where(heading_id: heading == 'all' ? nil : heading.presence)
|
where(heading_id: heading == "all" ? nil : heading.presence)
|
||||||
end
|
end
|
||||||
|
|
||||||
def undecided?
|
def undecided?
|
||||||
@@ -283,7 +283,7 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def register_selection(user)
|
def register_selection(user)
|
||||||
vote_by(voter: user, vote: 'yes') if selectable_by?(user)
|
vote_by(voter: user, vote: "yes") if selectable_by?(user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_confidence_score
|
def calculate_confidence_score
|
||||||
@@ -342,11 +342,11 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assigned_valuators
|
def assigned_valuators
|
||||||
self.valuators.collect(&:description_or_name).compact.join(', ').presence
|
self.valuators.collect(&:description_or_name).compact.join(", ").presence
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_valuation_groups
|
def assigned_valuation_groups
|
||||||
self.valuator_groups.collect(&:name).compact.join(', ').presence
|
self.valuator_groups.collect(&:name).compact.join(", ").presence
|
||||||
end
|
end
|
||||||
|
|
||||||
def valuation_tag_list
|
def valuation_tag_list
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Budget::Investment::Exporter
|
class Budget::Investment::Exporter
|
||||||
require 'csv'
|
require "csv"
|
||||||
|
|
||||||
def initialize(investments)
|
def initialize(investments)
|
||||||
@investments = investments
|
@investments = investments
|
||||||
@@ -37,13 +37,13 @@ class Budget::Investment::Exporter
|
|||||||
investment.title,
|
investment.title,
|
||||||
investment.total_votes.to_s,
|
investment.total_votes.to_s,
|
||||||
admin(investment),
|
admin(investment),
|
||||||
investment.assigned_valuators || '-',
|
investment.assigned_valuators || "-",
|
||||||
investment.assigned_valuation_groups || '-',
|
investment.assigned_valuation_groups || "-",
|
||||||
investment.heading.name,
|
investment.heading.name,
|
||||||
price(investment),
|
price(investment),
|
||||||
investment.valuation_finished? ? I18n.t('shared.yes') : I18n.t('shared.no'),
|
investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"),
|
||||||
investment.selected? ? I18n.t('shared.yes') : I18n.t('shared.no'),
|
investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"),
|
||||||
investment.visible_to_valuators? ? I18n.t('shared.yes') : I18n.t('shared.no'),
|
investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"),
|
||||||
investment.author.username
|
investment.author.username
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class Budget
|
|||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
belongs_to :budget
|
belongs_to :budget
|
||||||
belongs_to :next_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id
|
belongs_to :next_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id
|
||||||
has_one :prev_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id
|
has_one :prev_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id
|
||||||
|
|
||||||
validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH }
|
validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH }
|
||||||
validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
|
validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
|
||||||
@@ -26,17 +26,17 @@ class Budget
|
|||||||
after_save :touch_budget
|
after_save :touch_budget
|
||||||
|
|
||||||
scope :enabled, -> { where(enabled: true) }
|
scope :enabled, -> { where(enabled: true) }
|
||||||
scope :published, -> { enabled.where.not(kind: 'drafting') }
|
scope :published, -> { enabled.where.not(kind: "drafting") }
|
||||||
scope :drafting, -> { find_by_kind('drafting') }
|
scope :drafting, -> { find_by_kind("drafting") }
|
||||||
scope :informing, -> { find_by_kind('informing') }
|
scope :informing, -> { find_by_kind("informing") }
|
||||||
scope :accepting, -> { find_by_kind('accepting')}
|
scope :accepting, -> { find_by_kind("accepting")}
|
||||||
scope :reviewing, -> { find_by_kind('reviewing')}
|
scope :reviewing, -> { find_by_kind("reviewing")}
|
||||||
scope :selecting, -> { find_by_kind('selecting')}
|
scope :selecting, -> { find_by_kind("selecting")}
|
||||||
scope :valuating, -> { find_by_kind('valuating')}
|
scope :valuating, -> { find_by_kind("valuating")}
|
||||||
scope :publishing_prices, -> { find_by_kind('publishing_prices')}
|
scope :publishing_prices, -> { find_by_kind("publishing_prices")}
|
||||||
scope :balloting, -> { find_by_kind('balloting')}
|
scope :balloting, -> { find_by_kind("balloting")}
|
||||||
scope :reviewing_ballots, -> { find_by_kind('reviewing_ballots')}
|
scope :reviewing_ballots, -> { find_by_kind("reviewing_ballots")}
|
||||||
scope :finished, -> { find_by_kind('finished')}
|
scope :finished, -> { find_by_kind("finished")}
|
||||||
|
|
||||||
def next_enabled_phase
|
def next_enabled_phase
|
||||||
next_phase&.enabled? ? next_phase : next_phase&.next_enabled_phase
|
next_phase&.enabled? ? next_phase : next_phase&.next_enabled_phase
|
||||||
@@ -48,7 +48,7 @@ class Budget
|
|||||||
|
|
||||||
def invalid_dates_range?
|
def invalid_dates_range?
|
||||||
if starts_at.present? && ends_at.present? && starts_at >= ends_at
|
if starts_at.present? && ends_at.present? && starts_at >= ends_at
|
||||||
errors.add(:starts_at, I18n.t('budgets.phases.errors.dates_range_invalid'))
|
errors.add(:starts_at, I18n.t("budgets.phases.errors.dates_range_invalid"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ class Budget
|
|||||||
prev_enabled_phase.assign_attributes(ends_at: starts_at)
|
prev_enabled_phase.assign_attributes(ends_at: starts_at)
|
||||||
if prev_enabled_phase.invalid_dates_range?
|
if prev_enabled_phase.invalid_dates_range?
|
||||||
phase_name = I18n.t("budgets.phase.#{prev_enabled_phase.kind}")
|
phase_name = I18n.t("budgets.phase.#{prev_enabled_phase.kind}")
|
||||||
error = I18n.t('budgets.phases.errors.prev_phase_dates_invalid', phase_name: phase_name)
|
error = I18n.t("budgets.phases.errors.prev_phase_dates_invalid", phase_name: phase_name)
|
||||||
errors.add(:starts_at, error)
|
errors.add(:starts_at, error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -83,7 +83,7 @@ class Budget
|
|||||||
next_enabled_phase.assign_attributes(starts_at: ends_at)
|
next_enabled_phase.assign_attributes(starts_at: ends_at)
|
||||||
if next_enabled_phase.invalid_dates_range?
|
if next_enabled_phase.invalid_dates_range?
|
||||||
phase_name = I18n.t("budgets.phase.#{next_enabled_phase.kind}")
|
phase_name = I18n.t("budgets.phase.#{next_enabled_phase.kind}")
|
||||||
error = I18n.t('budgets.phases.errors.next_phase_dates_invalid', phase_name: phase_name)
|
error = I18n.t("budgets.phases.errors.next_phase_dates_invalid", phase_name: phase_name)
|
||||||
errors.add(:ends_at, error)
|
errors.add(:ends_at, error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class Ckeditor::Picture < Ckeditor::Asset
|
class Ckeditor::Picture < Ckeditor::Asset
|
||||||
has_attached_file :data,
|
has_attached_file :data,
|
||||||
url: '/ckeditor_assets/pictures/:id/:style_:basename.:extension',
|
url: "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
|
||||||
path: ':rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension',
|
path: ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension",
|
||||||
styles: { content: '800>', thumb: '118x100#' }
|
styles: { content: "800>", thumb: "118x100#" }
|
||||||
|
|
||||||
validates_attachment_presence :data
|
validates_attachment_presence :data
|
||||||
validates_attachment_size :data, less_than: 2.megabytes
|
validates_attachment_size :data, less_than: 2.megabytes
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class Comment < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.body_max_length
|
def self.body_max_length
|
||||||
Setting['comments_body_max_length'].to_i
|
Setting["comments_body_max_length"].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_confidence_score
|
def calculate_confidence_score
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ module Filterable
|
|||||||
|
|
||||||
def allowed_filter?(filter, value)
|
def allowed_filter?(filter, value)
|
||||||
return if value.blank?
|
return if value.blank?
|
||||||
['official_level', 'date_range'].include?(filter)
|
["official_level", "date_range"].include?(filter)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module Graphqlable
|
|||||||
class_methods do
|
class_methods do
|
||||||
|
|
||||||
def graphql_field_name
|
def graphql_field_name
|
||||||
name.gsub('::', '_').underscore.to_sym
|
name.gsub("::", "_").underscore.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def graphql_field_description
|
def graphql_field_description
|
||||||
@@ -12,7 +12,7 @@ module Graphqlable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def graphql_pluralized_field_name
|
def graphql_pluralized_field_name
|
||||||
name.gsub('::', '_').underscore.pluralize.to_sym
|
name.gsub("::", "_").underscore.pluralize.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def graphql_pluralized_field_description
|
def graphql_pluralized_field_description
|
||||||
@@ -20,7 +20,7 @@ module Graphqlable
|
|||||||
end
|
end
|
||||||
|
|
||||||
def graphql_type_name
|
def graphql_type_name
|
||||||
name.gsub('::', '_')
|
name.gsub("::", "_")
|
||||||
end
|
end
|
||||||
|
|
||||||
def graphql_type_description
|
def graphql_type_description
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ module Mappable
|
|||||||
return true if skip_map?
|
return true if skip_map?
|
||||||
|
|
||||||
unless map_location.try(:available?)
|
unless map_location.try(:available?)
|
||||||
skip_map_error = I18n.t('activerecord.errors.models.map_location.attributes.map.invalid')
|
skip_map_error = I18n.t("activerecord.errors.models.map_location.attributes.map.invalid")
|
||||||
errors.add(:skip_map, skip_map_error)
|
errors.add(:skip_map, skip_map_error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ module Measurable
|
|||||||
class_methods do
|
class_methods do
|
||||||
|
|
||||||
def title_max_length
|
def title_max_length
|
||||||
@@title_max_length ||= (columns.find { |c| c.name == 'title' }.limit rescue nil) || 80
|
@@title_max_length ||= (columns.find { |c| c.name == "title" }.limit rescue nil) || 80
|
||||||
end
|
end
|
||||||
|
|
||||||
def responsible_name_max_length
|
def responsible_name_max_length
|
||||||
@@responsible_name_max_length ||= (columns.find { |c| c.name == 'responsible_name' }.limit rescue nil) || 60
|
@@responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }.limit rescue nil) || 60
|
||||||
end
|
end
|
||||||
|
|
||||||
def question_max_length
|
def question_max_length
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ module Searchable
|
|||||||
pg_search_scope :pg_search, {
|
pg_search_scope :pg_search, {
|
||||||
against: :ignored, # not used since using a tsvector_column
|
against: :ignored, # not used since using a tsvector_column
|
||||||
using: {
|
using: {
|
||||||
tsearch: { tsvector_column: 'tsv', dictionary: "spanish", prefix: true }
|
tsearch: { tsvector_column: "tsv", dictionary: "spanish", prefix: true }
|
||||||
},
|
},
|
||||||
ignoring: :accents,
|
ignoring: :accents,
|
||||||
ranked_by: '(:tsearch)',
|
ranked_by: "(:tsearch)",
|
||||||
order_within_rank: (column_names.include?('cached_votes_up') ? "#{table_name}.cached_votes_up DESC" : nil)
|
order_within_rank: (column_names.include?("cached_votes_up") ? "#{table_name}.cached_votes_up DESC" : nil)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
require_dependency Rails.root.join('app', 'models', 'verification', 'residence').to_s
|
require_dependency Rails.root.join("app", "models", "verification", "residence").to_s
|
||||||
|
|
||||||
class Verification::Residence
|
class Verification::Residence
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ class Verification::Residence
|
|||||||
validate :residence_in_madrid
|
validate :residence_in_madrid
|
||||||
|
|
||||||
def postal_code_in_madrid
|
def postal_code_in_madrid
|
||||||
errors.add(:postal_code, I18n.t('verification.residence.new.error_not_allowed_postal_code')) unless valid_postal_code?
|
errors.add(:postal_code, I18n.t("verification.residence.new.error_not_allowed_postal_code")) unless valid_postal_code?
|
||||||
end
|
end
|
||||||
|
|
||||||
def residence_in_madrid
|
def residence_in_madrid
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'numeric'
|
require "numeric"
|
||||||
class Debate < ActiveRecord::Base
|
class Debate < ActiveRecord::Base
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
include Flaggable
|
include Flaggable
|
||||||
@@ -18,7 +18,7 @@ class Debate < ActiveRecord::Base
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
@@ -60,11 +60,11 @@ class Debate < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
author.username => 'B',
|
author.username => "B",
|
||||||
tag_list.join(' ') => 'B',
|
tag_list.join(" ") => "B",
|
||||||
geozone.try(:name) => 'B',
|
geozone.try(:name) => "B",
|
||||||
description => 'D'
|
description => "D"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ class Debate < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def editable?
|
def editable?
|
||||||
total_votes <= Setting['max_votes_for_debate_edit'].to_i
|
total_votes <= Setting["max_votes_for_debate_edit"].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def editable_by?(user)
|
def editable_by?(user)
|
||||||
@@ -115,8 +115,8 @@ class Debate < ActiveRecord::Base
|
|||||||
return false unless user
|
return false unless user
|
||||||
total_votes <= 100 ||
|
total_votes <= 100 ||
|
||||||
!user.unverified? ||
|
!user.unverified? ||
|
||||||
Setting['max_ratio_anon_votes_on_debates'].to_i == 100 ||
|
Setting["max_ratio_anon_votes_on_debates"].to_i == 100 ||
|
||||||
anonymous_votes_ratio < Setting['max_ratio_anon_votes_on_debates'].to_i ||
|
anonymous_votes_ratio < Setting["max_ratio_anon_votes_on_debates"].to_i ||
|
||||||
user.voted_for?(self)
|
user.voted_for?(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -139,11 +139,11 @@ class Debate < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_hide
|
def after_hide
|
||||||
tags.each{ |t| t.decrement_custom_counter_for('Debate') }
|
tags.each{ |t| t.decrement_custom_counter_for("Debate") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_restore
|
def after_restore
|
||||||
tags.each{ |t| t.increment_custom_counter_for('Debate') }
|
tags.each{ |t| t.increment_custom_counter_for("Debate") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def featured?
|
def featured?
|
||||||
@@ -152,7 +152,7 @@ class Debate < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.debates_orders(user)
|
def self.debates_orders(user)
|
||||||
orders = %w{hot_score confidence_score created_at relevance}
|
orders = %w{hot_score confidence_score created_at relevance}
|
||||||
orders << "recommendations" if Setting['feature.user.recommendations_on_debates'] && user&.recommended_debates
|
orders << "recommendations" if Setting["feature.user.recommendations_on_debates"] && user&.recommended_debates
|
||||||
return orders
|
return orders
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class DirectMessage < ActiveRecord::Base
|
class DirectMessage < ActiveRecord::Base
|
||||||
belongs_to :sender, class_name: 'User', foreign_key: 'sender_id'
|
belongs_to :sender, class_name: "User", foreign_key: "sender_id"
|
||||||
belongs_to :receiver, class_name: 'User', foreign_key: 'receiver_id'
|
belongs_to :receiver, class_name: "User", foreign_key: "receiver_id"
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :body, presence: true
|
validates :body, presence: true
|
||||||
@@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base
|
|||||||
validates :receiver, presence: true
|
validates :receiver, presence: true
|
||||||
validate :max_per_day
|
validate :max_per_day
|
||||||
|
|
||||||
scope :today, lambda { where('DATE(created_at) = DATE(?)', Time.current) }
|
scope :today, lambda { where("DATE(created_at) = DATE(?)", Time.current) }
|
||||||
|
|
||||||
def max_per_day
|
def max_per_day
|
||||||
return if errors.any?
|
return if errors.any?
|
||||||
@@ -16,7 +16,7 @@ class DirectMessage < ActiveRecord::Base
|
|||||||
return unless max
|
return unless max
|
||||||
|
|
||||||
if sender.direct_messages_sent.today.count >= max.to_i
|
if sender.direct_messages_sent.today.count >= max.to_i
|
||||||
errors.add(:title, I18n.t('activerecord.errors.models.direct_message.attributes.max_per_day.invalid'))
|
errors.add(:title, I18n.t("activerecord.errors.models.direct_message.attributes.max_per_day.invalid"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class FailedCensusCall < ActiveRecord::Base
|
class FailedCensusCall < ActiveRecord::Base
|
||||||
belongs_to :user, counter_cache: true
|
belongs_to :user, counter_cache: true
|
||||||
belongs_to :poll_officer, class_name: 'Poll::Officer', counter_cache: true
|
belongs_to :poll_officer, class_name: "Poll::Officer", counter_cache: true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class Flag < ActiveRecord::Base
|
|||||||
flaggable_id: flaggable.id)
|
flaggable_id: flaggable.id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
scope :for_comments, ->(comments) { where(flaggable_type: 'Comment', flaggable_id: comments) }
|
scope :for_comments, ->(comments) { where(flaggable_type: "Comment", flaggable_id: comments) }
|
||||||
|
|
||||||
def self.flag(user, flaggable)
|
def self.flag(user, flaggable)
|
||||||
return false if flagged?(user, flaggable)
|
return false if flagged?(user, flaggable)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Geozone < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.city
|
def self.city
|
||||||
where(name: 'city').first
|
where(name: "city").first
|
||||||
end
|
end
|
||||||
|
|
||||||
def safe_to_destroy?
|
def safe_to_destroy?
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class I18nContent < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.flat_hash(input, path = nil, output = {})
|
def self.flat_hash(input, path = nil, output = {})
|
||||||
return output.update({ path => input }) unless input.is_a? Hash
|
return output.update({ path => input }) unless input.is_a? Hash
|
||||||
input.map { |key, value| flat_hash(value, [path, key].compact.join('.'), output) }
|
input.map { |key, value| flat_hash(value, [path, key].compact.join("."), output) }
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Legislation
|
module Legislation
|
||||||
def self.table_name_prefix
|
def self.table_name_prefix
|
||||||
'legislation_'
|
"legislation_"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class Legislation::Annotation < ActiveRecord::Base
|
|||||||
|
|
||||||
serialize :ranges, Array
|
serialize :ranges, Array
|
||||||
|
|
||||||
belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id'
|
belongs_to :draft_version, class_name: "Legislation::DraftVersion", foreign_key: "legislation_draft_version_id"
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
has_many :comments, as: :commentable, dependent: :destroy
|
has_many :comments, as: :commentable, dependent: :destroy
|
||||||
|
|
||||||
validates :text, presence: true
|
validates :text, presence: true
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ class Legislation::Answer < ActiveRecord::Base
|
|||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id',
|
belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id",
|
||||||
inverse_of: :answers, counter_cache: true
|
inverse_of: :answers, counter_cache: true
|
||||||
belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id',
|
belongs_to :question_option, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_option_id",
|
||||||
inverse_of: :answers, counter_cache: true
|
inverse_of: :answers, counter_cache: true
|
||||||
belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers
|
belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
|||||||
translates :toc_html, touch: true
|
translates :toc_html, touch: true
|
||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id"
|
||||||
has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy
|
has_many :annotations, class_name: "Legislation::Annotation", foreign_key: "legislation_draft_version_id", dependent: :destroy
|
||||||
|
|
||||||
validates_translation :title, presence: true
|
validates_translation :title, presence: true
|
||||||
validates_translation :body, presence: true
|
validates_translation :body, presence: true
|
||||||
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
|
||||||
|
|
||||||
scope :published, -> { where(status: 'published').order('id DESC') }
|
scope :published, -> { where(status: "published").order("id DESC") }
|
||||||
|
|
||||||
before_save :render_html
|
before_save :render_html
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class Legislation::DraftVersion < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def display_title
|
def display_title
|
||||||
status == 'draft' ? "#{title} *" : title
|
status == "draft" ? "#{title} *" : title
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_comments
|
def total_comments
|
||||||
|
|||||||
@@ -24,16 +24,16 @@ class Legislation::Process < ActiveRecord::Base
|
|||||||
|
|
||||||
CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i
|
CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i
|
||||||
|
|
||||||
has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion',
|
has_many :draft_versions, -> { order(:id) }, class_name: "Legislation::DraftVersion",
|
||||||
foreign_key: 'legislation_process_id',
|
foreign_key: "legislation_process_id",
|
||||||
dependent: :destroy
|
dependent: :destroy
|
||||||
has_one :final_draft_version, -> { where final_version: true, status: 'published' },
|
has_one :final_draft_version, -> { where final_version: true, status: "published" },
|
||||||
class_name: 'Legislation::DraftVersion',
|
class_name: "Legislation::DraftVersion",
|
||||||
foreign_key: 'legislation_process_id'
|
foreign_key: "legislation_process_id"
|
||||||
has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question',
|
has_many :questions, -> { order(:id) }, class_name: "Legislation::Question",
|
||||||
foreign_key: 'legislation_process_id', dependent: :destroy
|
foreign_key: "legislation_process_id", dependent: :destroy
|
||||||
has_many :proposals, -> { order(:id) }, class_name: 'Legislation::Proposal',
|
has_many :proposals, -> { order(:id) }, class_name: "Legislation::Proposal",
|
||||||
foreign_key: 'legislation_process_id', dependent: :destroy
|
foreign_key: "legislation_process_id", dependent: :destroy
|
||||||
|
|
||||||
validates_translation :title, presence: true
|
validates_translation :title, presence: true
|
||||||
validates :start_date, presence: true
|
validates :start_date, presence: true
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
acts_as_votable
|
acts_as_votable
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
|
|
||||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id"
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
@@ -59,13 +59,13 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
question => 'B',
|
question => "B",
|
||||||
author.username => 'B',
|
author.username => "B",
|
||||||
tag_list.join(' ') => 'B',
|
tag_list.join(" ") => "B",
|
||||||
geozone.try(:name) => 'B',
|
geozone.try(:name) => "B",
|
||||||
summary => 'C',
|
summary => "C",
|
||||||
description => 'D'}
|
description => "D"}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(terms)
|
def self.search(terms)
|
||||||
@@ -136,11 +136,11 @@ class Legislation::Proposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_hide
|
def after_hide
|
||||||
tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') }
|
tags.each{ |t| t.decrement_custom_counter_for("LegislationProposal") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_restore
|
def after_restore
|
||||||
tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') }
|
tags.each{ |t| t.increment_custom_counter_for("LegislationProposal") }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ class Legislation::Question < ActiveRecord::Base
|
|||||||
translates :title, touch: true
|
translates :title, touch: true
|
||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id"
|
||||||
|
|
||||||
has_many :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id',
|
has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id",
|
||||||
dependent: :destroy, inverse_of: :question
|
dependent: :destroy, inverse_of: :question
|
||||||
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question
|
||||||
has_many :comments, as: :commentable, dependent: :destroy
|
has_many :comments, as: :commentable, dependent: :destroy
|
||||||
|
|
||||||
accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true
|
accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true
|
||||||
@@ -19,7 +19,7 @@ class Legislation::Question < ActiveRecord::Base
|
|||||||
validates :process, presence: true
|
validates :process, presence: true
|
||||||
validates_translation :title, presence: true
|
validates_translation :title, presence: true
|
||||||
|
|
||||||
scope :sorted, -> { order('id ASC') }
|
scope :sorted, -> { order("id ASC") }
|
||||||
|
|
||||||
def next_question_id
|
def next_question_id
|
||||||
@next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first
|
@next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ class Legislation::QuestionOption < ActiveRecord::Base
|
|||||||
translates :value, touch: true
|
translates :value, touch: true
|
||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id", inverse_of: :question_options
|
||||||
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question
|
||||||
|
|
||||||
validates :question, presence: true
|
validates :question, presence: true
|
||||||
validates_translation :value, presence: true
|
validates_translation :value, presence: true
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class Officing::Residence
|
|||||||
verified_at: Time.current,
|
verified_at: Time.current,
|
||||||
erased_at: Time.current,
|
erased_at: Time.current,
|
||||||
password: random_password,
|
password: random_password,
|
||||||
terms_of_service: '1',
|
terms_of_service: "1",
|
||||||
email: nil
|
email: nil
|
||||||
}
|
}
|
||||||
self.user = User.create!(user_params)
|
self.user = User.create!(user_params)
|
||||||
@@ -75,7 +75,7 @@ class Officing::Residence
|
|||||||
return unless @census_api_response.valid?
|
return unless @census_api_response.valid?
|
||||||
|
|
||||||
unless allowed_age?
|
unless allowed_age?
|
||||||
errors.add(:year_of_birth, I18n.t('verification.residence.new.error_not_allowed_age'))
|
errors.add(:year_of_birth, I18n.t("verification.residence.new.error_not_allowed_age"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ class Officing::Residence
|
|||||||
end
|
end
|
||||||
|
|
||||||
def random_password
|
def random_password
|
||||||
(0...20).map { ('a'..'z').to_a[rand(26)] }.join
|
(0...20).map { ("a".."z").to_a[rand(26)] }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,11 +43,11 @@ class Organization < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.name_max_length
|
def self.name_max_length
|
||||||
@@name_max_length ||= columns.find { |c| c.name == 'name' }.limit || 60
|
@@name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.responsible_name_max_length
|
def self.responsible_name_max_length
|
||||||
@@responsible_name_max_length ||= columns.find { |c| c.name == 'responsible_name' }.limit || 60
|
@@responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ class Poll < ActiveRecord::Base
|
|||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
has_and_belongs_to_many :geozones
|
has_and_belongs_to_many :geozones
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
|
|
||||||
validates_translation :name, presence: true
|
validates_translation :name, presence: true
|
||||||
validate :date_range
|
validate :date_range
|
||||||
|
|
||||||
scope :current, -> { where('starts_at <= ? and ? <= ends_at', Date.current.beginning_of_day, Date.current.beginning_of_day) }
|
scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) }
|
||||||
scope :expired, -> { where('ends_at < ?', Date.current.beginning_of_day) }
|
scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) }
|
||||||
scope :recounting, -> { Poll.where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) }
|
scope :recounting, -> { Poll.where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) }
|
||||||
scope :published, -> { where('published = ?', true) }
|
scope :published, -> { where("published = ?", true) }
|
||||||
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
||||||
scope :public_for_api, -> { all }
|
scope :public_for_api, -> { all }
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class Poll < ActiveRecord::Base
|
|||||||
def self.answerable_by(user)
|
def self.answerable_by(user)
|
||||||
return none if user.nil? || user.unverified?
|
return none if user.nil? || user.unverified?
|
||||||
current.joins('LEFT JOIN "geozones_polls" ON "geozones_polls"."poll_id" = "polls"."id"')
|
current.joins('LEFT JOIN "geozones_polls" ON "geozones_polls"."poll_id" = "polls"."id"')
|
||||||
.where('geozone_restricted = ? OR geozones_polls.geozone_id = ?', false, user.geozone_id)
|
.where("geozone_restricted = ? OR geozones_polls.geozone_id = ?", false, user.geozone_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.votable_by(user)
|
def self.votable_by(user)
|
||||||
@@ -103,7 +103,7 @@ class Poll < ActiveRecord::Base
|
|||||||
|
|
||||||
def date_range
|
def date_range
|
||||||
unless starts_at.present? && ends_at.present? && starts_at <= ends_at
|
unless starts_at.present? && ends_at.present? && starts_at <= ends_at
|
||||||
errors.add(:starts_at, I18n.t('errors.messages.invalid_date_range'))
|
errors.add(:starts_at, I18n.t("errors.messages.invalid_date_range"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class Poll::Answer < ActiveRecord::Base
|
class Poll::Answer < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :question, -> { with_hidden }
|
belongs_to :question, -> { with_hidden }
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
|
|
||||||
delegate :poll, :poll_id, to: :question
|
delegate :poll, :poll_id, to: :question
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class Poll::PartialResult < ActiveRecord::Base
|
|||||||
VALID_ORIGINS = %w{web booth}
|
VALID_ORIGINS = %w{web booth}
|
||||||
|
|
||||||
belongs_to :question, -> { with_hidden }
|
belongs_to :question, -> { with_hidden }
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :booth_assignment
|
belongs_to :booth_assignment
|
||||||
belongs_to :officer_assignment
|
belongs_to :officer_assignment
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ class Poll::Question < ActiveRecord::Base
|
|||||||
include Globalizable
|
include Globalizable
|
||||||
|
|
||||||
belongs_to :poll
|
belongs_to :poll
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
has_many :answers, class_name: 'Poll::Answer'
|
has_many :answers, class_name: "Poll::Answer"
|
||||||
has_many :question_answers, -> { order 'given_order asc' }, class_name: 'Poll::Question::Answer'
|
has_many :question_answers, -> { order "given_order asc" }, class_name: "Poll::Question::Answer"
|
||||||
has_many :partial_results
|
has_many :partial_results
|
||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class Poll::Question < ActiveRecord::Base
|
|||||||
|
|
||||||
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
|
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
|
||||||
|
|
||||||
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
|
scope :sort_for_list, -> { order("poll_questions.proposal_id IS NULL", :created_at)}
|
||||||
scope :for_render, -> { includes(:author, :proposal) }
|
scope :for_render, -> { includes(:author, :proposal) }
|
||||||
|
|
||||||
def self.search(params)
|
def self.search(params)
|
||||||
@@ -34,10 +34,10 @@ class Poll::Question < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
proposal.try(:title) => 'A',
|
proposal.try(:title) => "A",
|
||||||
author.username => 'C',
|
author.username => "C",
|
||||||
author_visible_name => 'C' }
|
author_visible_name => "C" }
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_attributes_from_proposal(proposal)
|
def copy_attributes_from_proposal(proposal)
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class Poll::Question::Answer < ActiveRecord::Base
|
|||||||
accepted_content_types: [ "application/pdf" ]
|
accepted_content_types: [ "application/pdf" ]
|
||||||
accepts_nested_attributes_for :documents, allow_destroy: true
|
accepts_nested_attributes_for :documents, allow_destroy: true
|
||||||
|
|
||||||
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
|
belongs_to :question, class_name: "Poll::Question", foreign_key: "question_id"
|
||||||
has_many :videos, class_name: 'Poll::Question::Answer::Video'
|
has_many :videos, class_name: "Poll::Question::Answer::Video"
|
||||||
|
|
||||||
validates_translation :title, presence: true
|
validates_translation :title, presence: true
|
||||||
validates :given_order, presence: true, uniqueness: { scope: :question_id }
|
validates :given_order, presence: true, uniqueness: { scope: :question_id }
|
||||||
@@ -34,7 +34,7 @@ class Poll::Question::Answer < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.last_position(question_id)
|
def self.last_position(question_id)
|
||||||
where(question_id: question_id).maximum('given_order') || 0
|
where(question_id: question_id).maximum("given_order") || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_votes
|
def total_votes
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Poll::Question::Answer::Video < ActiveRecord::Base
|
class Poll::Question::Answer::Video < ActiveRecord::Base
|
||||||
belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id'
|
belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id"
|
||||||
|
|
||||||
VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
|
VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/
|
||||||
YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ class Poll::Recount < ActiveRecord::Base
|
|||||||
|
|
||||||
VALID_ORIGINS = %w{web booth letter}.freeze
|
VALID_ORIGINS = %w{web booth letter}.freeze
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :booth_assignment
|
belongs_to :booth_assignment
|
||||||
belongs_to :officer_assignment
|
belongs_to :officer_assignment
|
||||||
|
|
||||||
validates :author, presence: true
|
validates :author, presence: true
|
||||||
validates :origin, inclusion: {in: VALID_ORIGINS}
|
validates :origin, inclusion: {in: VALID_ORIGINS}
|
||||||
|
|
||||||
scope :web, -> { where(origin: 'web') }
|
scope :web, -> { where(origin: "web") }
|
||||||
scope :booth, -> { where(origin: 'booth') }
|
scope :booth, -> { where(origin: "booth") }
|
||||||
scope :letter, -> { where(origin: 'letter') }
|
scope :letter, -> { where(origin: "letter") }
|
||||||
|
|
||||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ class Poll
|
|||||||
|
|
||||||
enum task: { vote_collection: 0, recount_scrutiny: 1 }
|
enum task: { vote_collection: 0, recount_scrutiny: 1 }
|
||||||
|
|
||||||
scope :vote_collection, -> { where(task: 'vote_collection') }
|
scope :vote_collection, -> { where(task: "vote_collection") }
|
||||||
scope :recount_scrutiny, -> { where(task: 'recount_scrutiny') }
|
scope :recount_scrutiny, -> { where(task: "recount_scrutiny") }
|
||||||
scope :current, -> { where(date: Date.current) }
|
scope :current, -> { where(date: Date.current) }
|
||||||
|
|
||||||
before_create :persist_data
|
before_create :persist_data
|
||||||
|
|||||||
@@ -18,121 +18,121 @@ class Poll
|
|||||||
private
|
private
|
||||||
|
|
||||||
def total_participants
|
def total_participants
|
||||||
stats_cache('total_participants') { total_participants_web + total_participants_booth }
|
stats_cache("total_participants") { total_participants_web + total_participants_booth }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_participants_web
|
def total_participants_web
|
||||||
stats_cache('total_participants_web') { total_web_valid + total_web_white + total_web_null }
|
stats_cache("total_participants_web") { total_web_valid + total_web_white + total_web_null }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_participants_web_percentage
|
def total_participants_web_percentage
|
||||||
stats_cache('total_participants_web_percentage') do
|
stats_cache("total_participants_web_percentage") do
|
||||||
total_participants.zero? ? 0 : total_participants_web * 100 / total_participants
|
total_participants.zero? ? 0 : total_participants_web * 100 / total_participants
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_participants_booth
|
def total_participants_booth
|
||||||
stats_cache('total_participants_booth') { voters.where(origin: 'booth').count }
|
stats_cache("total_participants_booth") { voters.where(origin: "booth").count }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_participants_booth_percentage
|
def total_participants_booth_percentage
|
||||||
stats_cache('total_participants_booth_percentage') do
|
stats_cache("total_participants_booth_percentage") do
|
||||||
total_participants.zero? ? 0 : total_participants_booth * 100 / total_participants.to_f
|
total_participants.zero? ? 0 : total_participants_booth * 100 / total_participants.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_web_valid
|
def total_web_valid
|
||||||
stats_cache('total_web_valid') { voters.where(origin: 'web').count }
|
stats_cache("total_web_valid") { voters.where(origin: "web").count }
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_percentage_web
|
def valid_percentage_web
|
||||||
stats_cache('valid_percentage_web') do
|
stats_cache("valid_percentage_web") do
|
||||||
total_valid_votes.zero? ? 0 : total_web_valid * 100 / total_valid_votes.to_f
|
total_valid_votes.zero? ? 0 : total_web_valid * 100 / total_valid_votes.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_web_white
|
def total_web_white
|
||||||
stats_cache('total_web_white') { 0 }
|
stats_cache("total_web_white") { 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def white_percentage_web
|
def white_percentage_web
|
||||||
stats_cache('white_percentage_web') { 0 }
|
stats_cache("white_percentage_web") { 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_web_null
|
def total_web_null
|
||||||
stats_cache('total_web_null') { 0 }
|
stats_cache("total_web_null") { 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def null_percentage_web
|
def null_percentage_web
|
||||||
stats_cache('null_percentage_web') { 0 }
|
stats_cache("null_percentage_web") { 0 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_booth_valid
|
def total_booth_valid
|
||||||
stats_cache('total_booth_valid') { recounts.sum(:total_amount) }
|
stats_cache("total_booth_valid") { recounts.sum(:total_amount) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def valid_percentage_booth
|
def valid_percentage_booth
|
||||||
stats_cache('valid_percentage_booth') do
|
stats_cache("valid_percentage_booth") do
|
||||||
total_valid_votes.zero? ? 0 : total_booth_valid * 100 / total_valid_votes.to_f
|
total_valid_votes.zero? ? 0 : total_booth_valid * 100 / total_valid_votes.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_booth_white
|
def total_booth_white
|
||||||
stats_cache('total_booth_white') { recounts.sum(:white_amount) }
|
stats_cache("total_booth_white") { recounts.sum(:white_amount) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def white_percentage_booth
|
def white_percentage_booth
|
||||||
stats_cache('white_percentage_booth') do
|
stats_cache("white_percentage_booth") do
|
||||||
total_white_votes.zero? ? 0 : total_booth_white * 100 / total_white_votes.to_f
|
total_white_votes.zero? ? 0 : total_booth_white * 100 / total_white_votes.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_booth_null
|
def total_booth_null
|
||||||
stats_cache('total_booth_null') { recounts.sum(:null_amount) }
|
stats_cache("total_booth_null") { recounts.sum(:null_amount) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def null_percentage_booth
|
def null_percentage_booth
|
||||||
stats_cache('null_percentage_booth') do
|
stats_cache("null_percentage_booth") do
|
||||||
total_null_votes.zero? ? 0 : total_booth_null * 100 / total_null_votes.to_f
|
total_null_votes.zero? ? 0 : total_booth_null * 100 / total_null_votes.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_valid_votes
|
def total_valid_votes
|
||||||
stats_cache('total_valid_votes') { total_web_valid + total_booth_valid }
|
stats_cache("total_valid_votes") { total_web_valid + total_booth_valid }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_valid_percentage
|
def total_valid_percentage
|
||||||
stats_cache('total_valid_percentage') do
|
stats_cache("total_valid_percentage") do
|
||||||
total_participants.zero? ? 0 : total_valid_votes * 100 / total_participants.to_f
|
total_participants.zero? ? 0 : total_valid_votes * 100 / total_participants.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_white_votes
|
def total_white_votes
|
||||||
stats_cache('total_white_votes') { total_web_white + total_booth_white }
|
stats_cache("total_white_votes") { total_web_white + total_booth_white }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_white_percentage
|
def total_white_percentage
|
||||||
stats_cache('total_white_percentage') do
|
stats_cache("total_white_percentage") do
|
||||||
total_participants.zero? ? 0 : total_white_votes * 100 / total_participants.to_f
|
total_participants.zero? ? 0 : total_white_votes * 100 / total_participants.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_null_votes
|
def total_null_votes
|
||||||
stats_cache('total_null_votes') { total_web_null + total_booth_null }
|
stats_cache("total_null_votes") { total_web_null + total_booth_null }
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_null_percentage
|
def total_null_percentage
|
||||||
stats_cache('total_null_percentage') do
|
stats_cache("total_null_percentage") do
|
||||||
total_participants.zero? ? 0 : total_null_votes * 100 / total_participants.to_f
|
total_participants.zero? ? 0 : total_null_votes * 100 / total_participants.to_f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def voters
|
def voters
|
||||||
stats_cache('voters') { @poll.voters }
|
stats_cache("voters") { @poll.voters }
|
||||||
end
|
end
|
||||||
|
|
||||||
def recounts
|
def recounts
|
||||||
stats_cache('recounts') { @poll.recounts }
|
stats_cache("recounts") { @poll.recounts }
|
||||||
end
|
end
|
||||||
|
|
||||||
def stats_cache(key, &block)
|
def stats_cache(key, &block)
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class Poll
|
|||||||
|
|
||||||
before_validation :set_demographic_info, :set_document_info
|
before_validation :set_demographic_info, :set_document_info
|
||||||
|
|
||||||
scope :web, -> { where(origin: 'web') }
|
scope :web, -> { where(origin: "web") }
|
||||||
scope :booth, -> { where(origin: 'booth') }
|
scope :booth, -> { where(origin: "booth") }
|
||||||
|
|
||||||
def set_demographic_info
|
def set_demographic_info
|
||||||
return if user.blank?
|
return if user.blank?
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Proposal < ActiveRecord::Base
|
|||||||
|
|
||||||
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
|
RETIRE_OPTIONS = %w(duplicated started unfeasible done other)
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
has_many :comments, as: :commentable, dependent: :destroy
|
has_many :comments, as: :commentable, dependent: :destroy
|
||||||
has_many :proposal_notifications, dependent: :destroy
|
has_many :proposal_notifications, dependent: :destroy
|
||||||
@@ -95,13 +95,13 @@ class Proposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
question => 'B',
|
question => "B",
|
||||||
author.username => 'B',
|
author.username => "B",
|
||||||
tag_list.join(' ') => 'B',
|
tag_list.join(" ") => "B",
|
||||||
geozone.try(:name) => 'B',
|
geozone.try(:name) => "B",
|
||||||
summary => 'C',
|
summary => "C",
|
||||||
description => 'D'
|
description => "D"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -179,15 +179,15 @@ class Proposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def after_hide
|
def after_hide
|
||||||
tags.each{ |t| t.decrement_custom_counter_for('Proposal') }
|
tags.each{ |t| t.decrement_custom_counter_for("Proposal") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_restore
|
def after_restore
|
||||||
tags.each{ |t| t.increment_custom_counter_for('Proposal') }
|
tags.each{ |t| t.increment_custom_counter_for("Proposal") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.votes_needed_for_success
|
def self.votes_needed_for_success
|
||||||
Setting['votes_for_proposal_success'].to_i
|
Setting["votes_for_proposal_success"].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def successful?
|
def successful?
|
||||||
@@ -208,7 +208,7 @@ class Proposal < ActiveRecord::Base
|
|||||||
|
|
||||||
def self.proposals_orders(user)
|
def self.proposals_orders(user)
|
||||||
orders = %w{hot_score confidence_score created_at relevance archival_date}
|
orders = %w{hot_score confidence_score created_at relevance archival_date}
|
||||||
orders << "recommendations" if Setting['feature.user.recommendations_on_proposals'] && user&.recommended_proposals
|
orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals
|
||||||
return orders
|
return orders
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ class ProposalNotification < ActiveRecord::Base
|
|||||||
include Graphqlable
|
include Graphqlable
|
||||||
include Notifiable
|
include Notifiable
|
||||||
|
|
||||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
@@ -29,7 +29,7 @@ class ProposalNotification < ActiveRecord::Base
|
|||||||
interval = Setting[:proposal_notification_minimum_interval_in_days]
|
interval = Setting[:proposal_notification_minimum_interval_in_days]
|
||||||
minimum_interval = (Time.current - interval.to_i.days).to_datetime
|
minimum_interval = (Time.current - interval.to_i.days).to_datetime
|
||||||
if proposal.notifications.last.created_at > minimum_interval
|
if proposal.notifications.last.created_at > minimum_interval
|
||||||
errors.add(:title, I18n.t('activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid', interval: interval))
|
errors.add(:title, I18n.t("activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid", interval: interval))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ class ProposalNotification < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def moderate_system_email(moderator)
|
def moderate_system_email(moderator)
|
||||||
Notification.where(notifiable_type: 'ProposalNotification', notifiable: self).destroy_all
|
Notification.where(notifiable_type: "ProposalNotification", notifiable: self).destroy_all
|
||||||
Activity.log(moderator, :hide, self)
|
Activity.log(moderator, :hide, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
class RelatedContent < ActiveRecord::Base
|
class RelatedContent < ActiveRecord::Base
|
||||||
RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f
|
RELATED_CONTENT_SCORE_THRESHOLD = Setting["related_content_score_threshold"].to_f
|
||||||
RELATIONABLE_MODELS = %w{proposals debates budgets investments}.freeze
|
RELATIONABLE_MODELS = %w{proposals debates budgets investments}.freeze
|
||||||
|
|
||||||
acts_as_paranoid column: :hidden_at
|
acts_as_paranoid column: :hidden_at
|
||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :parent_relationable, polymorphic: true, touch: true
|
belongs_to :parent_relationable, polymorphic: true, touch: true
|
||||||
belongs_to :child_relationable, polymorphic: true, touch: true
|
belongs_to :child_relationable, polymorphic: true, touch: true
|
||||||
has_one :opposite_related_content, class_name: 'RelatedContent', foreign_key: :related_content_id
|
has_one :opposite_related_content, class_name: "RelatedContent", foreign_key: :related_content_id
|
||||||
has_many :related_content_scores
|
has_many :related_content_scores
|
||||||
|
|
||||||
validates :parent_relationable_id, presence: true
|
validates :parent_relationable_id, presence: true
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ class Setting < ActiveRecord::Base
|
|||||||
|
|
||||||
def type
|
def type
|
||||||
if feature_flag?
|
if feature_flag?
|
||||||
'feature'
|
"feature"
|
||||||
else
|
else
|
||||||
'common'
|
"common"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def feature_flag?
|
def feature_flag?
|
||||||
key.start_with?('feature.')
|
key.start_with?("feature.")
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class Signature < ActiveRecord::Base
|
|||||||
def assign_vote_to_user
|
def assign_vote_to_user
|
||||||
set_user
|
set_user
|
||||||
if signable.is_a? Budget::Investment
|
if signable.is_a? Budget::Investment
|
||||||
signable.vote_by(voter: user, vote: 'yes') if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user))
|
signable.vote_by(voter: user, vote: "yes") if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user))
|
||||||
else
|
else
|
||||||
signable.register_vote(user, "yes")
|
signable.register_vote(user, "yes")
|
||||||
end
|
end
|
||||||
@@ -49,7 +49,7 @@ class Signature < ActiveRecord::Base
|
|||||||
verified_at: Time.current,
|
verified_at: Time.current,
|
||||||
erased_at: Time.current,
|
erased_at: Time.current,
|
||||||
password: random_password,
|
password: random_password,
|
||||||
terms_of_service: '1',
|
terms_of_service: "1",
|
||||||
email: nil,
|
email: nil,
|
||||||
date_of_birth: @census_api_response.date_of_birth,
|
date_of_birth: @census_api_response.date_of_birth,
|
||||||
gender: @census_api_response.gender,
|
gender: @census_api_response.gender,
|
||||||
@@ -64,7 +64,7 @@ class Signature < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def random_password
|
def random_password
|
||||||
(0...20).map { ('a'..'z').to_a[rand(26)] }.join
|
(0...20).map { ("a".."z").to_a[rand(26)] }.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_census?
|
def in_census?
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class SignatureSheet < ActiveRecord::Base
|
class SignatureSheet < ActiveRecord::Base
|
||||||
belongs_to :signable, polymorphic: true
|
belongs_to :signable, polymorphic: true
|
||||||
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, class_name: "User", foreign_key: "author_id"
|
||||||
|
|
||||||
VALID_SIGNABLES = %w(Proposal Budget::Investment SpendingProposal)
|
VALID_SIGNABLES = %w(Proposal Budget::Investment SpendingProposal)
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class SignatureSheet < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parsed_document_numbers
|
def parsed_document_numbers
|
||||||
document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, '') }
|
document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, "") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def signable_found
|
def signable_found
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module SiteCustomization
|
module SiteCustomization
|
||||||
def self.table_name_prefix
|
def self.table_name_prefix
|
||||||
'site_customization_'
|
"site_customization_"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_votable
|
acts_as_votable
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
belongs_to :administrator
|
belongs_to :administrator
|
||||||
has_many :valuation_assignments, dependent: :destroy
|
has_many :valuation_assignments, dependent: :destroy
|
||||||
@@ -29,7 +29,7 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
scope :feasible, -> { where(feasible: true) }
|
scope :feasible, -> { where(feasible: true) }
|
||||||
scope :unfeasible, -> { where(feasible: false) }
|
scope :unfeasible, -> { where(feasible: false) }
|
||||||
scope :not_unfeasible, -> { where("feasible IS ? OR feasible = ?", nil, true) }
|
scope :not_unfeasible, -> { where("feasible IS ? OR feasible = ?", nil, true) }
|
||||||
scope :with_supports, -> { where('cached_votes_up > 0') }
|
scope :with_supports, -> { where("cached_votes_up > 0") }
|
||||||
|
|
||||||
scope :by_admin, ->(admin) { where(administrator_id: admin.presence) }
|
scope :by_admin, ->(admin) { where(administrator_id: admin.presence) }
|
||||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
|
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
|
||||||
@@ -58,10 +58,10 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def searchable_values
|
def searchable_values
|
||||||
{ title => 'A',
|
{ title => "A",
|
||||||
author.username => 'B',
|
author.username => "B",
|
||||||
geozone.try(:name) => 'B',
|
geozone.try(:name) => "B",
|
||||||
description => 'C'
|
description => "C"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.by_geozone(geozone)
|
def self.by_geozone(geozone)
|
||||||
if geozone == 'all'
|
if geozone == "all"
|
||||||
where(geozone_id: nil)
|
where(geozone_id: nil)
|
||||||
else
|
else
|
||||||
where(geozone_id: geozone.presence)
|
where(geozone_id: geozone.presence)
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ class TagCloud
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_blacklist
|
def default_blacklist
|
||||||
['']
|
[""]
|
||||||
end
|
end
|
||||||
|
|
||||||
def table_name
|
def table_name
|
||||||
resource_model.to_s.downcase.pluralize.gsub("::", "/")
|
resource_model.to_s.downcase.pluralize.gsub("::", "/")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class Topic < ActiveRecord::Base
|
|||||||
include Notifiable
|
include Notifiable
|
||||||
|
|
||||||
belongs_to :community
|
belongs_to :community
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id"
|
||||||
|
|
||||||
has_many :comments, as: :commentable
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ class User < ActiveRecord::Base
|
|||||||
has_many :identities, dependent: :destroy
|
has_many :identities, dependent: :destroy
|
||||||
has_many :debates, -> { with_hidden }, foreign_key: :author_id
|
has_many :debates, -> { with_hidden }, foreign_key: :author_id
|
||||||
has_many :proposals, -> { with_hidden }, foreign_key: :author_id
|
has_many :proposals, -> { with_hidden }, foreign_key: :author_id
|
||||||
has_many :budget_investments, -> { with_hidden }, foreign_key: :author_id, class_name: 'Budget::Investment'
|
has_many :budget_investments, -> { with_hidden }, foreign_key: :author_id, class_name: "Budget::Investment"
|
||||||
has_many :comments, -> { with_hidden }
|
has_many :comments, -> { with_hidden }
|
||||||
has_many :spending_proposals, foreign_key: :author_id
|
has_many :spending_proposals, foreign_key: :author_id
|
||||||
has_many :failed_census_calls
|
has_many :failed_census_calls
|
||||||
has_many :notifications
|
has_many :notifications
|
||||||
has_many :direct_messages_sent, class_name: 'DirectMessage', foreign_key: :sender_id
|
has_many :direct_messages_sent, class_name: "DirectMessage", foreign_key: :sender_id
|
||||||
has_many :direct_messages_received, class_name: 'DirectMessage', foreign_key: :receiver_id
|
has_many :direct_messages_received, class_name: "DirectMessage", foreign_key: :receiver_id
|
||||||
has_many :legislation_answers, class_name: 'Legislation::Answer', dependent: :destroy, inverse_of: :user
|
has_many :legislation_answers, class_name: "Legislation::Answer", dependent: :destroy, inverse_of: :user
|
||||||
has_many :follows
|
has_many :follows
|
||||||
belongs_to :geozone
|
belongs_to :geozone
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class User < ActiveRecord::Base
|
|||||||
email: oauth_email,
|
email: oauth_email,
|
||||||
oauth_email: oauth_email,
|
oauth_email: oauth_email,
|
||||||
password: Devise.friendly_token[0, 20],
|
password: Devise.friendly_token[0, 20],
|
||||||
terms_of_service: '1',
|
terms_of_service: "1",
|
||||||
confirmed_at: oauth_email_confirmed ? DateTime.current : nil
|
confirmed_at: oauth_email_confirmed ? DateTime.current : nil
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -177,7 +177,7 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def has_official_email?
|
def has_official_email?
|
||||||
domain = Setting['email_domain_for_officials']
|
domain = Setting["email_domain_for_officials"]
|
||||||
email.present? && ((email.end_with? "@#{domain}") || (email.end_with? ".#{domain}"))
|
email.present? && ((email.end_with? "@#{domain}") || (email.end_with? ".#{domain}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -251,11 +251,11 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.username_max_length
|
def self.username_max_length
|
||||||
@@username_max_length ||= columns.find { |c| c.name == 'username' }.limit || 60
|
@@username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.minimum_required_age
|
def self.minimum_required_age
|
||||||
(Setting['min_age_to_participate'] || 16).to_i
|
(Setting["min_age_to_participate"] || 16).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_welcome_screen?
|
def show_welcome_screen?
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ class Valuator < ActiveRecord::Base
|
|||||||
|
|
||||||
has_many :valuation_assignments, dependent: :destroy
|
has_many :valuation_assignments, dependent: :destroy
|
||||||
has_many :spending_proposals, through: :valuation_assignments
|
has_many :spending_proposals, through: :valuation_assignments
|
||||||
has_many :valuator_assignments, dependent: :destroy, class_name: 'Budget::ValuatorAssignment'
|
has_many :valuator_assignments, dependent: :destroy, class_name: "Budget::ValuatorAssignment"
|
||||||
has_many :investments, through: :valuator_assignments, class_name: 'Budget::Investment'
|
has_many :investments, through: :valuator_assignments, class_name: "Budget::Investment"
|
||||||
|
|
||||||
validates :user_id, presence: true, uniqueness: true
|
validates :user_id, presence: true, uniqueness: true
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class ValuatorGroup < ActiveRecord::Base
|
class ValuatorGroup < ActiveRecord::Base
|
||||||
has_many :valuators
|
has_many :valuators
|
||||||
has_many :valuator_group_assignments, dependent: :destroy, class_name: 'Budget::ValuatorGroupAssignment'
|
has_many :valuator_group_assignments, dependent: :destroy, class_name: "Budget::ValuatorGroupAssignment"
|
||||||
has_many :investments, through: :valuator_group_assignments, class_name: 'Budget::Investment'
|
has_many :investments, through: :valuator_group_assignments, class_name: "Budget::Investment"
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: true
|
validates :name, presence: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ class Verification::Letter
|
|||||||
|
|
||||||
def validate_existing_user
|
def validate_existing_user
|
||||||
unless user
|
unless user
|
||||||
errors.add(:email, I18n.t('devise.failure.invalid', authentication_keys: 'email'))
|
errors.add(:email, I18n.t("devise.failure.invalid", authentication_keys: "email"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_correct_code
|
def validate_correct_code
|
||||||
return if errors.include?(:verification_code)
|
return if errors.include?(:verification_code)
|
||||||
if user.try(:letter_verification_code).to_i != verification_code.to_i
|
if user.try(:letter_verification_code).to_i != verification_code.to_i
|
||||||
errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code'))
|
errors.add(:verification_code, I18n.t("verification.letter.errors.incorrect_code"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ class Verification::Management::Email
|
|||||||
def validate_user
|
def validate_user
|
||||||
return if errors.count > 0
|
return if errors.count > 0
|
||||||
if !user?
|
if !user?
|
||||||
errors.add(:email, I18n.t('errors.messages.user_not_found'))
|
errors.add(:email, I18n.t("errors.messages.user_not_found"))
|
||||||
elsif user.level_three_verified?
|
elsif user.level_three_verified?
|
||||||
errors.add(:email, I18n.t('management.email_verifications.already_verified'))
|
errors.add(:email, I18n.t("management.email_verifications.already_verified"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ class Verification::Management::Email
|
|||||||
return if errors.count > 0
|
return if errors.count > 0
|
||||||
if document_number_mismatch?
|
if document_number_mismatch?
|
||||||
errors.add(:email,
|
errors.add(:email,
|
||||||
I18n.t('management.email_verifications.document_mismatch',
|
I18n.t("management.email_verifications.document_mismatch",
|
||||||
document_type: ApplicationController.helpers.humanize_document_type(user.document_type),
|
document_type: ApplicationController.helpers.humanize_document_type(user.document_type),
|
||||||
document_number: user.document_number))
|
document_number: user.document_number))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ class Verification::Management::ManagedUser
|
|||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
def self.find(document_type, document_number)
|
def self.find(document_type, document_number)
|
||||||
User.where('document_number is not null').
|
User.where("document_number is not null").
|
||||||
find_or_initialize_by(document_type: document_type,
|
find_or_initialize_by(document_type: document_type,
|
||||||
document_number: document_number)
|
document_number: document_number)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ class Verification::Residence
|
|||||||
validate :document_number_uniqueness
|
validate :document_number_uniqueness
|
||||||
|
|
||||||
def initialize(attrs = {})
|
def initialize(attrs = {})
|
||||||
self.date_of_birth = parse_date('date_of_birth', attrs)
|
self.date_of_birth = parse_date("date_of_birth", attrs)
|
||||||
attrs = remove_date('date_of_birth', attrs)
|
attrs = remove_date("date_of_birth", attrs)
|
||||||
super
|
super
|
||||||
clean_document_number
|
clean_document_number
|
||||||
end
|
end
|
||||||
@@ -39,11 +39,11 @@ class Verification::Residence
|
|||||||
|
|
||||||
def allowed_age
|
def allowed_age
|
||||||
return if errors[:date_of_birth].any? || Age.in_years(date_of_birth) >= User.minimum_required_age
|
return if errors[:date_of_birth].any? || Age.in_years(date_of_birth) >= User.minimum_required_age
|
||||||
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age'))
|
errors.add(:date_of_birth, I18n.t("verification.residence.new.error_not_allowed_age"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def document_number_uniqueness
|
def document_number_uniqueness
|
||||||
errors.add(:document_number, I18n.t('errors.messages.taken')) if User.active.where(document_number: document_number).any?
|
errors.add(:document_number, I18n.t("errors.messages.taken")) if User.active.where(document_number: document_number).any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def store_failed_attempt
|
def store_failed_attempt
|
||||||
|
|||||||
Reference in New Issue
Block a user