View and search users from admin panel
This commit is contained in:
16
app/controllers/admin/users_controller.rb
Normal file
16
app/controllers/admin/users_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class Admin::UsersController < Admin::BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
if params[:search]
|
||||
s = params[:search]
|
||||
@users = User.where("username ILIKE ? OR email ILIKE ? OR document_number ILIKE ?", "%#{s}%","%#{s}%","%#{s}%").page(params[:page])
|
||||
else
|
||||
@users = @users.page(params[:page])
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,7 +29,7 @@ module AdminHelper
|
||||
end
|
||||
|
||||
def menu_profiles?
|
||||
["administrators", "organizations", "officials", "moderators", "valuators", "managers"].include? controller_name
|
||||
["administrators", "organizations", "officials", "moderators", "valuators", "managers", "users"].include? controller_name
|
||||
end
|
||||
|
||||
def menu_banners?
|
||||
|
||||
@@ -38,6 +38,7 @@ module Abilities
|
||||
can [:search, :create, :index, :destroy], ::Moderator
|
||||
can [:search, :create, :index, :summary], ::Valuator
|
||||
can [:search, :create, :index, :destroy], ::Manager
|
||||
can [:search, :index], ::User
|
||||
|
||||
can :manage, Annotation
|
||||
|
||||
|
||||
@@ -118,6 +118,10 @@
|
||||
<li <%= "class=active" if controller_name == "managers" %>>
|
||||
<%= link_to t('admin.menu.managers'), admin_managers_path %>
|
||||
</li>
|
||||
|
||||
<li <%= 'class=active' if controller_name == 'users' %>>
|
||||
<%= link_to t('admin.menu.users'), admin_users_path %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
22
app/views/admin/users/_users.html.erb
Normal file
22
app/views/admin/users/_users.html.erb
Normal file
@@ -0,0 +1,22 @@
|
||||
<h3><%= page_entries_info @users %></h3>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t('admin.users.fields.name') %></th>
|
||||
<th><%= t('admin.users.fields.email') %></th>
|
||||
<th><%= t('admin.users.fields.document_number') %></th>
|
||||
<th><%= t('admin.users.fields.verification_level') %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<% @users.each do |user| %>
|
||||
<tr>
|
||||
<td><%= user.name %></td>
|
||||
<td><%= user.email %></td>
|
||||
<td><%= user.document_number %></td>
|
||||
<td><%= user.user_type %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<%= paginate @users %>
|
||||
16
app/views/admin/users/index.html.erb
Normal file
16
app/views/admin/users/index.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<h2><%= t("admin.users.index.title") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<%= form_tag admin_users_path, method: :get, remote: true do %>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= text_field_tag :search, '', placeholder: t('admin.users.search.placeholder') %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= submit_tag t('admin.users.search.search'), class: 'button' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div id="users">
|
||||
<%= render "users" %>
|
||||
</div>
|
||||
1
app/views/admin/users/index.js.erb
Normal file
1
app/views/admin/users/index.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#users").html("<%= j render 'users' %>");
|
||||
@@ -380,6 +380,7 @@ en:
|
||||
title_banners: Banners
|
||||
title_site_customization: Site customization
|
||||
legislation: Collaborative Legislation
|
||||
users: Users
|
||||
administrators:
|
||||
index:
|
||||
title: Administrators
|
||||
@@ -816,6 +817,19 @@ en:
|
||||
name:
|
||||
placeholder: Type the name of the topic
|
||||
update: Update Topic
|
||||
users:
|
||||
fields:
|
||||
name: Name
|
||||
email: Email
|
||||
document_number: Document number
|
||||
verification_level: Verification level
|
||||
index:
|
||||
title: User
|
||||
user:
|
||||
verify: Verify
|
||||
search:
|
||||
placeholder: Search user by email, name or document number
|
||||
search: Search
|
||||
verifications:
|
||||
index:
|
||||
phone_not_given: Phone not given
|
||||
|
||||
@@ -391,6 +391,7 @@ es:
|
||||
title_banners: Banners
|
||||
title_site_customization: Personalizar sitio
|
||||
legislation: Legislación colaborativa
|
||||
users: Usuarios
|
||||
moderators:
|
||||
index:
|
||||
title: Moderadores
|
||||
@@ -816,6 +817,19 @@ es:
|
||||
name:
|
||||
placeholder: Escribe el nombre del tema
|
||||
update: Actualizar Tema
|
||||
users:
|
||||
fields:
|
||||
name: Nombre
|
||||
email: Correo electrónico
|
||||
document_number: DNI/Pasaporte/Tarjeta de residencia
|
||||
verification_level: Nivel de verficación
|
||||
index:
|
||||
title: Usuarios
|
||||
user:
|
||||
verify: Verificar
|
||||
search:
|
||||
placeholder: Buscar usuario por email, nombre o DNI
|
||||
search: Buscar
|
||||
verifications:
|
||||
index:
|
||||
phone_not_given: No ha dado su teléfono
|
||||
|
||||
@@ -238,6 +238,8 @@ Rails.application.routes.draw do
|
||||
get :search, on: :collection
|
||||
end
|
||||
|
||||
resources :users, only: [:index, :show]
|
||||
|
||||
scope module: :poll do
|
||||
resources :polls do
|
||||
get :search_questions, on: :member
|
||||
|
||||
28
spec/features/admin/users_spec.rb
Normal file
28
spec/features/admin/users_spec.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'Admin users' do
|
||||
background do
|
||||
@admin = create(:administrator)
|
||||
@user = create(:user, username: 'Jose Luis Balbin')
|
||||
login_as(@admin.user)
|
||||
visit admin_users_path
|
||||
end
|
||||
|
||||
scenario 'Index' do
|
||||
expect(page).to have_content @user.name
|
||||
expect(page).to have_content @user.email
|
||||
expect(page).to have_content @admin.name
|
||||
expect(page).to have_content @admin.email
|
||||
end
|
||||
|
||||
scenario 'Search' do
|
||||
fill_in :search, with: "Luis"
|
||||
click_button 'Search'
|
||||
|
||||
expect(page).to have_content @user.name
|
||||
expect(page).to have_content @user.email
|
||||
expect(page).to_not have_content @admin.name
|
||||
expect(page).to_not have_content @admin.email
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user