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