merges with master

This commit is contained in:
kikito
2015-10-19 20:16:58 +02:00
51 changed files with 513 additions and 331 deletions

Binary file not shown.

View File

@@ -7,7 +7,6 @@
<font-face font-family="icons" units-per-em="512" ascent="480" descent="-32"/> <font-face font-family="icons" units-per-em="512" ascent="480" descent="-32"/>
<missing-glyph horiz-adv-x="512" /> <missing-glyph horiz-adv-x="512" />
<glyph glyph-name="angle-down" unicode="&#97;" d="M399 302c0-3-1-5-3-7l-133-133c-2-2-5-3-7-3-2 0-5 1-7 3l-133 133c-2 2-3 4-3 7 0 2 1 4 3 6l15 15c1 1 4 2 6 2 3 0 5-1 7-2l112-113 112 113c2 1 4 2 7 2 2 0 5-1 6-2l15-15c2-2 3-4 3-6z"/> <glyph glyph-name="angle-down" unicode="&#97;" d="M399 302c0-3-1-5-3-7l-133-133c-2-2-5-3-7-3-2 0-5 1-7 3l-133 133c-2 2-3 4-3 7 0 2 1 4 3 6l15 15c1 1 4 2 6 2 3 0 5-1 7-2l112-113 112 113c2 1 4 2 7 2 2 0 5-1 6-2l15-15c2-2 3-4 3-6z"/>
<glyph glyph-name="angle-left" unicode="&#98;" d="M344 357c0-3-1-5-3-7l-112-112 112-113c2-1 3-4 3-6 0-3-1-5-3-7l-14-14c-2-2-5-3-7-3-2 0-5 1-7 3l-133 133c-2 2-3 4-3 7 0 2 1 4 3 6l133 133c2 2 5 3 7 3 2 0 5-1 7-3l14-14c2-2 3-4 3-6z"/> <glyph glyph-name="angle-left" unicode="&#98;" d="M344 357c0-3-1-5-3-7l-112-112 112-113c2-1 3-4 3-6 0-3-1-5-3-7l-14-14c-2-2-5-3-7-3-2 0-5 1-7 3l-133 133c-2 2-3 4-3 7 0 2 1 4 3 6l133 133c2 2 5 3 7 3 2 0 5-1 7-3l14-14c2-2 3-4 3-6z"/>
<glyph glyph-name="angle-right" unicode="&#99;" d="M335 238c0-3-1-5-3-7l-133-133c-2-2-5-3-7-3-2 0-5 1-7 3l-14 14c-2 2-3 4-3 7 0 2 1 5 3 6l112 113-112 112c-2 2-3 4-3 7 0 2 1 4 3 6l14 14c2 2 5 3 7 3 2 0 5-1 7-3l133-133c2-2 3-4 3-6z"/> <glyph glyph-name="angle-right" unicode="&#99;" d="M335 238c0-3-1-5-3-7l-133-133c-2-2-5-3-7-3-2 0-5 1-7 3l-14 14c-2 2-3 4-3 7 0 2 1 5 3 6l112 113-112 112c-2 2-3 4-3 7 0 2 1 4 3 6l14 14c2 2 5 3 7 3 2 0 5-1 7-3l133-133c2-2 3-4 3-6z"/>
@@ -44,5 +43,5 @@
<glyph glyph-name="print" unicode="&#72;" d="M463 332c0 5-4 9-9 9l-67 0 0 110c0 5-5 10-10 10l-242 0c-5 0-10-5-10-10l0-110-67 0c0 0 0 0 0 0-5 0-9-4-9-9l0 0 0-188c0-5 4-10 9-10l67 0 0 79 262 0 0-79 67 0c5 0 9 5 9 10l0 188z m-102-33l-210 0 0 127c0 5 4 9 9 9l192 0c5 0 9-4 9-9l0-127z m-209-238c0-5 4-10 9-10l190 0c5 0 9 5 9 10l0 126-208 0z"/> <glyph glyph-name="print" unicode="&#72;" d="M463 332c0 5-4 9-9 9l-67 0 0 110c0 5-5 10-10 10l-242 0c-5 0-10-5-10-10l0-110-67 0c0 0 0 0 0 0-5 0-9-4-9-9l0 0 0-188c0-5 4-10 9-10l67 0 0 79 262 0 0-79 67 0c5 0 9 5 9 10l0 188z m-102-33l-210 0 0 127c0 5 4 9 9 9l192 0c5 0 9-4 9-9l0-127z m-209-238c0-5 4-10 9-10l190 0c5 0 9 5 9 10l0 126-208 0z"/>
<glyph glyph-name="blog" unicode="&#74;" d="M52 369c38 71 115 118 204 118 58 0 110-24 150-59-11 2-24 0-36-7-30-17-40-66-1-90 24-15 32-53 32-76-1-23-56-128-56-128l-54 184c0 0-2 13-2 17 0 4 2 10 5 13 2 3 5 7 8 7l26 0 0 21-139 0 0-21 5 0c4 0 9-6 13-10 5-6 11-25 19-45l20-67-43-100-48 200c0 0 2 14 5 16 1 2 4 6 8 6l1 0 0 21z m27-35c0 0-11 14-23 14l-12 0c-12-25-18-60-18-91 0-95 58-176 141-211z m375 36c5-20 4-46-5-73-22-72-77-202-99-252 81 36 136 116 136 209 0 43-11 82-32 116z m-193-194l-59-144c17-4 35-7 54-7 19 0 38 3 56 7z"/> <glyph glyph-name="blog" unicode="&#74;" d="M52 369c38 71 115 118 204 118 58 0 110-24 150-59-11 2-24 0-36-7-30-17-40-66-1-90 24-15 32-53 32-76-1-23-56-128-56-128l-54 184c0 0-2 13-2 17 0 4 2 10 5 13 2 3 5 7 8 7l26 0 0 21-139 0 0-21 5 0c4 0 9-6 13-10 5-6 11-25 19-45l20-67-43-100-48 200c0 0 2 14 5 16 1 2 4 6 8 6l1 0 0 21z m27-35c0 0-11 14-23 14l-12 0c-12-25-18-60-18-91 0-95 58-176 141-211z m375 36c5-20 4-46-5-73-22-72-77-202-99-252 81 36 136 116 136 209 0 43-11 82-32 116z m-193-194l-59-144c17-4 35-7 54-7 19 0 38 3 56 7z"/>
<glyph glyph-name="box" unicode="&#73;" d="M311 274c0 5-2 10-6 13-3 4-7 6-12 6l-74 0c-5 0-9-2-12-6-4-3-6-8-6-13 0-5 2-9 6-13 3-3 7-5 12-5l74 0c5 0 9 2 12 5 4 4 6 8 6 13z m164 55l0-274c0-5-1-9-5-13-4-4-8-5-13-5l-402 0c-5 0-9 1-13 5-4 4-5 8-5 13l0 274c0 5 1 9 5 13 4 4 8 5 13 5l402 0c5 0 9-1 13-5 4-4 5-8 5-13z m19 128l0-73c0-5-2-9-6-13-3-3-8-5-13-5l-438 0c-5 0-10 2-13 5-4 4-6 8-6 13l0 73c0 5 2 9 6 13 3 4 8 5 13 5l438 0c5 0 10-1 13-5 4-4 6-8 6-13z"/> <glyph glyph-name="box" unicode="&#73;" d="M311 274c0 5-2 10-6 13-3 4-7 6-12 6l-74 0c-5 0-9-2-12-6-4-3-6-8-6-13 0-5 2-9 6-13 3-3 7-5 12-5l74 0c5 0 9 2 12 5 4 4 6 8 6 13z m164 55l0-274c0-5-1-9-5-13-4-4-8-5-13-5l-402 0c-5 0-9 1-13 5-4 4-5 8-5 13l0 274c0 5 1 9 5 13 4 4 8 5 13 5l402 0c5 0 9-1 13-5 4-4 5-8 5-13z m19 128l0-73c0-5-2-9-6-13-3-3-8-5-13-5l-438 0c-5 0-10 2-13 5-4 4-6 8-6 13l0 73c0 5 2 9 6 13 3 4 8 5 13 5l438 0c5 0 10-1 13-5 4-4 6-8 6-13z"/>
<glyph glyph-name="youtube" unicode="&#75;" d="M314 157l0-61c0-12-4-19-11-19-5 0-9 2-13 6l0 86c4 5 8 7 13 7 7 0 11-7 11-19z m97-1l0-13-26 0 0 13c0 13 4 20 13 20 8 0 13-7 13-20z m-276 63l30 0 0 26-89 0 0-26 30 0 0-163 29 0z m82-163l25 0 0 141-25 0 0-108c-6-8-11-12-16-12-4 0-6 2-6 6-1 1-1 4-1 10l0 104-25 0 0-112c0-9 1-16 2-20 2-7 8-11 17-11 9 0 19 6 29 17z m122 42l0 57c0 13 0 23-2 28-3 11-10 16-20 16-10 0-19-5-27-16l0 62-25 0 0-189 25 0 0 14c9-11 17-16 27-16 10 0 17 5 20 16 2 5 2 14 2 28z m97 3l0 4-26 0c0-10 0-16-1-18-1-6-5-10-11-10-9 0-13 7-13 20l0 25 51 0 0 29c0 15-3 26-8 33-7 10-17 15-30 15-13 0-23-5-31-15-5-7-8-18-8-33l0-49c0-15 3-26 9-33 7-10 17-15 31-15 13 0 24 5 30 15 4 5 6 10 6 16 1 1 1 7 1 16z m-174 261l0 60c0 13-4 20-12 20-8 0-12-7-12-20l0-60c0-13 4-20 12-20 8 0 12 7 12 20z m206-215c0-44-3-77-8-100-2-11-8-20-16-28-9-7-18-12-29-13-35-4-88-6-159-6-71 0-124 2-159 6-11 1-20 6-29 13-8 8-14 17-16 28-5 22-8 55-8 100 0 45 3 78 8 100 2 12 8 21 16 29 9 7 18 12 30 13 35 4 87 6 158 6 71 0 124-2 159-6 11-1 20-6 29-13 8-8 14-17 16-29 5-21 8-54 8-100z m-285 365l29 0-35-114 0-77-28 0 0 77c-3 14-9 34-18 61-7 19-13 37-18 53l30 0 20-75z m105-95l0-50c0-16-2-27-8-34-7-10-17-14-30-14-13 0-23 4-30 14-5 7-8 19-8 34l0 50c0 15 3 26 8 33 7 10 17 15 30 15 13 0 23-5 30-15 6-7 8-18 8-33z m96 46l0-142-26 0 0 15c-10-12-20-17-29-17-9 0-15 3-17 10-2 5-3 12-3 22l0 112 26 0 0-105c0-6 1-9 1-10 0-4 2-6 6-6 5 0 10 4 16 12l0 109z"/>icons.eot <glyph glyph-name="youtube" unicode="&#75;" d="M314 157l0-61c0-12-4-19-11-19-5 0-9 2-13 6l0 86c4 5 8 7 13 7 7 0 11-7 11-19z m97-1l0-13-26 0 0 13c0 13 4 20 13 20 8 0 13-7 13-20z m-276 63l30 0 0 26-89 0 0-26 30 0 0-163 29 0z m82-163l25 0 0 141-25 0 0-108c-6-8-11-12-16-12-4 0-6 2-6 6-1 1-1 4-1 10l0 104-25 0 0-112c0-9 1-16 2-20 2-7 8-11 17-11 9 0 19 6 29 17z m122 42l0 57c0 13 0 23-2 28-3 11-10 16-20 16-10 0-19-5-27-16l0 62-25 0 0-189 25 0 0 14c9-11 17-16 27-16 10 0 17 5 20 16 2 5 2 14 2 28z m97 3l0 4-26 0c0-10 0-16-1-18-1-6-5-10-11-10-9 0-13 7-13 20l0 25 51 0 0 29c0 15-3 26-8 33-7 10-17 15-30 15-13 0-23-5-31-15-5-7-8-18-8-33l0-49c0-15 3-26 9-33 7-10 17-15 31-15 13 0 24 5 30 15 4 5 6 10 6 16 1 1 1 7 1 16z m-174 261l0 60c0 13-4 20-12 20-8 0-12-7-12-20l0-60c0-13 4-20 12-20 8 0 12 7 12 20z m206-215c0-44-3-77-8-100-2-11-8-20-16-28-9-7-18-12-29-13-35-4-88-6-159-6-71 0-124 2-159 6-11 1-20 6-29 13-8 8-14 17-16 28-5 22-8 55-8 100 0 45 3 78 8 100 2 12 8 21 16 29 9 7 18 12 30 13 35 4 87 6 158 6 71 0 124-2 159-6 11-1 20-6 29-13 8-8 14-17 16-29 5-21 8-54 8-100z m-285 365l29 0-35-114 0-77-28 0 0 77c-3 14-9 34-18 61-7 19-13 37-18 53l30 0 20-75z m105-95l0-50c0-16-2-27-8-34-7-10-17-14-30-14-13 0-23 4-30 14-5 7-8 19-8 34l0 50c0 15 3 26 8 33 7 10 17 15 30 15 13 0 23-5 30-15 6-7 8-18 8-33z m96 46l0-142-26 0 0 15c-10-12-20-17-29-17-9 0-15 3-17 10-2 5-3 12-3 22l0 112 26 0 0-105c0-6 1-9 1-10 0-4 2-6 6-6 5 0 10 4 16 12l0 109z"/>
</font></defs></svg> </font></defs></svg>

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -27,6 +27,12 @@ body.admin {
.button { .button {
margin-top: 0; margin-top: 0;
} }
input[type="text"] {
height: 36px\9;
line-height: 36px\9;
margin-bottom: 24px\9;
}
} }
.dashboard { .dashboard {
@@ -58,6 +64,18 @@ body.admin {
.admin-content { .admin-content {
margin-top: rem-calc(24); margin-top: rem-calc(24);
.filters h2 {
margin-top: 0;
}
.proposal-new, .proposal-edit {
padding-top: 0;
}
.proposal-show {
padding-top: rem-calc(54);
}
} }
.is-featured { .is-featured {
@@ -79,6 +97,10 @@ body.admin {
margin-left: rem-calc(-20); margin-left: rem-calc(-20);
} }
a {
color: white\9 !important;
}
ul { ul {
list-style-type: none; list-style-type: none;
margin-left: 0; margin-left: 0;
@@ -89,6 +111,8 @@ body.admin {
font-size: rem-calc(24); font-size: rem-calc(24);
padding-right: rem-calc(24); padding-right: rem-calc(24);
padding-top: rem-calc(4); padding-top: rem-calc(4);
padding-left: 12px\9 !important;
padding-right: 12px\9 !important;
} }
li { li {
@@ -277,11 +301,6 @@ body.admin {
// 05. Management // 05. Management
// - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - -
.postfix {
height: rem-calc(48);
line-height: rem-calc(48);
}
.user-permissions { .user-permissions {
ul { ul {

View File

@@ -450,7 +450,7 @@ header {
} }
.top-bar { .top-bar {
background: none; background: #112E51 !important;
color: white; color: white;
height: rem-calc(48); height: rem-calc(48);
max-width: 1170px !important; max-width: 1170px !important;
@@ -958,8 +958,7 @@ form {
em { em {
background: white; background: white;
display: inline-block; display: block;
padding-left: rem-calc(6);
} }
} }
@@ -1147,9 +1146,9 @@ img.avatar, img.admin-avatar, img.moderator-avatar, img.initialjs-avatar {
background-color: rgba(255,255,255,.5); background-color: rgba(255,255,255,.5);
color: rgba(0,0,0,.4); color: rgba(0,0,0,.4);
font-size: rem-calc(40); font-size: rem-calc(40);
left: 11px; left: rem-calc(11);
position: absolute; position: absolute;
top: 63px; top: rem-calc(72);
} }
.user-deleted { .user-deleted {

View File

@@ -2,40 +2,58 @@
/* Print proposals */ /* Print proposals */
.top-links, .tags a, .supports, .label-proposal, .tags a { display: none !important; }
#print_link, .admin-sidebar, img.left, .proposal-info a,
.icon-comments, .menu-icon, .icon-proposals, li.name span, .supports { display: none !important; }
p.proposal-info span:nth-child(3) {
display: none !important; .label-proposal { display: none !important; }
}
#print_link { display: none !important; }
.admin-sidebar { display: none !important; }
img.left { display: none !important; }
.proposal-info a { display: none !important; }
.icon-comments { display: none !important; }
.menu-icon { display: none !important; }
.icon-proposals { display: none !important; }
.captcha { display: none !important; }
li.name span { display: none !important; }
p.proposal-info span:nth-child(3) { display: none !important; }
.top-links { display: none !important; }
.button { display: none !important; }
input[type="submit"] { display: none !important; }
.select-order { .select-order {
border: 0; border: 0;
font-size: 24px; font-size: 24px;
font-weight: bold; font-weight: bold;
margin-left: -12px;
}
p.proposal-info {
margin-left: -6px; margin-left: -6px;
} }
a { p.proposal-info { margin-left: -6px; }
text-decoration: none !important;
}
a:after { a { text-decoration: none !important; }
content: none !important;
}
.proposal .panel, .proposal .panel .proposal-content, a:after { content: none !important; }
.proposal .panel h3 {
min-height: auto !important;
}
.proposal .panel .proposal-description { .proposal .panel { min-height: auto !important; }
height: auto;
} .proposal .panel .proposal-content { min-height: auto !important; }
.proposal .panel h3 { min-height: auto !important; }
.proposal .panel .proposal-description { height: auto; }
.proposal .panel { .proposal .panel {
border-left: 0 !important; border-left: 0 !important;

View File

@@ -1,5 +1,6 @@
module CommentableActions module CommentableActions
extend ActiveSupport::Concern extend ActiveSupport::Concern
include Polymorphic
def index def index
@resources = @search_terms.present? ? resource_model.search(@search_terms) : resource_model.all @resources = @search_terms.present? ? resource_model.search(@search_terms) : resource_model.all
@@ -59,29 +60,6 @@ module CommentableActions
end end
private private
def resource
@resource ||= instance_variable_get("@#{resource_name}")
end
def resource_name
@resource_name ||= resource_model.to_s.downcase
end
def set_resource_instance
instance_variable_set("@#{resource_name}", @resource)
end
def set_resources_instance
instance_variable_set("@#{resource_name.pluralize}", @resources)
end
def set_resource_votes(instance)
send("set_#{resource_name}_votes", instance)
end
def strong_params
send("#{resource_name}_params")
end
def track_event def track_event
ahoy.track "#{resource_name}_created".to_sym, "#{resource_name}_id": resource.id ahoy.track "#{resource_name}_created".to_sym, "#{resource_name}_id": resource.id
@@ -104,4 +82,8 @@ module CommentableActions
def parse_search_terms def parse_search_terms
@search_terms = params[:search] if params[:search].present? @search_terms = params[:search] if params[:search].present?
end end
def set_resource_votes(instance)
send("set_#{resource_name}_votes", instance)
end
end end

View File

@@ -0,0 +1,60 @@
module ModerateActions
extend ActiveSupport::Concern
include Polymorphic
def index
@resources = @resources.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
set_resources_instance
end
def hide
hide_resource resource
end
def moderate
set_resource_params
@resources = @resources.where(id: params[:resource_ids])
if params[:hide_resources].present?
@resources.accessible_by(current_ability, :hide).each {|resource| hide_resource resource}
elsif params[:ignore_flags].present?
@resources.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @resources.pluck(author_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each {|user| block_user user}
end
redirect_to request.query_parameters.merge(action: :index)
end
private
def load_resources
@resources = resource_model.accessible_by(current_ability, :moderate)
end
def hide_resource(resource)
resource.hide
Activity.log(current_user, :hide, resource)
end
def block_user(user)
user.block
Activity.log(current_user, :block, user)
end
def set_resource_params
params[:resource_ids] = params["#{resource_name}_ids"]
params[:hide_resources] = params["hide_#{resource_name.pluralize}"]
end
def author_id
:author_id
end
end

View File

@@ -0,0 +1,24 @@
module Polymorphic
private
def resource
@resource ||= instance_variable_get("@#{resource_name}")
end
def resource_name
@resource_name ||= resource_model.to_s.downcase
end
def set_resource_instance
instance_variable_set("@#{resource_name}", @resource)
end
def set_resources_instance
instance_variable_set("@#{resource_name.pluralize}", @resources)
end
def strong_params
send("#{resource_name}_params")
end
end

View File

@@ -12,7 +12,7 @@ class Management::BaseController < ActionController::Base
end end
def current_manager def current_manager
@current_manager ||= Manager.find(session["manager_id"]) if session["manager_id"] session["manager"]
end end
def managed_user def managed_user

View File

@@ -1,5 +1,6 @@
class Management::DocumentVerificationsController < Management::BaseController class Management::DocumentVerificationsController < Management::BaseController
before_action :clean_document_number, only: :check
before_action :set_document, only: :check before_action :set_document, only: :check
def index def index
@@ -41,4 +42,8 @@ class Management::DocumentVerificationsController < Management::BaseController
session[:document_number] = params[:document_verification][:document_number] session[:document_number] = params[:document_verification][:document_number]
end end
def clean_document_number
params[:document_verification][:document_number] = params[:document_verification][:document_number].gsub(/[^a-z0-9]+/i, "").upcase unless params[:document_verification][:document_number].blank?
end
end end

View File

@@ -6,7 +6,7 @@ class Management::ProposalsController < Management::BaseController
before_action :set_proposal, only: [:vote, :show] before_action :set_proposal, only: [:vote, :show]
before_action :parse_search_terms, only: :index before_action :parse_search_terms, only: :index
has_orders %w{hot_score confidence_score created_at most_commented random}, only: [:index, :print] has_orders %w{confidence_score hot_score created_at most_commented random}, only: [:index, :print]
def vote def vote
@proposal.register_vote(current_user, 'yes') @proposal.register_vote(current_user, 'yes')
@@ -34,7 +34,7 @@ class Management::ProposalsController < Management::BaseController
def check_verified_user def check_verified_user
unless current_user.level_two_or_three_verified? unless current_user.level_two_or_three_verified?
redirect_to management_root_path, alert: t("management.proposals.alert.unverified_user") redirect_to management_document_verifications_path, alert: t("management.proposals.alert.unverified_user")
end end
end end

View File

@@ -1,9 +1,11 @@
require "manager_authenticator"
class Management::SessionsController < ActionController::Base class Management::SessionsController < ActionController::Base
def create def create
destroy_session destroy_session
if manager = Manager.valid_manager(params[:login], params[:clave_usuario]) if manager = ManagerAuthenticator.new(params).auth
session["manager_id"] = manager.id session["manager"] = manager
redirect_to management_root_path redirect_to management_root_path
else else
raise ActionController::RoutingError.new('Not Found') raise ActionController::RoutingError.new('Not Found')
@@ -18,7 +20,7 @@ class Management::SessionsController < ActionController::Base
private private
def destroy_session def destroy_session
session["manager_id"] = nil session["manager"] = nil
end end
end end

View File

@@ -1,53 +1,20 @@
class Moderation::CommentsController < Moderation::BaseController class Moderation::CommentsController < Moderation::BaseController
include ModerateActions
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
has_orders %w{flags created_at}, only: :index has_orders %w{flags created_at}, only: :index
before_action :load_comments, only: [:index, :moderate] before_action :load_resources, only: [:index, :moderate]
load_and_authorize_resource load_and_authorize_resource
def index
@comments = @comments.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
end
def hide
hide_comment @comment
end
def moderate
@comments = @comments.where(id: params[:comment_ids])
if params[:hide_comments].present?
@comments.accessible_by(current_ability, :hide).each {|comment| hide_comment comment}
elsif params[:ignore_flags].present?
@comments.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @comments.pluck(:user_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each {|user| block_user user}
end
redirect_to request.query_parameters.merge(action: :index)
end
private private
def load_comments def resource_model
@comments = Comment.accessible_by(current_ability, :moderate) Comment
end end
def hide_comment(comment) def author_id
comment.hide :user_id
Activity.log(current_user, :hide, comment)
end end
def block_user(user)
user.block
Activity.log(current_user, :block, user)
end
end end

View File

@@ -1,53 +1,17 @@
class Moderation::DebatesController < Moderation::BaseController class Moderation::DebatesController < Moderation::BaseController
include ModerateActions
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
has_orders %w{flags created_at}, only: :index has_orders %w{flags created_at}, only: :index
before_action :load_debates, only: [:index, :moderate] before_action :load_resources, only: [:index, :moderate]
load_and_authorize_resource load_and_authorize_resource
def index
@debates = @debates.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
end
def hide
hide_debate @debate
end
def moderate
@debates = @debates.where(id: params[:debate_ids])
if params[:hide_debates].present?
@debates.accessible_by(current_ability, :hide).each {|debate| hide_debate debate}
elsif params[:ignore_flags].present?
@debates.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @debates.pluck(:author_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each {|user| block_user user}
end
redirect_to request.query_parameters.merge(action: :index)
end
private private
def load_debates def resource_model
@debates = Debate.accessible_by(current_ability, :moderate) Debate
end
def hide_debate(debate)
debate.hide
Activity.log(current_user, :hide, debate)
end
def block_user(user)
user.block
Activity.log(current_user, :block, user)
end end
end end

View File

@@ -1,54 +1,16 @@
class Moderation::ProposalsController < Moderation::BaseController class Moderation::ProposalsController < Moderation::BaseController
include ModerateActions
has_filters %w{pending_flag_review all with_ignored_flag}, only: :index has_filters %w{pending_flag_review all with_ignored_flag}, only: :index
has_orders %w{flags created_at}, only: :index has_orders %w{flags created_at}, only: :index
before_filter :load_proposals, only: [:index, :moderate] before_filter :load_resources, only: [:index, :moderate]
load_and_authorize_resource load_and_authorize_resource
def index
@proposals = @proposals.send(@current_filter)
.send("sort_by_#{@current_order}")
.page(params[:page])
.per(50)
end
def hide
hide_proposal @proposal
end
def moderate
@proposals = @proposals.where(id: params[:proposal_ids])
if params[:hide_proposals].present?
@proposals.accessible_by(current_ability, :hide).each {|proposal| hide_proposal proposal}
elsif params[:ignore_flags].present?
@proposals.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @proposals.pluck(:author_id).uniq
User.where(id: author_ids).accessible_by(current_ability, :block).each {|user| block_user user}
end
redirect_to request.query_parameters.merge(action: :index)
end
private private
def load_proposals def resource_model
@proposals = Proposal.accessible_by(current_ability, :moderate) Proposal
end end
def hide_proposal(proposal)
proposal.hide
Activity.log(current_user, :hide, proposal)
end
def block_user(user)
user.block
Activity.log(current_user, :block, user)
end
end end

View File

@@ -3,7 +3,7 @@ module Taggable
included do included do
acts_as_taggable acts_as_taggable
validate :max_number_of_tags validate :max_number_of_tags, on: :create
end end
def tag_list_with_limit(limit = nil) def tag_list_with_limit(limit = nil)

View File

@@ -1,12 +0,0 @@
class Manager < ActiveRecord::Base
validates :username, presence: true, uniqueness: true
validates :password_digest, presence: true
has_secure_password
def self.valid_manager(username = nil, password = nil)
return false unless username.present? && password.present?
Manager.find_by(username: username).try(:authenticate, password)
end
end

View File

@@ -1,5 +1,6 @@
class Verification::Management::Document class Verification::Management::Document
include ActiveModel::Model include ActiveModel::Model
include ActiveModel::Dates
attr_accessor :document_type attr_accessor :document_type
attr_accessor :document_number attr_accessor :document_number
@@ -17,7 +18,21 @@ class Verification::Management::Document
end end
def in_census? def in_census?
CensusApi.new.call(document_type, document_number).valid? response = CensusApi.new.call(document_type, document_number)
response.valid? && valid_age?(response)
end
def valid_age?(response)
if under_sixteen?(response)
errors.add(:age, true)
return false
else
return true
end
end
def under_sixteen?(response)
16.years.ago < string_to_date(response.date_of_birth)
end end
def verified? def verified?
@@ -28,7 +43,4 @@ class Verification::Management::Document
user.update(verified_at: Time.now) if user? user.update(verified_at: Time.now) if user?
end end
end end

View File

@@ -4,7 +4,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <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) : "Admin" %></title> <title><%= content_for?(:title) ? yield(:title) : "Admin" %></title>
<%= stylesheet_link_tag "application", media: "all" %> <%= stylesheet_link_tag "application", media: "all" %>
<%= stylesheet_link_tag "print", media: "print" %> <%= stylesheet_link_tag "print", media: "print" %>
@@ -17,17 +17,17 @@
<body class="admin"> <body class="admin">
<header class="<%= header_css %>"> <header class="<%= header_css %>">
<section class="top-links"> <div class="top-links">
<div class="row"> <div class="row">
<%= render 'shared/locale_switcher' %> <%= render 'shared/locale_switcher' %>
</div> </div>
</section> </div>
<div class="contain-to-grid clear"> <div class="contain-to-grid clear">
<nav class="top-bar" data-topbar role="navigation"> <nav class="top-bar" data-topbar role="navigation">
<ul class="title-area"> <ul class="title-area">
<li class="name"> <li class="name">
<%= link_to root_path do %> <%= link_to management_root_path do %>
<%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96') %> <%= image_tag('header_logo_madrid.png', class: 'left', size: '96x96') %>
<%= t("layouts.header.open_gov", open: "<strong>#{t('layouts.header.open')}</strong>").html_safe %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span> <%= t("layouts.header.open_gov", open: "<strong>#{t('layouts.header.open')}</strong>").html_safe %> <span>|</span> <span class="logo-site"><%= t("management.dashboard.index.title") %></span>
<% end %> <% end %>

View File

@@ -2,28 +2,37 @@
<section class="small-12 medium-9 column margin-top"> <section class="small-12 medium-9 column margin-top">
<div class="account-info"> <div class="account-info">
<%= link_to(t("management.account_info.logout"), logout_management_users_path, method: :delete, class: 'right') %> <%= link_to(t("management.account_info.change_user"), logout_management_users_path, method: :delete, class: 'right') %>
<% if managed_user.level_two_or_three_verified? %> <% if managed_user.level_two_or_three_verified? %>
<p><%= t("management.account_info.identified_label") %></p> <p>
<%= t("management.account_info.identified_label") %>
</p>
<% end %> <% end %>
<% if managed_user.username.present? %> <% if managed_user.username.present? %>
<p><%= t("management.account_info.username_label") %> <p>
<strong><%= managed_user.username %></strong></p> <%= t("management.account_info.username_label") %>
<strong><%= managed_user.username %></strong>
</p>
<% end %> <% end %>
<% if managed_user.email.present? %> <% if managed_user.email.present? %>
<p><%= t("management.account_info.email_label") %> <p>
<strong><%= managed_user.email %></strong></p> <%= t("management.account_info.email_label") %>
<strong><%= managed_user.email %></strong>
</p>
<% end %> <% end %>
<p><%= t("management.account_info.document_type_label") %> <p>
<strong><%= humanize_document_type(managed_user.document_type) %></strong> <%= t("management.account_info.document_type_label") %>
<strong><%= humanize_document_type(managed_user.document_type) %></strong>
</p>
<p><%= t("management.account_info.document_number_label") %> <p>
<strong><%= managed_user.document_number %></strong></p> <%= t("management.account_info.document_number_label") %>
</span> <strong><%= managed_user.document_number %></strong>
</p>
</div>
</section> </section>
<% end %> <% end %>

View File

@@ -1,4 +1,4 @@
<nav class="admin-sidebar"> <div class="admin-sidebar">
<ul id="admin_menu"> <ul id="admin_menu">
<li> <li>
<%= link_to t("management.menu.title"), management_root_path %> <%= link_to t("management.menu.title"), management_root_path %>
@@ -34,4 +34,4 @@
<% end %> <% end %>
</li> </li>
</ul> </ul>
</nav> </div>

View File

@@ -1,3 +1,14 @@
<div class="dashboard"> <div class="dashboard">
<h2><%= t("management.dashboard.index.title") %></h2> <h2><%= t("management.dashboard.index.title") %></h2>
<p>Desde aquí puedes gestionar usuarios a través de las siguientes acciones:</p>
<h3>Usuarios</h3>
<h3>Crear propuesta</h3>
<h3>Apoyar propuesta</h3>
<h3>Imprimir propuestas</h3>
</div> </div>

View File

@@ -1,5 +1,9 @@
<div class="alert-box alert radius"> <div class="alert-box alert radius">
<%= t("management.document_verifications.not_in_census") %> <% if @document_verification.errors[:age].any? %>
<%= t("management.document_verifications.under_age") %>
<% else %>
<%= t("management.document_verifications.not_in_census") %>
<% end %>
</div> </div>
<%= render 'management/user_permissions', <%= render 'management/user_permissions',

View File

@@ -1,6 +1,8 @@
<div class="proposal-new row"> <%= render '/shared/print' %>
<div class="proposal-new row">
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<h1><%= t("management.proposals.create_proposal") %></h1>
<%= render "proposals/form", form_url: management_proposals_url %> <%= render "proposals/form", form_url: management_proposals_url %>
</div> </div>

View File

@@ -1,7 +1,7 @@
<section id="printme" role="main"> <section role="main">
<div class="row"> <div class="row">
<div id="proposals" class="proposals-list small-12 column"> <div id="proposals" class="proposals-list small-12 column">
<a id="print_link" href="javascript:window.print(); void 0;" class="button warning radius right"> <a id="print_link" href="javascript:window.print();" class="button warning radius right">
<%= t('management.proposals.print.print_button') %> <%= t('management.proposals.print.print_button') %>
</a> </a>

View File

@@ -1 +1,3 @@
<%= render template: 'proposals/show' %> <%= render '/shared/print' %>
<%= render template: 'proposals/show' %>

View File

@@ -2,6 +2,9 @@
<div class="page row-full"> <div class="page row-full">
<div class="row"> <div class="row">
<div class="text small-12 column"> <div class="text small-12 column">
<%= render '/shared/print' %>
<h1><%= t("pages.conditions") %></h1> <h1><%= t("pages.conditions") %></h1>
<h2>AVISO LEGAL SOBRE LAS CONDICIONES DE USO, PRIVACIDAD Y PROTECCIÓN DE DATOS PERSONALES DEL PORTAL DE GOBIERNO ABIERTO DEL AYUNTAMIENTO DE MADRID</h2> <h2>AVISO LEGAL SOBRE LAS CONDICIONES DE USO, PRIVACIDAD Y PROTECCIÓN DE DATOS PERSONALES DEL PORTAL DE GOBIERNO ABIERTO DEL AYUNTAMIENTO DE MADRID</h2>

View File

@@ -2,6 +2,9 @@
<div class="page row-full"> <div class="page row-full">
<div class="row"> <div class="row">
<div class="text small-12 column"> <div class="text small-12 column">
<%= render '/shared/print' %>
<h1><%= t("pages.privacy") %></h1> <h1><%= t("pages.privacy") %></h1>
<h2>AVISO DE PROTECCIÓN DE DATOS</h2> <h2>AVISO DE PROTECCIÓN DE DATOS</h2>

View File

@@ -0,0 +1,3 @@
<a href="javascript:window.print();" id="print_link" class="button warning tiny radius right">
<%= t("shared.print.print_button") %>
</a>

View File

@@ -311,6 +311,8 @@ en:
shared: shared:
tags_cloud: tags_cloud:
tags: Trend tags: Trend
print:
print_button: "Print this info"
flag: Flag as inappropriate flag: Flag as inappropriate
unflag: Undo flag unflag: Undo flag
collective: Collective collective: Collective

View File

@@ -311,6 +311,8 @@ es:
shared: shared:
tags_cloud: tags_cloud:
tags: Tendencias tags: Tendencias
print:
print_button: "Imprimir esta información"
flag: Denunciar como inapropiado flag: Denunciar como inapropiado
unflag: Deshacer denuncia unflag: Deshacer denuncia
collective: Colectivo collective: Colectivo

View File

@@ -17,15 +17,16 @@ en:
title: "Management" title: "Management"
account_info: account_info:
identified_label: "Identified as:" identified_label: "Identified as:"
username_label: "Username" username_label: "Username:"
email_label: "Email" email_label: "Email:"
document_number_label: "Document number" document_number_label: "Document number:"
document_type_label: "Document type" document_type_label: "Document type:"
logout: "Logout" change_user: "Change user"
sessions: sessions:
signed_out: "Signed out successfully." signed_out: "Signed out successfully."
signed_out_managed_user: "Signed out successfully." signed_out_managed_user: "User session signed out successfully."
proposals: proposals:
create_proposal: "Create proposal"
print: print:
print_button: Print print_button: Print
alert: alert:
@@ -41,6 +42,7 @@ en:
already_verified: "This user account is already verified." already_verified: "This user account is already verified."
in_census_has_following_permissions: "This user can participate in the website with the following permissions:" in_census_has_following_permissions: "This user can participate in the website with the following permissions:"
not_in_census: "This document is not registered in Madrid." not_in_census: "This document is not registered in Madrid."
under_age: "You must be over 16 to verify your account."
not_in_census_info: "Citizens not in the Census can participate in the website with the following permissions:" not_in_census_info: "Citizens not in the Census can participate in the website with the following permissions:"
has_no_account_html: "In order to create an account, go to %{link} and click in <b>'Register'</b> in the upper-left part of the screen." has_no_account_html: "In order to create an account, go to %{link} and click in <b>'Register'</b> in the upper-left part of the screen."
verify: "Verify" verify: "Verify"

View File

@@ -21,11 +21,12 @@ es:
email_label: "Email:" email_label: "Email:"
document_number_label: "Número de documento:" document_number_label: "Número de documento:"
document_type_label: "Tipo de documento:" document_type_label: "Tipo de documento:"
logout: "Salir" change_user: "Cambiar usuario"
sessions: sessions:
signed_out: "Has cerrado la sesión correctamente." signed_out: "Has cerrado la sesión correctamente."
signed_out_managed_user: "Has cerrado la sesión correctamente." signed_out_managed_user: "Se ha cerrado correctamente la sesión del usuario."
proposals: proposals:
create_proposal: "Crear propuesta"
print: print:
print_button: Imprimir print_button: Imprimir
alert: alert:
@@ -41,6 +42,7 @@ es:
already_verified: "Esta cuenta de usuario ya está verificada." already_verified: "Esta cuenta de usuario ya está verificada."
in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
not_in_census: "Este documento no está registrado en el Padrón Municipal de Madrid." not_in_census: "Este documento no está registrado en el Padrón Municipal de Madrid."
under_age: "Debes ser mayor de 16 años para verificar tu cuenta."
not_in_census_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" not_in_census_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:"
has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción <b>'Registrarse'</b> en la parte superior derecha de la pantalla." has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción <b>'Registrarse'</b> en la parte superior derecha de la pantalla."
verify: "Verificar usuario" verify: "Verificar usuario"

View File

@@ -0,0 +1,16 @@
class DestroyManager < ActiveRecord::Migration
def self.up
drop_table :managers
end
def self.down
create_table :managers do |t|
t.string :username, null: false
t.string :password_digest, null: false
t.timestamp :last_login_at
t.timestamps
end
add_index :managers, [:username]
end
end

View File

@@ -168,16 +168,6 @@ ActiveRecord::Schema.define(version: 20151019133719) do
add_index "locks", ["user_id"], name: "index_locks_on_user_id", using: :btree add_index "locks", ["user_id"], name: "index_locks_on_user_id", using: :btree
create_table "managers", force: :cascade do |t|
t.string "username", null: false
t.string "password_digest", null: false
t.datetime "last_login_at"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "managers", ["username"], name: "index_managers_on_username", using: :btree
create_table "moderators", force: :cascade do |t| create_table "moderators", force: :cascade do |t|
t.integer "user_id" t.integer "user_id"
end end

View File

@@ -1,5 +1,5 @@
namespace :deploy do namespace :deploy do
desc "compiles assets locally then rsyncs" desc "rsyncs local config/secrets.yml file"
task :upload_secrets do task :upload_secrets do
on roles(:app) do |role| on roles(:app) do |role|
run_locally do run_locally do

View File

@@ -0,0 +1,44 @@
class ManagerAuthenticator
def initialize(data={})
@manager = {login: data[:login], user_key: data[:clave_usuario], date: data[:fecha_conexion]}
end
def auth
return false unless [@manager[:login], @manager[:user_key], @manager[:date]].all? {|_| _.present?}
return @manager if manager_exists? && application_authorized?
false
end
private
def manager_exists?
response = client.call(:get_status_user_data, message: { ub: {user_key: @manager[:user_key], date: @manager[:date]} }).body
parsed_response = parser.parse((response[:get_status_user_data_response][:get_status_user_data_return]))
@manager[:login] == parsed_response["USUARIO"]["LOGIN"]
rescue
false
end
def application_authorized?
response = client.call(:get_applications_user_list, message: { ub: {user_key: @manager[:user_key]} }).body
parsed_response = parser.parse((response[:get_applications_user_list_response][:get_applications_user_list_return]))
aplication_value = parsed_response["APLICACIONES"]["APLICACION"]
# aplication_value from UWEB can be an array of hashes or a hash
aplication_value.include?( {"CLAVE_APLICACION" => application_key}) || aplication_value["CLAVE_APLICACION"] == application_key
rescue
false
end
def client
@client ||= Savon.client(wsdl: Rails.application.secrets.managers_url)
end
def parser
@parser ||= Nori.new
end
def application_key
Rails.application.secrets.managers_application_key.to_s
end
end

View File

@@ -2,36 +2,28 @@ require 'rails_helper'
describe Management::SessionsController do describe Management::SessionsController do
before(:all) do
create(:manager, username: "supermanager" , password: "secret")
end
describe 'Sign in' do describe 'Sign in' do
it "should return 404 if not username/password" do it "should return 404 if wrong credentials" do
expect { get :create }.to raise_error "Not Found" allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(false)
end expect { get :create, login: "nonexistent" , clave_usuario: "wrong"}.to raise_error "Not Found"
it "should return 404 if wrong username" do
expect { get :create, login: "nonexistent" , clave_usuario: "secret" }.to raise_error "Not Found"
end
it "should return 404 if wrong password" do
expect { get :create, login: "supermanager" , clave_usuario: "wrong" }.to raise_error "Not Found"
end end
it "should redirect to management root path if right credentials" do it "should redirect to management root path if right credentials" do
get :create, login: "supermanager" , clave_usuario: "secret" manager = {login: "JJB033", user_key: "31415926" , date: "20151031135905"}
allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return(manager)
get :create, login: "JJB033" , clave_usuario: "31415926", fecha_conexion: "20151031135905"
expect(response).to be_redirect expect(response).to be_redirect
end end
end end
describe 'Sign out' do describe 'Sign out' do
it "should destroy the session and redirect" do it "should destroy the session and redirect" do
session[:manager_id] = 1 session[:manager] = {user_key: "31415926" , date: "20151031135905", login: "JJB033"}
delete :destroy delete :destroy
expect(session[:manager_id]).to be_nil expect(session[:manager]).to be_nil
expect(response).to be_redirect expect(response).to be_redirect
end end
end end

View File

@@ -223,11 +223,6 @@ FactoryGirl.define do
user user
end end
factory :manager do
sequence(:username) { |n| "manager#{n}" }
password 'supersecret'
end
factory :organization do factory :organization do
user user
responsible_name "Johnny Utah" responsible_name "Johnny Utah"

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'DocumentVerifications' do feature 'DocumentVerifications' do
background do background do
login_as_manager(create(:manager)) login_as_manager
end end
scenario 'Verifying a level 3 user shows an "already verified" page' do scenario 'Verifying a level 3 user shows an "already verified" page' do
@@ -53,4 +53,23 @@ feature 'DocumentVerifications' do
expect(page).to have_content "Please introduce the email used on the account" expect(page).to have_content "Please introduce the email used on the account"
end end
scenario 'Document number is format-standarized' do
visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '12345 - h'
click_button 'Check'
expect(page).to have_content "Document number: 12345H"
end
scenario 'User age is checked' do
expect_any_instance_of(Verification::Management::Document).to receive(:under_sixteen?).and_return(true)
visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '1234'
click_button 'Check'
expect(page).to have_content "You must be over 16 to verify your account."
end
end end

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'EmailVerifications' do feature 'EmailVerifications' do
scenario 'Verifying a level 1 user via email' do scenario 'Verifying a level 1 user via email' do
login_as_manager(create(:manager)) login_as_manager
user = create(:user) user = create(:user)

View File

@@ -3,7 +3,7 @@ require 'rails_helper'
feature 'Managed User' do feature 'Managed User' do
background do background do
login_as_manager(create(:manager)) login_as_manager
end end
context "Currently managed user" do context "Currently managed user" do
@@ -47,7 +47,7 @@ feature 'Managed User' do
end end
scenario "User becomes verified as level two (pending email confirmation for level three)" do scenario "User becomes verified as level two (pending email confirmation for level three)" do
login_as_manager(create(:manager)) login_as_manager
user = create(:user) user = create(:user)
@@ -71,7 +71,7 @@ feature 'Managed User' do
end end
scenario "User is created as level three from scratch" do scenario "User is created as level three from scratch" do
login_as_manager(create(:manager)) login_as_manager
visit management_document_verifications_path visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '1234' fill_in 'document_verification_document_number', with: '1234'
@@ -111,10 +111,10 @@ feature 'Managed User' do
expect(page).to have_content "Identified as" expect(page).to have_content "Identified as"
expect(page).to have_content "#{user.username}" expect(page).to have_content "#{user.username}"
click_link "Logout" click_link "Change user"
end end
expect(page).to have_content "Signed out successfully." expect(page).to have_content "User session signed out successfully."
expect(current_path).to eq(management_root_path) expect(current_path).to eq(management_root_path)
end end

View File

@@ -3,8 +3,7 @@ require 'rails_helper'
feature 'Proposals' do feature 'Proposals' do
background do background do
manager = create(:manager) login_as_manager
login_as_manager(manager)
end end
context "Create" do context "Create" do
@@ -118,8 +117,8 @@ feature 'Proposals' do
end end
scenario "Filtering proposals to be printed", :js do scenario "Filtering proposals to be printed", :js do
create(:proposal, title: 'Best proposal').update_column(:confidence_score, 10)
create(:proposal, title: 'Worst proposal').update_column(:confidence_score, 2) create(:proposal, title: 'Worst proposal').update_column(:confidence_score, 2)
create(:proposal, title: 'Best proposal').update_column(:confidence_score, 10)
create(:proposal, title: 'Medium proposal').update_column(:confidence_score, 5) create(:proposal, title: 'Medium proposal').update_column(:confidence_score, 5)
user = create(:user, :level_two) user = create(:user, :level_two)
@@ -127,8 +126,6 @@ feature 'Proposals' do
click_link "Print proposals" click_link "Print proposals"
select 'most supported', from: 'order-selector'
expect(page).to have_selector('.js-order-selector[data-order="confidence_score"]') expect(page).to have_selector('.js-order-selector[data-order="confidence_score"]')
within '#proposals' do within '#proposals' do
@@ -136,8 +133,17 @@ feature 'Proposals' do
expect('Medium proposal').to appear_before('Worst proposal') expect('Medium proposal').to appear_before('Worst proposal')
end end
expect(current_url).to include('order=confidence_score') select 'newest', from: 'order-selector'
expect(page).to have_selector('.js-order-selector[data-order="created_at"]')
expect(current_url).to include('order=created_at')
expect(current_url).to include('page=1') expect(current_url).to include('page=1')
within '#proposals' do
expect('Medium proposal').to appear_before('Best proposal')
expect('Best proposal').to appear_before('Worst proposal')
end
end end
end end

View File

@@ -4,7 +4,7 @@ feature 'users' do
scenario 'Creating a level 3 user from scratch' do scenario 'Creating a level 3 user from scratch' do
login_as_manager(create(:manager)) login_as_manager
visit management_document_verifications_path visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '1234' fill_in 'document_verification_document_number', with: '1234'

View File

@@ -0,0 +1,65 @@
require 'rails_helper'
describe ManagerAuthenticator do
describe 'initialization params' do
it 'should cause auth to return false if blank login' do
authenticator = ManagerAuthenticator.new({login: "", clave_usuario: "31415926", fecha_conexion: "20151031135905"})
expect(authenticator.auth).to be false
end
it 'should cause auth to return false if blank user_key' do
authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "", fecha_conexion: "20151031135905"})
expect(authenticator.auth).to be false
end
it 'should cause auth to return false if blank date' do
authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: ""})
expect(authenticator.auth).to be false
end
end
describe '#auth' do
before(:all) do
@authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905"})
end
it 'should return false if not manager_exists' do
allow(@authenticator).to receive(:manager_exists?).and_return(false)
allow(@authenticator).to receive(:application_authorized?).and_return(true)
expect(@authenticator.auth).to be false
end
it 'should return false if not application_authorized' do
allow(@authenticator).to receive(:manager_exists?).and_return(true)
allow(@authenticator).to receive(:application_authorized?).and_return(false)
expect(@authenticator.auth).to be false
end
it 'should return ok if manager_exists and application_authorized' do
allow(@authenticator).to receive(:manager_exists?).and_return(true)
allow(@authenticator).to receive(:application_authorized?).and_return(true)
expect(@authenticator.auth).to be_truthy
end
end
describe 'SOAP' do
before(:all) do
@authenticator = ManagerAuthenticator.new({login: "JJB033", clave_usuario: "31415926", fecha_conexion: "20151031135905"})
end
it 'should call the verification user method' do
allow(@authenticator).to receive(:application_authorized?).and_return(true)
expect(@authenticator.send(:client)).to receive(:call).with(:get_status_user_data, message: { ub: {user_key: "31415926", date: "20151031135905"} })
@authenticator.auth
end
it 'should call the permissions check method' do
allow(@authenticator).to receive(:manager_exists?).and_return(true)
expect(@authenticator.send(:client)).to receive(:call).with(:get_applications_user_list, message: { ub: {user_key: "31415926"} })
@authenticator.auth
end
end
end

View File

@@ -1,46 +0,0 @@
require 'rails_helper'
describe Manager do
describe "valid?" do
let(:manager) { create(:manager) }
it "is false when username is blank" do
manager.username = nil
expect(manager).to_not be_valid
end
it "is false when password is blank" do
manager.password_digest = nil
expect(manager).to_not be_valid
end
it "is true if username and password present" do
expect(manager).to be_valid
end
end
describe "self.valid_manager" do
before(:all) { create(:manager, username: "Silvia" ,password: "supersecret") }
it "is false when username is blank" do
expect(Manager.valid_manager(nil, "supersecret")).to be_blank
end
it "is false when password is blank" do
expect(Manager.valid_manager("Silvia", nil)).to be_blank
end
it "is false if manager unexistent" do
expect(Manager.valid_manager("Manager", "supersecret")).to be_blank
end
it "is false if wrong password unexistent" do
expect(Manager.valid_manager("Silvia", "wrong")).to be_blank
end
it "is true if right username/password combination" do
expect(Manager.valid_manager("Silvia", "supersecret")).to be_present
end
end
end

View File

@@ -194,6 +194,22 @@ describe Proposal do
end end
end end
describe '#cached_votes_up' do
describe "with deprecated long tag list" do
it "should increase number of cached_total_votes" do
proposal = create(:proposal)
tag_list = ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7"]
proposal.update_attribute(:tag_list, tag_list)
expect(proposal.update_cached_votes).to eq(true)
end
end
end
describe '#hot_score' do describe '#hot_score' do
let(:now) { Time.now } let(:now) { Time.now }

View File

@@ -0,0 +1,37 @@
require 'rails_helper'
describe Verification::Management::Document do
describe "#valid_age?" do
it "returns false when the user is younger than sixteen years old" do
census_response = double(date_of_birth: "31-12-#{16.years.ago.year}")
expect(Verification::Management::Document.new.valid_age?(census_response)).to be false
end
it "returns true when the user is sixteen years old" do
census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y"))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
it "returns true when the user is older than sixteen years old" do
census_response = double(date_of_birth: "31-12-#{33.years.ago.year}")
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
end
describe "#under_sixteen?" do
it "returns true when the user is younger than sixteen years old" do
census_response = double(date_of_birth: "31-12-#{16.years.ago.year}")
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true
end
it "returns false when the user is sixteen years old" do
census_response = double(date_of_birth: 16.years.ago.strftime("%d-%m-%Y"))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
end
it "returns false when the user is older than sixteen years old" do
census_response = double(date_of_birth: "31-12-#{33.years.ago.year}")
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
end
end
end

View File

@@ -24,8 +24,10 @@ module CommonActions
click_button 'Log in' click_button 'Log in'
end end
def login_as_manager(manager) def login_as_manager
visit management_sign_in_path(login: manager.username, clave_usuario: manager.password) login, user_key, date = "JJB042", "31415926", Time.now.strftime("%Y%m%d%H%M%S")
allow_any_instance_of(ManagerAuthenticator).to receive(:auth).and_return({login: login, user_key: user_key, date: date})
visit management_sign_in_path(login: login, clave_usuario: user_key, fecha_conexion: date)
end end
def login_managed_user(user) def login_managed_user(user)