fixes conflicts

This commit is contained in:
rgarcia
2015-10-09 17:37:45 +02:00
52 changed files with 988 additions and 61 deletions

View File

@@ -4,6 +4,7 @@
// 02. Sidebar
// 03. List elements
// 04. Stats
// 05. Management
//
// 01. Global styles
@@ -272,3 +273,37 @@ body.admin {
}
}
}
// 05. Management
// - - - - - - - - - - - - - - - - - - - - - - - - -
.postfix {
height: rem-calc(48);
line-height: rem-calc(48);
}
.user-permissions {
ul {
list-style-type: none;
margin-left: 0;
li {
font-size: rem-calc(14);
margin-bottom: rem-calc(12);
span {
color: $text-medium;
font-size: rem-calc(12);
}
.icon-check {
color: $check;
}
.icon-x {
color: $delete;
}
}
}
}

View File

@@ -0,0 +1,41 @@
class Management::DocumentVerificationsController < Management::BaseController
def index
@document_verification = Verification::Management::Document.new()
end
def check
@document_verification = Verification::Management::Document.new(document_verification_params)
if @document_verification.valid?
if @document_verification.verified?
render :verified
elsif @document_verification.user?
render :new
elsif @document_verification.in_census?
redirect_to new_management_email_verification_path(email_verification: document_verification_params)
else
render :invalid_document
end
else
render :index
end
end
def create
@document_verification = Verification::Management::Document.new(document_verification_params)
@document_verification.verify
render :verified
end
private
def document_verification_params
params.require(:document_verification).permit(:document_type, :document_number)
end
end

View File

@@ -0,0 +1,24 @@
class Management::EmailVerificationsController < Management::BaseController
def new
@email_verification = Verification::Management::Email.new(email_verification_params)
end
def create
@email_verification = Verification::Management::Email.new(email_verification_params)
if @email_verification.save
render :sent
else
render :new
end
end
private
def email_verification_params
params.require(:email_verification).permit(:document_type, :document_number, :email)
end
end

View File

@@ -0,0 +1,25 @@
class Management::UsersController < Management::BaseController
def new
@user = User.new(user_params)
end
def create
@user = User.new(user_params)
@user.skip_password_validation = true
@user.terms_of_service = '1'
@user.residence_verified_at = Time.now
@user.verified_at = Time.now
if @user.save then
render :show
else
render :new
end
end
private
def user_params
params.require(:user).permit(:document_type, :document_number, :username, :email)
end
end

View File

@@ -0,0 +1,51 @@
class Users::ConfirmationsController < Devise::ConfirmationsController
# new action, PATCH does not exist in the default Devise::ConfirmationsController
# PATCH /resource/confirmation
def update
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token])
if resource.encrypted_password.blank?
resource.assign_attributes(resource_params)
if resource.valid? # password is set correctly
resource.save
resource.confirm
set_flash_message(:notice, :confirmed) if is_flashing_format?
sign_in_and_redirect(resource_name, resource)
else
render :show
end
else
resource.errors.add(:email, :password_already_set)
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
end
end
# GET /resource/confirmation?confirmation_token=abcdef
def show
# In the default implementation, this already confirms the resource:
# self.resource = self.resource = resource_class.confirm_by_token(params[:confirmation_token])
self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token])
yield resource if block_given?
# New condition added to if: when no password was given, display the "show" view (which uses "update" above)
if resource.encrypted_password.blank?
respond_with_navigational(resource){ render :show }
elsif resource.errors.empty?
resource.confirm # Last change: confirm happens here for people with passwords instead of af the top of the show action
set_flash_message(:notice, :confirmed) if is_flashing_format?
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
end
end
protected
def resource_params
params.require(resource_name).permit(:password, :password_confirmation, :email)
end
end

View File

@@ -1,11 +1,18 @@
class Users::SessionsController < Devise::SessionsController
def after_sign_in_path_for(resource)
if resource.show_welcome_screen?
if !verifying_via_email? && resource.show_welcome_screen?
welcome_path
else
root_path
super
end
end
private
def verifying_via_email?
stored_path = session[stored_location_key_for(resource)] || ""
stored_path[0..5] == "/email"
end
end

View File

