diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index e5e6562d3..0ef13f01a 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -901,16 +901,12 @@ img.avatar, img.admin-avatar, img.moderator-avatar, img.initialjs-avatar { } .author-deleted, .user-deleted { - background-color: rgba(255,255,255,.5); color: rgba(0,0,0,.4); - font-size: rem-calc(40); - left: 11px; - position: absolute; - top: 72px; -} - -.user-deleted { - top: -4px; + display: inline-block; + font-size: rem-calc(32); + line-height: rem-calc(32); + height: rem-calc(32); + vertical-align: top; } .user-permissions { @@ -1069,10 +1065,6 @@ img.avatar, img.admin-avatar, img.moderator-avatar, img.initialjs-avatar { background: #C0392B; } -.is-deleted { - background: #E7E7E7; -} - .level-1 { background: #1ABC9C; } @@ -1601,7 +1593,10 @@ table { } .comment-body { - margin-left: rem-calc(42); + + img { + margin-right: $line-height/2; + } .reply { background: white; @@ -1609,20 +1604,28 @@ table { border-left: 0; border-right: 0; font-size: $small-font-size; - margin: rem-calc(6) 0; - padding: rem-calc(6); + margin: $line-height/4 0; + padding: $line-height/4; position: relative; + a.relative, [class^="icon-arrow"] { + padding-left: $line-height/2; + } + [class^="icon-arrow"] { - font-size: rem-calc(18); + font-size: $base-font-size; left: -20px; position: absolute; - top: 0; + top: -1px; } .divider { color: $text-light; } + + form { + margin-top: $line-height/2; + } } .comment-user { @@ -1650,27 +1653,19 @@ table { } } - .is-deleted { - background: #E7E7E7; - margin-left: rem-calc(42); - padding: $line-height/4 $line-height/2; - } - .comment-children { border-left: 1px dashed $border; - margin-left: rem-calc(42); - padding-left: $line-height/4; - - @media only screen and (max-width: 40em) { - margin-left: rem-calc(16); - } + display: inline-block; + margin-left: rem-calc(16); + padding-left: rem-calc(8); + width: 100%; } .comment-info { color: $text-medium; + display: inline-block; font-size: $small-font-size; - margin-top: $line-height/4; - vertical-align: middle; + line-height: rem-calc(32); // Same as avatar height span.user-name { color: $text; @@ -1703,6 +1698,11 @@ table { } } +.comment-form { + display: inline-block; + width: 100%; +} + // 16. Flags // --------- diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a5e1d7df2..143595de7 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -325,9 +325,13 @@ clear: both; color: $text-medium; font-size: $small-font-size; - min-height: $line-height*2; + margin-bottom: $line-height/2; position: relative; + span { + line-height: rem-calc(32); // Same as avatar height + } + a { color: $text-medium; } @@ -337,15 +341,6 @@ line-height: $line-height; margin: 0; } - - .author-deleted { - left: 0; - top: 4px; - } - - .author.deleted { - margin-left: rem-calc(48); - } } .debate-description, .proposal-description { @@ -370,9 +365,9 @@ } .author-photo { - line-height: $line-height*2; + line-height: rem-calc(32); margin-right: rem-calc(6); - vertical-align: middle; + vertical-align: top; width: 32px; } diff --git a/app/controllers/admin/signature_sheets_controller.rb b/app/controllers/admin/signature_sheets_controller.rb new file mode 100644 index 000000000..60299c5a6 --- /dev/null +++ b/app/controllers/admin/signature_sheets_controller.rb @@ -0,0 +1,32 @@ +class Admin::SignatureSheetsController < Admin::BaseController + + def index + @signature_sheets = SignatureSheet.all + end + + def new + @signature_sheet = SignatureSheet.new + end + + def create + @signature_sheet = SignatureSheet.new(signature_sheet_params) + @signature_sheet.author = current_user + if @signature_sheet.save + @signature_sheet.delay.verify_signatures + redirect_to [:admin, @signature_sheet], notice: I18n.t('flash.actions.create.signature_sheet') + else + render :new + end + end + + def show + @signature_sheet = SignatureSheet.find(params[:id]) + end + + private + + def signature_sheet_params + params.require(:signature_sheet).permit(:signable_type, :signable_id, :document_numbers) + end + +end \ No newline at end of file diff --git a/app/helpers/signature_sheets_helper.rb b/app/helpers/signature_sheets_helper.rb new file mode 100644 index 000000000..acd75a5ab --- /dev/null +++ b/app/helpers/signature_sheets_helper.rb @@ -0,0 +1,8 @@ +module SignatureSheetsHelper + + def signable_options + [[t("activerecord.models.proposal", count: 1), Proposal], + [t("activerecord.models.spending_proposal", count: 1), SpendingProposal]] + end + +end \ No newline at end of file diff --git a/app/models/proposal.rb b/app/models/proposal.rb index ad51436b0..6ddcf7085 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -51,7 +51,7 @@ class Proposal < ActiveRecord::Base scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} scope :retired, -> { where.not(retired_at: nil) } scope :not_retired, -> { where(retired_at: nil) } - scope :successfull, -> { where("cached_votes_up + physical_votes >= ?", Proposal.votes_needed_for_success)} + scope :successfull, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success)} def to_param "#{id}-#{title}".parameterize @@ -100,7 +100,7 @@ class Proposal < ActiveRecord::Base end def total_votes - cached_votes_up + physical_votes + cached_votes_up end def voters diff --git a/app/models/signature.rb b/app/models/signature.rb new file mode 100644 index 000000000..06ade968c --- /dev/null +++ b/app/models/signature.rb @@ -0,0 +1,92 @@ +class Signature < ActiveRecord::Base + belongs_to :signature_sheet + belongs_to :user + + validates :document_number, presence: true + validates :signature_sheet, presence: true + + scope :verified, -> { where(verified: true) } + scope :unverified, -> { where(verified: false) } + + delegate :signable, to: :signature_sheet + + 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 + create_user + assign_vote_to_user + end + end + + def assign_vote_to_user + 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? + User.where(document_number: document_number).any? + end + + def create_user + user_params = { + document_number: document_number, + created_from_signature: true, + verified_at: Time.now, + erased_at: Time.now, + password: random_password, + terms_of_service: '1', + email: nil + } + User.create!(user_params) + end + + def clean_document_number + return if self.document_number.blank? + self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase + end + + def random_password + (0...20).map { ('a'..'z').to_a[rand(26)] }.join + end + + def in_census? + response = document_types.detect do |document_type| + CensusApi.new.call(document_type, document_number).valid? + end + response.present? + 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 + +end \ No newline at end of file diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb new file mode 100644 index 000000000..9720c891f --- /dev/null +++ b/app/models/signature_sheet.rb @@ -0,0 +1,38 @@ +class SignatureSheet < ActiveRecord::Base + belongs_to :signable, polymorphic: true + belongs_to :author, class_name: 'User', foreign_key: 'author_id' + + VALID_SIGNABLES = %w( Proposal SpendingProposal ) + + has_many :signatures + + validates :author, presence: true + validates :signable_type, inclusion: {in: VALID_SIGNABLES} + validates :document_numbers, presence: true + validates :signable, presence: true + validate :signable_found + + def name + "#{signable_name} #{signable_id}" + end + + def signable_name + I18n.t("activerecord.models.#{signable_type.underscore}", count: 1) + end + + def verify_signatures + parsed_document_numbers.each do |document_number| + signature = self.signatures.where(document_number: document_number).first_or_create + signature.verify + end + update(processed: true) + end + + def parsed_document_numbers + document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, '') } + end + + def signable_found + errors.add(:signable_id, :not_found) if errors.messages[:signable].present? + end +end \ No newline at end of file diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 3d3e807c7..3cdb057fb 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -35,6 +35,14 @@ <% end %> + <% if feature?(:signature_sheets) %> +
| <%= t("admin.signature_sheets.name") %> | +<%= t("admin.signature_sheets.author") %> | +<%= t("admin.signature_sheets.created_at") %> | +
|---|---|---|
| + <%= link_to signature_sheet.name, [:admin, signature_sheet] %> + | ++ <%= signature_sheet.author.name %> + | ++ <%= l(signature_sheet.created_at, format: :short) %> + | +
<%= t("admin.signature_sheets.new.document_numbers_note") %>
+ <%= f.text_area :document_numbers, rows: "6", label: false %> + + <%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %> +<% end %> \ No newline at end of file diff --git a/app/views/admin/signature_sheets/show.html.erb b/app/views/admin/signature_sheets/show.html.erb new file mode 100644 index 000000000..0c2536b34 --- /dev/null +++ b/app/views/admin/signature_sheets/show.html.erb @@ -0,0 +1,44 @@ +<%= t("admin.signature_sheets.show.documents") %>
+ <%= simple_format @signature_sheet.document_numbers %> ++ + <%= t("admin.signature_sheets.show.unverified", + count: @signature_sheet.signatures.unverified.count ) %> + <%= t("admin.signature_sheets.show.unverified_error") %> + +
+ <%= @signature_sheet.signatures.unverified.map(&:document_number).join(", ") %> +<%= t("comments.comment.deleted") %>
<% child_comments_of(comment).each do |child| %> - <%= render 'comments/comment', comment: child %> +-
+ <%= render 'comments/comment', comment: child %>
+
<% end %>
- -