From 44131ce7d3227f372b8d161247a883df463b7e13 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 10 Apr 2020 18:28:34 +0500 Subject: [PATCH] Add action Settings::PassportsController#new --- .../settings/passports_controller.rb | 10 +++++ app/policies/settings/passport_policy.rb | 4 ++ app/views/settings/passports/index.html.erb | 11 ++++++ app/views/settings/passports/new.html.erb | 37 +++++++++++++++++++ config/routes.rb | 2 +- spec/requests/settings/passports/new_spec.rb | 7 ++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 app/views/settings/passports/new.html.erb create mode 100644 spec/requests/settings/passports/new_spec.rb diff --git a/app/controllers/settings/passports_controller.rb b/app/controllers/settings/passports_controller.rb index 2782615..079c375 100644 --- a/app/controllers/settings/passports_controller.rb +++ b/app/controllers/settings/passports_controller.rb @@ -7,6 +7,7 @@ class Settings::PassportsController < ApplicationController before_action :set_account before_action :set_passport, only: :show + before_action :new_passport, only: :new # GET /settings/passports def index @@ -20,6 +21,11 @@ class Settings::PassportsController < ApplicationController authorize [:settings, @passport] end + # GET /settings/passports/new + def new + authorize [:settings, Passport] + end + private def set_account @@ -29,4 +35,8 @@ private def set_passport @passport = Passport.find params[:id] end + + def new_passport + @passport = Passport.new person: @account&.person + end end diff --git a/app/policies/settings/passport_policy.rb b/app/policies/settings/passport_policy.rb index 4f5d786..c635cd1 100644 --- a/app/policies/settings/passport_policy.rb +++ b/app/policies/settings/passport_policy.rb @@ -8,4 +8,8 @@ class Settings::PassportPolicy < ApplicationPolicy def show? account&.person && record.person == account.person end + + def create? + account&.person + end end diff --git a/app/views/settings/passports/index.html.erb b/app/views/settings/passports/index.html.erb index 168f58c..13f132c 100644 --- a/app/views/settings/passports/index.html.erb +++ b/app/views/settings/passports/index.html.erb @@ -5,6 +5,17 @@
+ <% if policy([:settings, Passport]).new? %> +
+ <% if policy([:settings, Passport]).new? %> + <%= link_to translate(:create), + new_settings_passport_path, + class: 'btn btn-primary', + role: :button %> + <% end %> +
+ <% end %> + <%= render partial: 'table', locals: { passports: @passports } %> <%= pagination @passports %>
diff --git a/app/views/settings/passports/new.html.erb b/app/views/settings/passports/new.html.erb new file mode 100644 index 0000000..1784944 --- /dev/null +++ b/app/views/settings/passports/new.html.erb @@ -0,0 +1,37 @@ +
+
+
+ <%= render partial: 'settings/nav_sidebar', locals: { tab: :passports } %> +
+ +
+ <%= simple_form_for [:settings, @passport] do |f| %> + <%= f.error_notification %> + + <%= 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 %> +
+
+
diff --git a/config/routes.rb b/config/routes.rb index 66344e9..10d0a9d 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: %i[index show] + resources :passports, only: %i[index show new] resources :contacts, only: %i[index create destroy] do resource :security_notification_switch, diff --git a/spec/requests/settings/passports/new_spec.rb b/spec/requests/settings/passports/new_spec.rb new file mode 100644 index 0000000..93e8906 --- /dev/null +++ b/spec/requests/settings/passports/new_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'GET /settings/passports/new' do + pending "add some examples to (or delete) #{__FILE__}" +end