Remove Settings::PassportsController
This commit is contained in:
parent
545533885f
commit
2b53c09c63
14 changed files with 0 additions and 294 deletions
|
@ -1,57 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::PassportsController < ApplicationController
|
||||
include PaginalController
|
||||
|
||||
before_action :skip_policy_scope, only: :index
|
||||
|
||||
before_action :set_account
|
||||
before_action :set_passport, only: :show
|
||||
before_action :new_passport, only: :new
|
||||
before_action :build_passport, only: :create
|
||||
|
||||
# GET /settings/passports
|
||||
def index
|
||||
authorize [:settings, Passport]
|
||||
|
||||
@passports = @account.person.passports.page(active_page)
|
||||
end
|
||||
|
||||
# GET /settings/passports/:id
|
||||
def show
|
||||
authorize [:settings, @passport]
|
||||
end
|
||||
|
||||
# GET /settings/passports/new
|
||||
def new
|
||||
authorize [:settings, Passport]
|
||||
end
|
||||
|
||||
# POST /settings/passports
|
||||
def create
|
||||
authorize [:settings, @passport]
|
||||
|
||||
return render :new unless @passport.save
|
||||
|
||||
redirect_to [:settings, @passport]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_account
|
||||
@account = current_account.clone&.reload
|
||||
end
|
||||
|
||||
def set_passport
|
||||
@passport = Passport.find params[:id]
|
||||
end
|
||||
|
||||
def new_passport
|
||||
@passport = Passport.new person: @account&.person
|
||||
end
|
||||
|
||||
def build_passport
|
||||
@passport = Passport.new permitted_attributes [:settings, Passport]
|
||||
@passport.person = @account&.person
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Settings::PassportPolicy < ApplicationPolicy
|
||||
def index?
|
||||
account&.person
|
||||
end
|
||||
|
||||
def show?
|
||||
account&.person && record.person == account.person
|
||||
end
|
||||
|
||||
def create?
|
||||
account&.person
|
||||
end
|
||||
|
||||
def permitted_attributes_for_create
|
||||
%i[
|
||||
last_name first_name middle_name sex date_of_birth place_of_birth
|
||||
series number issued_by unit_code date_of_issue zip_code
|
||||
town_type town_name settlement_type settlement_name district_type
|
||||
district_name street_type street_name residence_type residence_name
|
||||
building_type building_name apartment_type apartment_name
|
||||
].freeze
|
||||
end
|
||||
end
|
|
@ -17,10 +17,6 @@
|
|||
policy([:settings, Person]).show?,
|
||||
settings_person_path,
|
||||
],
|
||||
passports: [
|
||||
policy([:settings, Passport]).index?,
|
||||
settings_passports_path,
|
||||
],
|
||||
contacts: [
|
||||
policy([:settings, Contact]).index?,
|
||||
settings_contacts_path,
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<%= Passport.human_attribute_name :series %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Passport.human_attribute_name :number %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Passport.human_attribute_name :unit_code %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Passport.human_attribute_name :date_of_issue %>
|
||||
</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% passports.each do |passport| %>
|
||||
<tr>
|
||||
<td><%= passport.series %></td>
|
||||
<td><%= passport.number %></td>
|
||||
<td><%= passport.unit_code %></td>
|
||||
<td><%= passport.date_of_issue %></td>
|
||||
<td>
|
||||
<% if policy([:settings, passport]).show? %>
|
||||
<%= open_action [:settings, passport] %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
|
@ -1,23 +0,0 @@
|
|||
<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-9">
|
||||
<% if policy([:settings, Passport]).new? %>
|
||||
<div class="btn-group mb-3" role="group">
|
||||
<% if policy([:settings, Passport]).new? %>
|
||||
<%= link_to translate(:create),
|
||||
new_settings_passport_path,
|
||||
class: 'btn btn-primary',
|
||||
role: :button %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render partial: 'table', locals: { passports: @passports } %>
|
||||
<%= pagination @passports %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,44 +0,0 @@
|
|||
<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-9">
|
||||
<%= simple_form_for [:settings, @passport] do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= f.input :last_name %>
|
||||
<%= f.input :first_name %>
|
||||
<%= f.input :middle_name %>
|
||||
<%= f.input :sex, collection: Passport.sexes.keys.map(&:to_sym) %>
|
||||
<%= f.input :date_of_birth, start_year: 1900, end_year: Time.zone.now.year %>
|
||||
<%= f.input :place_of_birth %>
|
||||
|
||||
<%= f.input :series %>
|
||||
<%= f.input :number %>
|
||||
<%= f.input :issued_by %>
|
||||
<%= f.input :unit_code %>
|
||||
<%= f.input :date_of_issue %>
|
||||
|
||||
<%= f.input :zip_code %>
|
||||
<%= f.input :town_type %>
|
||||
<%= f.input :town_name %>
|
||||
<%= f.input :settlement_type %>
|
||||
<%= f.input :settlement_name %>
|
||||
<%= f.input :district_type %>
|
||||
<%= f.input :district_name %>
|
||||
<%= f.input :street_type %>
|
||||
<%= f.input :street_name %>
|
||||
<%= f.input :residence_type %>
|
||||
<%= f.input :residence_name %>
|
||||
<%= f.input :building_type %>
|
||||
<%= f.input :building_name %>
|
||||
<%= f.input :apartment_type %>
|
||||
<%= f.input :apartment_name %>
|
||||
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,17 +0,0 @@
|
|||
<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">
|
||||
<%= render partial: 'passports/common_descr_list',
|
||||
locals: { passport: @passport } %>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<%= render partial: 'passports/registration_descr_list',
|
||||
locals: { passport: @passport } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -13,6 +13,5 @@ en:
|
|||
profile: Public profile
|
||||
appearance: Appearance
|
||||
person: Person
|
||||
passports: Passports
|
||||
contacts: Contacts
|
||||
sessions: Sessions
|
||||
|
|
|
@ -13,6 +13,5 @@ ru:
|
|||
profile: Публичный профиль
|
||||
appearance: Внешний вид
|
||||
person: Личность
|
||||
passports: Паспорта
|
||||
contacts: Контакты
|
||||
sessions: Сессии
|
||||
|
|
|
@ -35,7 +35,6 @@ Rails.application.routes.draw do
|
|||
resource :appearance, only: %i[edit update]
|
||||
resource :person, only: %i[show new]
|
||||
resources :sessions, only: :index
|
||||
resources :passports, only: %i[index show new create]
|
||||
|
||||
resources :contacts, only: %i[index create destroy] do
|
||||
resource :security_notification_switch,
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'POST /settings/passports' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /settings/passports' do
|
||||
let(:current_account) { create :personal_account }
|
||||
|
||||
let :passports_count do
|
||||
[0, 1, rand(2..4), rand(5..10), rand(20..100)].sample
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
if current_account&.person
|
||||
create_list :empty_passport, passports_count,
|
||||
person: current_account.person
|
||||
end
|
||||
|
||||
get '/settings/passports'
|
||||
end
|
||||
|
||||
it_behaves_like 'paginal controller', :passports_count
|
||||
|
||||
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
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /settings/passports/new' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
# 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