Simplify Settings API
This commit is contained in:
@@ -75,7 +75,7 @@ class Debate < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes <= Setting.value_for('max_votes_for_debate_edit').to_i
|
||||
total_votes <= Setting['max_votes_for_debate_edit'].to_i
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
@@ -93,8 +93,8 @@ class Debate < ActiveRecord::Base
|
||||
return false unless user
|
||||
total_votes <= 100 ||
|
||||
!user.unverified? ||
|
||||
Setting.value_for('max_ratio_anon_votes_on_debates').to_i == 100 ||
|
||||
anonymous_votes_ratio < Setting.value_for('max_ratio_anon_votes_on_debates').to_i ||
|
||||
Setting['max_ratio_anon_votes_on_debates'].to_i == 100 ||
|
||||
anonymous_votes_ratio < Setting['max_ratio_anon_votes_on_debates'].to_i ||
|
||||
user.voted_for?(self)
|
||||
end
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def editable?
|
||||
total_votes <= Setting.value_for("max_votes_for_proposal_edit").to_i
|
||||
total_votes <= Setting["max_votes_for_proposal_edit"].to_i
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
@@ -98,7 +98,7 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def code
|
||||
"#{Setting.value_for("proposal_code_prefix")}-#{created_at.strftime('%Y-%m')}-#{id}"
|
||||
"#{Setting["proposal_code_prefix"]}-#{created_at.strftime('%Y-%m')}-#{id}"
|
||||
end
|
||||
|
||||
def after_commented
|
||||
@@ -129,7 +129,7 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.votes_needed_for_success
|
||||
Setting.value_for('votes_for_proposal_success').to_i
|
||||
Setting['votes_for_proposal_success'].to_i
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -3,7 +3,16 @@ class Setting < ActiveRecord::Base
|
||||
|
||||
default_scope { order(id: :asc) }
|
||||
|
||||
def self.value_for(key)
|
||||
where(key: key).pluck(:value).first
|
||||
class << self
|
||||
def [](key)
|
||||
where(key: key).pluck(:value).first
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
setting = where(key: key).first || new(key: key)
|
||||
setting.value = value
|
||||
setting.save!
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -202,7 +202,7 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def has_official_email?
|
||||
domain = Setting.value_for 'email_domain_for_officials'
|
||||
domain = Setting['email_domain_for_officials']
|
||||
!email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") )
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user