Add action Staff::People::ResidentRegistrationsController#index
This commit is contained in:
parent
90b0ab2929
commit
2779868456
9 changed files with 102 additions and 0 deletions
|
@ -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
|
15
app/policies/staff/person/resident_registration_policy.rb
Normal file
15
app/policies/staff/person/resident_registration_policy.rb
Normal 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
|
|
@ -4,5 +4,6 @@
|
|||
tab,
|
||||
overview: [:staff, person],
|
||||
passports: staff_person_passports_path(person),
|
||||
resident_registrations: staff_person_resident_registrations_path(person),
|
||||
) %>
|
||||
</div>
|
||||
|
|
24
app/views/staff/people/resident_registrations/index.html.erb
Normal file
24
app/views/staff/people/resident_registrations/index.html.erb
Normal 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>
|
|
@ -6,6 +6,7 @@ en:
|
|||
person:
|
||||
overview: Overview
|
||||
passports: Passports
|
||||
resident_registrations: Resident registrations
|
||||
settings:
|
||||
credentials: Credentials
|
||||
profile: Public profile
|
||||
|
|
|
@ -6,6 +6,7 @@ ru:
|
|||
person:
|
||||
overview: Обзор
|
||||
passports: Паспорта
|
||||
resident_registrations: Прописки
|
||||
settings:
|
||||
credentials: Данные для входа
|
||||
profile: Публичный профиль
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
Reference in a new issue