1
0
Fork 0

Add action Staff::PeopleController#index

This commit is contained in:
Alex Kotov 2019-03-26 05:27:48 +05:00
parent 3a0327e505
commit 835005106a
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
8 changed files with 107 additions and 0 deletions

View 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

View 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

View 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>

View file

@ -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

View file

@ -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: Название

View file

@ -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',

View 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

View 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