Move passport routes
This commit is contained in:
parent
33bde8d1ac
commit
5b3927c26a
15 changed files with 35 additions and 31 deletions
|
@ -1,16 +1,19 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class PassportsController < ApplicationController
|
class Staff::PassportsController < ApplicationController
|
||||||
before_action :set_passport, except: %i[index new create]
|
before_action :set_passport, except: %i[index new create]
|
||||||
|
|
||||||
# GET /passports
|
# GET /passports
|
||||||
def index
|
def index
|
||||||
@passports = policy_scope(Passport)
|
@passports = policy_scope(
|
||||||
|
Passport,
|
||||||
|
policy_scope_class: Staff::PassportPolicy::Scope,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /passports/:id
|
# GET /passports/:id
|
||||||
def show
|
def show
|
||||||
authorize @passport
|
authorize [:staff, @passport]
|
||||||
@passport.passport_maps.build if @passport.passport_map.nil?
|
@passport.passport_maps.build if @passport.passport_map.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,18 +22,18 @@ class PassportsController < ApplicationController
|
||||||
@passport = Passport.new
|
@passport = Passport.new
|
||||||
@passport.passport_maps.build
|
@passport.passport_maps.build
|
||||||
|
|
||||||
authorize @passport
|
authorize [:staff, @passport]
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /passports
|
# POST /passports
|
||||||
def create
|
def create
|
||||||
@passport = Passport.new permitted_attributes Passport
|
@passport = Passport.new permitted_attributes [:staff, Passport]
|
||||||
|
|
||||||
authorize @passport
|
authorize [:staff, @passport]
|
||||||
|
|
||||||
return render :new unless @passport.save
|
return render :new unless @passport.save
|
||||||
|
|
||||||
redirect_to @passport
|
redirect_to [:staff, @passport]
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
|
@ -5,7 +5,7 @@ class PassportConfirmationPolicy < ApplicationPolicy
|
||||||
return false if record.passport.nil?
|
return false if record.passport.nil?
|
||||||
return false if record.account != context.account
|
return false if record.account != context.account
|
||||||
|
|
||||||
policy(record.passport).show?
|
policy([:staff, record.passport]).show?
|
||||||
end
|
end
|
||||||
|
|
||||||
class Scope < Scope
|
class Scope < Scope
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class PassportPolicy < ApplicationPolicy
|
class Staff::PassportPolicy < ApplicationPolicy
|
||||||
def show?
|
def show?
|
||||||
true
|
true
|
||||||
end
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<%= render partial: 'passports/nav_tabs', locals: { passport: @passport,
|
<%= render partial: 'staff/passports/nav_tabs',
|
||||||
|
locals: { passport: @passport,
|
||||||
tab: :confirmations } %>
|
tab: :confirmations } %>
|
||||||
|
|
||||||
<% if @passport.can_have_confirmations? && current_account %>
|
<% if @passport.can_have_confirmations? && current_account %>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<ul class="nav nav-tabs d-none d-sm-flex">
|
<ul class="nav nav-tabs d-none d-sm-flex">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<%= link_to translate(:overview, scope: %i[nav_tabs passport]),
|
<%= link_to translate(:overview, scope: %i[nav_tabs passport]),
|
||||||
passport,
|
[:staff, passport],
|
||||||
class: "nav-link #{:active if tab == :overview}" %>
|
class: "nav-link #{:active if tab == :overview}" %>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
<ul class="nav flex-column nav-pills d-flex d-sm-none">
|
<ul class="nav flex-column nav-pills d-flex d-sm-none">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<%= link_to translate(:overview, scope: %i[nav_tabs passport]),
|
<%= link_to translate(:overview, scope: %i[nav_tabs passport]),
|
||||||
passport,
|
[:staff, passport],
|
||||||
class: "nav-link #{:active if tab == :overview}" %>
|
class: "nav-link #{:active if tab == :overview}" %>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
|
@ -40,8 +40,8 @@
|
||||||
<%= truncate passport.passport_map&.place_of_birth, length: 15 %>
|
<%= truncate passport.passport_map&.place_of_birth, length: 15 %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if policy(passport).show? %>
|
<% if policy([:staff, passport]).show? %>
|
||||||
<%= link_to passport_path(passport),
|
<%= link_to staff_passport_path(passport),
|
||||||
role: :button, class: 'btn btn-light btn-sm' do %>
|
role: :button, class: 'btn btn-light btn-sm' do %>
|
||||||
<i class="far fa-eye"></i>
|
<i class="far fa-eye"></i>
|
||||||
<% end %>
|
<% end %>
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<%= simple_form_for @passport, wrapper: :horizontal_form do |f| %>
|
<%= simple_form_for [:staff, @passport], wrapper: :horizontal_form do |f| %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<%= f.simple_fields_for :passport_maps do |ff| %>
|
<%= f.simple_fields_for :passport_maps do |ff| %>
|
|
@ -47,7 +47,7 @@
|
||||||
<hr/>
|
<hr/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= simple_form_for @passport, wrapper: :horizontal_form, defaults: { readonly: true } do |f| %>
|
<%= simple_form_for [:staff, @passport], wrapper: :horizontal_form, defaults: { readonly: true } do |f| %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<%= f.simple_fields_for :passport_maps do |ff| %>
|
<%= f.simple_fields_for :passport_maps do |ff| %>
|
|
@ -16,8 +16,6 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :membership_apps, only: %i[show new create]
|
resources :membership_apps, only: %i[show new create]
|
||||||
|
|
||||||
resources :passports, only: %i[index show new create]
|
|
||||||
|
|
||||||
resources :passports, only: [] do
|
resources :passports, only: [] do
|
||||||
resources :passport_confirmations,
|
resources :passport_confirmations,
|
||||||
controller: 'passports/passport_confirmations',
|
controller: 'passports/passport_confirmations',
|
||||||
|
@ -36,6 +34,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
|
get '/sidekiq', to: redirect('/', status: 307), as: :forbidden_sidekiq
|
||||||
|
|
||||||
|
resources :passports, only: %i[index show new create]
|
||||||
|
|
||||||
resources :telegram_chats, only: %i[index show]
|
resources :telegram_chats, only: %i[index show]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Feature: Passport creation
|
Feature: Passport creation
|
||||||
Background:
|
Background:
|
||||||
Given I visit "/passports/new"
|
Given I visit "/staff/passports/new"
|
||||||
|
|
||||||
Scenario: all fields are filled
|
Scenario: all fields are filled
|
||||||
Given I want to create the following passport:
|
Given I want to create the following passport:
|
||||||
|
@ -37,4 +37,4 @@ Feature: Passport creation
|
||||||
Scenario: only image is uploaded, no fields are filled
|
Scenario: only image is uploaded, no fields are filled
|
||||||
When I upload "passport_image_1.jpg" as "Изображения"
|
When I upload "passport_image_1.jpg" as "Изображения"
|
||||||
And I click the passport creation button
|
And I click the passport creation button
|
||||||
Then I am at "/passports/\d+"
|
Then I am at "/staff/passports/\d+"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe PassportPolicy do
|
RSpec.describe Staff::PassportPolicy do
|
||||||
permissions '.scope' do
|
permissions '.scope' do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
end
|
end
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'POST /passports' do
|
RSpec.describe 'POST /staff/passports' do
|
||||||
let(:passport_plain_attributes) { attributes_for :empty_passport }
|
let(:passport_plain_attributes) { attributes_for :empty_passport }
|
||||||
|
|
||||||
let :passport_all_attributes do
|
let :passport_all_attributes do
|
||||||
|
@ -16,7 +16,7 @@ RSpec.describe 'POST /passports' do
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_request
|
def make_request
|
||||||
post '/passports', params: { passport: passport_all_attributes }
|
post '/staff/passports', params: { passport: passport_all_attributes }
|
||||||
end
|
end
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
|
@ -27,7 +27,7 @@ RSpec.describe 'POST /passports' do
|
||||||
before { make_request }
|
before { make_request }
|
||||||
|
|
||||||
specify do
|
specify do
|
||||||
expect(response).to redirect_to Passport.last
|
expect(response).to redirect_to [:staff, Passport.last]
|
||||||
end
|
end
|
||||||
|
|
||||||
specify do
|
specify do
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'GET /passports' do
|
RSpec.describe 'GET /staff/passports' do
|
||||||
before do
|
before do
|
||||||
create :empty_passport
|
create :empty_passport
|
||||||
create :passport_with_passport_map
|
create :passport_with_passport_map
|
||||||
|
@ -12,7 +12,7 @@ RSpec.describe 'GET /passports' do
|
||||||
create :passport_with_enough_confirmations
|
create :passport_with_enough_confirmations
|
||||||
create :confirmed_passport
|
create :confirmed_passport
|
||||||
|
|
||||||
get '/passports'
|
get '/staff/passports'
|
||||||
end
|
end
|
||||||
|
|
||||||
specify do
|
specify do
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'GET /passports/new' do
|
RSpec.describe 'GET /staff/passports/new' do
|
||||||
before do
|
before do
|
||||||
get '/passports/new'
|
get '/staff/passports/new'
|
||||||
end
|
end
|
||||||
|
|
||||||
specify do
|
specify do
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'GET /passports/:id' do
|
RSpec.describe 'GET /staff/passports/:id' do
|
||||||
let!(:passport) { create :confirmed_passport }
|
let!(:passport) { create :confirmed_passport }
|
||||||
let(:current_account) { create :usual_account }
|
let(:current_account) { create :usual_account }
|
||||||
|
|
||||||
def make_request
|
def make_request
|
||||||
get "/passports/#{passport.id}"
|
get "/staff/passports/#{passport.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
Reference in a new issue