refactors managed user info into management layout

This commit is contained in:
rgarcia
2015-10-12 14:03:23 +02:00
parent e66572b8ba
commit f55c3974aa
15 changed files with 44 additions and 43 deletions

View File

@@ -14,11 +14,7 @@ class Management::BaseController < ActionController::Base
end
def current_user
@current_user ||= User.find(session["managed_user_id"]) if session["managed_user_id"]
end
def set_managed_user(user)
session["managed_user_id"] = user.id
@current_user ||= Verification::Management::ManagedUser.find(session[:document_type], session[:document_number])
end
end

View File

@@ -1,5 +1,7 @@
class Management::DocumentVerificationsController < Management::BaseController
before_action :set_document, only: :check
def index
@document_verification = Verification::Management::Document.new()
end
@@ -9,7 +11,6 @@ class Management::DocumentVerificationsController < Management::BaseController
if @document_verification.valid?
if @document_verification.verified?
set_managed_user(@document_verification.user)
render :verified
elsif @document_verification.user?
render :new
@@ -26,7 +27,6 @@ class Management::DocumentVerificationsController < Management::BaseController
def create
@document_verification = Verification::Management::Document.new(document_verification_params)
@document_verification.verify
set_managed_user(@document_verification.user)
render :verified
end
@@ -36,4 +36,9 @@ class Management::DocumentVerificationsController < Management::BaseController
params.require(:document_verification).permit(:document_type, :document_number)
end
def set_document
session[:document_type] = params[:document_verification][:document_type]
session[:document_number] = params[:document_verification][:document_number]
end
end

View File

@@ -8,7 +8,6 @@ class Management::EmailVerificationsController < Management::BaseController
@email_verification = Verification::Management::Email.new(email_verification_params)
if @email_verification.save
set_managed_user(@email_verification.user)
render :sent
else
render :new

View File

@@ -12,7 +12,6 @@ class Management::UsersController < Management::BaseController
@user.verified_at = Time.now
if @user.save then
set_managed_user(@user)
render :show
else
render :new

View File

@@ -0,0 +1,12 @@
class Verification::Management::ManagedUser
include ActiveModel::Model
attr_accessor :user
def self.find(document_type, document_number)
User.where('document_number is not null').
find_or_initialize_by(document_type: document_type,
document_number: document_number)
end
end

View File

@@ -42,6 +42,10 @@
<%= render "/management/menu" %>
</div>
<section class="top-bar-section">
<%= render "management/account_info" %>
</section>
<div class="admin-content small-12 medium-9 column">
<% if notice %>
<div data-alert class="alert-box radius success">

View File

@@ -1,23 +1,25 @@
<p class="account-info">
<% if current_user %>
<%= t("management.account_info.managed_user_title") %>
<% if current_user.document_number.present? %>
<span class="account-info right">
<% if current_user.level_two_or_three_verified? %>
<%= t("management.account_info.identified_label") %>
<% end %>
<% if account.username.present? %>
<%= t("management.username_label") %>
<strong><%= account.username %></strong>
<% if current_user.username.present? %>
<%= t("management.account_info.username_label") %>
<strong><%= current_user.username %></strong>
<% end %>
<% if account.email.present? %>
<%= t("management.email_label") %>
<strong><%= account.email %></strong>
<% if current_user.email.present? %>
<%= t("management.account_info.email_label") %>
<strong><%= current_user.email %></strong>
<% end %>
<%= t("management.document_type_label") %>
<strong><%= humanize_document_type(account.document_type) %></strong>
<%= t("management.account_info.document_type_label") %>
<strong><%= humanize_document_type(current_user.document_type) %></strong>
<%= t("management.document_number") %>
<strong><%= account.document_number %></strong>
<%= t("management.account_info.document_number_label") %>
<strong><%= current_user.document_number %></strong>
<%= link_to(t("management.account_info.logout"), management_session_path, method: :delete) %>
</p>
<%= link_to(t("management.account_info.logout"), logout_management_users_path, method: :delete) %>
</span>
<% end %>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box alert radius">
<%= t("management.document_verifications.not_in_census") %>
</div>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box success radius">
<%= t("management.document_verifications.please_check_account_data") %>
</div>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @document_verification %>
<div class="alert-box success radius">
<%= t("management.document_verifications.already_verified") %>
</div>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @email_verification %>
<div class="alert-box success radius">
<%= t("management.email_verifications.document_found_in_census") %>
</div>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @email_verification %>
<div class="alert-box success radius">
<%= t("management.email_verifications.email_sent_instructions") %>
</div>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: current_user %>
<section role="main">
<%= render 'admin/shared/proposal_search', url: management_proposals_path %>

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_info") %></p>
<%= render 'management/user_permissions',

View File

@@ -1,5 +1,3 @@
<%= render 'management/account_info.html', account: @user %>
<p><%= t("management.users.create_user_success_html", email: @user.email) %></p>
<%= render 'management/user_permissions',