From ecbcd2933873e3a1fda3cd8bb3fb782e97b3c7bd Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 10 Apr 2020 15:54:31 +0500 Subject: [PATCH] Add action Settings::PassportsController#show --- .../settings/passports_controller.rb | 10 +++ app/policies/settings/passport_policy.rb | 4 + app/views/settings/passports/_table.html.erb | 2 +- app/views/settings/passports/show.html.erb | 75 +++++++++++++++++++ config/routes.rb | 2 +- spec/requests/settings/passports/show_spec.rb | 36 +++++++++ 6 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 app/views/settings/passports/show.html.erb create mode 100644 spec/requests/settings/passports/show_spec.rb diff --git a/app/controllers/settings/passports_controller.rb b/app/controllers/settings/passports_controller.rb index 2070d00..2782615 100644 --- a/app/controllers/settings/passports_controller.rb +++ b/app/controllers/settings/passports_controller.rb @@ -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 diff --git a/app/policies/settings/passport_policy.rb b/app/policies/settings/passport_policy.rb index 85143cf..4f5d786 100644 --- a/app/policies/settings/passport_policy.rb +++ b/app/policies/settings/passport_policy.rb @@ -4,4 +4,8 @@ class Settings::PassportPolicy < ApplicationPolicy def index? account&.person end + + def show? + account&.person && record.person == account.person + end end diff --git a/app/views/settings/passports/_table.html.erb b/app/views/settings/passports/_table.html.erb index 2d14f81..3ad3baa 100644 --- a/app/views/settings/passports/_table.html.erb +++ b/app/views/settings/passports/_table.html.erb @@ -26,7 +26,7 @@ <%= passport.date_of_issue %> <% if policy([:settings, passport]).show? %> - <%#= open_action [:settings, passport] %> + <%= open_action [:settings, passport] %> <% end %> diff --git a/app/views/settings/passports/show.html.erb b/app/views/settings/passports/show.html.erb new file mode 100644 index 0000000..81f40e7 --- /dev/null +++ b/app/views/settings/passports/show.html.erb @@ -0,0 +1,75 @@ +
+
+
+ <%= render partial: 'settings/nav_sidebar', locals: { tab: :passports } %> +
+ +
+
+
<%= Passport.human_attribute_name :series %>
+
<%= @passport.series %>
+ +
<%= Passport.human_attribute_name :number %>
+
<%= @passport.number %>
+ +
<%= Passport.human_attribute_name :issued_by %>
+
<%= @passport.issued_by %>
+ +
<%= Passport.human_attribute_name :unit_code %>
+
<%= @passport.unit_code %>
+ +
<%= Passport.human_attribute_name :date_of_issue %>
+
<%= localize @passport.date_of_issue %>
+
+
+ +
+
+
<%= Passport.human_attribute_name :zip_code %>
+
<%= @passport.zip_code %>
+ +
<%= Passport.human_attribute_name :town_type %>
+
<%= @passport.town_type %>
+ +
<%= Passport.human_attribute_name :town_name %>
+
<%= @passport.town_name %>
+ +
<%= Passport.human_attribute_name :settlement_type %>
+
<%= @passport.settlement_type %>
+ +
<%= Passport.human_attribute_name :settlement_name %>
+
<%= @passport.settlement_name %>
+ +
<%= Passport.human_attribute_name :district_type %>
+
<%= @passport.district_type %>
+ +
<%= Passport.human_attribute_name :district_name %>
+
<%= @passport.district_name %>
+ +
<%= Passport.human_attribute_name :street_type %>
+
<%= @passport.street_type %>
+ +
<%= Passport.human_attribute_name :street_name %>
+
<%= @passport.street_name %>
+ +
<%= Passport.human_attribute_name :residence_type %>
+
<%= @passport.residence_type %>
+ +
<%= Passport.human_attribute_name :residence_name %>
+
<%= @passport.residence_name %>
+ +
<%= Passport.human_attribute_name :building_type %>
+
<%= @passport.building_type %>
+ +
<%= Passport.human_attribute_name :building_name %>
+
<%= @passport.building_name %>
+ +
<%= Passport.human_attribute_name :apartment_type %>
+
<%= @passport.apartment_type %>
+ +
<%= Passport.human_attribute_name :apartment_name %>
+
<%= @passport.apartment_name %>
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb index c5a80fa..66344e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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, diff --git a/spec/requests/settings/passports/show_spec.rb b/spec/requests/settings/passports/show_spec.rb new file mode 100644 index 0000000..707e4fb --- /dev/null +++ b/spec/requests/settings/passports/show_spec.rb @@ -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