1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/controllers/staff/passports/passport_confirmations_controller.rb

42 lines
1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-12-12 21:40:04 -05:00
class Staff::Passports::PassportConfirmationsController < ApplicationController
2018-12-03 07:18:23 -05:00
before_action :authenticate_user!, only: :create
2018-12-03 07:18:23 -05:00
before_action :set_passport, only: %i[index create]
2018-12-13 02:01:06 -05:00
# GET /staff/passports/:passport_id/passport_confirmations
2018-12-03 07:18:23 -05:00
def index
2018-12-12 21:40:04 -05:00
@passport_confirmations = policy_scope(
@passport.passport_confirmations,
policy_scope_class: Staff::PassportConfirmationPolicy::Scope,
)
2018-12-03 07:18:23 -05:00
end
2018-12-13 02:01:06 -05:00
# POST /staff/passports/:passport_id/passport_confirmations
def create
2018-11-30 19:40:34 -05:00
ActiveRecord::Base.transaction do
ConfirmPassport.call(passport: @passport,
2018-12-01 21:28:34 -05:00
account: current_account).tap do |context|
2018-12-01 06:05:50 -05:00
authorize_if_present context.passport_confirmation
2018-11-30 19:40:34 -05:00
end
end
2018-12-12 21:40:04 -05:00
redirect_to staff_passport_passport_confirmations_path @passport
end
private
def set_passport
@passport = Passport.find params[:passport_id]
end
2018-12-01 06:05:50 -05:00
def authorize_if_present(record)
if record
2018-12-12 21:40:04 -05:00
authorize [:staff, record]
2018-12-01 06:05:50 -05:00
else
skip_authorization
end
end
end