Merge branch 'budget' into budget-public-controllers
This commit is contained in:
@@ -42,7 +42,9 @@ module Abilities
|
||||
|
||||
can [:read, :update, :valuate, :destroy, :summary], SpendingProposal
|
||||
|
||||
can [:create, :update], Budget
|
||||
can [:index, :read, :new, :create, :update, :destroy], Budget
|
||||
can [:read, :create, :update, :destroy], Budget::Group
|
||||
can [:read, :create, :update, :destroy], Budget::Heading
|
||||
can [:hide, :update], Budget::Investment
|
||||
can :valuate, Budget::Investment, budget: { valuating: true }
|
||||
can :create, Budget::ValuatorAssignment
|
||||
|
||||
@@ -3,7 +3,9 @@ class Budget < ActiveRecord::Base
|
||||
include Sanitizable
|
||||
|
||||
VALID_PHASES = %W{on_hold accepting selecting balloting finished}
|
||||
CURRENCY_SYMBOLS = %W{€ $ £ ¥}
|
||||
|
||||
validates :name, presence: true
|
||||
validates :phase, inclusion: { in: VALID_PHASES }
|
||||
validates :currency_symbol, presence: true
|
||||
|
||||
@@ -13,6 +15,9 @@ class Budget < ActiveRecord::Base
|
||||
has_many :headings, through: :groups
|
||||
has_many :investments, through: :headings
|
||||
|
||||
scope :open, -> { where.not(phase: "finished") }
|
||||
scope :finished, -> { where(phase: "finished") }
|
||||
|
||||
def on_hold?
|
||||
phase == "on_hold"
|
||||
end
|
||||
|
||||
0
app/models/custom/.keep
Normal file
0
app/models/custom/.keep
Normal file
29
app/models/custom/verification/residence.rb
Normal file
29
app/models/custom/verification/residence.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
require_dependency Rails.root.join('app', 'models', 'verification', 'residence').to_s
|
||||
|
||||
class Verification::Residence
|
||||
|
||||
validate :postal_code_in_madrid
|
||||
validate :residence_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?
|
||||
end
|
||||
|
||||
def residence_in_madrid
|
||||
return if errors.any?
|
||||
|
||||
unless residency_valid?
|
||||
errors.add(:residence_in_madrid, false)
|
||||
store_failed_attempt
|
||||
Lock.increase_tries(user)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid_postal_code?
|
||||
postal_code =~ /^280/
|
||||
end
|
||||
|
||||
end
|
||||
@@ -2,9 +2,11 @@ class Notification < ActiveRecord::Base
|
||||
belongs_to :user, counter_cache: true
|
||||
belongs_to :notifiable, polymorphic: true
|
||||
|
||||
scope :unread, -> { all }
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
scope :for_render, -> { includes(:notifiable) }
|
||||
scope :unread, -> { all }
|
||||
scope :recent, -> { order(id: :desc) }
|
||||
scope :not_emailed, -> { where(emailed_at: nil) }
|
||||
scope :for_render, -> { includes(:notifiable) }
|
||||
|
||||
|
||||
def timestamp
|
||||
notifiable.created_at
|
||||
|
||||
@@ -95,7 +95,7 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def voters
|
||||
votes_for.voters
|
||||
User.active.where(id: votes_for.voters)
|
||||
end
|
||||
|
||||
def editable?
|
||||
|
||||
@@ -53,6 +53,7 @@ class User < ActiveRecord::Base
|
||||
scope :for_render, -> { includes(:organization) }
|
||||
scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }
|
||||
scope :email_digest, -> { where(email_digest: true) }
|
||||
scope :active, -> { where(erased_at: nil) }
|
||||
|
||||
before_validation :clean_document_number
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ class Verification::Residence
|
||||
|
||||
validate :allowed_age
|
||||
validate :document_number_uniqueness
|
||||
validate :postal_code_in_madrid
|
||||
validate :residence_in_madrid
|
||||
|
||||
def initialize(attrs={})
|
||||
self.date_of_birth = parse_date('date_of_birth', attrs)
|
||||
@@ -45,20 +43,6 @@ class Verification::Residence
|
||||
errors.add(:document_number, I18n.t('errors.messages.taken')) if User.where(document_number: document_number).any?
|
||||
end
|
||||
|
||||
def postal_code_in_madrid
|
||||
errors.add(:postal_code, I18n.t('verification.residence.new.error_not_allowed_postal_code')) unless valid_postal_code?
|
||||
end
|
||||
|
||||
def residence_in_madrid
|
||||
return if errors.any?
|
||||
|
||||
unless residency_valid?
|
||||
errors.add(:residence_in_madrid, false)
|
||||
store_failed_attempt
|
||||
Lock.increase_tries(user)
|
||||
end
|
||||
end
|
||||
|
||||
def store_failed_attempt
|
||||
FailedCensusCall.create({
|
||||
user: user,
|
||||
@@ -97,8 +81,4 @@ class Verification::Residence
|
||||
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?
|
||||
end
|
||||
|
||||
def valid_postal_code?
|
||||
postal_code =~ /^280/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user