refactors signatures
This commit is contained in:
@@ -13,7 +13,7 @@ class Admin::SignatureSheetsController < Admin::BaseController
|
||||
@signature_sheet.author = current_user
|
||||
if @signature_sheet.save
|
||||
@signature_sheet.delay.verify_signatures
|
||||
redirect_to [:admin, @signature_sheet]
|
||||
redirect_to [:admin, @signature_sheet], notice: I18n.t('flash.actions.create.signature_sheet')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
|
||||
@@ -122,9 +122,9 @@ class Proposal < ActiveRecord::Base
|
||||
retired_at.present?
|
||||
end
|
||||
|
||||
def register_vote(user, vote_value, signature=nil)
|
||||
def register_vote(user, vote_value)
|
||||
if votable_by?(user) && !archived?
|
||||
vote_by(voter: user, vote: vote_value, vote_scope: signature)
|
||||
vote_by(voter: user, vote: vote_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,19 +10,16 @@ class Signature < ActiveRecord::Base
|
||||
|
||||
delegate :signable, to: :signature_sheet
|
||||
|
||||
before_save :verify
|
||||
|
||||
def verify
|
||||
if verified?
|
||||
assign_vote
|
||||
self.verified = true
|
||||
end
|
||||
end
|
||||
|
||||
def verified?
|
||||
user_exists? || in_census?
|
||||
end
|
||||
|
||||
def verify
|
||||
if verified?
|
||||
assign_vote
|
||||
mark_as_verified
|
||||
end
|
||||
end
|
||||
|
||||
def assign_vote
|
||||
if user_exists?
|
||||
@@ -34,16 +31,32 @@ class Signature < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def assign_vote_to_user
|
||||
signable.register_vote(user, "yes", "signature")
|
||||
set_user
|
||||
signable.register_vote(user, "yes")
|
||||
assign_signature_to_vote
|
||||
end
|
||||
|
||||
def assign_signature_to_vote
|
||||
vote = Vote.where(votable: signable, voter: user).first
|
||||
vote.update(signature: self)
|
||||
end
|
||||
|
||||
def user_exists?
|
||||
self.user = User.where(document_number: document_number).first
|
||||
self.user.present?
|
||||
User.where(document_number: document_number).any?
|
||||
end
|
||||
|
||||
def create_user
|
||||
user = User.where(document_number: document_number, erased_at: Time.now).create
|
||||
user_params = {
|
||||
document_number: document_number,
|
||||
created_from_signature: true,
|
||||
verified_at: Time.now,
|
||||
erased_at: Time.now,
|
||||
email: "#{document_number}@signatures.com",
|
||||
password: "12345678",
|
||||
username: document_number,
|
||||
terms_of_service: '1'
|
||||
}
|
||||
User.create(user_params)
|
||||
end
|
||||
|
||||
def in_census?
|
||||
@@ -52,6 +65,15 @@ class Signature < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def set_user
|
||||
user = User.where(document_number: document_number).first
|
||||
update(user: user)
|
||||
end
|
||||
|
||||
def mark_as_verified
|
||||
update(verified: true)
|
||||
end
|
||||
|
||||
def document_types
|
||||
%w(1 2 3 4)
|
||||
end
|
||||
|
||||
@@ -23,6 +23,7 @@ class SignatureSheet < ActiveRecord::Base
|
||||
def verify_signatures
|
||||
parsed_document_numbers.each do |document_number|
|
||||
signature = signatures.create(document_number: document_number)
|
||||
signature.verify
|
||||
end
|
||||
update(processed: true)
|
||||
end
|
||||
|
||||
@@ -133,9 +133,9 @@ class SpendingProposal < ActiveRecord::Base
|
||||
reason_for_not_being_votable_by(user).blank?
|
||||
end
|
||||
|
||||
def register_vote(user, vote_value, signature=nil)
|
||||
def register_vote(user, vote_value)
|
||||
if votable_by?(user)
|
||||
vote_by(voter: user, vote: vote_value, vote_scope: signature)
|
||||
vote_by(voter: user, vote: vote_value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<th><%= t("admin.signature_sheets.created_at") %></th>
|
||||
</tr>
|
||||
<% @signature_sheets.each do |signature_sheet| %>
|
||||
<tr id="<%= dom_id(signature_sheet) %>">
|
||||
<tr id="<%= dom_id(signature_sheet) %>" class="signature_sheet">
|
||||
<td>
|
||||
<%= link_to signature_sheet.name, [:admin, signature_sheet] %>
|
||||
</td>
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
</div>
|
||||
|
||||
<% if @signature_sheet.signatures.unverified.any? %>
|
||||
<div class="callout success">
|
||||
<div id="verified_signatures" class="callout success">
|
||||
<strong>
|
||||
<%= t("admin.signature_sheets.show.verified",
|
||||
count: @signature_sheet.signatures.verified.count ) %>
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div class="callout alert">
|
||||
<div id="unverified_signatures" class="callout alert">
|
||||
<p>
|
||||
<strong>
|
||||
<%= t("admin.signature_sheets.show.unverified",
|
||||
|
||||
@@ -308,7 +308,7 @@ en:
|
||||
title: New signature sheets
|
||||
signable_type: Type of signature sheet
|
||||
document_numbers_note: "Write the numbers separated by commas (,)"
|
||||
submit: Create signature sheets
|
||||
submit: Create signature sheet
|
||||
show:
|
||||
created_at: Created
|
||||
author: Author
|
||||
|
||||
@@ -9,7 +9,7 @@ en:
|
||||
proposal: "Proposal created successfully."
|
||||
proposal_notification: "Your message has been sent correctly."
|
||||
spending_proposal: "Spending proposal created successfully. You can access it from %{activity}"
|
||||
|
||||
signature_sheet: "Signature sheet created successfully"
|
||||
save_changes:
|
||||
notice: Changes saved
|
||||
update:
|
||||
|
||||
@@ -9,6 +9,7 @@ es:
|
||||
proposal: "Propuesta creada correctamente."
|
||||
proposal_notification: "Tu message ha sido enviado correctamente."
|
||||
spending_proposal: "Propuesta de inversión creada correctamente. Puedes acceder a ella desde %{activity}"
|
||||
signature_sheet: "Hoja de firmas creada correctamente"
|
||||
save_changes:
|
||||
notice: Cambios guardados
|
||||
update:
|
||||
|
||||
5
db/migrate/20161221131403_add_signture_id_to_votes.rb
Normal file
5
db/migrate/20161221131403_add_signture_id_to_votes.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddSigntureIdToVotes < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :votes, :signature, index: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCreatedFromSignatureToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :created_from_signature, :boolean, default: false
|
||||
end
|
||||
end
|
||||
92
db/schema.rb
92
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
ActiveRecord::Schema.define(version: 20161221151239) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -211,6 +211,14 @@ ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
t.string "census_code"
|
||||
end
|
||||
|
||||
create_table "geozones_poll_questions", force: :cascade do |t|
|
||||
t.integer "geozone_id"
|
||||
t.integer "question_id"
|
||||
end
|
||||
|
||||
add_index "geozones_poll_questions", ["geozone_id"], name: "index_geozones_poll_questions_on_geozone_id", using: :btree
|
||||
add_index "geozones_poll_questions", ["question_id"], name: "index_geozones_poll_questions_on_question_id", using: :btree
|
||||
|
||||
create_table "identities", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.string "provider"
|
||||
@@ -270,6 +278,78 @@ ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
|
||||
add_index "organizations", ["user_id"], name: "index_organizations_on_user_id", using: :btree
|
||||
|
||||
create_table "poll_booth_assignments", force: :cascade do |t|
|
||||
t.integer "booth_id"
|
||||
t.integer "poll_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "poll_booths", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "location"
|
||||
end
|
||||
|
||||
create_table "poll_officer_assignments", force: :cascade do |t|
|
||||
t.integer "booth_assignment_id"
|
||||
t.integer "officer_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "poll_officers", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
create_table "poll_partial_results", force: :cascade do |t|
|
||||
t.integer "question_id"
|
||||
t.integer "author_id"
|
||||
t.string "answer"
|
||||
t.integer "amount"
|
||||
t.string "origin"
|
||||
end
|
||||
|
||||
add_index "poll_partial_results", ["answer"], name: "index_poll_partial_results_on_answer", using: :btree
|
||||
add_index "poll_partial_results", ["author_id"], name: "index_poll_partial_results_on_author_id", using: :btree
|
||||
add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree
|
||||
add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree
|
||||
|
||||
create_table "poll_questions", force: :cascade do |t|
|
||||
t.integer "proposal_id"
|
||||
t.integer "poll_id"
|
||||
t.integer "author_id"
|
||||
t.string "author_visible_name"
|
||||
t.string "title"
|
||||
t.string "summary"
|
||||
t.string "valid_answers"
|
||||
t.text "description"
|
||||
t.integer "comments_count"
|
||||
t.datetime "hidden_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "all_geozones", default: false
|
||||
t.tsvector "tsv"
|
||||
end
|
||||
|
||||
add_index "poll_questions", ["author_id"], name: "index_poll_questions_on_author_id", using: :btree
|
||||
add_index "poll_questions", ["poll_id"], name: "index_poll_questions_on_poll_id", using: :btree
|
||||
add_index "poll_questions", ["proposal_id"], name: "index_poll_questions_on_proposal_id", using: :btree
|
||||
add_index "poll_questions", ["tsv"], name: "index_poll_questions_on_tsv", using: :gin
|
||||
|
||||
create_table "poll_voters", force: :cascade do |t|
|
||||
t.string "document_number"
|
||||
t.string "document_type"
|
||||
t.integer "booth_assignment_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "polls", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "starts_at"
|
||||
t.datetime "ends_at"
|
||||
end
|
||||
|
||||
create_table "proposal_notifications", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
@@ -484,6 +564,7 @@ ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
t.boolean "email_on_direct_message", default: true
|
||||
t.boolean "official_position_badge", default: false
|
||||
t.datetime "password_changed_at", default: '2016-11-02 13:51:14', null: false
|
||||
t.boolean "created_from_signature", default: false
|
||||
end
|
||||
|
||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
||||
@@ -563,8 +644,10 @@ ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
t.integer "vote_weight"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "signature_id"
|
||||
end
|
||||
|
||||
add_index "votes", ["signature_id"], name: "index_votes_on_signature_id", using: :btree
|
||||
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
|
||||
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
||||
|
||||
@@ -573,12 +656,19 @@ ActiveRecord::Schema.define(version: 20161214233817) do
|
||||
add_foreign_key "annotations", "users"
|
||||
add_foreign_key "failed_census_calls", "users"
|
||||
add_foreign_key "flags", "users"
|
||||
add_foreign_key "geozones_poll_questions", "geozones"
|
||||
add_foreign_key "geozones_poll_questions", "poll_questions", column: "question_id"
|
||||
add_foreign_key "identities", "users"
|
||||
add_foreign_key "locks", "users"
|
||||
add_foreign_key "managers", "users"
|
||||
add_foreign_key "moderators", "users"
|
||||
add_foreign_key "notifications", "users"
|
||||
add_foreign_key "organizations", "users"
|
||||
add_foreign_key "poll_partial_results", "poll_questions", column: "question_id"
|
||||
add_foreign_key "poll_partial_results", "users", column: "author_id"
|
||||
add_foreign_key "poll_questions", "polls"
|
||||
add_foreign_key "poll_questions", "proposals"
|
||||
add_foreign_key "poll_questions", "users", column: "author_id"
|
||||
add_foreign_key "users", "geozones"
|
||||
add_foreign_key "valuators", "users"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user