Add action Staff::PeopleController#index
This commit is contained in:
parent
3a0327e505
commit
835005106a
8 changed files with 107 additions and 0 deletions
12
app/controllers/staff/people_controller.rb
Normal file
12
app/controllers/staff/people_controller.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staff::PeopleController < ApplicationController
|
||||
# GET /staff/people
|
||||
def index
|
||||
authorize %i[staff person]
|
||||
@people = policy_scope(
|
||||
Person,
|
||||
policy_scope_class: Staff::PersonPolicy::Scope,
|
||||
)
|
||||
end
|
||||
end
|
15
app/policies/staff/person_policy.rb
Normal file
15
app/policies/staff/person_policy.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staff::PersonPolicy < ApplicationPolicy
|
||||
def index?
|
||||
account&.is_superuser?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.all if account&.is_superuser?
|
||||
|
||||
scope.none
|
||||
end
|
||||
end
|
||||
end
|
31
app/views/staff/people/index.html.erb
Normal file
31
app/views/staff/people/index.html.erb
Normal file
|
@ -0,0 +1,31 @@
|
|||
<div class="container">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= Person.human_attribute_name :id %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Person.human_attribute_name :regional_office %>
|
||||
</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @people.each do |person| %>
|
||||
<tr>
|
||||
<td scope="row"><%= person.id %></td>
|
||||
<td>
|
||||
<% if person.regional_office %>
|
||||
<%= link_to person.regional_office.country_state.display_name,
|
||||
person.regional_office.country_state %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
|
@ -19,6 +19,9 @@ en:
|
|||
passport_map:
|
||||
one: Passport mapping
|
||||
other: Passport mappings
|
||||
person:
|
||||
one: Person
|
||||
other: People
|
||||
roles:
|
||||
one: Role
|
||||
other: Roles
|
||||
|
@ -78,6 +81,9 @@ en:
|
|||
passport_map/sex:
|
||||
male: Male
|
||||
female: Female
|
||||
person:
|
||||
id: ID
|
||||
regional_office: Regional office
|
||||
role:
|
||||
id: ID
|
||||
name: Name
|
||||
|
|
|
@ -19,6 +19,9 @@ ru:
|
|||
passport_map:
|
||||
one: Отображение паспорта
|
||||
other: Отображения паспортов
|
||||
person:
|
||||
one: Человек
|
||||
other: Люди
|
||||
roles:
|
||||
one: Роль
|
||||
other: Роли
|
||||
|
@ -78,6 +81,9 @@ ru:
|
|||
passport_map/sex:
|
||||
male: Мужской
|
||||
female: Женский
|
||||
person:
|
||||
id: ID
|
||||
regional_office: Региональное отделение
|
||||
role:
|
||||
id: ID
|
||||
name: Название
|
||||
|
|
|
@ -51,6 +51,8 @@ Rails.application.routes.draw do
|
|||
|
||||
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
|
||||
|
||||
resources :people, only: :index
|
||||
|
||||
resources :passports, only: %i[index show new create] do
|
||||
resources :passport_confirmations,
|
||||
controller: 'passports/passport_confirmations',
|
||||
|
|
7
spec/policies/staff/person_policy_spec.rb
Normal file
7
spec/policies/staff/person_policy_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Staff::PersonPolicy do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
28
spec/requests/staff/people/index_spec.rb
Normal file
28
spec/requests/staff/people/index_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /staff/people' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
create :initial_person
|
||||
create :supporter_person
|
||||
create :member_person
|
||||
create :excluded_person
|
||||
|
||||
get '/staff/people'
|
||||
end
|
||||
|
||||
for_account_types nil, :guest, :usual do
|
||||
specify do
|
||||
expect(response).to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
for_account_types :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue