1
0
Fork 0

Add action Settings::PassportsController#show

This commit is contained in:
Alex Kotov 2020-04-10 15:54:31 +05:00
parent 6e96a22758
commit ecbcd29338
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 127 additions and 2 deletions

View file

@ -6,6 +6,7 @@ class Settings::PassportsController < ApplicationController
before_action :skip_policy_scope, only: :index
before_action :set_account
before_action :set_passport, only: :show
# GET /settings/passports
def index
@ -14,9 +15,18 @@ class Settings::PassportsController < ApplicationController
@passports = @account.person.passports.page(active_page)
end
# GET /settings/passports/:id
def show
authorize [:settings, @passport]
end
private
def set_account
@account = current_account.clone&.reload
end
def set_passport
@passport = Passport.find params[:id]
end
end

View file

@ -4,4 +4,8 @@ class Settings::PassportPolicy < ApplicationPolicy
def index?
account&.person
end
def show?
account&.person && record.person == account.person
end
end

View file

@ -26,7 +26,7 @@
<td><%= passport.date_of_issue %></td>
<td>
<% if policy([:settings, passport]).show? %>
<%#= open_action [:settings, passport] %>
<%= open_action [:settings, passport] %>
<% end %>
</td>
</tr>

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

View file

@ -35,7 +35,7 @@ Rails.application.routes.draw do
resource :appearance, only: %i[edit update]
resource :person, only: %i[show new]
resources :sessions, only: :index
resources :passports, only: :index
resources :passports, only: %i[index show]
resources :contacts, only: %i[index create destroy] do
resource :security_notification_switch,

View 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