1
0
Fork 0

Add action Staff::People::ResidentRegistrationsController#index

This commit is contained in:
Alex Kotov 2019-03-27 07:00:26 +05:00
parent 90b0ab2929
commit 2779868456
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
9 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,20 @@
# frozen_string_literal: true
class Staff::People::ResidentRegistrationsController < ApplicationController
before_action :set_person
# GET /staff/people/:person_id/resident_registrations
def index
authorize [:staff, @person, :resident_registration]
@resident_registrations = policy_scope(
@person.resident_registrations,
policy_scope_class: Staff::Person::ResidentRegistrationPolicy::Scope,
)
end
private
def set_person
@person = ::Person.find params[:person_id]
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class Staff::Person::ResidentRegistrationPolicy < 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

@ -4,5 +4,6 @@
tab,
overview: [:staff, person],
passports: staff_person_passports_path(person),
resident_registrations: staff_person_resident_registrations_path(person),
) %>
</div>

View file

@ -0,0 +1,24 @@
<div class="container">
<%= render partial: 'staff/people/nav_tabs',
locals: { person: @person, tab: :resident_registrations } %>
<table class="table">
<thead>
<tr>
<th scope="col">
<%= ResidentRegistration.human_attribute_name :id %>
</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<% @resident_registrations.each do |resident_registration| %>
<tr>
<td scope="row"><%= resident_registration.id %></td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View file

@ -6,6 +6,7 @@ en:
person:
overview: Overview
passports: Passports
resident_registrations: Resident registrations
settings:
credentials: Credentials
profile: Public profile

View file

@ -6,6 +6,7 @@ ru:
person:
overview: Обзор
passports: Паспорта
resident_registrations: Прописки
settings:
credentials: Данные для входа
profile: Публичный профиль

View file

@ -55,6 +55,10 @@ Rails.application.routes.draw do
resources :passports,
controller: 'people/passports',
only: :index
resources :resident_registrations,
controller: 'people/resident_registrations',
only: :index
end
resources :passports, only: %i[index show new create] do

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Staff::Person::ResidentRegistrationPolicy do
pending "add some examples to (or delete) #{__FILE__}"
end

View file

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