Merge pull request #1482 from consul/signatures

Signature sheets for budget investments
This commit is contained in:
Enrique García
2017-04-05 14:07:36 +02:00
committed by GitHub
8 changed files with 141 additions and 73 deletions

View File

@@ -2,7 +2,7 @@ module SignatureSheetsHelper
def signable_options
[[t("activerecord.models.proposal", count: 1), Proposal],
[t("activerecord.models.spending_proposal", count: 1), SpendingProposal]]
[t("activerecord.models.budget/investment", count: 1), Budget::Investment]]
end
end

View File

@@ -12,35 +12,30 @@ class Signature < ActiveRecord::Base
before_validation :clean_document_number
def verified?
user_exists? || in_census?
end
def verify
if verified?
assign_vote
mark_as_verified
end
end
def assign_vote
if user_exists?
assign_vote_to_user
else
mark_as_verified
elsif in_census?
create_user
assign_vote_to_user
mark_as_verified
end
end
def assign_vote_to_user
set_user
signable.register_vote(user, "yes")
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))
else
signable.register_vote(user, "yes")
end
assign_signature_to_vote
end
def assign_signature_to_vote
vote = Vote.where(votable: signable, voter: user).first
vote.update(signature: self)
vote.update(signature: self) if vote
end
def user_exists?
@@ -55,7 +50,10 @@ class Signature < ActiveRecord::Base
erased_at: Time.now,
password: random_password,
terms_of_service: '1',
email: nil
email: nil,
date_of_birth: @census_api_response.date_of_birth,
gender: @census_api_response.gender,
geozone: Geozone.where(census_code: @census_api_response.district_code).first
}
User.create!(user_params)
end
@@ -70,10 +68,17 @@ class Signature < ActiveRecord::Base
end
def in_census?
response = document_types.detect do |document_type|
CensusApi.new.call(document_type, document_number).valid?
document_types.detect do |document_type|
response = CensusApi.new.call(document_type, document_number)
if response.valid?
@census_api_response = response
true
else
false
end
end
response.present?
@census_api_response.present?
end
def set_user

View File

@@ -2,7 +2,7 @@ class SignatureSheet < ActiveRecord::Base
belongs_to :signable, polymorphic: true
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
VALID_SIGNABLES = %w( Proposal SpendingProposal )
VALID_SIGNABLES = %w( Proposal Budget::Investment SpendingProposal )
has_many :signatures