Filter erased users and show erase reason in admin

This commit is contained in:
decabeza
2020-07-17 22:21:52 +02:00
parent 240cad793f
commit f72f255d15
6 changed files with 61 additions and 11 deletions

View File

@@ -1,8 +1,11 @@
class Admin::UsersController < Admin::BaseController class Admin::UsersController < Admin::BaseController
load_and_authorize_resource load_and_authorize_resource
has_filters %w[active erased], only: :index
def index def index
@users = User.by_username_email_or_document_number(params[:search]) if params[:search] @users = @users.send(@current_filter)
@users = @users.by_username_email_or_document_number(params[:search]) if params[:search]
@users = @users.page(params[:page]) @users = @users.page(params[:page])
respond_to do |format| respond_to do |format|
format.html format.html

View File

@@ -1,24 +1,36 @@
<%= render "shared/filter_subnav", i18n_namespace: "admin.users.index" %>
<% if @users.any? %> <% if @users.any? %>
<h3 class="margin"><%= page_entries_info @users %></h3> <h3 class="margin"><%= page_entries_info @users %></h3>
<table> <table>
<thead> <thead>
<tr> <tr>
<th scope="col"><%= t("admin.users.columns.name") %></th> <% if @current_filter == "erased" %>
<th scope="col"><%= t("admin.users.columns.email") %></th> <th scope="col"><%= t("admin.users.columns.id") %></th>
<th scope="col"><%= t("admin.users.columns.document_number") %></th> <th scope="col"><%= t("admin.users.columns.erase_reason") %></th>
<th scope="col"><%= t("admin.users.columns.roles") %></th> <% else %>
<th scope="col"><%= t("admin.users.columns.verification_level") %></th> <th scope="col"><%= t("admin.users.columns.name") %></th>
<th scope="col"><%= t("admin.users.columns.email") %></th>
<th scope="col"><%= t("admin.users.columns.document_number") %></th>
<th scope="col"><%= t("admin.users.columns.roles") %></th>
<th scope="col"><%= t("admin.users.columns.verification_level") %></th>
<% end %>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @users.each do |user| %> <% @users.each do |user| %>
<tr> <tr>
<td><%= link_to user.name, user_path(user), target: "_blank" %></td> <% if @current_filter == "erased" %>
<td><%= user.email %></td> <td><%= link_to user.id, user_path(user), target: "_blank" %></td>
<td><%= user.document_number %></td> <td><%= user.erase_reason %></td>
<td><%= display_user_roles(user) %></td> <% else %>
<td><%= user.user_type %></td> <td><%= link_to user.name, user_path(user), target: "_blank" %></td>
<td><%= user.email %></td>
<td><%= user.document_number %></td>
<td><%= display_user_roles(user) %></td>
<td><%= user.user_type %></td>
<% end %>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>

View File

@@ -159,6 +159,7 @@ ignore_unused:
- "admin.homepage.*" - "admin.homepage.*"
- "admin.dashboard.administrator_tasks.index.filter*" - "admin.dashboard.administrator_tasks.index.filter*"
- "admin.dashboard.actions.index.default.*" - "admin.dashboard.actions.index.default.*"
- "admin.users.index.filter*"
- "moderation.comments.index.filter*" - "moderation.comments.index.filter*"
- "moderation.comments.index.order*" - "moderation.comments.index.order*"
- "moderation.debates.index.filter*" - "moderation.debates.index.filter*"

View File

@@ -1439,6 +1439,8 @@ en:
help: "When a user creates a proposal, the following topics are suggested as default tags." help: "When a user creates a proposal, the following topics are suggested as default tags."
users: users:
columns: columns:
id: ID
erase_reason: Erase reason
name: Name name: Name
email: Email email: Email
document_number: Document number document_number: Document number
@@ -1447,6 +1449,10 @@ en:
index: index:
title: User title: User
no_users: There are no users. no_users: There are no users.
filter: Filter
filters:
active: Active
erased: Erased
search: search:
placeholder: Search user by email, name or document number placeholder: Search user by email, name or document number
search: Search search: Search

View File

@@ -1438,6 +1438,8 @@ es:
help: "Cuando un usuario crea una propuesta se le sugieren como etiquetas por defecto los siguientes temas." help: "Cuando un usuario crea una propuesta se le sugieren como etiquetas por defecto los siguientes temas."
users: users:
columns: columns:
id: ID
erase_reason: Razón de la baja
name: Nombre name: Nombre
email: Email email: Email
document_number: Número de documento document_number: Número de documento
@@ -1446,6 +1448,10 @@ es:
index: index:
title: Usuarios title: Usuarios
no_users: No hay usuarios. no_users: No hay usuarios.
filter: Filtro
filters:
active: Activos
erased: Borrados
search: search:
placeholder: Buscar usuario por email, nombre o DNI placeholder: Buscar usuario por email, nombre o DNI
search: Buscar search: Buscar

View File

@@ -22,6 +22,28 @@ describe "Admin users" do
expect(page).to have_current_path(user_path(user)) expect(page).to have_current_path(user_path(user))
end end
scenario "Show active or erased users using filters" do
erased_user = create(:user, username: "Erased")
erased_user.erase("I don't like this site.")
visit admin_users_path
expect(page).not_to have_link("#{erased_user.id}", href: user_path(erased_user))
expect(page).to have_link("Erased")
click_link "Erased"
expect(page).to have_link("Active")
expect(page).to have_link("#{erased_user.id}", href: user_path(erased_user))
expect(page).to have_content "I don't like this site."
expect(page).to have_content("Erased")
fill_in :search, with: "Erased"
click_button "Search"
expect(page).to have_content "There are no users."
end
scenario "Search" do scenario "Search" do
fill_in :search, with: "Luis" fill_in :search, with: "Luis"
click_button "Search" click_button "Search"