Merge branch 'master' into api-dev-0.18.11

This commit is contained in:
Alberto Miedes Garcés
2017-01-04 16:21:32 +01:00
63 changed files with 964 additions and 165 deletions

View File

@@ -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
// ---------

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

92
app/models/signature.rb Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -35,6 +35,14 @@
</li>
<% end %>
<% if feature?(:signature_sheets) %>
<li <%= "class=active" if controller_name == "signature_sheets" %>>
<%= link_to admin_signature_sheets_path do %>
<span class="icon-budget"></span><%= t("admin.menu.signature_sheets") %>
<% end %>
</li>
<% end %>
<li <%= "class=active" if controller_name == "banners" %>>
<%= link_to admin_banners_path do %>
<span class="icon-eye"></span><%= t("admin.menu.banner") %>

View File

@@ -0,0 +1,31 @@
<h2 class="inline-block"><%= t("admin.signature_sheets.index.title") %></h2>
<%= link_to t("admin.signature_sheets.index.new"), new_admin_signature_sheet_path,
class: "button success float-right" %>
<% if @signature_sheets.any? %>
<table>
<tr>
<th><%= t("admin.signature_sheets.name") %></th>
<th><%= t("admin.signature_sheets.author") %></th>
<th><%= t("admin.signature_sheets.created_at") %></th>
</tr>
<% @signature_sheets.each do |signature_sheet| %>
<tr id="<%= dom_id(signature_sheet) %>" class="signature_sheet">
<td>
<%= link_to signature_sheet.name, [:admin, signature_sheet] %>
</td>
<td>
<%= signature_sheet.author.name %>
</td>
<td>
<%= l(signature_sheet.created_at, format: :short) %>
</td>
</tr>
<% end %>
</table>
<% else %>
<div class="callout primary margin-top">
<%= t("admin.signature_sheets.no_signature_sheets") %>
</div>
<% end %>

View File

@@ -0,0 +1,22 @@
<%= render 'shared/back_link' %>
<h2><%= t("admin.signature_sheets.new.title") %></h2>
<%= form_for [:admin, @signature_sheet] do |f| %>
<%= render 'shared/errors',
resource: @signature_sheet %>
<div class="small-12 medium-6 large-4">
<%= f.select :signable_type, signable_options %>
</div>
<div class="small-12 medium-6 large-4">
<%= f.text_field :signable_id %>
</div>
<%= f.label :document_numbers %>
<p class="note"><%= t("admin.signature_sheets.new.document_numbers_note") %></p>
<%= f.text_area :document_numbers, rows: "6", label: false %>
<%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %>
<% end %>

View File

@@ -0,0 +1,44 @@
<h2 class="inline-block"><%= @signature_sheet.name %></h2>
<div class="callout secondary float-right">
<%= t("admin.signature_sheets.show.created_at") %>
<strong><%= l(@signature_sheet.created_at, format: :short) %></strong>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= t("admin.signature_sheets.show.author") %>
<strong><%= @signature_sheet.author.name %></strong>
</div>
<h3 id="document_count" class="block">
<%= t("admin.signature_sheets.show.document_count") %>
<%= @signature_sheet.signatures.count %>
</h3>
<div class="callout margin-top">
<p><strong><%= t("admin.signature_sheets.show.documents") %></strong></p>
<%= simple_format @signature_sheet.document_numbers %>
</div>
<div id="verified_signatures" class="callout success">
<strong>
<%= t("admin.signature_sheets.show.verified",
count: @signature_sheet.signatures.verified.count ) %>
</strong>
</div>
<div id="unverified_signatures" class="callout alert">
<p>
<strong>
<%= t("admin.signature_sheets.show.unverified",
count: @signature_sheet.signatures.unverified.count ) %>
<%= t("admin.signature_sheets.show.unverified_error") %>
</strong>
</p>
<%= @signature_sheet.signatures.unverified.map(&:document_number).join(", ") %>
</div>
<% unless @signature_sheet.processed? %>
<div class="callout primary margin-top">
<%= t("admin.signature_sheets.show.loading") %>
</div>
<% end %>

View File

