1
0
Fork 0

Add action Staff::PeopleController#show

This commit is contained in:
Alex Kotov 2019-03-27 03:57:37 +05:00
parent c7c91e9212
commit e515853dd7
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
8 changed files with 113 additions and 7 deletions

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class Staff::PeopleController < ApplicationController
before_action :set_person, except: :index
# GET /staff/people
def index
authorize %i[staff person]
@ -9,4 +11,15 @@ class Staff::PeopleController < ApplicationController
policy_scope_class: Staff::PersonPolicy::Scope,
)
end
# GET /staff/people/:id
def show
authorize [:staff, @person]
end
private
def set_person
@person = Person.find params[:id]
end
end

View file

@ -5,6 +5,10 @@ class Staff::PersonPolicy < ApplicationPolicy
account&.is_superuser?
end
def show?
account&.is_superuser?
end
class Scope < Scope
def resolve
return scope.all if account&.is_superuser?

View file

@ -6,7 +6,19 @@
<%= Person.human_attribute_name :id %>
</th>
<th scope="col">
<%= Person.human_attribute_name :regional_office %>
<%= Person.human_attribute_name :first_name %>
</th>
<th scope="col">
<%= Person.human_attribute_name :middle_name %>
</th>
<th scope="col">
<%= Person.human_attribute_name :last_name %>
</th>
<th scope="col" class="d-none d-lg-table-cell">
<%= Person.human_attribute_name :date_of_birth %>
</th>
<th scope="col" class="d-none d-md-table-cell">
<%= Person.human_attribute_name :place_of_birth %>
</th>
<th scope="col"></th>
</tr>
@ -16,13 +28,22 @@
<% @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><%= truncate person.first_name, length: 15 %></td>
<td><%= truncate person.middle_name, length: 15 %></td>
<td><%= truncate person.last_name, length: 15 %></td>
<td class="d-none d-lg-table-cell">
<%= localize person.date_of_birth %>
</td>
<td class="d-none d-md-table-cell">
<%= truncate person.place_of_birth, length: 15 %>
</td>
<td>
<% if policy([:staff, person]).show? %>
<%= link_to [:staff, person],
role: :button, class: 'btn btn-light btn-sm' do %>
<i class="far fa-eye"></i>
<% end %>
<% end %>
</td>
</tr>
<% end %>

View file

@ -0,0 +1,21 @@
<div class="container">
<dl>
<dt><%= Person.human_attribute_name :first_name %></dt>
<dd><%= truncate @person.first_name %></dd>
<dt><%= Person.human_attribute_name :middle_name %></dt>
<dd><%= truncate @person.middle_name %></dd>
<dt><%= Person.human_attribute_name :last_name %></dt>
<dd><%= truncate @person.last_name %></dd>
<dt><%= Person.human_attribute_name :sex %></dt>
<dd><%= Person.human_attribute_name "sex.#{@person.sex}" %></dd>
<dt><%= Person.human_attribute_name :date_of_birth %></dt>
<dd><%= localize @person.date_of_birth %></dd>
<dt><%= Person.human_attribute_name :place_of_birth %></dt>
<dd><%= truncate @person.place_of_birth %></dd>
</dl>
</div>

View file

@ -84,6 +84,15 @@ en:
person:
id: ID
regional_office: Regional office
first_name: First name
middle_name: Middle name
last_name: Last name
sex: Sex
date_of_birth: Date of birth
place_of_birth: Place of birth
person/sex:
male: Male
female: Female
role:
id: ID
name: Name

View file

@ -84,6 +84,15 @@ ru:
person:
id: ID
regional_office: Региональное отделение
first_name: Имя
middle_name: Отчество
last_name: Фамилия
sex: Пол
date_of_birth: Дата рождения
place_of_birth: Место рождения
person/sex:
male: Мужской
female: Женский
role:
id: ID
name: Название

View file

@ -51,7 +51,7 @@ Rails.application.routes.draw do
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
resources :people, only: :index
resources :people, only: %i[index show]
resources :passports, only: %i[index show new create] do
resources :passport_confirmations,

View file

@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /staff/people/:id' do
let!(:person) { create :initial_person }
let(:current_account) { create :usual_account }
def make_request
get "/staff/people/#{person.id}"
end
before do
sign_in current_account.user if current_account&.user
make_request
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