@@ -6,7 +6,11 @@ class Verification::EmailController < ApplicationController
def show
if Verification::Email.find(current_user, params[:email_verification_token])
current_user.update(verified_at: Time.now)
current_user.update(verified_at: Time.now,
document_number: current_user.document_number || current_user.unconfirmed_document_number,
residence_verified_at: current_user.residence_verified_at || Time.now)
redirect_to account_path, notice: t('verification.email.show.flash.success')
else
redirect_to verified_user_path, alert: t('verification.email.show.alert.failure')
@@ -17,7 +21,11 @@ class Verification::EmailController < ApplicationController
@email = Verification::Email.new(@verified_user)
if @email.save
current_user.reload
Mailer.email_verification(current_user, @email.recipient, @email.encrypted_token).deliver_later
Mailer.email_verification(current_user,
@email.recipient,
@email.encrypted_token,
@verified_user.document_type,
@verified_user.document_number).deliver_later
redirect_to account_path, notice: t('verification.email.create.flash.success', email: @verified_user.email)
else
redirect_to verified_user_path, alert: t('verification.email.create.alert.failure')
@@ -33,4 +41,4 @@ class Verification::EmailController < ApplicationController
def verified_user_params
params.require(:verified_user).permit(:id)
end
end
end

View File

@@ -12,21 +12,10 @@ module AdminHelper
options
end
def humanize_document_type(document_type)
case document_type
when "1"
t "verification.residence.new.document_type.spanish_id"
when "2"
t "verification.residence.new.document_type.passport"
when "3"
t "verification.residence.new.document_type.residence_card"
end
end
private
def namespace
controller.class.parent.name.downcase
end
end
end

View File

@@ -0,0 +1,12 @@
module UserHelper
def humanize_document_type(document_type)
case document_type
when "1"
t "verification.residence.new.document_type.spanish_id"
when "2"
t "verification.residence.new.document_type.passport"
when "3"
t "verification.residence.new.document_type.residence_card"
end
end
end

View File

