Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Admin::UsersController < ApplicationController
def index
@search = User.ransack(params[:q])
@users = @search.result(distinct: true).page(params[:page])
end
end
8 changes: 8 additions & 0 deletions app/views/admin/users/_search_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= search_form_for @search, url: admin_users_path, data: { controller: "search" } do |f|
.input-group
.input-group-prepend
span.input-group-text = t("users.index.search_title")
= f.search_field :first_name_or_last_name_cont, class: "form-control", data: { "search-target": "name" }, placeholder: t("users.index.search_field")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XaoGao Когда добавляю роль и ищу по ней получаю ошибку:

PG::UndefinedFunction: ERROR:  operator does not exist: integer ~~* unknown
LINE 1: ...s"."last_name" ILIKE '%admin%') OR "users"."role" ILIKE '%0%...

Пишут что user - зарезервированное слово, вы не можете назвать им таблицу или поле.

Получается рядового usera надо как то иначе называть?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@XaoGao Интересный момент. По условиям задачи поиск в фильтре должен учитывать роль. Роль же под капотом имеет тип данных Integer, который регулируется enum role: [:user, :moderator, :admin], то есть при ввводе в поле поиска admin должно отдаваться 2?

.input-group-append
= f.submit t("button.search"), class: "btn btn-primary"
button[class="btn btn-outline-secondary" data-action="click->search#clear"] = t("button.clear")
10 changes: 10 additions & 0 deletions app/views/admin/users/_user.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tr
td = index + 1
td = user.id
td = user.full_name
td = user.username
td = user.email
td = user.role
- if user.delete_at.present?
td.text-center
i.fa.fa-times.text-danger
21 changes: 21 additions & 0 deletions app/views/admin/users/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
h3.text-center.mb-4 =t(".title")

hr
= render partial: "search_form"
hr

table.table
thead
th = t(".order")
th = t(".id")
th = t(".full_name")
th = t(".username")
th = t(".email")
th = sort_link(@search, :role, t(".role"))
th = t(".status")
tbody
- @users.each_with_index do |user,index|
= render partial: "user", locals: { user: user, index: index }

.d-flex.justify-content-center
= paginate @users
15 changes: 15 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ en:
position: "Position: %{position}"
your_project: "Your projects"
common_projects: "Common projects"
index:
search_field: "Full name"
search_title: "Search"
favorites:
index:
title: "Favorites"
Expand Down Expand Up @@ -135,6 +138,18 @@ en:
confirm:
not_found: "Invitation is not found"

admin:
users:
index:
title: "Users list"
user:
order: "Ordinal number"
id: "ID"
full_name: "Full name"
username: "Username"
email: "E-mail"
role: "Role"
status: "Enable"

api:
v1:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
put :toggle, to: "background_jobs#toggle"
end
end
resources :users, only: [:index]
end

# TODO: check user is admin
Expand Down
12 changes: 0 additions & 12 deletions config/webpack/environment.js

This file was deleted.

1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require_relative "./support/desvise"
require_relative "./support/view_component_helper"
require_relative "./support/api_helper"
require_relative "./support/capybara"

begin
ActiveRecord::Migration.maintain_test_schema!
Expand Down
25 changes: 25 additions & 0 deletions spec/requests/admin/users_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rails_helper'

RSpec.describe "Admin::Users", type: :request do
before do
create_list(:user, 26)
end

describe "GET /admin/users" do
it "http status success" do
get admin_users_path
expect(response).to have_http_status(:success)
end

it "displays 25 users on the first page" do
visit admin_users_path
expect(page).to have_selector("tbody tr", count: 25)
end

it "displays 1 user on the second page" do
visit admin_users_path
click_link "2"
expect(page).to have_selector("tbody tr", count: 1)
end
end
end
3 changes: 3 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include Capybara::DSL, type: :request
end