Add action Settings::PassportsController#show
This commit is contained in:
parent
6e96a22758
commit
ecbcd29338
6 changed files with 127 additions and 2 deletions
|
@ -6,6 +6,7 @@ class Settings::PassportsController < ApplicationController
|
||||||
before_action :skip_policy_scope, only: :index
|
before_action :skip_policy_scope, only: :index
|
||||||
|
|
||||||
before_action :set_account
|
before_action :set_account
|
||||||
|
before_action :set_passport, only: :show
|
||||||
|
|
||||||
# GET /settings/passports
|
# GET /settings/passports
|
||||||
def index
|
def index
|
||||||
|
@ -14,9 +15,18 @@ class Settings::PassportsController < ApplicationController
|
||||||
@passports = @account.person.passports.page(active_page)
|
@passports = @account.person.passports.page(active_page)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /settings/passports/:id
|
||||||
|
def show
|
||||||
|
authorize [:settings, @passport]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_account
|
def set_account
|
||||||
@account = current_account.clone&.reload
|
@account = current_account.clone&.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_passport
|
||||||
|
@passport = Passport.find params[:id]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,8 @@ class Settings::PassportPolicy < ApplicationPolicy
|
||||||
def index?
|
def index?
|
||||||
account&.person
|
account&.person
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show?
|
||||||
|
account&.person && record.person == account.person
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<td><%= passport.date_of_issue %></td>
|
<td><%= passport.date_of_issue %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if policy([:settings, passport]).show? %>
|
<% if policy([:settings, passport]).show? %>
|
||||||
<%#= open_action [:settings, passport] %>
|
<%= open_action [:settings, passport] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
75
app/views/settings/passports/show.html.erb
Normal file
75
app/views/settings/passports/show.html.erb
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3 mb-4">
|
||||||
|
<%= render partial: 'settings/nav_sidebar', locals: { tab: :passports } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4">
|
||||||
|
<dl>
|
||||||
|
<dt><%= Passport.human_attribute_name :series %></dt>
|
||||||
|
<dd><%= @passport.series %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :number %></dt>
|
||||||
|
<dd><%= @passport.number %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :issued_by %></dt>
|
||||||
|
<dd><%= @passport.issued_by %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :unit_code %></dt>
|
||||||
|
<dd><%= @passport.unit_code %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :date_of_issue %></dt>
|
||||||
|
<dd><%= localize @passport.date_of_issue %></dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-4">
|
||||||
|
<dl>
|
||||||
|
<dt><%= Passport.human_attribute_name :zip_code %></dt>
|
||||||
|
<dd><%= @passport.zip_code %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :town_type %></dt>
|
||||||
|
<dd><%= @passport.town_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :town_name %></dt>
|
||||||
|
<dd><%= @passport.town_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :settlement_type %></dt>
|
||||||
|
<dd><%= @passport.settlement_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :settlement_name %></dt>
|
||||||
|
<dd><%= @passport.settlement_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :district_type %></dt>
|
||||||
|
<dd><%= @passport.district_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :district_name %></dt>
|
||||||
|
<dd><%= @passport.district_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :street_type %></dt>
|
||||||
|
<dd><%= @passport.street_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :street_name %></dt>
|
||||||
|
<dd><%= @passport.street_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :residence_type %></dt>
|
||||||
|
<dd><%= @passport.residence_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :residence_name %></dt>
|
||||||
|
<dd><%= @passport.residence_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :building_type %></dt>
|
||||||
|
<dd><%= @passport.building_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :building_name %></dt>
|
||||||
|
<dd><%= @passport.building_name %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :apartment_type %></dt>
|
||||||
|
<dd><%= @passport.apartment_type %></dd>
|
||||||
|
|
||||||
|
<dt><%= Passport.human_attribute_name :apartment_name %></dt>
|
||||||
|
<dd><%= @passport.apartment_name %></dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -35,7 +35,7 @@ Rails.application.routes.draw do
|
||||||
resource :appearance, only: %i[edit update]
|
resource :appearance, only: %i[edit update]
|
||||||
resource :person, only: %i[show new]
|
resource :person, only: %i[show new]
|
||||||
resources :sessions, only: :index
|
resources :sessions, only: :index
|
||||||
resources :passports, only: :index
|
resources :passports, only: %i[index show]
|
||||||
|
|
||||||
resources :contacts, only: %i[index create destroy] do
|
resources :contacts, only: %i[index create destroy] do
|
||||||
resource :security_notification_switch,
|
resource :security_notification_switch,
|
||||||
|
|
36
spec/requests/settings/passports/show_spec.rb
Normal file
36
spec/requests/settings/passports/show_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'GET /settings/passports/:id' do
|
||||||
|
let(:current_account) { create :superuser_account }
|
||||||
|
|
||||||
|
let(:person) { current_account&.person || create(:initial_person) }
|
||||||
|
let(:passport) { create :empty_passport, person: person }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in current_account.user if current_account&.user
|
||||||
|
|
||||||
|
get "/settings/passports/#{passport.to_param}"
|
||||||
|
end
|
||||||
|
|
||||||
|
for_account_types nil, :usual do
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :forbidden
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for_account_types :personal, :superuser do
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when person is not linked to current account' do
|
||||||
|
let(:person) { create :initial_person }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(response).to have_http_status :forbidden
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in a new issue