@@ -1,6 +1,7 @@
class Mailer < ApplicationMailer
helper :text_with_links
helper :mailer
helper :user
def comment(comment)
@comment = comment
@@ -16,10 +17,12 @@ class Mailer < ApplicationMailer
mail(to: @recipient.email, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present?
end
def email_verification(user, recipient, token)
def email_verification(user, recipient, token, document_type, document_number)
@user = user
@recipient = recipient
@token = token
@document_type = document_type
@document_number = document_number
mail(to: @recipient, subject: t('mailers.email_verification.subject'))
end

View File

@@ -25,6 +25,7 @@ class User < ActiveRecord::Base
validates :username, presence: true, unless: :organization?
validates :username, uniqueness: true, unless: :organization?
validates :document_number, uniqueness: { scope: :document_type }, allow_nil: true
validate :validate_username_length
validates :official_level, inclusion: {in: 0..5}
@@ -35,11 +36,16 @@ class User < ActiveRecord::Base
accepts_nested_attributes_for :organization, update_only: true
attr_accessor :skip_password_validation
scope :administrators, -> { joins(:administrators) }
scope :moderators, -> { joins(:moderator) }
scope :organizations, -> { joins(:organization) }
scope :officials, -> { where("official_level > 0") }
scope :for_render, -> { includes(:organization) }
scope :by_document, -> (document_type, document_number) { where(document_type: document_type, document_number: document_number) }
before_validation :clean_document_number
def self.find_for_oauth(auth, signed_in_resource = nil)
# Get the identity and user if they exist
@@ -158,11 +164,20 @@ class User < ActiveRecord::Base
end
def show_welcome_screen?
sign_in_count == 1 && unverified? && !organization
sign_in_count == 1 && unverified? && !organization && !administrator?
end
def password_required?
return false if skip_password_validation
super
end
private
def clean_document_number
self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank?
end
def validate_username_length
validator = ActiveModel::Validations::LengthValidator.new(
attributes: :username,

View File

@@ -0,0 +1,34 @@
class Verification::Management::Document
include ActiveModel::Model
attr_accessor :document_type
attr_accessor :document_number
validates :document_type, :document_number, presence: true
delegate :username, :email, to: :user, allow_nil: true
def user
@user = User.by_document(document_type, document_number).first
end
def user?
user.present?
end
def in_census?
CensusApi.new.call(document_type, document_number).valid?
end
def verified?
user? && user.level_three_verified?
end
def verify
user.update(verified_at: Time.now) if user?
end
end

View File

@@ -0,0 +1,61 @@
class Verification::Management::Email
include ActiveModel::Model
attr_accessor :document_type
attr_accessor :document_number
attr_accessor :email
validates :document_type, :document_number, :email, presence: true
validates :email, format: { with: Devise.email_regexp }, allow_blank: true
validate :validate_user
validate :validate_document_number
delegate :username, to: :user, allow_nil: true
def user
@user ||= User.where(email: email).first
end
def user?
user.present?
end
def save
return false unless valid?
plain_token, encrypted_token = Devise.token_generator.generate(User, :email_verification_token)
user.update(document_type: document_type,
unconfirmed_document_number: document_number,
email_verification_token: plain_token)
Mailer.email_verification(user, email, encrypted_token, document_type, document_number).deliver_later
true
end
private
def validate_user
return if errors.count > 0
if !user?
errors.add(:email, I18n.t('errors.messages.user_not_found'))
elsif user.level_three_verified?
errors.add(:email, I18n.t('management.email_verifications.already_verified'))
end
end
def validate_document_number
return if errors.count > 0
if document_number_mismatch?
errors.add(:email,
I18n.t('management.email_verifications.document_mismatch',
document_type: ApplicationController.helpers.humanize_document_type(user.document_type),
document_number: user.document_number))
end
end
def document_number_mismatch?
user? && user.document_number.present? &&
(user.document_number != document_number || user.document_type != document_type)
end
end

View File

@@ -1,16 +1,23 @@
<% provide :title do %><%= t("devise_views.confirmations.title") %><% end %>
<h1 class="text-center"><%= t("devise_views.confirmations.title") %></h1>
<% provide :title do %><%= t("devise_views.confirmations.new.title") %><% end %>
<h1 class="text-center"><%= t("devise_views.confirmations.new.title") %></h1>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= render 'shared/errors', resource: resource %>
<div class="row">
<div class="small-12 columns">
<%= f.email_field :email, autofocus: true, placeholder: t("devise_views.confirmations.email_label"), value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
<%= f.email_field :email, autofocus: true, placeholder: t("devise_views.confirmations.new.email_label"), value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<% if @requires_password %>
<p><%= f.password_field :password %></p>
<p><%= f.password_field :password_confirmation %></p>
<% end %>
<%= hidden_field_tag :confirmation_token,@confirmation_token %>
<div class="small-12 columns">
<%= f.submit(t("devise_views.confirmations.submit"), class: "button radius expand") %>
<%= f.submit(t("devise_views.confirmations.new.submit"), class: "button radius expand") %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,34 @@
<% provide :title do %><%= t("devise_views.confirmations.show.title") %><% end %>
<h1 class="text-center"><%= t("devise_views.confirmations.show.title") %></h1>
<p><%= t('devise_views.confirmations.show.instructions_html', email: resource.email) %></p>
<%= form_for(resource,
as: resource_name,
url: update_user_confirmation_path,
html: { method: :patch }) do |f| %>
<p><%= t('devise_views.confirmations.show.please_set_password') %></p>
<%= render 'shared/errors', resource: resource %>
<div class="row">
<div class="small-12 columns">
<%= f.password_field :password,
autofocus: true,
label: t('devise_views.confirmations.show.new_password_label') %>
</div>
<div class="small-12 columns">
<%= f.password_field :password_confirmation,
label: t('devise_views.confirmations.show.new_password_confirmation_label') %>
</div>
</div>
<%= hidden_field_tag :confirmation_token, params[:confirmation_token] %>
<div class="small-12 columns">
<%= f.submit(t("devise_views.confirmations.show.submit"), class: "button radius expand") %>
</div>
<% end %>
<%= render "devise/shared/links" %>

View File

@@ -9,6 +9,12 @@
t('mailers.email_verification.click_here_to_verify'),
email_url(email_verification_token: @token))) %>
</p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.email_verification.instructions_2_html",
document_type: humanize_document_type(@document_type),
document_number: @document_number) %>
</p>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.email_verification.thanks") %>
</p>

View File

@@ -0,0 +1,10 @@
<p class="account-info">
<%= t("management.document_type_label") %> <strong><%= humanize_document_type(account.document_type) %></strong>
<%= t("management.document_number") %> <strong><%= account.document_number %></strong>
<% if account.username.present? %>
<%= t("management.username_label") %> <strong><%= account.username %></strong>
<% end %>
<% if account.email.present? %>
<%= t("management.email_label") %> <strong><%= account.email %></strong>
<% end %>
</p>

View File

@@ -0,0 +1,16 @@
<nav class="admin-sidebar">
<ul id="admin_menu">
<li>
<%= link_to t("management.menu.title"), management_root_path %>
</li>
<li <%= "class=active" if controller_name == "document_verifications" ||
controller_name == "email_verifications" ||
controller_name == "users" %>>
<%= link_to management_document_verifications_path do %>
<i class="icon-tag"></i>
<%= t("management.menu.users") %>
<% end %>
</li>
</ul>
</nav>