@@ -1,10 +1,9 @@
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
<div class="row">
<ul id="<%= dom_id(comment) %>" class="comment no-bullet small-12 column">
<ul id="<%= dom_id(comment) %>" class="comment no-bullet small-12">
<li class="comment-body">
<% if comment.hidden? || comment.user.hidden? %>
<% if comment.children.size > 0 %>
<div class="is-deleted">
<div class="callout secondary">
<p><%= t("comments.comment.deleted") %></p>
</div>
<% end %>
@@ -23,82 +22,84 @@
<% end %>
<% end %>
<li class="comment-body">
<div class="comment-info">
<div class="comment-info">
<% if comment.as_administrator? %>
<span class="user-name"><%= t("comments.comment.admin") %> #<%= comment.administrator_id%></span>
<% elsif comment.as_moderator? %>
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id%></span>
<% if comment.as_administrator? %>
<span class="user-name"><%= t("comments.comment.admin") %> #<%= comment.administrator_id%></span>
<% elsif comment.as_moderator? %>
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id%></span>
<% else %>
<% if comment.user.hidden? || comment.user.erased? %>
<span class="user-name"><%= t("comments.comment.user_deleted") %></span>
<% else %>
<% if comment.user.hidden? || comment.user.erased? %>
<span class="user-name"><%= t("comments.comment.user_deleted") %></span>
<% else %>
<span class="user-name"><%= link_to comment.user.name, user_path(comment.user) %></span>
<% if comment.user.display_official_position_badge? %>
&nbsp;&bull;&nbsp;
<span class="label round level-<%= comment.user.official_level %>">
<%= comment.user.official_position %>
</span>
<% end %>
<% end %>
<% if comment.user.verified_organization? %>
<span class="user-name"><%= link_to comment.user.name, user_path(comment.user) %></span>
<% if comment.user.display_official_position_badge? %>
&nbsp;&bull;&nbsp;
<span class="label round is-association">
<%= t("shared.collective") %>
<span class="label round level-<%= comment.user.official_level %>">
<%= comment.user.official_position %>
</span>
<% end %>
<% if comment.user_id == comment.commentable.author_id %>
&nbsp;&bull;&nbsp;
<span class="label round is-author">
<%= t("comments.comment.author") %>
</span>
<% end %>
<% end %>
<% if comment.user.verified_organization? %>
&nbsp;&bull;&nbsp;
<span class="label round is-association">
<%= t("shared.collective") %>
</span>
<% end %>
<% if comment.user_id == comment.commentable.author_id %>
&nbsp;&bull;&nbsp;
<span class="label round is-author">
<%= t("comments.comment.author") %>
</span>
<% end %>
&nbsp;&bull;&nbsp;<time><%= l comment.created_at.to_datetime, format: :datetime %></time>
<% end %>
&nbsp;&bull;&nbsp;<span><%= l comment.created_at.to_datetime, format: :datetime %></span>
</div>
<div class="comment-user
<%= user_level_class comment %>
<%= comment_author_class comment, comment.commentable.author_id %>">
<%= simple_format text_with_links(comment.body), {}, sanitize: false %>
</div>
<div id="<%= dom_id(comment) %>_reply" class="reply">
<div id="<%= dom_id(comment) %>_votes" class="comment-votes float-right">
<%= render 'comments/votes', comment: comment %>
</div>
<div class="comment-user
<%= user_level_class comment %>
<%= comment_author_class comment, comment.commentable.author_id %>">
<%= simple_format text_with_links(comment.body), {}, sanitize: false %>
</div>
<div id="<%= dom_id(comment) %>_reply" class="reply">
<span id="<%= dom_id(comment) %>_votes" class="comment-votes float-right">
<%= render 'comments/votes', comment: comment %>
</span>
<% if comment.children.size > 0 %>
<%= link_to "", class: "js-toggle-children relative", data: {'id': "#{dom_id(comment)}"} do %>
<span class="sr-only js-child-toggle" style="display: none;"><%= t("shared.show") %></span>
<span class="sr-only js-child-toggle"><%= t("shared.hide") %></span>
<span id="<%= dom_id(comment) %>_children_arrow" class="icon-arrow-down"></span> <%= t("comments.comment.responses", count: comment.children.size) %>
<% end %>
<% else %>
<%= t("comments.comment.responses", count: 0) %>
<% if comment.children.size > 0 %>
<%= link_to "#{dom_id(comment)}", class: "js-toggle-children relative", data: {'id': "#{dom_id(comment)}"} do %>
<span class="sr-only js-child-toggle" style="display: none;"><%= t("shared.show") %></span>
<span class="sr-only js-child-toggle"><%= t("shared.hide") %></span>
<span id="<%= dom_id(comment) %>_children_arrow" class="icon-arrow-down"></span> <%= t("comments.comment.responses", count: comment.children.size) %>
<% end %>
<% else %>
<%= t("comments.comment.responses", count: 0) %>
<% end %>
<% if user_signed_in? %>
<span class="divider">&nbsp;|&nbsp;</span>
<%= link_to(comment_link_text(comment), "",
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
<% if user_signed_in? %>
<span class="divider">&nbsp;|&nbsp;</span>
<%= link_to(comment_link_text(comment), "",
class: "js-add-comment-link", data: {'id': dom_id(comment)}) %>
<%= render 'comments/actions', comment: comment %>
<%= render 'comments/actions', comment: comment %>
<%= render 'comments/form', {commentable: comment.commentable, parent_id: comment.id, toggeable: true} %>
<% end %>
</div>
</li>
<%= render 'comments/form', {commentable: comment.commentable, parent_id: comment.id, toggeable: true} %>
<% end %>
</div>
<% end %>
</li>
<li>
<ul id="<%= dom_id(comment) %>_children" class="no-bullet comment-children">
<% child_comments_of(comment).each do |child| %>
<%= render 'comments/comment', comment: child %>
<li>
<%= render 'comments/comment', comment: child %>
</li>
<% end %>
</ul>
</ul>
</div>
</li>
</ul>
<% end %>

View File

@@ -1,6 +1,6 @@
<% cache [locale_and_user_status, parent_id, commentable_cache_key(commentable)] do %>
<% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %>>
<div id="js-comment-form-<%= css_id %>" <%= "style='display:none'".html_safe if toggeable %> class="comment-form">
<%= form_for Comment.new, remote: true do |f| %>
<%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %>
<%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: false %>

View File

@@ -1,6 +1,5 @@
<%= form_for(@debate) do |f| %>
<%= render 'shared/errors', resource: @debate %>
<div class="row">

View File

@@ -58,6 +58,7 @@
</a>
<% end %>
</div>
</aside>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,5 @@
<meta name="description"
content="<%= content_for?(:meta_description) ? yield(:meta_description) : setting["meta_description"] %>" />
<meta name="keywords"
content="<%= content_for?(:meta_keywords) ? yield(:meta_keywords) : setting["meta_keywords"] %>" />

View File

@@ -4,7 +4,8 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<%=render "layouts/tracking_data"%>
<%= render "layouts/tracking_data" %>
<%= render "layouts/meta_tags" %>
<title><%= content_for?(:title) ? yield(:title) : setting['org_name'] %></title>
<%= stylesheet_link_tag "application" %>
<!--[if lt IE 9]>

View File

@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title><%= content_for?(:title) ? yield(:title) : "Gobierno abierto" %></title>
<%= render "layouts/meta_tags" %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>

View File

@@ -1,9 +1,9 @@
<div class="relative">
<%= link_to t("shared.advanced_search.title"), "#", id: 'js-advanced-search-title', class: "advanced-search small" %>
<%= link_to t("shared.advanced_search.title"), "#advanced_search_form", id: 'js-advanced-search-title', class: "advanced-search small" %>
</div>
<div class="row advanced-search-form">
<%= form_tag search_path, method: :get do %>
<%= form_tag search_path, id: "advanced_search_form", method: :get do %>
<div id='js-advanced-search' data-advanced-search-terms=<%= @advanced_search_terms.present? %> style="display: none">
<div class="small-12 column">
@@ -36,6 +36,7 @@
</label>
<%= text_field_tag 'advanced_search[date_min]',
params[:advanced_search].try(:[], :date_min),
type: "date",
placeholder: t("shared.advanced_search.date_placeholder"),
class: 'js-calendar' %>
</div>
@@ -45,6 +46,7 @@
</label>
<%= text_field_tag 'advanced_search[date_max]',
params[:advanced_search].try(:[], :date_max),
type: "date",
placeholder: t("shared.advanced_search.date_placeholder"),
class: 'js-calendar' %>
</div>

View File

@@ -50,7 +50,7 @@
<ul>
<li>
<%= t("verification.letter.new.office",
office: link_to(t("verification.letter.new.offices"), t("verification.letter.new.offices_url"),
office: link_to(t("verification.letter.new.offices"), setting['verification_offices_url'],
target: "blank")).html_safe %>
</li>
<li>

View File

@@ -12,7 +12,7 @@
<div data-alert class="callout success">
<%= t("verification.letter.create.flash.success_html",
offices: link_to(t("verification.letter.create.flash.offices"),
t("verification.letter.create.flash.offices_url"),
setting['verification_offices_url'],
title: t('shared.target_blank_html'),
target: "_blank")).html_safe
%>

View File

@@ -6,7 +6,7 @@
</button>
<%= t("verification.residence.new.error_verifying_census",
offices: link_to( t("verification.residence.new.error_verifying_census_offices"),
t("verification.residence.new.error_verifying_census_offices_url"), title: t('shared.target_blank_html'), target: "_blank")).html_safe %>
setting['verification_offices_url'], title: t('shared.target_blank_html'), target: "_blank")).html_safe %>
</div>
<% else %>