View File

@@ -0,0 +1,20 @@
<%
# Parameters:
# message: A string explaining the permissions
# permissions: An array of symbols containing the permissions
# (can be :debates, :proposal, :support_proposal, :votes)
%>
<div class="user-permissions">
<p><%= message %></p>
<ul>
<% [:debates, :create_proposals, :support_proposals, :vote_proposals].each do |permission| %>
<li>
<i class="<%= permissions.include?(permission) ? 'icon-check' : 'icon-x' %>"></i>
<%= t("management.permissions.#{permission}") %>
</li>
<% end %>
</ul>
</div>

View File

@@ -0,0 +1,25 @@
<h2><%= t("management.document_verifications.title") %></h2>
<div class="row">
<div class="small-12 medium-8 column">
<%= form_for(@document_verification,
as: :document_verification,
url: check_management_document_verifications_path) do |f| %>
<div class="small-12 medium-4">
<%= f.select(:document_type,
[[humanize_document_type("1"), 1],
[humanize_document_type("2"), 2],
[humanize_document_type("3"), 3]],
label: t("management.document_type_label")) %>
</div>
<div class="small-12 medium-5">
<%= f.text_field :document_number,
placeholder: t('management.document_number'),
label: t("management.document_number")
%>
</div>
<%= f.submit t("management.check") %>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,15 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box alert radius">
<%= t("management.document_verifications.not_in_census") %>
</div>
<%= render 'management/user_permissions',
message: t("management.document_verifications.not_in_census_info"),
permissions: [:debates, :create_proposals] %>
<p>
<%= t("management.document_verifications.has_no_account_html",
link: link_to('http://decide.madrid.es', 'http://decide.madrid.es'),
target: "_blank") %>
</p>

View File

@@ -0,0 +1,17 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box success radius">
<%= t("management.document_verifications.please_check_account_data") %>
</div>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals] %>
<%= form_for @document_verification,
as: :document_verification,
url: management_document_verifications_path do |f| %>
<%= f.hidden_field :document_type %>
<%= f.hidden_field :document_number %>
<%= f.submit t("management.document_verifications.verify"), class: "button success radius" %>
<% end %>

View File

@@ -0,0 +1,11 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box success radius">
<%= t("management.document_verifications.already_verified") %>
</div>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>

View File

@@ -0,0 +1,31 @@
<%= render 'management/account_info.html', account: @email_verification %>
<div class="alert-box success radius">
<%= t("management.email_verifications.document_found_in_census") %>
</div>
<ul>
<li>
<strong><%= t("management.email_verifications.if_existing_account") %></strong>
<p><%= t("management.email_verifications.introduce_email") %></p>
<%= form_for @email_verification,
as: :email_verification,
url: management_email_verifications_path do |f| %>
<%= f.hidden_field :document_type %>
<%= f.hidden_field :document_number %>
<%= f.text_field :email, label: false, placeholder: t('management.email_verifications.email_placeholder') %>
<%= f.submit t("management.email_verifications.send_email"), class: "button success radius" %>
<% end %>
</li>
<li>
<strong><%= t("management.email_verifications.if_no_existing_account") %></strong>
<p class="margin-top">
<%= link_to t('management.users.create_user'), new_management_user_path(user: params[:email_verification]), class: "button warning radius" %>
</p>
</li>
</ul>

View File

@@ -0,0 +1,14 @@
<%= render 'management/account_info.html', account: @email_verification %>
<div class="alert-box success radius">
<%= t("management.email_verifications.email_sent_instructions") %>
</div>
<%= render 'management/user_permissions',
message: t("management.email_verifications.document_found_in_census"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>
<p>
<a href="javascript:window.print();" class="button warning radius"><%= t("management.print_info") %></a>
</p>

View File

@@ -0,0 +1,25 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_info") %></p>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>
<div class="row">
<div class="small-12 medium-9 column">
<%= form_for @user, url: management_users_path do |f| %>
<%= f.hidden_field :document_type %>
<%= f.hidden_field :document_number %>
<%= f.text_field :username,
label: t('management.username_label'),
placeholder: t('management.username_label') %>
<%= f.text_field :email,
label: t('management.email_label'),
placeholder: t('management.email_label') %>
<%= f.submit t("management.users.create_user_submit"), class: "button success radius" %>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,7 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_success_html", email: @user.email) %></p>
<%= render 'management/user_permissions',
message: t("management.document_verifications.in_census_has_following_permissions"),
permissions: [:debates, :create_proposals, :support_proposals, :vote_proposals] %>